@n3rdw1z4rd/core 0.23.1 → 0.24.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/dist/index.cjs +64 -15
- package/dist/index.d.cts +8 -0
- package/dist/input/input-action-map.d.ts +9 -1
- package/dist/input/input-action-map.js +64 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2258,6 +2258,27 @@ var Observable = class {
|
|
|
2258
2258
|
}
|
|
2259
2259
|
};
|
|
2260
2260
|
// src/input/input-action-map.ts
|
|
2261
|
+
const SHIFT = 1;
|
|
2262
|
+
const CTRL = 2;
|
|
2263
|
+
const ALT = 4;
|
|
2264
|
+
const META = 8;
|
|
2265
|
+
const MODIFIER_KEYS = [
|
|
2266
|
+
["ShiftLeft", SHIFT],
|
|
2267
|
+
["ShiftRight", SHIFT],
|
|
2268
|
+
["ControlLeft", CTRL],
|
|
2269
|
+
["ControlRight", CTRL],
|
|
2270
|
+
["AltLeft", ALT],
|
|
2271
|
+
["AltRight", ALT],
|
|
2272
|
+
["MetaLeft", META],
|
|
2273
|
+
["MetaRight", META]
|
|
2274
|
+
];
|
|
2275
|
+
const modifierBits = (m) => (m.shift ? SHIFT : 0) | (m.ctrl ? CTRL : 0) | (m.alt ? ALT : 0) | (m.meta ? META : 0);
|
|
2276
|
+
const modifiersOf = (bits) => ({
|
|
2277
|
+
shift: !!(bits & SHIFT),
|
|
2278
|
+
ctrl: !!(bits & CTRL),
|
|
2279
|
+
alt: !!(bits & ALT),
|
|
2280
|
+
meta: !!(bits & META)
|
|
2281
|
+
});
|
|
2261
2282
|
const ANY = -1;
|
|
2262
2283
|
const now = () => performance.now();
|
|
2263
2284
|
const MOUSE_BUTTONS = [
|
|
@@ -2408,35 +2429,49 @@ var InputActionMap = class {
|
|
|
2408
2429
|
this._updateGestures(time);
|
|
2409
2430
|
const devices = [...this._controls.keys()];
|
|
2410
2431
|
const fired = [];
|
|
2432
|
+
const heldMods = this._heldMods();
|
|
2411
2433
|
for (const name of this.actions.names) {
|
|
2412
2434
|
const action = this.actions.get(name);
|
|
2413
2435
|
let states = this._actionStates.get(name);
|
|
2414
2436
|
if (!states) this._actionStates.set(name, states = /* @__PURE__ */ new Map());
|
|
2415
2437
|
let anyRaw = 0;
|
|
2438
|
+
let anyPressMods = -1;
|
|
2416
2439
|
for (const device of devices) {
|
|
2417
2440
|
let raw = 0;
|
|
2418
|
-
|
|
2441
|
+
let pressMods = -1;
|
|
2442
|
+
for (const binding of action.bindings) {
|
|
2443
|
+
const value = this._bindingValue(binding, device);
|
|
2444
|
+
raw = Math.max(raw, value);
|
|
2445
|
+
const control = this._controls.get(device)?.get(controlId(binding));
|
|
2446
|
+
if (value > 0 && control?.pressed) pressMods = Math.max(0, pressMods) | control.mods;
|
|
2447
|
+
}
|
|
2419
2448
|
anyRaw = Math.max(anyRaw, raw);
|
|
2449
|
+
if (pressMods >= 0) anyPressMods = Math.max(0, anyPressMods) | pressMods;
|
|
2420
2450
|
const phase = this._advance(states, device, raw, action, time);
|
|
2451
|
+
const state = states.get(device);
|
|
2421
2452
|
if (phase) fired.push({
|
|
2422
2453
|
action: name,
|
|
2423
2454
|
phase,
|
|
2424
2455
|
device,
|
|
2425
|
-
repeat:
|
|
2456
|
+
repeat: state.repeated,
|
|
2457
|
+
mods: phase === "pressed" && !state.repeated && pressMods >= 0 ? pressMods : heldMods
|
|
2426
2458
|
});
|
|
2427
2459
|
}
|
|
2428
2460
|
const phase = this._advance(states, ANY, anyRaw, action, time);
|
|
2461
|
+
const state = states.get(ANY);
|
|
2429
2462
|
if (phase) fired.push({
|
|
2430
2463
|
action: name,
|
|
2431
2464
|
phase,
|
|
2432
2465
|
device: ANY,
|
|
2433
|
-
repeat:
|
|
2466
|
+
repeat: state.repeated,
|
|
2467
|
+
mods: phase === "pressed" && !state.repeated && anyPressMods >= 0 ? anyPressMods : heldMods
|
|
2434
2468
|
});
|
|
2435
2469
|
}
|
|
2436
2470
|
for (const controls of this._controls.values()) for (const state of controls.values()) state.pressed = false;
|
|
2437
|
-
for (const { action, phase, device, repeat } of fired) for (const listener of [...this._actionListeners]) if (listener.action === action && listener.phase === phase && listener.device === device) listener.callback({
|
|
2471
|
+
for (const { action, phase, device, repeat, mods } of fired) for (const listener of [...this._actionListeners]) if (listener.action === action && listener.phase === phase && listener.device === device) listener.callback({
|
|
2438
2472
|
action,
|
|
2439
|
-
repeat
|
|
2473
|
+
repeat,
|
|
2474
|
+
modifiers: modifiersOf(mods)
|
|
2440
2475
|
});
|
|
2441
2476
|
}
|
|
2442
2477
|
/** Whether the action is held past its deadzone. Unknown actions return false (and warn once). */
|
|
@@ -2646,13 +2681,11 @@ var InputActionMap = class {
|
|
|
2646
2681
|
_bindingValue(binding, device) {
|
|
2647
2682
|
const value = this._controlValue(device, controlId(binding));
|
|
2648
2683
|
if (value === 0 || binding.type !== "key" || !binding.modifiers) return value;
|
|
2649
|
-
const
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
if (m.meta && !held("MetaLeft", "MetaRight")) return 0;
|
|
2655
|
-
return value;
|
|
2684
|
+
const control = this._controls.get(device)?.get(controlId(binding));
|
|
2685
|
+
let held = control?.pressed ? control.mods : 0;
|
|
2686
|
+
for (const [code, bit] of MODIFIER_KEYS) if (this._controlValue(device, `key:${code}`) > 0) held |= bit;
|
|
2687
|
+
const need = modifierBits(binding.modifiers);
|
|
2688
|
+
return (held & need) === need ? value : 0;
|
|
2656
2689
|
}
|
|
2657
2690
|
_control(device, binding) {
|
|
2658
2691
|
let controls = this._controls.get(device);
|
|
@@ -2662,7 +2695,8 @@ var InputActionMap = class {
|
|
|
2662
2695
|
if (!state) controls.set(id, state = {
|
|
2663
2696
|
value: 0,
|
|
2664
2697
|
pressed: false,
|
|
2665
|
-
suppressed: false
|
|
2698
|
+
suppressed: false,
|
|
2699
|
+
mods: 0
|
|
2666
2700
|
});
|
|
2667
2701
|
return state;
|
|
2668
2702
|
}
|
|
@@ -2673,14 +2707,29 @@ var InputActionMap = class {
|
|
|
2673
2707
|
state.value = value;
|
|
2674
2708
|
if (value >= .5 && !wasDown) {
|
|
2675
2709
|
if (this._tryCapture(binding)) state.suppressed = true;
|
|
2676
|
-
else
|
|
2710
|
+
else {
|
|
2711
|
+
state.pressed = true;
|
|
2712
|
+
state.mods = this._heldMods();
|
|
2713
|
+
}
|
|
2677
2714
|
}
|
|
2678
2715
|
if (value === 0) state.suppressed = false;
|
|
2679
2716
|
}
|
|
2680
2717
|
/** A one-frame press with no held state: wheel steps, gestures. */
|
|
2681
2718
|
_pulse(device, binding) {
|
|
2682
2719
|
const state = this._control(device, binding);
|
|
2683
|
-
if (!this._tryCapture(binding))
|
|
2720
|
+
if (!this._tryCapture(binding)) {
|
|
2721
|
+
state.pressed = true;
|
|
2722
|
+
state.mods = this._heldMods();
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
/** the keyboard's modifier keys held right now (bits); they apply to every device's presses (Shift + click) */
|
|
2726
|
+
_heldMods() {
|
|
2727
|
+
const keys = this._controls.get(0);
|
|
2728
|
+
let bits = 0;
|
|
2729
|
+
if (keys) {
|
|
2730
|
+
for (const [code, bit] of MODIFIER_KEYS) if ((keys.get(`key:${code}`)?.value ?? 0) > 0) bits |= bit;
|
|
2731
|
+
}
|
|
2732
|
+
return bits;
|
|
2684
2733
|
}
|
|
2685
2734
|
_tryCapture(binding) {
|
|
2686
2735
|
const capture = this._capture;
|
package/dist/index.d.cts
CHANGED
|
@@ -1449,6 +1449,12 @@ export interface ActionEvent {
|
|
|
1449
1449
|
action: string;
|
|
1450
1450
|
/** an auto-repeat of a held action (see {@link ActionRepeat}), not a new press */
|
|
1451
1451
|
repeat: boolean;
|
|
1452
|
+
/**
|
|
1453
|
+
* The modifier keys that were held when the press happened, even if they were let go again
|
|
1454
|
+
* before update() (a quick Shift + arrow between two frames). For auto-repeats and releases:
|
|
1455
|
+
* the ones held now.
|
|
1456
|
+
*/
|
|
1457
|
+
modifiers: Required<KeyModifiers>;
|
|
1452
1458
|
}
|
|
1453
1459
|
/**
|
|
1454
1460
|
* Options for the {@link InputActionMap} constructor.
|
|
@@ -1700,6 +1706,8 @@ export declare class InputActionMap {
|
|
|
1700
1706
|
protected _setControl(device: InputDevice, binding: Binding, value: number): void;
|
|
1701
1707
|
/** A one-frame press with no held state: wheel steps, gestures. */
|
|
1702
1708
|
protected _pulse(device: InputDevice, binding: Binding): void;
|
|
1709
|
+
/** the keyboard's modifier keys held right now (bits); they apply to every device's presses (Shift + click) */
|
|
1710
|
+
private _heldMods;
|
|
1703
1711
|
private _tryCapture;
|
|
1704
1712
|
private _setLastDevice;
|
|
1705
1713
|
/**
|
|
@@ -2,7 +2,7 @@ import { Observable } from "../observable.js";
|
|
|
2
2
|
import { ActionMap } from "./action-map.js";
|
|
3
3
|
import { GestureFrame, GestureRecognizer, TouchPoint } from "./gestures.js";
|
|
4
4
|
import { Input } from "./input.js";
|
|
5
|
-
import { Binding, MouseButton } from "./bindings.js";
|
|
5
|
+
import { Binding, KeyModifiers, MouseButton } from "./bindings.js";
|
|
6
6
|
/**
|
|
7
7
|
* 0 = keyboard, mouse, pen, touch and VR; 1, 2, ... = gamepads.
|
|
8
8
|
*
|
|
@@ -31,6 +31,12 @@ export interface ActionEvent {
|
|
|
31
31
|
action: string;
|
|
32
32
|
/** an auto-repeat of a held action (see {@link ActionRepeat}), not a new press */
|
|
33
33
|
repeat: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The modifier keys that were held when the press happened, even if they were let go again
|
|
36
|
+
* before update() (a quick Shift + arrow between two frames). For auto-repeats and releases:
|
|
37
|
+
* the ones held now.
|
|
38
|
+
*/
|
|
39
|
+
modifiers: Required<KeyModifiers>;
|
|
34
40
|
}
|
|
35
41
|
/**
|
|
36
42
|
* Options for the {@link InputActionMap} constructor.
|
|
@@ -282,6 +288,8 @@ export declare class InputActionMap {
|
|
|
282
288
|
protected _setControl(device: InputDevice, binding: Binding, value: number): void;
|
|
283
289
|
/** A one-frame press with no held state: wheel steps, gestures. */
|
|
284
290
|
protected _pulse(device: InputDevice, binding: Binding): void;
|
|
291
|
+
/** the keyboard's modifier keys held right now (bits); they apply to every device's presses (Shift + click) */
|
|
292
|
+
private _heldMods;
|
|
285
293
|
private _tryCapture;
|
|
286
294
|
private _setLastDevice;
|
|
287
295
|
/**
|
|
@@ -4,6 +4,27 @@ import { GestureRecognizer } from "./gestures.js";
|
|
|
4
4
|
import { Input } from "./input.js";
|
|
5
5
|
import { GAMEPAD_AXES, GAMEPAD_BUTTONS, XR_AXES, XR_BUTTONS, controlId } from "./bindings.js";
|
|
6
6
|
// src/input/input-action-map.ts
|
|
7
|
+
const SHIFT = 1;
|
|
8
|
+
const CTRL = 2;
|
|
9
|
+
const ALT = 4;
|
|
10
|
+
const META = 8;
|
|
11
|
+
const MODIFIER_KEYS = [
|
|
12
|
+
["ShiftLeft", SHIFT],
|
|
13
|
+
["ShiftRight", SHIFT],
|
|
14
|
+
["ControlLeft", CTRL],
|
|
15
|
+
["ControlRight", CTRL],
|
|
16
|
+
["AltLeft", ALT],
|
|
17
|
+
["AltRight", ALT],
|
|
18
|
+
["MetaLeft", META],
|
|
19
|
+
["MetaRight", META]
|
|
20
|
+
];
|
|
21
|
+
const modifierBits = (m) => (m.shift ? SHIFT : 0) | (m.ctrl ? CTRL : 0) | (m.alt ? ALT : 0) | (m.meta ? META : 0);
|
|
22
|
+
const modifiersOf = (bits) => ({
|
|
23
|
+
shift: !!(bits & SHIFT),
|
|
24
|
+
ctrl: !!(bits & CTRL),
|
|
25
|
+
alt: !!(bits & ALT),
|
|
26
|
+
meta: !!(bits & META)
|
|
27
|
+
});
|
|
7
28
|
const ANY = -1;
|
|
8
29
|
const now = () => performance.now();
|
|
9
30
|
const MOUSE_BUTTONS = [
|
|
@@ -154,35 +175,49 @@ var InputActionMap = class {
|
|
|
154
175
|
this._updateGestures(time);
|
|
155
176
|
const devices = [...this._controls.keys()];
|
|
156
177
|
const fired = [];
|
|
178
|
+
const heldMods = this._heldMods();
|
|
157
179
|
for (const name of this.actions.names) {
|
|
158
180
|
const action = this.actions.get(name);
|
|
159
181
|
let states = this._actionStates.get(name);
|
|
160
182
|
if (!states) this._actionStates.set(name, states = /* @__PURE__ */ new Map());
|
|
161
183
|
let anyRaw = 0;
|
|
184
|
+
let anyPressMods = -1;
|
|
162
185
|
for (const device of devices) {
|
|
163
186
|
let raw = 0;
|
|
164
|
-
|
|
187
|
+
let pressMods = -1;
|
|
188
|
+
for (const binding of action.bindings) {
|
|
189
|
+
const value = this._bindingValue(binding, device);
|
|
190
|
+
raw = Math.max(raw, value);
|
|
191
|
+
const control = this._controls.get(device)?.get(controlId(binding));
|
|
192
|
+
if (value > 0 && control?.pressed) pressMods = Math.max(0, pressMods) | control.mods;
|
|
193
|
+
}
|
|
165
194
|
anyRaw = Math.max(anyRaw, raw);
|
|
195
|
+
if (pressMods >= 0) anyPressMods = Math.max(0, anyPressMods) | pressMods;
|
|
166
196
|
const phase = this._advance(states, device, raw, action, time);
|
|
197
|
+
const state = states.get(device);
|
|
167
198
|
if (phase) fired.push({
|
|
168
199
|
action: name,
|
|
169
200
|
phase,
|
|
170
201
|
device,
|
|
171
|
-
repeat:
|
|
202
|
+
repeat: state.repeated,
|
|
203
|
+
mods: phase === "pressed" && !state.repeated && pressMods >= 0 ? pressMods : heldMods
|
|
172
204
|
});
|
|
173
205
|
}
|
|
174
206
|
const phase = this._advance(states, ANY, anyRaw, action, time);
|
|
207
|
+
const state = states.get(ANY);
|
|
175
208
|
if (phase) fired.push({
|
|
176
209
|
action: name,
|
|
177
210
|
phase,
|
|
178
211
|
device: ANY,
|
|
179
|
-
repeat:
|
|
212
|
+
repeat: state.repeated,
|
|
213
|
+
mods: phase === "pressed" && !state.repeated && anyPressMods >= 0 ? anyPressMods : heldMods
|
|
180
214
|
});
|
|
181
215
|
}
|
|
182
216
|
for (const controls of this._controls.values()) for (const state of controls.values()) state.pressed = false;
|
|
183
|
-
for (const { action, phase, device, repeat } of fired) for (const listener of [...this._actionListeners]) if (listener.action === action && listener.phase === phase && listener.device === device) listener.callback({
|
|
217
|
+
for (const { action, phase, device, repeat, mods } of fired) for (const listener of [...this._actionListeners]) if (listener.action === action && listener.phase === phase && listener.device === device) listener.callback({
|
|
184
218
|
action,
|
|
185
|
-
repeat
|
|
219
|
+
repeat,
|
|
220
|
+
modifiers: modifiersOf(mods)
|
|
186
221
|
});
|
|
187
222
|
}
|
|
188
223
|
/** Whether the action is held past its deadzone. Unknown actions return false (and warn once). */
|
|
@@ -392,13 +427,11 @@ var InputActionMap = class {
|
|
|
392
427
|
_bindingValue(binding, device) {
|
|
393
428
|
const value = this._controlValue(device, controlId(binding));
|
|
394
429
|
if (value === 0 || binding.type !== "key" || !binding.modifiers) return value;
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (m.meta && !held("MetaLeft", "MetaRight")) return 0;
|
|
401
|
-
return value;
|
|
430
|
+
const control = this._controls.get(device)?.get(controlId(binding));
|
|
431
|
+
let held = control?.pressed ? control.mods : 0;
|
|
432
|
+
for (const [code, bit] of MODIFIER_KEYS) if (this._controlValue(device, `key:${code}`) > 0) held |= bit;
|
|
433
|
+
const need = modifierBits(binding.modifiers);
|
|
434
|
+
return (held & need) === need ? value : 0;
|
|
402
435
|
}
|
|
403
436
|
_control(device, binding) {
|
|
404
437
|
let controls = this._controls.get(device);
|
|
@@ -408,7 +441,8 @@ var InputActionMap = class {
|
|
|
408
441
|
if (!state) controls.set(id, state = {
|
|
409
442
|
value: 0,
|
|
410
443
|
pressed: false,
|
|
411
|
-
suppressed: false
|
|
444
|
+
suppressed: false,
|
|
445
|
+
mods: 0
|
|
412
446
|
});
|
|
413
447
|
return state;
|
|
414
448
|
}
|
|
@@ -419,14 +453,29 @@ var InputActionMap = class {
|
|
|
419
453
|
state.value = value;
|
|
420
454
|
if (value >= .5 && !wasDown) {
|
|
421
455
|
if (this._tryCapture(binding)) state.suppressed = true;
|
|
422
|
-
else
|
|
456
|
+
else {
|
|
457
|
+
state.pressed = true;
|
|
458
|
+
state.mods = this._heldMods();
|
|
459
|
+
}
|
|
423
460
|
}
|
|
424
461
|
if (value === 0) state.suppressed = false;
|
|
425
462
|
}
|
|
426
463
|
/** A one-frame press with no held state: wheel steps, gestures. */
|
|
427
464
|
_pulse(device, binding) {
|
|
428
465
|
const state = this._control(device, binding);
|
|
429
|
-
if (!this._tryCapture(binding))
|
|
466
|
+
if (!this._tryCapture(binding)) {
|
|
467
|
+
state.pressed = true;
|
|
468
|
+
state.mods = this._heldMods();
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
/** the keyboard's modifier keys held right now (bits); they apply to every device's presses (Shift + click) */
|
|
472
|
+
_heldMods() {
|
|
473
|
+
const keys = this._controls.get(0);
|
|
474
|
+
let bits = 0;
|
|
475
|
+
if (keys) {
|
|
476
|
+
for (const [code, bit] of MODIFIER_KEYS) if ((keys.get(`key:${code}`)?.value ?? 0) > 0) bits |= bit;
|
|
477
|
+
}
|
|
478
|
+
return bits;
|
|
430
479
|
}
|
|
431
480
|
_tryCapture(binding) {
|
|
432
481
|
const capture = this._capture;
|