@asyra/input-system 0.5.4 → 0.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/CHANGELOG.md +130 -0
- package/README.md +9 -5
- package/dist/event-mappings.d.ts +8 -1
- package/dist/input-system.d.ts +12 -0
- package/dist/input-system.js +218 -33
- package/dist/keymap.js +4 -2
- package/package.json +6 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @asyra/input-system
|
|
2
|
+
|
|
3
|
+
## Pending - Office input and spatial materials
|
|
4
|
+
|
|
5
|
+
```update-note
|
|
6
|
+
{
|
|
7
|
+
"change": "office-input-and-spatial-materials",
|
|
8
|
+
"owner": "Framework - @asyra/input-system",
|
|
9
|
+
"summary": "Support held keyboard control or optional spatial material effects used by the Office preview, preserving existing defaults.",
|
|
10
|
+
"sources": [
|
|
11
|
+
"packages/input-system/src/__tests__/held-keyboard.test.ts",
|
|
12
|
+
"packages/input-system/src/__tests__/input-system.test.ts",
|
|
13
|
+
"packages/input-system/src/__tests__/runtime-reset.test.ts",
|
|
14
|
+
"packages/input-system/src/event-mappings.ts",
|
|
15
|
+
"packages/input-system/src/input-system.ts"
|
|
16
|
+
],
|
|
17
|
+
"impact": "integration",
|
|
18
|
+
"guides": [
|
|
19
|
+
"docs/public/updates/held-input-and-spatial-materials-r1.md"
|
|
20
|
+
],
|
|
21
|
+
"reason": "Optional APIs require explicit consumer registration and preservation of app-owned policies; see the adoption guide."
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 0.5.5
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- 22883b1: Support owner-coordinated runtime replacement for applications such as Asyra Sim.
|
|
30
|
+
Quiesce feature work before retiring runtime-owned state, subscriptions, input
|
|
31
|
+
bindings, render resources, and registration graphs. Retain preset installation
|
|
32
|
+
cleanup and prevent callbacks from a retired runtime from affecting its successor.
|
|
33
|
+
|
|
34
|
+
Expose Core document-load preflight and validated renderer resizing through the
|
|
35
|
+
public facade. Applications can validate a replacement document before retiring
|
|
36
|
+
the active runtime, while ordinary document loading retains its existing history
|
|
37
|
+
ownership contract.
|
|
38
|
+
|
|
39
|
+
- Updated dependencies [22883b1]
|
|
40
|
+
- @asyra/utils@0.5.2
|
|
41
|
+
- @asyra/reactive-events@0.5.4
|
|
42
|
+
|
|
43
|
+
## 0.5.4
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Republish the affected Framework packages with publishable internal dependency
|
|
48
|
+
ranges instead of monorepo-only `workspace:*` metadata.
|
|
49
|
+
- Updated dependencies
|
|
50
|
+
- @asyra/reactive-events@0.5.3
|
|
51
|
+
|
|
52
|
+
## 0.5.3
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- Exceptional synchronized patch release for the fixed 19-package Framework set.
|
|
57
|
+
- Updated dependencies
|
|
58
|
+
- @asyra/reactive-events@0.5.2
|
|
59
|
+
- @asyra/utils@0.5.1
|
|
60
|
+
|
|
61
|
+
## 0.5.2
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- c714696: Make InputSystem import and construction DOM-neutral, add explicit browser host
|
|
66
|
+
and pointer-target lifecycle APIs, and provide symmetric listener cleanup.
|
|
67
|
+
|
|
68
|
+
## 0.5.1
|
|
69
|
+
|
|
70
|
+
### Patch Changes
|
|
71
|
+
|
|
72
|
+
- Updated dependencies [889f7b4]
|
|
73
|
+
- @asyra/reactive-events@0.5.1
|
|
74
|
+
|
|
75
|
+
## 0.5.0
|
|
76
|
+
|
|
77
|
+
### Minor Changes
|
|
78
|
+
|
|
79
|
+
- Exceptional synchronized minor release for the fixed 19-package Framework set.
|
|
80
|
+
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Updated dependencies
|
|
84
|
+
- @asyra/reactive-events@0.5.0
|
|
85
|
+
- @asyra/utils@0.5.0
|
|
86
|
+
|
|
87
|
+
## 0.2.5
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- Auto-patch all packages.
|
|
92
|
+
- Updated dependencies
|
|
93
|
+
- @asyra/reactive-events@0.2.5
|
|
94
|
+
- @asyra/utils@0.2.5
|
|
95
|
+
|
|
96
|
+
## 0.2.4
|
|
97
|
+
|
|
98
|
+
### Patch Changes
|
|
99
|
+
|
|
100
|
+
- Auto-patch all packages.
|
|
101
|
+
- Updated dependencies
|
|
102
|
+
- @asyra/reactive-events@0.2.4
|
|
103
|
+
- @asyra/utils@0.2.4
|
|
104
|
+
|
|
105
|
+
## 0.2.3
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- Auto-patch all packages.
|
|
110
|
+
- Updated dependencies
|
|
111
|
+
- @asyra/reactive-events@0.2.3
|
|
112
|
+
- @asyra/utils@0.2.3
|
|
113
|
+
|
|
114
|
+
## 0.2.2
|
|
115
|
+
|
|
116
|
+
### Patch Changes
|
|
117
|
+
|
|
118
|
+
- Auto-patch all packages.
|
|
119
|
+
- Updated dependencies
|
|
120
|
+
- @asyra/reactive-events@0.2.2
|
|
121
|
+
- @asyra/utils@0.2.2
|
|
122
|
+
|
|
123
|
+
## 0.2.1
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- Auto-patch all packages.
|
|
128
|
+
- Updated dependencies
|
|
129
|
+
- @asyra/reactive-events@0.2.1
|
|
130
|
+
- @asyra/utils@0.2.1
|
package/README.md
CHANGED
|
@@ -43,8 +43,12 @@ Attachment adds listeners to the selected host and target. Reattachment is idemp
|
|
|
43
43
|
|
|
44
44
|
## Support and policy
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
GitHub Discussions is the intended public channel for community conversation and
|
|
47
|
+
general help. Discussions is not enabled for this repository yet, so there is
|
|
48
|
+
currently no public community support destination. GitHub Issues are not a
|
|
49
|
+
general public support channel. External pull requests are not accepted by
|
|
50
|
+
default. Community participation creates no SLA or response deadline.
|
|
51
|
+
|
|
52
|
+
You may use, inspect, and fork the package under the [MIT License](https://github.com/karote00/asyra/blob/main/LICENSE).
|
|
53
|
+
Read the <a href="https://github.com/karote00/asyra/blob/main/SUPPORT.md" target="_blank" rel="noopener noreferrer">support policy</a>.
|
|
54
|
+
For suspected vulnerabilities, follow the <a href="https://github.com/karote00/asyra/blob/main/SECURITY.md" target="_blank" rel="noopener noreferrer">security policy</a> and report privately.
|
package/dist/event-mappings.d.ts
CHANGED
|
@@ -38,6 +38,13 @@ export interface InputEventCombo {
|
|
|
38
38
|
type: InputType;
|
|
39
39
|
keys: KeyboardKey[];
|
|
40
40
|
modifiers?: ModifierKey[];
|
|
41
|
+
/**
|
|
42
|
+
* Keyboard-only held observation: keys are alternatives, not an exact chord.
|
|
43
|
+
* Reports down/up/cancel with live modifiers; callback owns modifier admission.
|
|
44
|
+
* `modifiers` is a chord-mode filter and is not applied in held mode.
|
|
45
|
+
*/
|
|
46
|
+
keyboardMode?: 'held';
|
|
41
47
|
detail?: DetailType;
|
|
42
|
-
|
|
48
|
+
/** Return false to ignore this input before dispatch; policy belongs to the caller. */
|
|
49
|
+
callback?: ((raw: RawInputEvent) => void) | ((raw: RawInputEvent) => boolean);
|
|
43
50
|
}
|
package/dist/input-system.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { InputSystemRegistry } from './registry.js';
|
|
|
3
3
|
type Callback = (raw: RawInputEvent) => void | Promise<void>;
|
|
4
4
|
type Combinations = Record<string, string[]>;
|
|
5
5
|
declare class InputSystem {
|
|
6
|
+
private heldKeyboardKeys;
|
|
6
7
|
private browserHost;
|
|
7
8
|
private pointerTarget;
|
|
8
9
|
private combinations;
|
|
@@ -14,6 +15,8 @@ declare class InputSystem {
|
|
|
14
15
|
private pointerInputBlocked;
|
|
15
16
|
private pointerCaptureId;
|
|
16
17
|
registry: InputSystemRegistry;
|
|
18
|
+
private runtimeGeneration;
|
|
19
|
+
private browserListeners;
|
|
17
20
|
constructor();
|
|
18
21
|
attachBrowserHost(host: Window, pointerTarget?: Window | HTMLElement): void;
|
|
19
22
|
detachBrowserHost(): void;
|
|
@@ -21,6 +24,9 @@ declare class InputSystem {
|
|
|
21
24
|
private removeKeyboardListeners;
|
|
22
25
|
private addPointerListeners;
|
|
23
26
|
private removePointerListeners;
|
|
27
|
+
private keyboardBindings;
|
|
28
|
+
private pointerBindings;
|
|
29
|
+
private browserListener;
|
|
24
30
|
setCombinations(combinations: Combinations): void;
|
|
25
31
|
on(action: string, callback: Callback): this;
|
|
26
32
|
off(action: string, callback: Callback): boolean;
|
|
@@ -30,7 +36,12 @@ declare class InputSystem {
|
|
|
30
36
|
private _isInputActive;
|
|
31
37
|
private _hasTriggerBrowserShortcut;
|
|
32
38
|
private handleKeyDown;
|
|
39
|
+
private releaseKey;
|
|
33
40
|
private handleKeyUp;
|
|
41
|
+
private hasHeldInterest;
|
|
42
|
+
private dispatchHeldKeyboard;
|
|
43
|
+
private cancelHeldKeyboard;
|
|
44
|
+
private hiddenKeyboard;
|
|
34
45
|
private handleMouseDown;
|
|
35
46
|
private handleMouseUp;
|
|
36
47
|
private handleMouseMove;
|
|
@@ -48,6 +59,7 @@ declare class InputSystem {
|
|
|
48
59
|
private clearTransientState;
|
|
49
60
|
dispose(): void;
|
|
50
61
|
reset(): void;
|
|
62
|
+
resetRuntime(): void;
|
|
51
63
|
}
|
|
52
64
|
export { InputSystem };
|
|
53
65
|
declare const inputSystem: InputSystem;
|
package/dist/input-system.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MouseButton, SpecialEvent, InputType, arrEqual, DefaultPointerEventData, measureBrowserDragPhase } from '@asyra/utils';
|
|
1
|
+
import { MouseButton, SpecialEvent, InputType, ModifierKey, arrEqual, DefaultPointerEventData, measureBrowserDragPhase } from '@asyra/utils';
|
|
2
2
|
import { InputFieldsList } from '@asyra/utils';
|
|
3
3
|
import { PointerKey } from '@asyra/utils';
|
|
4
4
|
import { CLICK_THRESHOLD, CLEAR_KEY_TIME } from './constants.js';
|
|
@@ -31,6 +31,7 @@ const getMouseButtonFromButtonsMask = (buttons) => {
|
|
|
31
31
|
return MouseButton.NONE;
|
|
32
32
|
};
|
|
33
33
|
class InputSystem {
|
|
34
|
+
heldKeyboardKeys = new Set();
|
|
34
35
|
browserHost;
|
|
35
36
|
pointerTarget;
|
|
36
37
|
combinations = {};
|
|
@@ -42,6 +43,8 @@ class InputSystem {
|
|
|
42
43
|
pointerInputBlocked;
|
|
43
44
|
pointerCaptureId;
|
|
44
45
|
registry;
|
|
46
|
+
runtimeGeneration = 0;
|
|
47
|
+
browserListeners = new Map();
|
|
45
48
|
constructor() {
|
|
46
49
|
this.browserHost = null;
|
|
47
50
|
this.pointerTarget = null;
|
|
@@ -86,26 +89,65 @@ class InputSystem {
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
addKeyboardListeners(host) {
|
|
89
|
-
host.addEventListener(
|
|
90
|
-
host.addEventListener('
|
|
92
|
+
this.keyboardBindings().forEach((binding) => host.addEventListener(...binding));
|
|
93
|
+
host.document.addEventListener('visibilitychange', this.browserListener(this.hiddenKeyboard));
|
|
91
94
|
}
|
|
92
|
-
removeKeyboardListeners(host) {
|
|
93
|
-
host.removeEventListener(
|
|
94
|
-
host.removeEventListener('
|
|
95
|
+
removeKeyboardListeners(host, attempt = (cleanup) => cleanup()) {
|
|
96
|
+
this.keyboardBindings().forEach((binding) => attempt(() => host.removeEventListener(...binding)));
|
|
97
|
+
attempt(() => host.document.removeEventListener('visibilitychange', this.browserListener(this.hiddenKeyboard)));
|
|
98
|
+
attempt(this.cancelHeldKeyboard);
|
|
95
99
|
}
|
|
96
100
|
addPointerListeners(target) {
|
|
97
|
-
target.addEventListener(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
this.pointerBindings().forEach((binding) => target.addEventListener(...binding));
|
|
102
|
+
}
|
|
103
|
+
removePointerListeners(target, attempt = (cleanup) => cleanup()) {
|
|
104
|
+
this.pointerBindings().forEach((binding) => attempt(() => target.removeEventListener(...binding)));
|
|
105
|
+
}
|
|
106
|
+
keyboardBindings() {
|
|
107
|
+
return [
|
|
108
|
+
['keydown', this.browserListener(this.handleKeyDown)],
|
|
109
|
+
['keyup', this.browserListener(this.releaseKey), true],
|
|
110
|
+
['keyup', this.browserListener(this.handleKeyUp)],
|
|
111
|
+
['blur', this.browserListener(this.cancelHeldKeyboard)],
|
|
112
|
+
['focusin', this.browserListener(this.cancelHeldKeyboard)],
|
|
113
|
+
['compositionstart', this.browserListener(this.cancelHeldKeyboard)]
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
pointerBindings() {
|
|
117
|
+
return [
|
|
118
|
+
[
|
|
119
|
+
'mousedown',
|
|
120
|
+
this.browserListener(this.handleMouseDown)
|
|
121
|
+
],
|
|
122
|
+
['mouseup', this.browserListener(this.handleMouseUp)],
|
|
123
|
+
[
|
|
124
|
+
'mousemove',
|
|
125
|
+
this.browserListener(this.handleMouseMove)
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
'dblclick',
|
|
129
|
+
this.browserListener(this.handleDoubleClick)
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
'wheel',
|
|
133
|
+
this.browserListener(this.handleWheel),
|
|
134
|
+
WHEEL_EVENT_OPTIONS
|
|
135
|
+
]
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
browserListener(listener) {
|
|
139
|
+
const existing = this.browserListeners.get(listener);
|
|
140
|
+
if (existing) {
|
|
141
|
+
return existing;
|
|
142
|
+
}
|
|
143
|
+
const generation = this.runtimeGeneration;
|
|
144
|
+
const guarded = (event) => {
|
|
145
|
+
if (generation === this.runtimeGeneration) {
|
|
146
|
+
listener(event);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
this.browserListeners.set(listener, guarded);
|
|
150
|
+
return guarded;
|
|
109
151
|
}
|
|
110
152
|
setCombinations(combinations) {
|
|
111
153
|
this.combinations = combinations;
|
|
@@ -146,7 +188,11 @@ class InputSystem {
|
|
|
146
188
|
clearTimeout(currentTimer);
|
|
147
189
|
}
|
|
148
190
|
}
|
|
191
|
+
const generation = this.runtimeGeneration;
|
|
149
192
|
const timer = setTimeout(() => {
|
|
193
|
+
if (generation !== this.runtimeGeneration) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
150
196
|
this.activeKeys.delete(key);
|
|
151
197
|
this.timers.delete(key);
|
|
152
198
|
}, CLEAR_KEY_TIME);
|
|
@@ -162,7 +208,7 @@ class InputSystem {
|
|
|
162
208
|
}
|
|
163
209
|
}
|
|
164
210
|
_isInputActive(event) {
|
|
165
|
-
return (InputFieldsList.includes(event.target
|
|
211
|
+
return (InputFieldsList.includes(event.target?.tagName?.toLowerCase()) || event.target?.isContentEditable);
|
|
166
212
|
}
|
|
167
213
|
_hasTriggerBrowserShortcut(event) {
|
|
168
214
|
const hasMeta = this.activeKeys.has('Meta');
|
|
@@ -171,10 +217,23 @@ class InputSystem {
|
|
|
171
217
|
return hasMeta && hasNumber;
|
|
172
218
|
}
|
|
173
219
|
handleKeyDown = (event) => {
|
|
174
|
-
|
|
220
|
+
const key = this.keyMap.mapKey(event.code);
|
|
221
|
+
const interested = this.hasHeldInterest(key);
|
|
222
|
+
if (event.isComposing) {
|
|
223
|
+
this.cancelHeldKeyboard();
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
if (key && !this.keyMap.isModifierKeys(key)) {
|
|
227
|
+
this.heldKeyboardKeys.add(key);
|
|
228
|
+
}
|
|
229
|
+
if (this.dispatchHeldKeyboard(event, key, 'down')) {
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (!interested &&
|
|
234
|
+
(!this._isInputActive(event) || this._hasTriggerBrowserShortcut(event))) {
|
|
175
235
|
event.preventDefault();
|
|
176
236
|
}
|
|
177
|
-
const key = this.keyMap.mapKey(event.code);
|
|
178
237
|
if (key) {
|
|
179
238
|
this.activeKeys.add(key);
|
|
180
239
|
if (!this.keyMap.isModifierKeys(key)) {
|
|
@@ -183,17 +242,96 @@ class InputSystem {
|
|
|
183
242
|
this.checkCombinations(InputType.KEYBOARD);
|
|
184
243
|
}
|
|
185
244
|
};
|
|
245
|
+
// Release bookkeeping must survive editors stopping event propagation.
|
|
246
|
+
// Capture publishes opted-in held releases only; ordinary chord dispatch stays in bubble phase.
|
|
247
|
+
releaseKey = (event, notifyHeld = true) => {
|
|
248
|
+
const key = this.keyMap.mapKey(event.code);
|
|
249
|
+
if (key) {
|
|
250
|
+
this.activeKeys.delete(key);
|
|
251
|
+
this.clearTimer(key);
|
|
252
|
+
if (notifyHeld) {
|
|
253
|
+
this.heldKeyboardKeys.delete(key);
|
|
254
|
+
this.dispatchHeldKeyboard(event, key, 'up');
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
186
258
|
handleKeyUp = (event) => {
|
|
187
|
-
if (!this.
|
|
259
|
+
if (!this.hasHeldInterest(this.keyMap.mapKey(event.code)) &&
|
|
260
|
+
(!this._isInputActive(event) || this._hasTriggerBrowserShortcut(event))) {
|
|
188
261
|
event.preventDefault();
|
|
189
262
|
}
|
|
190
263
|
const key = this.keyMap.mapKey(event.code);
|
|
191
264
|
if (key) {
|
|
192
|
-
this.
|
|
193
|
-
this.clearTimer(key);
|
|
265
|
+
this.releaseKey(event, false);
|
|
194
266
|
this.checkCombinations(InputType.KEYBOARD);
|
|
195
267
|
}
|
|
196
268
|
};
|
|
269
|
+
hasHeldInterest(key) {
|
|
270
|
+
return this.registry
|
|
271
|
+
.getEventNames()
|
|
272
|
+
.some((name) => this.registry
|
|
273
|
+
.getCombinations(name)
|
|
274
|
+
?.some((combo) => combo.type === InputType.KEYBOARD &&
|
|
275
|
+
combo.keyboardMode === 'held' &&
|
|
276
|
+
combo.keys.some((candidate) => candidate === key || this.heldKeyboardKeys.has(candidate))));
|
|
277
|
+
}
|
|
278
|
+
dispatchHeldKeyboard(event, key, phase) {
|
|
279
|
+
let accepted = false;
|
|
280
|
+
const raw = {
|
|
281
|
+
type: InputType.KEYBOARD,
|
|
282
|
+
keys: [...this.heldKeyboardKeys],
|
|
283
|
+
modifiers: {
|
|
284
|
+
shift: event?.shiftKey ?? false,
|
|
285
|
+
ctrl: event?.ctrlKey ?? false,
|
|
286
|
+
alt: event?.altKey ?? false,
|
|
287
|
+
meta: event?.metaKey ?? false
|
|
288
|
+
},
|
|
289
|
+
pointer: DefaultPointerEventData,
|
|
290
|
+
keyboard: {
|
|
291
|
+
phase,
|
|
292
|
+
changedKey: key ?? null,
|
|
293
|
+
target: event?.target ?? null,
|
|
294
|
+
repeat: event?.repeat ?? false,
|
|
295
|
+
isComposing: event?.isComposing ?? false
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
for (const name of this.registry.getEventNames()) {
|
|
299
|
+
for (const combo of this.registry.getCombinations(name) ?? []) {
|
|
300
|
+
if (combo.type !== InputType.KEYBOARD ||
|
|
301
|
+
combo.keyboardMode !== 'held') {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (phase !== 'cancel' &&
|
|
305
|
+
!combo.keys.some((candidate) => candidate === key || this.heldKeyboardKeys.has(candidate))) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const snapshot = {
|
|
309
|
+
...raw,
|
|
310
|
+
keys: [...raw.keys],
|
|
311
|
+
modifiers: { ...raw.modifiers },
|
|
312
|
+
detail: combo.detail
|
|
313
|
+
};
|
|
314
|
+
if (combo.callback?.(snapshot) === false) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
accepted = true;
|
|
318
|
+
this.triggerAction(name, snapshot);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return accepted;
|
|
322
|
+
}
|
|
323
|
+
cancelHeldKeyboard = () => {
|
|
324
|
+
if (!this.heldKeyboardKeys.size) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
this.heldKeyboardKeys.clear();
|
|
328
|
+
this.dispatchHeldKeyboard(null, undefined, 'cancel');
|
|
329
|
+
};
|
|
330
|
+
hiddenKeyboard = () => {
|
|
331
|
+
if (this.browserHost?.document.hidden) {
|
|
332
|
+
this.cancelHeldKeyboard();
|
|
333
|
+
}
|
|
334
|
+
};
|
|
197
335
|
handleMouseDown = (event) => {
|
|
198
336
|
if (this.pointerInputBlocked) {
|
|
199
337
|
return;
|
|
@@ -279,11 +417,12 @@ class InputSystem {
|
|
|
279
417
|
this.activeKeys.delete(PointerKey.MOUSE_DOUBLE_CLICK);
|
|
280
418
|
};
|
|
281
419
|
getMouseEventKey(button, state) {
|
|
282
|
-
if (button === MouseButton.NONE)
|
|
420
|
+
if (button === MouseButton.NONE) {
|
|
283
421
|
return;
|
|
422
|
+
}
|
|
284
423
|
return `${button}Mouse${state}`;
|
|
285
424
|
}
|
|
286
|
-
checkCombinations(type, pointerData = DefaultPointerEventData) {
|
|
425
|
+
checkCombinations(type, pointerData = DefaultPointerEventData, activeModifiers = this.getActiveModifiers(this.activeKeys)) {
|
|
287
426
|
const currentKeys = Array.from(this.activeKeys).filter((key) => {
|
|
288
427
|
if (this.keyMap.isModifierKeys(key)) {
|
|
289
428
|
return false;
|
|
@@ -296,13 +435,16 @@ class InputSystem {
|
|
|
296
435
|
}
|
|
297
436
|
return POINTER_KEYS.has(key) && key !== SpecialEvent.WHEEL;
|
|
298
437
|
});
|
|
299
|
-
const activeModifiers = this.getActiveModifiers(this.activeKeys);
|
|
300
438
|
const allModifiers = this.getAllModifiers(activeModifiers);
|
|
301
439
|
for (const eventName of this.registry.getEventNames()) {
|
|
302
440
|
const combos = this.registry.getCombinations(eventName);
|
|
303
|
-
if (!combos)
|
|
441
|
+
if (!combos) {
|
|
304
442
|
continue;
|
|
443
|
+
}
|
|
305
444
|
for (const combo of combos) {
|
|
445
|
+
if (combo.keyboardMode === 'held') {
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
306
448
|
if (this.isExactMatch(type, currentKeys, combo, activeModifiers)) {
|
|
307
449
|
const raw = {
|
|
308
450
|
type,
|
|
@@ -313,9 +455,9 @@ class InputSystem {
|
|
|
313
455
|
if (combo.detail) {
|
|
314
456
|
raw.detail = combo.detail;
|
|
315
457
|
}
|
|
316
|
-
//
|
|
317
|
-
if (combo.callback) {
|
|
318
|
-
|
|
458
|
+
// Admission happens before any downstream queue or session receives input.
|
|
459
|
+
if (combo.callback?.(raw) === false) {
|
|
460
|
+
continue;
|
|
319
461
|
}
|
|
320
462
|
this.triggerAction(eventName, raw);
|
|
321
463
|
}
|
|
@@ -324,8 +466,9 @@ class InputSystem {
|
|
|
324
466
|
}
|
|
325
467
|
isExactMatch(type, keys, combo, modifiers) {
|
|
326
468
|
const isKeysMatch = arrEqual(keys, combo.keys);
|
|
327
|
-
if (type !== combo.type || !isKeysMatch)
|
|
469
|
+
if (type !== combo.type || !isKeysMatch) {
|
|
328
470
|
return false;
|
|
471
|
+
}
|
|
329
472
|
if (isKeysMatch && (!combo.modifiers || !combo.modifiers.length)) {
|
|
330
473
|
return true;
|
|
331
474
|
}
|
|
@@ -362,7 +505,22 @@ class InputSystem {
|
|
|
362
505
|
clientY: event.clientY,
|
|
363
506
|
button: MouseButton.MIDDLE
|
|
364
507
|
};
|
|
365
|
-
|
|
508
|
+
// Trackpad pinch supplies ctrlKey on the wheel event without a keydown.
|
|
509
|
+
// Keep these modifiers local to this event; never latch them into keys.
|
|
510
|
+
const modifiers = new Set(this.getActiveModifiers(this.activeKeys));
|
|
511
|
+
if (event.ctrlKey) {
|
|
512
|
+
modifiers.add(ModifierKey.CTRL);
|
|
513
|
+
}
|
|
514
|
+
if (event.metaKey) {
|
|
515
|
+
modifiers.add(ModifierKey.META);
|
|
516
|
+
}
|
|
517
|
+
if (event.shiftKey) {
|
|
518
|
+
modifiers.add(ModifierKey.SHIFT);
|
|
519
|
+
}
|
|
520
|
+
if (event.altKey) {
|
|
521
|
+
modifiers.add(ModifierKey.ALT);
|
|
522
|
+
}
|
|
523
|
+
this.checkCombinations(InputType.WHEEL, wheelData, [...modifiers]);
|
|
366
524
|
// Remove wheel key immediately as scrolling is continuous
|
|
367
525
|
this.activeKeys.delete(key);
|
|
368
526
|
}
|
|
@@ -424,6 +582,7 @@ class InputSystem {
|
|
|
424
582
|
this.timers.forEach((timer) => clearTimeout(timer));
|
|
425
583
|
this.timers.clear();
|
|
426
584
|
this.activeKeys.clear();
|
|
585
|
+
this.heldKeyboardKeys.clear();
|
|
427
586
|
this.combinations = {};
|
|
428
587
|
this._startPos = null;
|
|
429
588
|
this.pointerInputBlocked = false;
|
|
@@ -436,6 +595,32 @@ class InputSystem {
|
|
|
436
595
|
reset() {
|
|
437
596
|
this.clearTransientState();
|
|
438
597
|
}
|
|
598
|
+
resetRuntime() {
|
|
599
|
+
this.runtimeGeneration += 1;
|
|
600
|
+
const failures = [];
|
|
601
|
+
const attempt = (cleanup) => {
|
|
602
|
+
try {
|
|
603
|
+
cleanup();
|
|
604
|
+
}
|
|
605
|
+
catch (error) {
|
|
606
|
+
failures.push(error);
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
if (this.pointerTarget) {
|
|
610
|
+
this.removePointerListeners(this.pointerTarget, attempt);
|
|
611
|
+
}
|
|
612
|
+
if (this.browserHost) {
|
|
613
|
+
this.removeKeyboardListeners(this.browserHost, attempt);
|
|
614
|
+
}
|
|
615
|
+
this.pointerTarget = null;
|
|
616
|
+
this.browserHost = null;
|
|
617
|
+
this.browserListeners.clear();
|
|
618
|
+
this.clearTransientState();
|
|
619
|
+
this.registry.clear();
|
|
620
|
+
if (failures.length > 0) {
|
|
621
|
+
throw failures[0];
|
|
622
|
+
}
|
|
623
|
+
}
|
|
439
624
|
}
|
|
440
625
|
export { InputSystem };
|
|
441
626
|
const inputSystem = new InputSystem();
|
package/dist/keymap.js
CHANGED
|
@@ -16,10 +16,12 @@ export class KeyMap {
|
|
|
16
16
|
navigator.platform ||
|
|
17
17
|
'').toLowerCase();
|
|
18
18
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
19
|
-
if (platform.includes('mac') || userAgent.includes('mac'))
|
|
19
|
+
if (platform.includes('mac') || userAgent.includes('mac')) {
|
|
20
20
|
return Platforms.MAC;
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
if (platform.includes('win') || userAgent.includes('win')) {
|
|
22
23
|
return Platforms.WINDOWS;
|
|
24
|
+
}
|
|
23
25
|
return Platforms.LINUX;
|
|
24
26
|
}
|
|
25
27
|
createKeyMap() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyra/input-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Keyboard and Mouse event listener plugin",
|
|
5
5
|
"author": "Asa Tsai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/karote00/asyra.git",
|
|
10
10
|
"directory": "packages/input-system"
|
|
11
11
|
},
|
|
12
|
-
"homepage": "https://asyra-framework.
|
|
12
|
+
"homepage": "https://asyra-framework.pages.dev",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": "24.x"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"has:test": "find . -type f \\( -name \"*.test.ts\" -o -name \"*.test.tsx\" \\) | grep -q .",
|
|
39
39
|
"test": "yarn has:test && vitest || echo 'No test files found. Skipping test.'",
|
|
40
40
|
"test:local": "vitest run",
|
|
41
|
-
"test:ci": "yarn has:test && vitest run --coverage --reporter=default --reporter=junit
|
|
41
|
+
"test:ci": "yarn has:test && vitest run --coverage --reporter=default --reporter=junit"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@vitest/coverage-v8": "^3.2.6",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"vitest": "^3.2.6"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@asyra/reactive-events": "0.
|
|
50
|
-
"@asyra/utils": "0.
|
|
49
|
+
"@asyra/reactive-events": "0.6.0",
|
|
50
|
+
"@asyra/utils": "0.6.0"
|
|
51
51
|
}
|
|
52
|
-
}
|
|
52
|
+
}
|