@kelnishi/satmouse-client 0.12.3 → 0.12.5
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/README.md +55 -36
- package/dist/react/index.cjs +8 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +292 -0
- package/dist/react/index.d.ts +292 -0
- package/dist/react/index.js +8 -1
- package/dist/react/index.js.map +1 -1
- package/dist/utils/index.cjs +8 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js +8 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Client SDK for [SatMouse](https://kelnishi.github.io/SatMouse/) — stream 6DOF spatial input from SpaceMouse and other devices to web apps and PWAs.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Four tree-shakeable modules:
|
|
6
6
|
|
|
7
7
|
| Module | Import | Purpose |
|
|
8
8
|
|---|---|---|
|
|
9
|
-
| **core** | `@kelnishi/satmouse-client` |
|
|
10
|
-
| **utils** | `@kelnishi/satmouse-client/utils` | InputManager
|
|
11
|
-
| **react** | `@kelnishi/satmouse-client/react` |
|
|
9
|
+
| **core** | `@kelnishi/satmouse-client` | `SatMouseConnection`, discovery, binary decode. Zero dependencies. |
|
|
10
|
+
| **utils** | `@kelnishi/satmouse-client/utils` | `InputManager` — per-device axis routing, scale, button-to-key mapping, persistence. |
|
|
11
|
+
| **react** | `@kelnishi/satmouse-client/react` | `<SatMouseProvider>`, `useSpatialData()`, `useButtonEvent()`, components. |
|
|
12
|
+
| **elements** | `@kelnishi/satmouse-client/elements` | Web Components: `<satmouse-status>`, `<satmouse-devices>`, `<satmouse-debug>`. |
|
|
12
13
|
|
|
13
14
|
## Quick Start
|
|
14
15
|
|
|
@@ -27,7 +28,7 @@ const manager = new InputManager();
|
|
|
27
28
|
manager.addConnection(connection);
|
|
28
29
|
|
|
29
30
|
manager.onSpatialData((data) => {
|
|
30
|
-
console.log(data.translation, data.rotation);
|
|
31
|
+
console.log(data.translation, data.rotation, data.w);
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
await connection.connect();
|
|
@@ -48,62 +49,80 @@ function App() {
|
|
|
48
49
|
|
|
49
50
|
function Scene() {
|
|
50
51
|
const data = useSpatialData();
|
|
51
|
-
// data.translation.x/y/z, data.rotation.x/y/z
|
|
52
|
+
// data.translation.x/y/z, data.rotation.x/y/z, data.w
|
|
52
53
|
}
|
|
53
54
|
```
|
|
54
55
|
|
|
56
|
+
### Web Components
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<script type="module">
|
|
60
|
+
import { SatMouseConnection } from "@kelnishi/satmouse-client";
|
|
61
|
+
import { InputManager } from "@kelnishi/satmouse-client/utils";
|
|
62
|
+
import { registerSatMouse } from "@kelnishi/satmouse-client/elements";
|
|
63
|
+
|
|
64
|
+
const connection = new SatMouseConnection();
|
|
65
|
+
const manager = new InputManager();
|
|
66
|
+
manager.addConnection(connection);
|
|
67
|
+
registerSatMouse(manager);
|
|
68
|
+
await connection.connect();
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<satmouse-status></satmouse-status>
|
|
72
|
+
<satmouse-devices></satmouse-devices>
|
|
73
|
+
<satmouse-debug></satmouse-debug>
|
|
74
|
+
```
|
|
75
|
+
|
|
55
76
|
## Per-Device Configuration
|
|
56
77
|
|
|
78
|
+
Axis routing with per-device flip, scale, and remapping:
|
|
79
|
+
|
|
57
80
|
```typescript
|
|
58
81
|
const manager = new InputManager({
|
|
59
|
-
|
|
82
|
+
translateScale: 0.001,
|
|
83
|
+
rotateScale: 0.001,
|
|
84
|
+
wScale: 0.001,
|
|
60
85
|
devices: {
|
|
61
|
-
"
|
|
62
|
-
|
|
86
|
+
"cnx-*": {
|
|
87
|
+
routes: [
|
|
88
|
+
{ source: "tx", target: "tx" },
|
|
89
|
+
{ source: "ty", target: "ty", flip: true },
|
|
90
|
+
{ source: "tz", target: "tz", flip: true },
|
|
91
|
+
{ source: "rx", target: "rx" },
|
|
92
|
+
{ source: "ry", target: "ry", flip: true },
|
|
93
|
+
{ source: "rz", target: "rz", flip: true },
|
|
94
|
+
],
|
|
95
|
+
},
|
|
63
96
|
},
|
|
64
97
|
});
|
|
65
98
|
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// Update per-device
|
|
70
|
-
manager.updateDeviceConfig("spacemouse-c635", {
|
|
71
|
-
sensitivity: { rotation: 0.005 },
|
|
72
|
-
});
|
|
99
|
+
// Update per-device at runtime
|
|
100
|
+
manager.updateDeviceConfig("cnx-c635", { translateScale: 0.0005 });
|
|
73
101
|
```
|
|
74
102
|
|
|
75
|
-
##
|
|
103
|
+
## Button-to-Key Mapping
|
|
76
104
|
|
|
77
|
-
|
|
105
|
+
Map device buttons to keyboard events:
|
|
78
106
|
|
|
79
107
|
```typescript
|
|
80
|
-
import { InputManager, swapActions, DEFAULT_ACTION_MAP } from "@kelnishi/satmouse-client/utils";
|
|
81
|
-
|
|
82
|
-
// Swap ty and tz
|
|
83
|
-
const manager = new InputManager({
|
|
84
|
-
actionMap: swapActions(DEFAULT_ACTION_MAP, "ty", "tz"),
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// Per-device remapping
|
|
88
108
|
manager.updateDeviceConfig("hid-054c-*", {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
109
|
+
buttonRoutes: [
|
|
110
|
+
{ button: 1, key: " ", code: "Space" }, // Cross → Space
|
|
111
|
+
{ button: 2, key: "Escape", code: "Escape" }, // Circle → Escape
|
|
112
|
+
],
|
|
94
113
|
});
|
|
95
114
|
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
115
|
+
// Button presses dispatch KeyboardEvent on document
|
|
116
|
+
// Also available as raw events:
|
|
117
|
+
manager.onButtonEvent((event) => {
|
|
118
|
+
console.log(`Button ${event.button} ${event.pressed ? "pressed" : "released"}`);
|
|
100
119
|
});
|
|
101
120
|
```
|
|
102
121
|
|
|
103
122
|
## Connection Options
|
|
104
123
|
|
|
105
124
|
```typescript
|
|
106
|
-
// Auto-discover via Thing Description
|
|
125
|
+
// Auto-discover via Thing Description (default: localhost:18945)
|
|
107
126
|
new SatMouseConnection();
|
|
108
127
|
|
|
109
128
|
// Direct URL
|
package/dist/react/index.cjs
CHANGED
|
@@ -607,7 +607,14 @@ function loadSettings(storage) {
|
|
|
607
607
|
const raw = s.getItem(STORAGE_KEY);
|
|
608
608
|
if (!raw) return null;
|
|
609
609
|
try {
|
|
610
|
-
|
|
610
|
+
const parsed = JSON.parse(raw);
|
|
611
|
+
if (parsed.scale != null && parsed.translateScale == null) {
|
|
612
|
+
parsed.translateScale = parsed.scale;
|
|
613
|
+
parsed.rotateScale = parsed.scale;
|
|
614
|
+
parsed.wScale = parsed.scale;
|
|
615
|
+
delete parsed.scale;
|
|
616
|
+
}
|
|
617
|
+
return parsed;
|
|
611
618
|
} catch {
|
|
612
619
|
return null;
|
|
613
620
|
}
|