@typeonce/ritmo-browser 0.10.0 → 0.12.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 +106 -0
- package/README.md +6 -1
- package/dist/Controls.d.ts +496 -0
- package/dist/Controls.d.ts.map +1 -0
- package/dist/Controls.js +343 -0
- package/dist/Controls.js.map +1 -0
- package/dist/Gamepad.d.ts +376 -0
- package/dist/Gamepad.d.ts.map +1 -0
- package/dist/Gamepad.js +459 -0
- package/dist/Gamepad.js.map +1 -0
- package/dist/InputCapture.d.ts +46 -16
- package/dist/InputCapture.d.ts.map +1 -1
- package/dist/InputCapture.js +1 -1
- package/dist/InputCapture.js.map +1 -1
- package/dist/Keyboard.d.ts +177 -25
- package/dist/Keyboard.d.ts.map +1 -1
- package/dist/Keyboard.js +257 -91
- package/dist/Keyboard.js.map +1 -1
- package/dist/Pointer.d.ts +233 -64
- package/dist/Pointer.d.ts.map +1 -1
- package/dist/Pointer.js +205 -145
- package/dist/Pointer.js.map +1 -1
- package/dist/Touch.d.ts +75 -33
- package/dist/Touch.d.ts.map +1 -1
- package/dist/Touch.js +25 -30
- package/dist/Touch.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/buttons.d.ts +52 -0
- package/dist/internal/buttons.d.ts.map +1 -0
- package/dist/internal/buttons.js +211 -0
- package/dist/internal/buttons.js.map +1 -0
- package/dist/internal/introspect.d.ts +14 -0
- package/dist/internal/introspect.d.ts.map +1 -0
- package/dist/internal/introspect.js +19 -0
- package/dist/internal/introspect.js.map +1 -0
- package/dist/internal/state.d.ts +13 -0
- package/dist/internal/state.d.ts.map +1 -0
- package/dist/internal/state.js +2 -0
- package/dist/internal/state.js.map +1 -0
- package/dist/internal/used.d.ts +8 -0
- package/dist/internal/used.d.ts.map +1 -0
- package/dist/internal/used.js +14 -0
- package/dist/internal/used.js.map +1 -0
- package/dist/internal/vectors.d.ts +29 -0
- package/dist/internal/vectors.d.ts.map +1 -0
- package/dist/internal/vectors.js +22 -0
- package/dist/internal/vectors.js.map +1 -0
- package/package.json +4 -3
- package/src/Controls.ts +800 -0
- package/src/Gamepad.ts +752 -0
- package/src/InputCapture.ts +43 -24
- package/src/Keyboard.ts +387 -72
- package/src/Pointer.ts +392 -166
- package/src/Touch.ts +113 -61
- package/src/index.ts +10 -1
- package/src/internal/buttons.ts +222 -0
- package/src/internal/introspect.ts +23 -0
- package/src/internal/state.ts +12 -0
- package/src/internal/used.ts +14 -0
- package/src/internal/vectors.ts +41 -0
package/dist/Pointer.d.ts
CHANGED
|
@@ -1,68 +1,173 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Mouse and pen input over one element:
|
|
3
|
-
* are ignored by default; on-screen touch controls are
|
|
2
|
+
* Mouse and pen input over one element: bound actions, raw buttons, and the
|
|
3
|
+
* position. Touches are ignored by default; on-screen touch controls are
|
|
4
|
+
* `Touch`.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
* actions
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
6
|
+
* `Pointer.actions(target, window, bindings)` binds game actions to
|
|
7
|
+
* buttons, like `Keyboard.actions` and `Gamepad.actions`, so the pointer
|
|
8
|
+
* merges into `Controls` (group it with the keyboard there, so the two count
|
|
9
|
+
* as one device for `lastUsed` and `available`). Games that aim with the
|
|
10
|
+
* mouse read `position`. The module owns the browser plumbing:
|
|
11
|
+
* element-relative coordinates, press/release edges that survive clicks
|
|
12
|
+
* shorter than one frame, pointer capture so a release outside the element
|
|
13
|
+
* is still seen, suppressing the context menu, clearing buttons on window
|
|
14
|
+
* blur, and listener cleanup. It does not know about the ECS;
|
|
15
|
+
* `InputCapture.system(...)` copies snapshots into a resource.
|
|
13
16
|
*
|
|
14
17
|
* Positions are in CSS pixels relative to the element's top-left corner.
|
|
15
18
|
* Converting them into world coordinates (camera, zoom, projection) is game
|
|
16
|
-
* code.
|
|
19
|
+
* code. `rebind(...)` swaps the buttons of the same actions, and
|
|
20
|
+
* `parseRebinding(...)` validates saved ones.
|
|
21
|
+
*
|
|
22
|
+
* The wheel reports both ways games use it: `wheel` is how far it scrolled
|
|
23
|
+
* (zoom), and the `wheelUp`/`wheelDown`/`wheelLeft`/`wheelRight` buttons
|
|
24
|
+
* pulse once per notch, so a stepping action (next weapon) binds them and
|
|
25
|
+
* merges with a gamepad bumper. For mouse look, pass `lock: document`: a
|
|
26
|
+
* click locks the pointer to the element, `movement` keeps reporting raw
|
|
27
|
+
* motion, and `locked` turns `false` when the player presses Escape.
|
|
17
28
|
*
|
|
18
29
|
* @module Pointer
|
|
19
30
|
* @docGroup browser
|
|
20
31
|
*
|
|
21
32
|
* @example
|
|
22
33
|
* ```ts
|
|
23
|
-
* const
|
|
34
|
+
* const bindings = { fire: ["primary"], aim: ["secondary"], nextWeapon: ["wheelDown"] } as const
|
|
35
|
+
* const mouse = Pointer.actions(canvas, window, bindings, { lock: document })
|
|
36
|
+
*
|
|
37
|
+
* // Once per update (through InputCapture in a game):
|
|
38
|
+
* const input = mouse.snapshot()
|
|
39
|
+
* aimAt(input.position)
|
|
40
|
+
* if (input.actions.fire.pressed) fire()
|
|
41
|
+
*
|
|
42
|
+
* // Zoom with the wheel, look with a locked pointer:
|
|
43
|
+
* zoomBy(input.wheel.y)
|
|
44
|
+
* if (input.locked) turn(input.movement.x)
|
|
24
45
|
*
|
|
25
|
-
* //
|
|
26
|
-
* const
|
|
27
|
-
*
|
|
28
|
-
* if (snapshot.primary.held) fire()
|
|
46
|
+
* // Settings screen: bind the button the player clicks.
|
|
47
|
+
* const clicked = Pointer.buttonNames.find((button) => input.buttons[button].pressed)
|
|
48
|
+
* if (clicked !== undefined) mouse.rebind({ fire: [clicked], aim: ["secondary"], nextWeapon: ["wheelDown"] })
|
|
29
49
|
*
|
|
30
50
|
* // On teardown:
|
|
31
|
-
*
|
|
51
|
+
* mouse.dispose()
|
|
32
52
|
* ```
|
|
33
53
|
*
|
|
34
|
-
* For tests, replays, and headless runs, `scripted(
|
|
35
|
-
* moves, presses, and releases, and `recording(...)`
|
|
36
|
-
* capture the timeline a session produced.
|
|
37
|
-
* timeline loaded from JSON.
|
|
54
|
+
* For tests, replays, and headless runs, `scripted(bindings, timeline)`
|
|
55
|
+
* plays a timeline of moves, presses, and releases, and `recording(...)`
|
|
56
|
+
* wraps a live pointer to capture the timeline a session produced.
|
|
57
|
+
* `parseTimeline(...)` validates a timeline loaded from JSON.
|
|
38
58
|
*/
|
|
59
|
+
import type * as System from "@typeonce/ritmo/System";
|
|
39
60
|
import * as Result from "@typeonce/ritmo/Result";
|
|
40
|
-
import type { ActionState } from "./
|
|
41
|
-
|
|
42
|
-
/** The buttons
|
|
43
|
-
|
|
61
|
+
import type { ActionState } from "./internal/state.ts";
|
|
62
|
+
import * as ButtonsInternal from "./internal/buttons.ts";
|
|
63
|
+
/** The physical buttons, in `PointerEvent.button` order 0 to 4. */
|
|
64
|
+
declare const physicalButtons: readonly ["primary", "middle", "secondary", "back", "forward"];
|
|
65
|
+
/** A button that goes down and up, unlike the wheel's pulses: what a timeline presses and releases. */
|
|
66
|
+
export type PhysicalButton = (typeof physicalButtons)[number];
|
|
67
|
+
/**
|
|
68
|
+
* The buttons a snapshot reports: the main (usually left) button, the wheel
|
|
69
|
+
* button, the secondary (usually right) button, the side buttons, then the
|
|
70
|
+
* wheel's four directions. A wheel direction is a pulse, pressed and
|
|
71
|
+
* released in the same window, once per {@link wheelStep} pixels scrolled,
|
|
72
|
+
* so it binds actions that step (next weapon) and merges with a gamepad
|
|
73
|
+
* bumper in `Controls`; read the snapshot's `wheel` for how far it scrolled
|
|
74
|
+
* (zoom).
|
|
75
|
+
*/
|
|
76
|
+
export declare const buttonNames: readonly ["primary", "middle", "secondary", "back", "forward", "wheelUp", "wheelDown", "wheelLeft", "wheelRight"];
|
|
77
|
+
/** One pointer button, see {@link buttonNames}. */
|
|
78
|
+
export type Button = (typeof buttonNames)[number];
|
|
79
|
+
/** Pixels scrolled per wheel pulse: one notch of a typical mouse wheel. */
|
|
80
|
+
export declare const wheelStep = 100;
|
|
81
|
+
/** Whether `name` is a pointer button, for validating stored bindings. */
|
|
82
|
+
export declare const isButton: (name: unknown) => name is Button;
|
|
83
|
+
/**
|
|
84
|
+
* Action name to the buttons that trigger it. Every action needs at least
|
|
85
|
+
* one button; `{}` tracks the position and raw buttons only.
|
|
86
|
+
*/
|
|
87
|
+
export type Bindings = Readonly<Record<string, readonly [Button, ...Array<Button>]>>;
|
|
88
|
+
/**
|
|
89
|
+
* New buttons for the same actions, for {@link Actions.rebind}. Load saved
|
|
90
|
+
* ones with {@link parseRebinding}.
|
|
91
|
+
*/
|
|
92
|
+
export type Rebinding<B extends Bindings> = {
|
|
93
|
+
readonly [Action in keyof B]: readonly [Button, ...Array<Button>];
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Rejects actions a rebinding names that the bindings do not have, so
|
|
97
|
+
* {@link Actions.rebind} takes exactly the actions it was made with.
|
|
98
|
+
*/
|
|
99
|
+
export type OnlyActionsOf<R, B extends Bindings> = {
|
|
100
|
+
readonly [Name in Exclude<keyof R, keyof B>]: `${Name & string} is not an action of these bindings`;
|
|
101
|
+
};
|
|
44
102
|
/** A position in CSS pixels relative to the element's top-left corner. */
|
|
45
103
|
export interface Position {
|
|
46
104
|
readonly x: number;
|
|
47
105
|
readonly y: number;
|
|
48
106
|
}
|
|
49
|
-
|
|
107
|
+
/** A change in CSS pixels since the previous snapshot. */
|
|
108
|
+
export interface Delta {
|
|
109
|
+
readonly x: number;
|
|
110
|
+
readonly y: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The pointer's state, with the same core as the other devices' snapshots
|
|
114
|
+
* (`actions`, `vectors`, and `used`) so `Controls` can merge it.
|
|
115
|
+
*/
|
|
116
|
+
export interface Snapshot<B extends Bindings> {
|
|
117
|
+
/** Every bound action's state. */
|
|
118
|
+
readonly actions: {
|
|
119
|
+
readonly [Action in keyof B]: ActionState;
|
|
120
|
+
};
|
|
121
|
+
/** None: a pointer binds no vector actions (read `position` and `movement`); there for the snapshot core every device shares. */
|
|
122
|
+
readonly vectors: {
|
|
123
|
+
readonly [Action in never]: Delta;
|
|
124
|
+
};
|
|
125
|
+
/** Every button's state by name, whatever the bindings (capture the button to bind from here). */
|
|
126
|
+
readonly buttons: {
|
|
127
|
+
readonly [Name in Button]: ActionState;
|
|
128
|
+
};
|
|
50
129
|
/** The last position the pointer was seen at, or where it was last left. */
|
|
51
130
|
readonly position: Position;
|
|
131
|
+
/**
|
|
132
|
+
* How far the pointer moved since the previous snapshot, from the raw
|
|
133
|
+
* motion (`movementX`/`movementY`), which keeps coming while the pointer is
|
|
134
|
+
* locked and the position stands still: read it for mouse look.
|
|
135
|
+
*/
|
|
136
|
+
readonly movement: Delta;
|
|
137
|
+
/** How far the wheel scrolled since the previous snapshot, in CSS pixels (positive `y` scrolls down). */
|
|
138
|
+
readonly wheel: Delta;
|
|
52
139
|
/** Whether the pointer is currently over the element (or captured by it). */
|
|
53
140
|
readonly over: boolean;
|
|
54
|
-
readonly primary: ActionState;
|
|
55
|
-
readonly secondary: ActionState;
|
|
56
|
-
readonly middle: ActionState;
|
|
57
|
-
}
|
|
58
|
-
export interface Pointer {
|
|
59
141
|
/**
|
|
60
|
-
*
|
|
142
|
+
* Whether the pointer is locked to the element (with the `lock` option).
|
|
143
|
+
* The player leaves the lock with Escape; show "click to resume" while it
|
|
144
|
+
* is `false`.
|
|
145
|
+
*/
|
|
146
|
+
readonly locked: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Some button was pressed in this window or is held, or the pointer moved
|
|
149
|
+
* or scrolled over the element: the player is using the pointer.
|
|
61
150
|
*/
|
|
62
|
-
|
|
151
|
+
readonly used: boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A pointer bound to actions, built with {@link actions} (live),
|
|
155
|
+
* {@link scripted}, or {@link recording}. Capture it with
|
|
156
|
+
* `InputCapture.system(...)`, or group it with the keyboard in `Controls`.
|
|
157
|
+
*/
|
|
158
|
+
export interface Actions<B extends Bindings> extends System.Consumes<"snapshot"> {
|
|
159
|
+
/** Returns the pointer state and starts a new press/release window. */
|
|
160
|
+
snapshot(): Snapshot<B>;
|
|
63
161
|
/**
|
|
64
|
-
*
|
|
162
|
+
* Binds the same actions to new buttons, from the next snapshot, for a
|
|
163
|
+
* settings screen where players remap controls (capture the button to bind
|
|
164
|
+
* from the snapshot's `buttons`). An action held only through buttons it
|
|
165
|
+
* lost reports `released`; a button held across the rebind holds a newly
|
|
166
|
+
* bound action only once it is pressed again. It takes exactly the actions
|
|
167
|
+
* the pointer was made with.
|
|
65
168
|
*/
|
|
169
|
+
rebind<const R extends Rebinding<B>>(bindings: R & OnlyActionsOf<R, B>): void;
|
|
170
|
+
/** Removes the event listeners. */
|
|
66
171
|
dispose(): void;
|
|
67
172
|
}
|
|
68
173
|
/**
|
|
@@ -71,6 +176,9 @@ export interface Pointer {
|
|
|
71
176
|
export interface PointerEventLike {
|
|
72
177
|
readonly clientX: number;
|
|
73
178
|
readonly clientY: number;
|
|
179
|
+
/** Raw motion since the previous event; events without it count as 0. */
|
|
180
|
+
readonly movementX?: number;
|
|
181
|
+
readonly movementY?: number;
|
|
74
182
|
readonly button: number;
|
|
75
183
|
readonly pointerId: number;
|
|
76
184
|
/** `"mouse"`, `"pen"`, or `"touch"`; events without it count as mouse. */
|
|
@@ -89,12 +197,35 @@ export interface PointerTarget {
|
|
|
89
197
|
removeEventListener(type: "contextmenu", listener: (event: {
|
|
90
198
|
preventDefault(): void;
|
|
91
199
|
}) => void): void;
|
|
200
|
+
addEventListener(type: "wheel", listener: (event: WheelEventLike) => void, options: {
|
|
201
|
+
readonly passive: false;
|
|
202
|
+
}): void;
|
|
203
|
+
removeEventListener(type: "wheel", listener: (event: WheelEventLike) => void): void;
|
|
92
204
|
getBoundingClientRect(): {
|
|
93
205
|
readonly left: number;
|
|
94
206
|
readonly top: number;
|
|
95
207
|
};
|
|
96
208
|
setPointerCapture?(pointerId: number): void;
|
|
97
209
|
releasePointerCapture?(pointerId: number): void;
|
|
210
|
+
/** Called on a click with the `lock` option while the pointer is not locked. */
|
|
211
|
+
requestPointerLock?(): unknown;
|
|
212
|
+
}
|
|
213
|
+
/** The subset of `WheelEvent` the module reads. */
|
|
214
|
+
export interface WheelEventLike {
|
|
215
|
+
readonly deltaX: number;
|
|
216
|
+
readonly deltaY: number;
|
|
217
|
+
/** 0 for pixels, 1 for lines (16 px each), 2 for pages (800 px each). */
|
|
218
|
+
readonly deltaMode: number;
|
|
219
|
+
preventDefault(): void;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Where the pointer lock is observed, usually `document`, for the `lock`
|
|
223
|
+
* option.
|
|
224
|
+
*/
|
|
225
|
+
export interface LockHost {
|
|
226
|
+
readonly pointerLockElement: unknown;
|
|
227
|
+
addEventListener(type: "pointerlockchange", listener: () => void): void;
|
|
228
|
+
removeEventListener(type: "pointerlockchange", listener: () => void): void;
|
|
98
229
|
}
|
|
99
230
|
/**
|
|
100
231
|
* Where window blur is observed, usually `window`. Buttons held when the
|
|
@@ -104,7 +235,8 @@ export interface BlurHost {
|
|
|
104
235
|
addEventListener(type: "blur", listener: () => void): void;
|
|
105
236
|
removeEventListener(type: "blur", listener: () => void): void;
|
|
106
237
|
}
|
|
107
|
-
|
|
238
|
+
/** Options for {@link actions}. */
|
|
239
|
+
export interface ActionsOptions {
|
|
108
240
|
/**
|
|
109
241
|
* Suppress the context menu over the element, so the secondary button is
|
|
110
242
|
* usable. Defaults to `true`.
|
|
@@ -116,59 +248,76 @@ export interface TrackOptions {
|
|
|
116
248
|
* also a click.
|
|
117
249
|
*/
|
|
118
250
|
readonly pointerTypes?: ReadonlyArray<string>;
|
|
251
|
+
/**
|
|
252
|
+
* Keep the page from scrolling while the wheel turns over the element.
|
|
253
|
+
* Defaults to `true`.
|
|
254
|
+
*/
|
|
255
|
+
readonly preventScroll?: boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Lock the pointer to the element on a click, for mouse look: pass where
|
|
258
|
+
* the lock is observed (usually `document`). Browsers grant a lock only
|
|
259
|
+
* inside a click, so the module requests it in its own listener; the
|
|
260
|
+
* click that locks is not reported as a press. Read `locked` and
|
|
261
|
+
* `movement`.
|
|
262
|
+
*/
|
|
263
|
+
readonly lock?: LockHost;
|
|
119
264
|
}
|
|
120
265
|
/**
|
|
121
|
-
* A snapshot with no buttons down, for initializing an input
|
|
122
|
-
* the first capture.
|
|
266
|
+
* A snapshot with no buttons down and no use yet, for initializing an input
|
|
267
|
+
* resource before the first capture.
|
|
123
268
|
*/
|
|
124
|
-
export declare const idle: (position?: Position) => Snapshot
|
|
269
|
+
export declare const idle: <const B extends Bindings>(bindings: B, position?: Position) => Snapshot<B>;
|
|
125
270
|
/**
|
|
126
|
-
* Starts tracking the pointer over `target
|
|
127
|
-
* releases held buttons when the
|
|
271
|
+
* Starts tracking the pointer over `target` with `bindings`, until
|
|
272
|
+
* `dispose()`. `blurHost` (usually `window`) releases held buttons when the
|
|
273
|
+
* page loses focus; a cancelled pointer and leaving the pointer lock release
|
|
274
|
+
* them too. Use `Touch.actions` for on-screen touch controls.
|
|
128
275
|
*/
|
|
129
|
-
export declare const
|
|
276
|
+
export declare const actions: <const B extends Bindings>(target: PointerTarget, blurHost: BlurHost, bindings: B, options?: ActionsOptions) => Actions<B>;
|
|
130
277
|
/**
|
|
131
|
-
* Pointer changes applied just before one snapshot: the move
|
|
132
|
-
* presses, then releases. `frame` is the
|
|
133
|
-
* the first `snapshot()` call. A button
|
|
134
|
-
* is a click shorter than a frame.
|
|
278
|
+
* Pointer changes applied just before one snapshot: the move, the raw
|
|
279
|
+
* motion, and the wheel first, then presses, then releases. `frame` is the
|
|
280
|
+
* snapshot's index, counting from 0 at the first `snapshot()` call. A button
|
|
281
|
+
* both pressed and released in one frame is a click shorter than a frame.
|
|
282
|
+
* Wheel pulses come from `wheel`, not from `press`.
|
|
135
283
|
*/
|
|
136
284
|
export interface TimelineEntry {
|
|
137
285
|
readonly frame: number;
|
|
138
286
|
readonly move?: Position;
|
|
139
|
-
readonly
|
|
140
|
-
readonly
|
|
287
|
+
readonly movement?: Delta;
|
|
288
|
+
readonly wheel?: Delta;
|
|
289
|
+
/** Locks or unlocks the pointer from this frame on; unlocking releases what was held. */
|
|
290
|
+
readonly locked?: boolean;
|
|
291
|
+
readonly press?: ReadonlyArray<PhysicalButton>;
|
|
292
|
+
readonly release?: ReadonlyArray<PhysicalButton>;
|
|
141
293
|
}
|
|
142
294
|
/**
|
|
143
295
|
* Pointer changes by snapshot index. Plain data, so it round-trips through
|
|
144
|
-
* JSON; load it back with `parseTimeline`.
|
|
296
|
+
* JSON; load it back with `parseTimeline`. It names buttons, not actions, so
|
|
297
|
+
* a replay follows the bindings as live play does.
|
|
145
298
|
*/
|
|
146
299
|
export type Timeline = ReadonlyArray<TimelineEntry>;
|
|
147
|
-
/**
|
|
148
|
-
|
|
149
|
-
*/
|
|
150
|
-
export interface Scripted extends Pointer {
|
|
300
|
+
/** A pointer driven by a timeline instead of an element. */
|
|
301
|
+
export interface Scripted<B extends Bindings> extends Actions<B> {
|
|
151
302
|
/** Number of snapshots taken so far, which is the next frame index. */
|
|
152
303
|
readonly frames: () => number;
|
|
153
304
|
}
|
|
154
305
|
/**
|
|
155
|
-
* Plays `timeline`: before the snapshot at index `frame`,
|
|
156
|
-
* frame is applied. Buttons stay held from their press
|
|
157
|
-
* The scripted pointer is always over the element.
|
|
158
|
-
*/
|
|
159
|
-
export declare const scripted: (timeline: Timeline, start?: Position) => Scripted;
|
|
160
|
-
/**
|
|
161
|
-
* A live pointer that also records the timeline it produces.
|
|
306
|
+
* Plays `timeline` with `bindings`: before the snapshot at index `frame`,
|
|
307
|
+
* every entry for that frame is applied. Buttons stay held from their press
|
|
308
|
+
* until their release. The scripted pointer is always over the element.
|
|
162
309
|
*/
|
|
163
|
-
export
|
|
164
|
-
|
|
310
|
+
export declare const scripted: <const B extends Bindings>(bindings: B, timeline: Timeline, start?: Position) => Scripted<B>;
|
|
311
|
+
/** A live pointer that also records the timeline it produces. */
|
|
312
|
+
export interface Recording<B extends Bindings> extends Actions<B> {
|
|
313
|
+
/** The recorded timeline; `scripted(bindings, timeline)` replays the same positions and buttons. */
|
|
165
314
|
readonly timeline: () => Timeline;
|
|
166
315
|
}
|
|
167
316
|
/**
|
|
168
317
|
* Wraps `pointer` and records, for every snapshot, the position when it moved
|
|
169
318
|
* and the buttons pressed and released since the previous one.
|
|
170
319
|
*/
|
|
171
|
-
export declare const recording: (pointer:
|
|
320
|
+
export declare const recording: <B extends Bindings>(pointer: Actions<B>) => Recording<B>;
|
|
172
321
|
/**
|
|
173
322
|
* Why loaded data is not a pointer timeline. `path` points at the offending
|
|
174
323
|
* value, for example `[3].move.x`.
|
|
@@ -180,8 +329,28 @@ export interface InvalidTimeline {
|
|
|
180
329
|
}
|
|
181
330
|
/**
|
|
182
331
|
* Validates untrusted data, such as a parsed JSON file, as a pointer
|
|
183
|
-
* timeline: an array of entries with a non-negative integer `frame`,
|
|
184
|
-
* optional finite `move`, and
|
|
332
|
+
* timeline: an array of entries with a non-negative integer `frame`,
|
|
333
|
+
* optional finite `move`, `movement`, and `wheel`, an optional boolean
|
|
334
|
+
* `locked`, and optional `press`/`release` arrays of physical buttons.
|
|
185
335
|
*/
|
|
186
336
|
export declare const parseTimeline: (data: unknown) => Result.Result<Timeline, InvalidTimeline>;
|
|
337
|
+
/**
|
|
338
|
+
* Why loaded data is not a rebinding for the bindings. `path` points at the
|
|
339
|
+
* offending value, for example `fire[1]`.
|
|
340
|
+
*/
|
|
341
|
+
export type InvalidRebinding = ButtonsInternal.InvalidRebinding;
|
|
342
|
+
/**
|
|
343
|
+
* Validates untrusted data, such as saved settings parsed from JSON, as new
|
|
344
|
+
* buttons for `bindings`: an object with exactly the same action names, each
|
|
345
|
+
* mapped to a non-empty array of button names. Pass the result to
|
|
346
|
+
* {@link Actions.rebind}; on failure, keep the defaults.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* const saved = Pointer.parseRebinding(bindings, JSON.parse(stored))
|
|
351
|
+
* if (saved.ok) mouse.rebind(saved.value)
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
export declare const parseRebinding: <const B extends Bindings>(bindings: B, data: unknown) => Result.Result<Rebinding<B>, InvalidRebinding>;
|
|
355
|
+
export {};
|
|
187
356
|
//# sourceMappingURL=Pointer.d.ts.map
|
package/dist/Pointer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pointer.d.ts","sourceRoot":"","sources":["../src/Pointer.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Pointer.d.ts","sourceRoot":"","sources":["../src/Pointer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAA;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAA;AAIxD,mEAAmE;AACnE,QAAA,MAAM,eAAe,YAAI,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,CAAU,CAAA;AAEtF,uGAAuG;AACvG,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;AAI7D;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,mHAAmF,CAAA;AAE3G,mDAAmD;AACnD,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,WAAW,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