@yagejs/input 0.2.0 → 0.4.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/api-CTGj55Rb.d.cts +208 -0
- package/dist/api-CTGj55Rb.d.ts +208 -0
- package/dist/api.cjs +34 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +2 -0
- package/dist/api.d.ts +2 -0
- package/dist/api.js +7 -0
- package/dist/api.js.map +1 -0
- package/dist/chunk-CYWOKPMI.js +12 -0
- package/dist/chunk-CYWOKPMI.js.map +1 -0
- package/dist/index.cjs +138 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -156
- package/dist/index.d.ts +4 -156
- package/dist/index.js +142 -26
- package/dist/index.js.map +1 -1
- package/package.json +13 -3
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { Vec2, ServiceKey, RendererAdapter } from '@yagejs/core';
|
|
2
|
+
|
|
3
|
+
/** Central input state manager. Resolved via DI with InputManagerKey. */
|
|
4
|
+
declare class InputManager {
|
|
5
|
+
private pressedKeys;
|
|
6
|
+
private justPressedKeys;
|
|
7
|
+
private justReleasedKeys;
|
|
8
|
+
private holdStart;
|
|
9
|
+
private syntheticPressedActions;
|
|
10
|
+
private syntheticActionStarts;
|
|
11
|
+
private actionMap;
|
|
12
|
+
private defaultBindings;
|
|
13
|
+
private groups;
|
|
14
|
+
private actionGroups;
|
|
15
|
+
private disabledGroups;
|
|
16
|
+
private pointerScreenPos;
|
|
17
|
+
private pointerDownState;
|
|
18
|
+
private pressedMouseButtons;
|
|
19
|
+
private gamepadButtons;
|
|
20
|
+
private gamepadAxes;
|
|
21
|
+
private camera;
|
|
22
|
+
private elapsedMs;
|
|
23
|
+
private listenResolve;
|
|
24
|
+
/** Whether any key mapped to this action is currently held. */
|
|
25
|
+
isPressed(action: string): boolean;
|
|
26
|
+
/** Whether any key mapped to this action was pressed this frame. */
|
|
27
|
+
isJustPressed(action: string): boolean;
|
|
28
|
+
/** Whether any key mapped to this action was released this frame. */
|
|
29
|
+
isJustReleased(action: string): boolean;
|
|
30
|
+
/** Returns true if any key bound to the action exists in the given set. */
|
|
31
|
+
private anyKeyInSet;
|
|
32
|
+
/** Milliseconds the action has been held. Returns 0 if not held. */
|
|
33
|
+
getHoldDuration(action: string): number;
|
|
34
|
+
/** Whether the action has been held for at least `minTime` ms. */
|
|
35
|
+
isHeldFor(action: string, minTime: number): boolean;
|
|
36
|
+
/** Returns -1, 0, or 1 based on negative/positive action states. */
|
|
37
|
+
getAxis(negative: string, positive: string): number;
|
|
38
|
+
/** Returns a Vec2 from four directional actions. Not normalized. */
|
|
39
|
+
getVector(left: string, right: string, up: string, down: string): Vec2;
|
|
40
|
+
/** Pointer position in world coordinates (via Camera), or screen coords if no camera. */
|
|
41
|
+
getPointerPosition(): Vec2;
|
|
42
|
+
/** Raw pointer position in screen coordinates. */
|
|
43
|
+
getPointerScreenPosition(): Vec2;
|
|
44
|
+
/** Whether any pointer button is currently held. */
|
|
45
|
+
isPointerDown(): boolean;
|
|
46
|
+
/** Replace the entire action map and store it as the default for {@link resetBindings}. */
|
|
47
|
+
setActionMap(actions: ActionMapDefinition): void;
|
|
48
|
+
/** Add a key binding to an action. Creates the action if it doesn't exist. */
|
|
49
|
+
bindKey(action: string, key: string): void;
|
|
50
|
+
/** Remove a key binding from an action. */
|
|
51
|
+
unbindKey(action: string, key: string): void;
|
|
52
|
+
/** Returns the current key bindings for an action, or an empty array if unmapped. */
|
|
53
|
+
getBindings(action: string): readonly string[];
|
|
54
|
+
/** Returns all action names that have the given key bound. */
|
|
55
|
+
getActionsForKey(key: string): string[];
|
|
56
|
+
/**
|
|
57
|
+
* Rebind a key to an action with optional conflict detection.
|
|
58
|
+
* Conflicts are only detected between actions sharing at least one group.
|
|
59
|
+
*/
|
|
60
|
+
rebind(action: string, key: string, opts?: RebindOptions): RebindResult;
|
|
61
|
+
/**
|
|
62
|
+
* Finds the first action that uses the given key AND shares at least one
|
|
63
|
+
* group with the target action. Ungrouped actions never conflict.
|
|
64
|
+
*/
|
|
65
|
+
private findConflictInGroups;
|
|
66
|
+
/** Reset bindings to defaults. If an action name is provided, only reset that action. */
|
|
67
|
+
resetBindings(action?: string): void;
|
|
68
|
+
/** Export the current bindings as a plain object for serialization. */
|
|
69
|
+
exportBindings(): ActionMapDefinition;
|
|
70
|
+
/** Load bindings from a plain object. Resets to defaults first, then overlays the provided map. */
|
|
71
|
+
loadBindings(map: ActionMapDefinition): void;
|
|
72
|
+
/** Configure input groups. Group name -> array of action names. */
|
|
73
|
+
setGroups(groups: Record<string, string[]>): void;
|
|
74
|
+
/** Enable a group by name. */
|
|
75
|
+
enableGroup(name: string): void;
|
|
76
|
+
/** Disable a group by name. Actions only in disabled groups become inactive. */
|
|
77
|
+
disableGroup(name: string): void;
|
|
78
|
+
/** Set exactly these groups as active; all others are disabled. */
|
|
79
|
+
setActiveGroups(names: string[]): void;
|
|
80
|
+
/** Whether a group is currently enabled. Returns true for unknown group names. */
|
|
81
|
+
isGroupEnabled(name: string): boolean;
|
|
82
|
+
/** Get all configured group names. */
|
|
83
|
+
getGroups(): string[];
|
|
84
|
+
/** Get the action names belonging to a group. Returns empty array for unknown groups. */
|
|
85
|
+
getGroupActions(name: string): readonly string[];
|
|
86
|
+
/** Returns true if the action is ungrouped or any of its groups is enabled. */
|
|
87
|
+
private isActionEnabled;
|
|
88
|
+
/** Returns a promise that resolves with the next key code pressed. Intercepts the key. */
|
|
89
|
+
listenForNextKey(): Promise<string | null>;
|
|
90
|
+
/** Cancel an active {@link listenForNextKey}. Resolves the pending promise with `null`. */
|
|
91
|
+
cancelListen(): void;
|
|
92
|
+
/** Public wrapper for synthetic key-down injection. */
|
|
93
|
+
fireKeyDown(code: string): void;
|
|
94
|
+
/** Public wrapper for synthetic key-up injection. */
|
|
95
|
+
fireKeyUp(code: string): void;
|
|
96
|
+
/** Public wrapper for synthetic pointer movement. */
|
|
97
|
+
firePointerMove(screenX: number, screenY: number): void;
|
|
98
|
+
/** Public wrapper for synthetic pointer-button presses. */
|
|
99
|
+
firePointerDown(button?: 0 | 1 | 2): void;
|
|
100
|
+
/** Public wrapper for synthetic pointer-button releases. */
|
|
101
|
+
firePointerUp(button?: 0 | 1 | 2): void;
|
|
102
|
+
/** Store synthetic gamepad button state. */
|
|
103
|
+
fireGamepadButton(idx: number, pressed: boolean): void;
|
|
104
|
+
/** Store synthetic gamepad axis state. */
|
|
105
|
+
fireGamepadAxis(idx: number, value: number): void;
|
|
106
|
+
/** Inject a one-frame synthetic action pulse. */
|
|
107
|
+
fireAction(name: string): void;
|
|
108
|
+
/** Release all synthetic and physical input state. */
|
|
109
|
+
clearAll(): void;
|
|
110
|
+
/** Release any pressed pointer buttons without touching keyboard state. */
|
|
111
|
+
clearPointerButtons(): void;
|
|
112
|
+
/** Snapshot of current held input state for inspector tooling. */
|
|
113
|
+
snapshotState(): {
|
|
114
|
+
keys: string[];
|
|
115
|
+
actions: string[];
|
|
116
|
+
mouse: {
|
|
117
|
+
x: number;
|
|
118
|
+
y: number;
|
|
119
|
+
buttons: number[];
|
|
120
|
+
down: boolean;
|
|
121
|
+
};
|
|
122
|
+
gamepad: {
|
|
123
|
+
buttons: number[];
|
|
124
|
+
axes: Array<{
|
|
125
|
+
index: number;
|
|
126
|
+
value: number;
|
|
127
|
+
}>;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
/** @internal */
|
|
131
|
+
_onKeyDown(code: string): void;
|
|
132
|
+
/** @internal */
|
|
133
|
+
_onKeyUp(code: string): void;
|
|
134
|
+
/** @internal */
|
|
135
|
+
_onPointerMove(screenX: number, screenY: number): void;
|
|
136
|
+
/** @internal */
|
|
137
|
+
_onPointerDown(): void;
|
|
138
|
+
/** @internal */
|
|
139
|
+
_onPointerUp(): void;
|
|
140
|
+
/** @internal Clear per-frame justPressed/justReleased flags. */
|
|
141
|
+
_clearFrameState(): void;
|
|
142
|
+
/** Set camera for pointer world-coord conversion. */
|
|
143
|
+
setCamera(camera: CameraLike): void;
|
|
144
|
+
/** Clear the camera reference (e.g. on scene exit). */
|
|
145
|
+
clearCamera(): void;
|
|
146
|
+
/** Get all configured action names. */
|
|
147
|
+
getActionNames(): string[];
|
|
148
|
+
/** @internal Advance the elapsed game-time clock. Called by InputPollSystem. */
|
|
149
|
+
_advanceTime(dtMs: number): void;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Service key for the InputManager. */
|
|
153
|
+
declare const InputManagerKey: ServiceKey<InputManager>;
|
|
154
|
+
/** Minimal camera surface needed by InputManager for pointer world-coord conversion. */
|
|
155
|
+
interface CameraLike {
|
|
156
|
+
screenToWorld(screenX: number, screenY: number): {
|
|
157
|
+
x: number;
|
|
158
|
+
y: number;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Minimal renderer surface needed by InputPlugin for canvas access and
|
|
163
|
+
* coordinate mapping. Alias of the cross-package `RendererAdapter` contract.
|
|
164
|
+
*/
|
|
165
|
+
type RendererLike = RendererAdapter;
|
|
166
|
+
/** Configuration for the InputPlugin. */
|
|
167
|
+
interface InputConfig {
|
|
168
|
+
/** Target element for pointer events (default: canvas from renderer, or document). */
|
|
169
|
+
target?: HTMLElement;
|
|
170
|
+
/** Action map: action name -> array of physical key codes. */
|
|
171
|
+
actions?: ActionMapDefinition;
|
|
172
|
+
/** Input groups: group name -> array of action names belonging to it. */
|
|
173
|
+
groups?: Record<string, string[]>;
|
|
174
|
+
/** Key codes to call preventDefault() on (default: none). */
|
|
175
|
+
preventDefaultKeys?: string[];
|
|
176
|
+
/**
|
|
177
|
+
* Optional override for the renderer service key. When omitted, InputPlugin
|
|
178
|
+
* auto-resolves `RendererAdapterKey` — the canonical `@yagejs/renderer`
|
|
179
|
+
* plugin registers itself under that key, so pointer events target its
|
|
180
|
+
* canvas and coordinates route through `canvasToVirtual` out of the box.
|
|
181
|
+
* Set this only if you ship a custom renderer registered under a different
|
|
182
|
+
* key.
|
|
183
|
+
*/
|
|
184
|
+
rendererKey?: ServiceKey<RendererAdapter>;
|
|
185
|
+
}
|
|
186
|
+
/** Maps action names to arrays of physical key codes. */
|
|
187
|
+
type ActionMapDefinition = Record<string, string[]>;
|
|
188
|
+
/** How to handle a conflict when rebinding a key already used by another action in the same group. */
|
|
189
|
+
type InputConflictPolicy = "replace" | "keep-both" | "reject";
|
|
190
|
+
/** Options for {@link InputManager.rebind}. */
|
|
191
|
+
interface RebindOptions {
|
|
192
|
+
/** Index of the binding slot to replace. Appends if the slot does not exist. */
|
|
193
|
+
slot?: number;
|
|
194
|
+
/** How to resolve conflicts with other actions in the same group(s). Default: `"reject"`. */
|
|
195
|
+
conflict?: InputConflictPolicy;
|
|
196
|
+
}
|
|
197
|
+
/** Result of a {@link InputManager.rebind} call. */
|
|
198
|
+
interface RebindResult {
|
|
199
|
+
/** Whether the rebind succeeded. */
|
|
200
|
+
ok: boolean;
|
|
201
|
+
/** Present when `ok` is false due to a conflict with `conflict: "reject"`. */
|
|
202
|
+
conflict?: {
|
|
203
|
+
action: string;
|
|
204
|
+
key: string;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { type ActionMapDefinition as A, type CameraLike as C, type InputConfig as I, type RebindOptions as R, type InputConflictPolicy as a, InputManager as b, InputManagerKey as c, type RebindResult as d, type RendererLike as e };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { Vec2, ServiceKey, RendererAdapter } from '@yagejs/core';
|
|
2
|
+
|
|
3
|
+
/** Central input state manager. Resolved via DI with InputManagerKey. */
|
|
4
|
+
declare class InputManager {
|
|
5
|
+
private pressedKeys;
|
|
6
|
+
private justPressedKeys;
|
|
7
|
+
private justReleasedKeys;
|
|
8
|
+
private holdStart;
|
|
9
|
+
private syntheticPressedActions;
|
|
10
|
+
private syntheticActionStarts;
|
|
11
|
+
private actionMap;
|
|
12
|
+
private defaultBindings;
|
|
13
|
+
private groups;
|
|
14
|
+
private actionGroups;
|
|
15
|
+
private disabledGroups;
|
|
16
|
+
private pointerScreenPos;
|
|
17
|
+
private pointerDownState;
|
|
18
|
+
private pressedMouseButtons;
|
|
19
|
+
private gamepadButtons;
|
|
20
|
+
private gamepadAxes;
|
|
21
|
+
private camera;
|
|
22
|
+
private elapsedMs;
|
|
23
|
+
private listenResolve;
|
|
24
|
+
/** Whether any key mapped to this action is currently held. */
|
|
25
|
+
isPressed(action: string): boolean;
|
|
26
|
+
/** Whether any key mapped to this action was pressed this frame. */
|
|
27
|
+
isJustPressed(action: string): boolean;
|
|
28
|
+
/** Whether any key mapped to this action was released this frame. */
|
|
29
|
+
isJustReleased(action: string): boolean;
|
|
30
|
+
/** Returns true if any key bound to the action exists in the given set. */
|
|
31
|
+
private anyKeyInSet;
|
|
32
|
+
/** Milliseconds the action has been held. Returns 0 if not held. */
|
|
33
|
+
getHoldDuration(action: string): number;
|
|
34
|
+
/** Whether the action has been held for at least `minTime` ms. */
|
|
35
|
+
isHeldFor(action: string, minTime: number): boolean;
|
|
36
|
+
/** Returns -1, 0, or 1 based on negative/positive action states. */
|
|
37
|
+
getAxis(negative: string, positive: string): number;
|
|
38
|
+
/** Returns a Vec2 from four directional actions. Not normalized. */
|
|
39
|
+
getVector(left: string, right: string, up: string, down: string): Vec2;
|
|
40
|
+
/** Pointer position in world coordinates (via Camera), or screen coords if no camera. */
|
|
41
|
+
getPointerPosition(): Vec2;
|
|
42
|
+
/** Raw pointer position in screen coordinates. */
|
|
43
|
+
getPointerScreenPosition(): Vec2;
|
|
44
|
+
/** Whether any pointer button is currently held. */
|
|
45
|
+
isPointerDown(): boolean;
|
|
46
|
+
/** Replace the entire action map and store it as the default for {@link resetBindings}. */
|
|
47
|
+
setActionMap(actions: ActionMapDefinition): void;
|
|
48
|
+
/** Add a key binding to an action. Creates the action if it doesn't exist. */
|
|
49
|
+
bindKey(action: string, key: string): void;
|
|
50
|
+
/** Remove a key binding from an action. */
|
|
51
|
+
unbindKey(action: string, key: string): void;
|
|
52
|
+
/** Returns the current key bindings for an action, or an empty array if unmapped. */
|
|
53
|
+
getBindings(action: string): readonly string[];
|
|
54
|
+
/** Returns all action names that have the given key bound. */
|
|
55
|
+
getActionsForKey(key: string): string[];
|
|
56
|
+
/**
|
|
57
|
+
* Rebind a key to an action with optional conflict detection.
|
|
58
|
+
* Conflicts are only detected between actions sharing at least one group.
|
|
59
|
+
*/
|
|
60
|
+
rebind(action: string, key: string, opts?: RebindOptions): RebindResult;
|
|
61
|
+
/**
|
|
62
|
+
* Finds the first action that uses the given key AND shares at least one
|
|
63
|
+
* group with the target action. Ungrouped actions never conflict.
|
|
64
|
+
*/
|
|
65
|
+
private findConflictInGroups;
|
|
66
|
+
/** Reset bindings to defaults. If an action name is provided, only reset that action. */
|
|
67
|
+
resetBindings(action?: string): void;
|
|
68
|
+
/** Export the current bindings as a plain object for serialization. */
|
|
69
|
+
exportBindings(): ActionMapDefinition;
|
|
70
|
+
/** Load bindings from a plain object. Resets to defaults first, then overlays the provided map. */
|
|
71
|
+
loadBindings(map: ActionMapDefinition): void;
|
|
72
|
+
/** Configure input groups. Group name -> array of action names. */
|
|
73
|
+
setGroups(groups: Record<string, string[]>): void;
|
|
74
|
+
/** Enable a group by name. */
|
|
75
|
+
enableGroup(name: string): void;
|
|
76
|
+
/** Disable a group by name. Actions only in disabled groups become inactive. */
|
|
77
|
+
disableGroup(name: string): void;
|
|
78
|
+
/** Set exactly these groups as active; all others are disabled. */
|
|
79
|
+
setActiveGroups(names: string[]): void;
|
|
80
|
+
/** Whether a group is currently enabled. Returns true for unknown group names. */
|
|
81
|
+
isGroupEnabled(name: string): boolean;
|
|
82
|
+
/** Get all configured group names. */
|
|
83
|
+
getGroups(): string[];
|
|
84
|
+
/** Get the action names belonging to a group. Returns empty array for unknown groups. */
|
|
85
|
+
getGroupActions(name: string): readonly string[];
|
|
86
|
+
/** Returns true if the action is ungrouped or any of its groups is enabled. */
|
|
87
|
+
private isActionEnabled;
|
|
88
|
+
/** Returns a promise that resolves with the next key code pressed. Intercepts the key. */
|
|
89
|
+
listenForNextKey(): Promise<string | null>;
|
|
90
|
+
/** Cancel an active {@link listenForNextKey}. Resolves the pending promise with `null`. */
|
|
91
|
+
cancelListen(): void;
|
|
92
|
+
/** Public wrapper for synthetic key-down injection. */
|
|
93
|
+
fireKeyDown(code: string): void;
|
|
94
|
+
/** Public wrapper for synthetic key-up injection. */
|
|
95
|
+
fireKeyUp(code: string): void;
|
|
96
|
+
/** Public wrapper for synthetic pointer movement. */
|
|
97
|
+
firePointerMove(screenX: number, screenY: number): void;
|
|
98
|
+
/** Public wrapper for synthetic pointer-button presses. */
|
|
99
|
+
firePointerDown(button?: 0 | 1 | 2): void;
|
|
100
|
+
/** Public wrapper for synthetic pointer-button releases. */
|
|
101
|
+
firePointerUp(button?: 0 | 1 | 2): void;
|
|
102
|
+
/** Store synthetic gamepad button state. */
|
|
103
|
+
fireGamepadButton(idx: number, pressed: boolean): void;
|
|
104
|
+
/** Store synthetic gamepad axis state. */
|
|
105
|
+
fireGamepadAxis(idx: number, value: number): void;
|
|
106
|
+
/** Inject a one-frame synthetic action pulse. */
|
|
107
|
+
fireAction(name: string): void;
|
|
108
|
+
/** Release all synthetic and physical input state. */
|
|
109
|
+
clearAll(): void;
|
|
110
|
+
/** Release any pressed pointer buttons without touching keyboard state. */
|
|
111
|
+
clearPointerButtons(): void;
|
|
112
|
+
/** Snapshot of current held input state for inspector tooling. */
|
|
113
|
+
snapshotState(): {
|
|
114
|
+
keys: string[];
|
|
115
|
+
actions: string[];
|
|
116
|
+
mouse: {
|
|
117
|
+
x: number;
|
|
118
|
+
y: number;
|
|
119
|
+
buttons: number[];
|
|
120
|
+
down: boolean;
|
|
121
|
+
};
|
|
122
|
+
gamepad: {
|
|
123
|
+
buttons: number[];
|
|
124
|
+
axes: Array<{
|
|
125
|
+
index: number;
|
|
126
|
+
value: number;
|
|
127
|
+
}>;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
/** @internal */
|
|
131
|
+
_onKeyDown(code: string): void;
|
|
132
|
+
/** @internal */
|
|
133
|
+
_onKeyUp(code: string): void;
|
|
134
|
+
/** @internal */
|
|
135
|
+
_onPointerMove(screenX: number, screenY: number): void;
|
|
136
|
+
/** @internal */
|
|
137
|
+
_onPointerDown(): void;
|
|
138
|
+
/** @internal */
|
|
139
|
+
_onPointerUp(): void;
|
|
140
|
+
/** @internal Clear per-frame justPressed/justReleased flags. */
|
|
141
|
+
_clearFrameState(): void;
|
|
142
|
+
/** Set camera for pointer world-coord conversion. */
|
|
143
|
+
setCamera(camera: CameraLike): void;
|
|
144
|
+
/** Clear the camera reference (e.g. on scene exit). */
|
|
145
|
+
clearCamera(): void;
|
|
146
|
+
/** Get all configured action names. */
|
|
147
|
+
getActionNames(): string[];
|
|
148
|
+
/** @internal Advance the elapsed game-time clock. Called by InputPollSystem. */
|
|
149
|
+
_advanceTime(dtMs: number): void;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Service key for the InputManager. */
|
|
153
|
+
declare const InputManagerKey: ServiceKey<InputManager>;
|
|
154
|
+
/** Minimal camera surface needed by InputManager for pointer world-coord conversion. */
|
|
155
|
+
interface CameraLike {
|
|
156
|
+
screenToWorld(screenX: number, screenY: number): {
|
|
157
|
+
x: number;
|
|
158
|
+
y: number;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Minimal renderer surface needed by InputPlugin for canvas access and
|
|
163
|
+
* coordinate mapping. Alias of the cross-package `RendererAdapter` contract.
|
|
164
|
+
*/
|
|
165
|
+
type RendererLike = RendererAdapter;
|
|
166
|
+
/** Configuration for the InputPlugin. */
|
|
167
|
+
interface InputConfig {
|
|
168
|
+
/** Target element for pointer events (default: canvas from renderer, or document). */
|
|
169
|
+
target?: HTMLElement;
|
|
170
|
+
/** Action map: action name -> array of physical key codes. */
|
|
171
|
+
actions?: ActionMapDefinition;
|
|
172
|
+
/** Input groups: group name -> array of action names belonging to it. */
|
|
173
|
+
groups?: Record<string, string[]>;
|
|
174
|
+
/** Key codes to call preventDefault() on (default: none). */
|
|
175
|
+
preventDefaultKeys?: string[];
|
|
176
|
+
/**
|
|
177
|
+
* Optional override for the renderer service key. When omitted, InputPlugin
|
|
178
|
+
* auto-resolves `RendererAdapterKey` — the canonical `@yagejs/renderer`
|
|
179
|
+
* plugin registers itself under that key, so pointer events target its
|
|
180
|
+
* canvas and coordinates route through `canvasToVirtual` out of the box.
|
|
181
|
+
* Set this only if you ship a custom renderer registered under a different
|
|
182
|
+
* key.
|
|
183
|
+
*/
|
|
184
|
+
rendererKey?: ServiceKey<RendererAdapter>;
|
|
185
|
+
}
|
|
186
|
+
/** Maps action names to arrays of physical key codes. */
|
|
187
|
+
type ActionMapDefinition = Record<string, string[]>;
|
|
188
|
+
/** How to handle a conflict when rebinding a key already used by another action in the same group. */
|
|
189
|
+
type InputConflictPolicy = "replace" | "keep-both" | "reject";
|
|
190
|
+
/** Options for {@link InputManager.rebind}. */
|
|
191
|
+
interface RebindOptions {
|
|
192
|
+
/** Index of the binding slot to replace. Appends if the slot does not exist. */
|
|
193
|
+
slot?: number;
|
|
194
|
+
/** How to resolve conflicts with other actions in the same group(s). Default: `"reject"`. */
|
|
195
|
+
conflict?: InputConflictPolicy;
|
|
196
|
+
}
|
|
197
|
+
/** Result of a {@link InputManager.rebind} call. */
|
|
198
|
+
interface RebindResult {
|
|
199
|
+
/** Whether the rebind succeeded. */
|
|
200
|
+
ok: boolean;
|
|
201
|
+
/** Present when `ok` is false due to a conflict with `conflict: "reject"`. */
|
|
202
|
+
conflict?: {
|
|
203
|
+
action: string;
|
|
204
|
+
key: string;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { type ActionMapDefinition as A, type CameraLike as C, type InputConfig as I, type RebindOptions as R, type InputConflictPolicy as a, InputManager as b, InputManagerKey as c, type RebindResult as d, type RendererLike as e };
|
package/dist/api.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/api.ts
|
|
21
|
+
var api_exports = {};
|
|
22
|
+
__export(api_exports, {
|
|
23
|
+
InputManagerKey: () => InputManagerKey
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(api_exports);
|
|
26
|
+
|
|
27
|
+
// src/types.ts
|
|
28
|
+
var import_core = require("@yagejs/core");
|
|
29
|
+
var InputManagerKey = new import_core.ServiceKey("inputManager");
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
InputManagerKey
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=api.cjs.map
|
package/dist/api.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/api.ts","../src/types.ts"],"sourcesContent":["export { InputManagerKey } from \"./types.js\";\nexport type { InputConfig } from \"./types.js\";\n","import { ServiceKey } from \"@yagejs/core\";\nimport type { RendererAdapter } from \"@yagejs/core\";\nimport type { InputManager } from \"./InputManager.js\";\n\n/** Service key for the InputManager. */\nexport const InputManagerKey = new ServiceKey<InputManager>(\"inputManager\");\n\n/** Minimal camera surface needed by InputManager for pointer world-coord conversion. */\nexport interface CameraLike {\n screenToWorld(screenX: number, screenY: number): { x: number; y: number };\n}\n\n/**\n * Minimal renderer surface needed by InputPlugin for canvas access and\n * coordinate mapping. Alias of the cross-package `RendererAdapter` contract.\n */\nexport type RendererLike = RendererAdapter;\n\n/** Configuration for the InputPlugin. */\nexport interface InputConfig {\n /** Target element for pointer events (default: canvas from renderer, or document). */\n target?: HTMLElement;\n /** Action map: action name -> array of physical key codes. */\n actions?: ActionMapDefinition;\n /** Input groups: group name -> array of action names belonging to it. */\n groups?: Record<string, string[]>;\n /** Key codes to call preventDefault() on (default: none). */\n preventDefaultKeys?: string[];\n /**\n * Optional override for the renderer service key. When omitted, InputPlugin\n * auto-resolves `RendererAdapterKey` — the canonical `@yagejs/renderer`\n * plugin registers itself under that key, so pointer events target its\n * canvas and coordinates route through `canvasToVirtual` out of the box.\n * Set this only if you ship a custom renderer registered under a different\n * key.\n */\n rendererKey?: ServiceKey<RendererAdapter>;\n}\n\n/** Maps action names to arrays of physical key codes. */\nexport type ActionMapDefinition = Record<string, string[]>;\n\n/** How to handle a conflict when rebinding a key already used by another action in the same group. */\nexport type InputConflictPolicy = \"replace\" | \"keep-both\" | \"reject\";\n\n/** Options for {@link InputManager.rebind}. */\nexport interface RebindOptions {\n /** Index of the binding slot to replace. Appends if the slot does not exist. */\n slot?: number;\n /** How to resolve conflicts with other actions in the same group(s). Default: `\"reject\"`. */\n conflict?: InputConflictPolicy;\n}\n\n/** Result of a {@link InputManager.rebind} call. */\nexport interface RebindResult {\n /** Whether the rebind succeeded. */\n ok: boolean;\n /** Present when `ok` is false due to a conflict with `conflict: \"reject\"`. */\n conflict?: { action: string; key: string };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA2B;AAKpB,IAAM,kBAAkB,IAAI,uBAAyB,cAAc;","names":[]}
|
package/dist/api.d.cts
ADDED
package/dist/api.d.ts
ADDED
package/dist/api.js
ADDED
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/types.ts
|
|
5
|
+
import { ServiceKey } from "@yagejs/core";
|
|
6
|
+
var InputManagerKey = new ServiceKey("inputManager");
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
__name,
|
|
10
|
+
InputManagerKey
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=chunk-CYWOKPMI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import { ServiceKey } from \"@yagejs/core\";\nimport type { RendererAdapter } from \"@yagejs/core\";\nimport type { InputManager } from \"./InputManager.js\";\n\n/** Service key for the InputManager. */\nexport const InputManagerKey = new ServiceKey<InputManager>(\"inputManager\");\n\n/** Minimal camera surface needed by InputManager for pointer world-coord conversion. */\nexport interface CameraLike {\n screenToWorld(screenX: number, screenY: number): { x: number; y: number };\n}\n\n/**\n * Minimal renderer surface needed by InputPlugin for canvas access and\n * coordinate mapping. Alias of the cross-package `RendererAdapter` contract.\n */\nexport type RendererLike = RendererAdapter;\n\n/** Configuration for the InputPlugin. */\nexport interface InputConfig {\n /** Target element for pointer events (default: canvas from renderer, or document). */\n target?: HTMLElement;\n /** Action map: action name -> array of physical key codes. */\n actions?: ActionMapDefinition;\n /** Input groups: group name -> array of action names belonging to it. */\n groups?: Record<string, string[]>;\n /** Key codes to call preventDefault() on (default: none). */\n preventDefaultKeys?: string[];\n /**\n * Optional override for the renderer service key. When omitted, InputPlugin\n * auto-resolves `RendererAdapterKey` — the canonical `@yagejs/renderer`\n * plugin registers itself under that key, so pointer events target its\n * canvas and coordinates route through `canvasToVirtual` out of the box.\n * Set this only if you ship a custom renderer registered under a different\n * key.\n */\n rendererKey?: ServiceKey<RendererAdapter>;\n}\n\n/** Maps action names to arrays of physical key codes. */\nexport type ActionMapDefinition = Record<string, string[]>;\n\n/** How to handle a conflict when rebinding a key already used by another action in the same group. */\nexport type InputConflictPolicy = \"replace\" | \"keep-both\" | \"reject\";\n\n/** Options for {@link InputManager.rebind}. */\nexport interface RebindOptions {\n /** Index of the binding slot to replace. Appends if the slot does not exist. */\n slot?: number;\n /** How to resolve conflicts with other actions in the same group(s). Default: `\"reject\"`. */\n conflict?: InputConflictPolicy;\n}\n\n/** Result of a {@link InputManager.rebind} call. */\nexport interface RebindResult {\n /** Whether the rebind succeeded. */\n ok: boolean;\n /** Present when `ok` is false due to a conflict with `conflict: \"reject\"`. */\n conflict?: { action: string; key: string };\n}\n"],"mappings":";;;;AAAA,SAAS,kBAAkB;AAKpB,IAAM,kBAAkB,IAAI,WAAyB,cAAc;","names":[]}
|