@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 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
- Three tree-shakeable modules:
5
+ Four tree-shakeable modules:
6
6
 
7
7
  | Module | Import | Purpose |
8
8
  |---|---|---|
9
- | **core** | `@kelnishi/satmouse-client` | Connection, discovery, binary decode. Zero dependencies. |
10
- | **utils** | `@kelnishi/satmouse-client/utils` | InputManager, transforms, per-device config, action mapping, persistence |
11
- | **react** | `@kelnishi/satmouse-client/react` | Provider, hooks, headless components |
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
- sensitivity: { translation: 0.001, rotation: 0.001 },
82
+ translateScale: 0.001,
83
+ rotateScale: 0.001,
84
+ wScale: 0.001,
60
85
  devices: {
61
- "hid-054c-*": { sensitivity: { translation: 0.002 } },
62
- "spacemouse-c635": { flip: { rz: false } },
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
- // Query devices and their resolved config
67
- const devices = manager.getDevicesWithConfig();
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
- ## Action Mapping
103
+ ## Button-to-Key Mapping
76
104
 
77
- Remap input axes to named actions. Default passes through 1:1.
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
- actionMap: {
90
- tx: { source: "tx" },
91
- tz: { source: "ty", invert: true },
92
- ry: { source: "rx", scale: 2.0 },
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
- // Named action values
97
- manager.onActionValues((values) => {
98
- scene.pan(values.tx, values.ty);
99
- scene.zoom(values.tz);
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
@@ -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
- return JSON.parse(raw);
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
  }