@realnation/builder-shared-sdk 2.5.0 → 2.6.0
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 +253 -252
- package/dist/gamepad/controls.d.ts +44 -0
- package/dist/gamepad/controls.d.ts.map +1 -0
- package/dist/gamepad/controls.js +109 -0
- package/dist/gamepad/index.d.ts +26 -0
- package/dist/gamepad/index.d.ts.map +1 -0
- package/dist/gamepad/index.js +19 -0
- package/dist/gamepad/normalize.d.ts +121 -0
- package/dist/gamepad/normalize.d.ts.map +1 -0
- package/dist/gamepad/normalize.js +110 -0
- package/dist/gamepad/profiles.d.ts +81 -0
- package/dist/gamepad/profiles.d.ts.map +1 -0
- package/dist/gamepad/profiles.js +99 -0
- package/dist/gamepad/session.d.ts +140 -0
- package/dist/gamepad/session.d.ts.map +1 -0
- package/dist/gamepad/session.js +305 -0
- package/dist/gamepad/signals.d.ts +78 -0
- package/dist/gamepad/signals.d.ts.map +1 -0
- package/dist/gamepad/signals.js +112 -0
- package/dist/gamepad/source.d.ts +78 -0
- package/dist/gamepad/source.d.ts.map +1 -0
- package/dist/gamepad/source.js +92 -0
- package/dist/souvenir/render.d.ts.map +1 -1
- package/dist/souvenir/render.js +3 -2
- package/package.json +68 -64
package/README.md
CHANGED
|
@@ -1,252 +1,253 @@
|
|
|
1
|
-
# @realnation/builder-shared-sdk
|
|
2
|
-
|
|
3
|
-
一个为Vite模块联邦微前端设计的轻量级SDK,旨在简化Host(宿主应用)与Remote(远程模块)之间的通信和流程控制。
|
|
4
|
-
|
|
5
|
-
## ✨ 功能
|
|
6
|
-
|
|
7
|
-
- **HTTP客户端共享**: 提供统一的`axios`实例,自动处理鉴权Token,避免在每个Remote中重复配置。
|
|
8
|
-
- **全局事件总线**: 一个简单的发布/订阅系统,用于在Host和Remotes之间或Remotes彼此之间进行解耦的通信。
|
|
9
|
-
- **动态流程控制**: 一个极其灵活的事件驱动流程控制机制,允许Host动态注册回调,由任意Remote在特定时机触发。
|
|
10
|
-
- **交互态 (Interaction State)**: Builder 里配的两态外观与四种触发方式的唯一实现,模块自渲染的元件调一下就和平台表现一致。见 [`src/interaction/README.md`](src/interaction/README.md)。
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
*
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
* 如果Host
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
import {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
import
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
-
|
|
197
|
-
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
- `
|
|
205
|
-
- `
|
|
206
|
-
- `
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
- `
|
|
212
|
-
- `eventBus.
|
|
213
|
-
- `eventBus.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
- `
|
|
219
|
-
- `
|
|
220
|
-
- `
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
- `
|
|
226
|
-
- `
|
|
227
|
-
- `
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
1
|
+
# @realnation/builder-shared-sdk
|
|
2
|
+
|
|
3
|
+
一个为Vite模块联邦微前端设计的轻量级SDK,旨在简化Host(宿主应用)与Remote(远程模块)之间的通信和流程控制。
|
|
4
|
+
|
|
5
|
+
## ✨ 功能
|
|
6
|
+
|
|
7
|
+
- **HTTP客户端共享**: 提供统一的`axios`实例,自动处理鉴权Token,避免在每个Remote中重复配置。
|
|
8
|
+
- **全局事件总线**: 一个简单的发布/订阅系统,用于在Host和Remotes之间或Remotes彼此之间进行解耦的通信。
|
|
9
|
+
- **动态流程控制**: 一个极其灵活的事件驱动流程控制机制,允许Host动态注册回调,由任意Remote在特定时机触发。
|
|
10
|
+
- **交互态 (Interaction State)**: Builder 里配的两态外观与四种触发方式的唯一实现,模块自渲染的元件调一下就和平台表现一致。见 [`src/interaction/README.md`](src/interaction/README.md)。
|
|
11
|
+
- **方向盘 (Gamepad)**: 赛车方向盘与踏板的接入层。按型号内置设备档案、现场零校准,玩法订阅 `wheel-left` 这样的控制名而不读 `navigator.getGamepads()`。会话由 Host 持有。见 [`src/gamepad/README.md`](src/gamepad/README.md)。
|
|
12
|
+
|
|
13
|
+
## 📦 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @realnation/builder-shared-sdk
|
|
17
|
+
# or
|
|
18
|
+
yarn add @realnation/builder-shared-sdk
|
|
19
|
+
# or
|
|
20
|
+
pnpm add @realnation/builder-shared-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 🚀 快速上手
|
|
24
|
+
|
|
25
|
+
### 1. 初始化HTTP客户端 (在Host中)
|
|
26
|
+
|
|
27
|
+
在您的Host应用启动时,配置共享的HTTP客户端。
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { configureHttpClient, setAuthToken } from '@realnation/builder-shared-sdk';
|
|
31
|
+
|
|
32
|
+
// 登录后,从您的用户会话中获取Token
|
|
33
|
+
const userToken = 'your-jwt-token-here';
|
|
34
|
+
setAuthToken(userToken);
|
|
35
|
+
|
|
36
|
+
// 配置API基础URL和超时
|
|
37
|
+
configureHttpClient({
|
|
38
|
+
baseURL: 'https://api.example.com',
|
|
39
|
+
timeout: 15000,
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. 在Remote中使用HTTP客户端
|
|
44
|
+
|
|
45
|
+
在任何Remote模块中,直接获取已配置好的`axios`实例来发起请求。
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { getHttpClient } from '@realnation/builder-shared-sdk';
|
|
49
|
+
|
|
50
|
+
async function fetchSomeData() {
|
|
51
|
+
try {
|
|
52
|
+
const httpClient = getHttpClient();
|
|
53
|
+
const response = await httpClient.get('/data');
|
|
54
|
+
console.log(response.data);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error('Request failed:', error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. 使用全局事件总线
|
|
62
|
+
|
|
63
|
+
`SdkEventBus`可用于在不同模块间传递消息,而无需直接依赖。
|
|
64
|
+
|
|
65
|
+
**在Host或某个Remote中监听事件:**
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { getGlobalEventBus } from '@realnation/builder-shared-sdk';
|
|
69
|
+
|
|
70
|
+
const eventBus = getGlobalEventBus();
|
|
71
|
+
|
|
72
|
+
// 监听模块导航事件
|
|
73
|
+
const unsubscribe = eventBus.on('module:navigate', (payload) => {
|
|
74
|
+
console.log('Navigating to:', payload.path);
|
|
75
|
+
// 在这里执行路由跳转逻辑...
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// 在组件卸载或不再需要时取消监听
|
|
79
|
+
// unsubscribe();
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**在另一个Remote中触发事件:**
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { getGlobalEventBus } from '@realnation/builder-shared-sdk';
|
|
86
|
+
|
|
87
|
+
const eventBus = getGlobalEventBus();
|
|
88
|
+
|
|
89
|
+
function onButtonClick() {
|
|
90
|
+
eventBus.emit('module:navigate', { path: '/new-page' });
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 🔗 动态流程控制 (Flow Control)
|
|
95
|
+
|
|
96
|
+
这是SDK的核心亮点之一,提供了一种比传统模块联邦更灵活的模块间协作方式。Host可以定义一组具名事件(例如 `success`, `failure`, `nextStep`),并将它们与具体的操作(例如加载下一个Remote模块)关联起来。Remote模块在完成其任务后,只需触发这些预定义的事件,而无需关心接下来会发生什么。
|
|
97
|
+
|
|
98
|
+
### 系统事件与自定义事件
|
|
99
|
+
|
|
100
|
+
Flow Control区分两种事件类型:
|
|
101
|
+
|
|
102
|
+
1. **系统事件 (System Events)**: 以`sys:`为前缀,由SDK或框架约定,用于处理通用的生命周期钩子。例如 `sys:ready`。这些事件**不会**被`clearEvents()`清除。
|
|
103
|
+
2. **自定义事件 (Custom Events)**: 不带前缀,由业务逻辑定义,例如 `welcome:completed` 或 `profile:submitted`。这些事件会被`clearEvents()`清除。
|
|
104
|
+
|
|
105
|
+
### 工作流程
|
|
106
|
+
|
|
107
|
+
1. **Host注册事件**: Host应用使用`registerEvent`注册系统事件和自定义事件的回调。
|
|
108
|
+
* 注册`sys:ready`来处理Remote模块加载完成后的显示逻辑。
|
|
109
|
+
* 注册自定义事件来编排业务流程。
|
|
110
|
+
2. **Remote触发事件**:
|
|
111
|
+
* Remote模块加载并初始化完成后,应立即触发`sys:ready`事件,通知Host可以将其UI插入DOM并显示。
|
|
112
|
+
* 在用户交互或内部状态改变后,触发相应的自定义事件。
|
|
113
|
+
3. **执行与回退**:
|
|
114
|
+
* 如果Host注册了该事件,对应的回调函数将被执行。
|
|
115
|
+
* 如果Host**没有**注册该事件,`emitEvent`会执行一个可选的本地回退函数(最后一个函数类型的参数),确保Remote在独立运行时也能正常工作。
|
|
116
|
+
4. **清理**: 在业务流程结束时,Host调用`clearEvents()`来清理所有**自定义事件**,而系统事件保持不变。
|
|
117
|
+
|
|
118
|
+
### 代码示例
|
|
119
|
+
|
|
120
|
+
#### 在Host中编排流程
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { registerEvent, clearEvents } from '@realnation/builder-shared-sdk/flow';
|
|
124
|
+
import { loadRemoteModule, showRemote, hideRemote } from './remoteLoader'; // 假设的加载器
|
|
125
|
+
|
|
126
|
+
// 注册系统事件,用于显示已加载的模块
|
|
127
|
+
registerEvent('sys:ready', (remoteId) => {
|
|
128
|
+
console.log(`Remote module [${remoteId}] is ready to be displayed.`);
|
|
129
|
+
showRemote(remoteId);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// 注册自定义业务事件
|
|
133
|
+
registerEvent('welcome:completed', () => {
|
|
134
|
+
hideRemote('welcome'); // 隐藏旧模块
|
|
135
|
+
loadRemoteModule('user-profile'); // 加载新模块
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
registerEvent('profile:submitted', (userData) => {
|
|
139
|
+
hideRemote('user-profile');
|
|
140
|
+
loadRemoteModule('summary-view', { user: userData });
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// 当整个业务流程结束时,清理自定义事件
|
|
144
|
+
function cleanupBusinessFlow() {
|
|
145
|
+
clearEvents();
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### 在Remote中触发事件
|
|
150
|
+
|
|
151
|
+
**`welcome-module` (远程模块):**
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { emitEvent } from '@realnation/builder-shared-sdk/flow';
|
|
155
|
+
import React, { useEffect } from 'react';
|
|
156
|
+
|
|
157
|
+
function WelcomeComponent({ remoteId }) {
|
|
158
|
+
// 1. 组件挂载后,触发 sys:ready 事件
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
emitEvent('sys:ready', remoteId, () => {
|
|
161
|
+
console.log(`Standalone mode: [${remoteId}] is ready.`);
|
|
162
|
+
});
|
|
163
|
+
}, [remoteId]);
|
|
164
|
+
|
|
165
|
+
const handleStartClick = () => {
|
|
166
|
+
// 2. 用户交互,触发自定义事件
|
|
167
|
+
emitEvent('welcome:completed', () => {
|
|
168
|
+
console.log('Standalone mode: Welcome journey would start here.');
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return <button onClick={handleStartClick}>开始</button>;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**`user-profile-module` (远程模块):**
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import { emitEvent } from '@realnation/builder-shared-sdk/flow';
|
|
180
|
+
|
|
181
|
+
function UserProfileForm() {
|
|
182
|
+
const handleSubmit = (formData) => {
|
|
183
|
+
// 触发 'profile:submitted' 事件,并传递表单数据
|
|
184
|
+
emitEvent('profile:submitted', formData, () => {
|
|
185
|
+
console.log('In standalone mode: Form submitted locally.', formData);
|
|
186
|
+
// 在独立模式下可以导航到本地的下一页
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// ... 表单逻辑
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
这种模式的优势在于:
|
|
195
|
+
|
|
196
|
+
- **高度解耦**: Remote模块不关心下一个模块是什么,只关心在何时完成了自己的任务。
|
|
197
|
+
- **灵活编排**: Host可以随时改变流程,例如在A/B测试中,通过注册不同的回调来加载不同的下一个模块,而无需修改任何Remote模块的代码。
|
|
198
|
+
- **易于测试**: Remote模块可以独立开发和测试,只需为其`emitEvent`提供本地回退函数即可。
|
|
199
|
+
|
|
200
|
+
## 🛠️ API参考
|
|
201
|
+
|
|
202
|
+
### HTTP
|
|
203
|
+
|
|
204
|
+
- `setAuthToken(token: string | null)`: 设置全局JWT Token。
|
|
205
|
+
- `setTokenResolver(resolver: () => string | null)`: (高级) 设置一个函数来动态解析Token,优先级高于`setAuthToken`。
|
|
206
|
+
- `configureHttpClient(options: HttpClientOptions)`: 配置共享的`axios`实例。
|
|
207
|
+
- `getHttpClient(): AxiosInstance`: 获取配置好的`axios`实例。
|
|
208
|
+
|
|
209
|
+
### Events
|
|
210
|
+
|
|
211
|
+
- `getGlobalEventBus(): SdkEventBus`: 获取全局事件总线实例。
|
|
212
|
+
- `eventBus.on(name, handler)`: 监听一个事件。
|
|
213
|
+
- `eventBus.emit(name, payload)`: 触发一个事件。
|
|
214
|
+
- `eventBus.off(name, handler)`: 取消监听。
|
|
215
|
+
|
|
216
|
+
### Flow
|
|
217
|
+
|
|
218
|
+
- `registerEvent(type: string, callback: Function)`: Host注册一个流程事件。以`sys:`为前缀的事件为系统事件,不会被`clearEvents`清除。
|
|
219
|
+
- `removeEvent(type: string)`: 移除一个已注册的事件。
|
|
220
|
+
- `clearEvents()`: 移除所有**非系统级**的自定义事件。
|
|
221
|
+
- `emitEvent(type: string, ...args: any[])`: Remote触发一个流程事件。参数会透传给回调,如果最后一个参数是函数,则被视作本地回退`callback`。
|
|
222
|
+
|
|
223
|
+
### OSS
|
|
224
|
+
|
|
225
|
+
- `fetchOssCredential(options: OssCredentialRequestOptions)`: 获取固定接口的OSS临时凭证。
|
|
226
|
+
- `createOssClient(credential: OssCredential, options?)`: 使用临时凭证创建OSS客户端。
|
|
227
|
+
- `uploadOssFile(options: OssUploadOptions)`: 上传文件并返回对象地址与Key,支持进度回调和上传目录配置。
|
|
228
|
+
- `clearOssCache(projectId?)`: 清理OSS凭证与客户端缓存,可按项目或全量清理。
|
|
229
|
+
|
|
230
|
+
说明:SDK会基于接口返回的`expireAtUnix/expireAt/expiration`自动缓存并复用凭证与客户端,默认提前60秒刷新;可通过`cacheSkewMs`调整。`uploadOssFile` 默认在凭证失效时重试1次,可用 `retryTimes` 控制,并支持 `allowedExtensions`、`maxSizeBytes`、`minSizeBytes` 限制上传文件。
|
|
231
|
+
|
|
232
|
+
#### OSS 快速示例
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { uploadOssFile } from '@realnation/builder-shared-sdk';
|
|
236
|
+
|
|
237
|
+
const result = await uploadOssFile({
|
|
238
|
+
projectId: 'project-id',
|
|
239
|
+
file,
|
|
240
|
+
directory: 'uploads/images',
|
|
241
|
+
onProgress: (ratio) => console.log('progress:', ratio)
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
console.log(result.url);
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## 🔧 构建
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
npm run build
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
该命令会使用`tsc`将`src`目录下的TypeScript源文件编译到`dist`目录。
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The platform's vocabulary of wheel controls.
|
|
3
|
+
*
|
|
4
|
+
* These names describe a *role* on a racing wheel, never the glyph printed on
|
|
5
|
+
* one particular device. A second wheel model maps its own axes and buttons
|
|
6
|
+
* onto the same names, so the Builder's Key Event Code dropdown never has to
|
|
7
|
+
* change when hardware does.
|
|
8
|
+
*
|
|
9
|
+
* Each control owns a code in the 1001+ range, deliberately outside the
|
|
10
|
+
* keyboard keyCode space. The runner synthesises keyboard events carrying
|
|
11
|
+
* these codes so that every element which already binds a Key Event Code works
|
|
12
|
+
* with a wheel without any module change. The stored value is the number: the
|
|
13
|
+
* English label is display only and can be reworded later.
|
|
14
|
+
*/
|
|
15
|
+
/** Continuous controls. The wheel reports a direction as two opposite controls. */
|
|
16
|
+
export declare const AXIS_CONTROLS: readonly ["wheel-left", "wheel-right", "throttle", "brake", "clutch"];
|
|
17
|
+
/**
|
|
18
|
+
* Button roles. Named after the standard gamepad layout so a second model can
|
|
19
|
+
* be mapped by position rather than by the glyph it happens to print.
|
|
20
|
+
* `aux-1..4` absorbs whatever a device has that does not fit the roles above.
|
|
21
|
+
*/
|
|
22
|
+
export declare const BUTTON_CONTROLS: readonly ["start", "select", "home", "paddle-left", "paddle-right", "dpad-up", "dpad-down", "dpad-left", "dpad-right", "action-1", "action-2", "action-3", "action-4", "shoulder-left", "shoulder-right", "aux-1", "aux-2", "aux-3", "aux-4"];
|
|
23
|
+
export type AxisControl = (typeof AXIS_CONTROLS)[number];
|
|
24
|
+
export type ButtonControl = (typeof BUTTON_CONTROLS)[number];
|
|
25
|
+
export type ControlName = AxisControl | ButtonControl;
|
|
26
|
+
export declare const CONTROL_NAMES: readonly ControlName[];
|
|
27
|
+
export interface ControlDefinition {
|
|
28
|
+
name: ControlName;
|
|
29
|
+
/** The synthetic keyCode the runner dispatches for this control. */
|
|
30
|
+
code: number;
|
|
31
|
+
/** English label for the Builder dropdown. Display only. */
|
|
32
|
+
label: string;
|
|
33
|
+
}
|
|
34
|
+
export declare const CONTROLS: readonly ControlDefinition[];
|
|
35
|
+
export declare function controlByName(name: ControlName): ControlDefinition;
|
|
36
|
+
export declare function controlByCode(code: number): ControlDefinition | null;
|
|
37
|
+
export declare function controlCode(name: ControlName): number;
|
|
38
|
+
/**
|
|
39
|
+
* True for codes this module owns. The runner uses it to keep synthetic wheel
|
|
40
|
+
* events apart from real keyboard ones.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isControlCode(code: number): boolean;
|
|
43
|
+
export declare function isAxisControl(name: ControlName): name is AxisControl;
|
|
44
|
+
//# sourceMappingURL=controls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controls.d.ts","sourceRoot":"","sources":["../../src/gamepad/controls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,mFAAmF;AACnF,eAAO,MAAM,aAAa,uEAAwE,CAAC;AAEnG;;;;GAIG;AACH,eAAO,MAAM,eAAe,+OAoBlB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7D,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,aAAa,CAAC;AAEtD,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAA2C,CAAC;AAE5F,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;CACf;AAsCD,eAAO,MAAM,QAAQ,EAAE,SAAS,iBAAiB,EAOhD,CAAC;AAKF,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,iBAAiB,CAIlE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAEpE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAErD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,IAAI,WAAW,CAEpE"}
|