@makefully/engagefully 0.2.0 → 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.
@@ -1,96 +1,96 @@
1
- /* global TextDecoder */
2
- export default [{ // 0x0
3
- description: "Reserved For Future Use",
4
- convert: (dataView) => dataView.byteLength ? dataView : null
5
- }, { // 0x1
6
- description: "Boolean",
7
- convert: (dataView) => dataView.getInt8()
8
- }, { // 0x2
9
- description: "unsigned 2-bit integer",
10
- convert: (dataView) => dataView.getUint8()
11
- }, { // 0x3
12
- description: "unsigned 4-bit integer",
13
- convert: (dataView) => dataView.getUint8()
14
- }, { // 0x4
15
- description: "unsigned 8-bit integer",
16
- convert: (dataView) => dataView.getUint8()
17
- }, { // 0x5
18
- description: "unsigned 12-bit integer",
19
- convert: (dataView) => dataView.getUint16()
20
- }, { // 0x6
21
- description: "unsigned 16-bit integer",
22
- convert: (dataView) => dataView.getUint16()
23
- }, { // 0x7
24
- description: "unsigned 24-bit integer",
25
- convert: (dataView) => dataView.getUint32()
26
- }, { // 0x8
27
- description: "unsigned 32-bit integer",
28
- convert: (dataView) => dataView.getUint32()
29
- }, { // 0x9
30
- description: "unsigned 48-bit integer",
31
- convert: (dataView) => dataView.getBigUint64()
32
- }, { // 0xA
33
- description: "unsigned 64-bit integer",
34
- convert: (dataView) => dataView.getBigUint64()
35
- }, { // 0xB
36
- description: "unsigned 128-bit integer",
37
- convert: (dataView) => [dataView.getBigUint64(), dataView.getBigUint64(8)]
38
- }, { // 0xC
39
- description: "signed 8-bit integer",
40
- convert: (dataView) => dataView.getInt8()
41
- }, { // 0xD
42
- description: "signed 12-bit integer",
43
- convert: (dataView) => dataView.getInt16()
44
- }, { // 0xE
45
- description: "signed 16-bit integer",
46
- convert: (dataView) => dataView.getInt16()
47
- }, { // 0xF
48
- description: "signed 24-bit integer",
49
- convert: (dataView) => dataView.getInt32()
50
- }, { // 0x10
51
- description: "signed 32-bit integer",
52
- convert: (dataView) => dataView.getInt32()
53
- }, { // 0x11
54
- description: "signed 48-bit integer",
55
- convert: (dataView) => dataView.getBigInt64()
56
- }, { // 0x12
57
- description: "signed 64-bit integer",
58
- convert: (dataView) => dataView.getBigInt64()
59
- }, { // 0x13
60
- description: "signed 128-bit integer",
61
- convert: (dataView) => [dataView.getBigInt64(), dataView.getBigInt64(8)]
62
- }, { // 0x14
63
- description: "IEEE-754 32-bit floating point",
64
- convert: (dataView) => dataView.getFloat32()
65
- }, { // 0x15
66
- description: "IEEE-754 64-bit floating point",
67
- convert: (dataView) => dataView.getFloat64()
68
- }, { // 0x16
69
- description: "IEEE-11073 16-bit SFLOAT",
70
- convert: (dataView) => dataView // TODO: Add conversion
71
- }, { // 0x17
72
- description: "IEEE-11073 32-bit FLOAT",
73
- convert: (dataView) => dataView // TODO: Add conversion
74
- }, { // 0x18
75
- description: "IEEE-20601 format",
76
- convert: (dataView) => dataView // TODO: Add conversion
77
- }, { // 0x19
78
- description: "UTF-8 string",
79
- convert: (dataView) => {
80
- const
81
- decoder = new TextDecoder('utf-8');
82
-
83
- return decoder.decode(dataView);
84
- }
85
- }, { // 0x1A
86
- description: "UTF-16 string",
87
- convert: (dataView) => {
88
- const
89
- decoder = new TextDecoder('utf-16');
90
-
91
- return decoder.decode(dataView);
92
- }
93
- }, { // 0x1B
94
- description: "Opaque Structure",
95
- convert: (dataView) => dataView
1
+ /* global TextDecoder */
2
+ export default [{ // 0x0
3
+ description: "Reserved For Future Use",
4
+ convert: (dataView) => dataView.byteLength ? dataView : null
5
+ }, { // 0x1
6
+ description: "Boolean",
7
+ convert: (dataView) => dataView.getInt8()
8
+ }, { // 0x2
9
+ description: "unsigned 2-bit integer",
10
+ convert: (dataView) => dataView.getUint8()
11
+ }, { // 0x3
12
+ description: "unsigned 4-bit integer",
13
+ convert: (dataView) => dataView.getUint8()
14
+ }, { // 0x4
15
+ description: "unsigned 8-bit integer",
16
+ convert: (dataView) => dataView.getUint8()
17
+ }, { // 0x5
18
+ description: "unsigned 12-bit integer",
19
+ convert: (dataView) => dataView.getUint16()
20
+ }, { // 0x6
21
+ description: "unsigned 16-bit integer",
22
+ convert: (dataView) => dataView.getUint16()
23
+ }, { // 0x7
24
+ description: "unsigned 24-bit integer",
25
+ convert: (dataView) => dataView.getUint32()
26
+ }, { // 0x8
27
+ description: "unsigned 32-bit integer",
28
+ convert: (dataView) => dataView.getUint32()
29
+ }, { // 0x9
30
+ description: "unsigned 48-bit integer",
31
+ convert: (dataView) => dataView.getBigUint64()
32
+ }, { // 0xA
33
+ description: "unsigned 64-bit integer",
34
+ convert: (dataView) => dataView.getBigUint64()
35
+ }, { // 0xB
36
+ description: "unsigned 128-bit integer",
37
+ convert: (dataView) => [dataView.getBigUint64(), dataView.getBigUint64(8)]
38
+ }, { // 0xC
39
+ description: "signed 8-bit integer",
40
+ convert: (dataView) => dataView.getInt8()
41
+ }, { // 0xD
42
+ description: "signed 12-bit integer",
43
+ convert: (dataView) => dataView.getInt16()
44
+ }, { // 0xE
45
+ description: "signed 16-bit integer",
46
+ convert: (dataView) => dataView.getInt16()
47
+ }, { // 0xF
48
+ description: "signed 24-bit integer",
49
+ convert: (dataView) => dataView.getInt32()
50
+ }, { // 0x10
51
+ description: "signed 32-bit integer",
52
+ convert: (dataView) => dataView.getInt32()
53
+ }, { // 0x11
54
+ description: "signed 48-bit integer",
55
+ convert: (dataView) => dataView.getBigInt64()
56
+ }, { // 0x12
57
+ description: "signed 64-bit integer",
58
+ convert: (dataView) => dataView.getBigInt64()
59
+ }, { // 0x13
60
+ description: "signed 128-bit integer",
61
+ convert: (dataView) => [dataView.getBigInt64(), dataView.getBigInt64(8)]
62
+ }, { // 0x14
63
+ description: "IEEE-754 32-bit floating point",
64
+ convert: (dataView) => dataView.getFloat32()
65
+ }, { // 0x15
66
+ description: "IEEE-754 64-bit floating point",
67
+ convert: (dataView) => dataView.getFloat64()
68
+ }, { // 0x16
69
+ description: "IEEE-11073 16-bit SFLOAT",
70
+ convert: (dataView) => dataView // TODO: Add conversion
71
+ }, { // 0x17
72
+ description: "IEEE-11073 32-bit FLOAT",
73
+ convert: (dataView) => dataView // TODO: Add conversion
74
+ }, { // 0x18
75
+ description: "IEEE-20601 format",
76
+ convert: (dataView) => dataView // TODO: Add conversion
77
+ }, { // 0x19
78
+ description: "UTF-8 string",
79
+ convert: (dataView) => {
80
+ const
81
+ decoder = new TextDecoder('utf-8');
82
+
83
+ return decoder.decode(dataView);
84
+ }
85
+ }, { // 0x1A
86
+ description: "UTF-16 string",
87
+ convert: (dataView) => {
88
+ const
89
+ decoder = new TextDecoder('utf-16');
90
+
91
+ return decoder.decode(dataView);
92
+ }
93
+ }, { // 0x1B
94
+ description: "Opaque Structure",
95
+ convert: (dataView) => dataView
96
96
  }];
package/src/index.js CHANGED
@@ -1,28 +1,28 @@
1
- /**
2
- * @namespace engagefully
3
- */
4
- /* global window */
5
- import Controller from './Controller';
6
- import ActionMap from './ActionMap';
7
- import actions from './actions';
8
- import devices from './devices';
9
- import { quantizeStick } from './utils/quantizeStick';
10
- import { focusGate } from './utils/focusGate';
11
-
12
- window.engagefully = {
13
- Controller,
14
- ActionMap,
15
- actions,
16
- devices,
17
- quantizeStick,
18
- focusGate
19
- };
20
-
21
- export {
22
- Controller,
23
- ActionMap,
24
- actions,
25
- devices,
26
- quantizeStick,
27
- focusGate
28
- };
1
+ /**
2
+ * @namespace engagefully
3
+ */
4
+ /* global window */
5
+ import Controller from './Controller';
6
+ import ActionMap from './ActionMap';
7
+ import actions from './actions';
8
+ import devices from './devices';
9
+ import { quantizeStick } from './utils/quantizeStick';
10
+ import { focusGate } from './utils/focusGate';
11
+
12
+ window.engagefully = {
13
+ Controller,
14
+ ActionMap,
15
+ actions,
16
+ devices,
17
+ quantizeStick,
18
+ focusGate
19
+ };
20
+
21
+ export {
22
+ Controller,
23
+ ActionMap,
24
+ actions,
25
+ devices,
26
+ quantizeStick,
27
+ focusGate
28
+ };
@@ -1,22 +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;
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;
@@ -1,26 +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;
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;