-
Notifications
You must be signed in to change notification settings - Fork 252
/
Copy pathtypes.ts
87 lines (79 loc) · 2.05 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* @internal Do not create/alter this by yourself as this type might be subject to changes.
*/
export type keyboardState = {
/**
All keys that have been pressed and not been lifted up yet.
*/
pressed: {keyDef: keyboardKey; unpreventedDefault: boolean}[]
/**
Active modifiers
*/
modifiers: {
alt: boolean
caps: boolean
ctrl: boolean
meta: boolean
shift: boolean
}
/**
The element the keyboard input is performed on.
Some behavior might differ if the activeElement changes between corresponding keyboard events.
*/
activeElement: Element | null
/**
For HTMLInputElements type='number':
If the last input char is '.', '-' or 'e',
the IDL value attribute does not reflect the input value.
*/
carryValue?: string
/**
Carry over characters to following key handlers.
E.g. ^1
*/
carryChar: string
}
export type keyboardOptions = {
/** Document in which to perform the events */
document: Document
/** Delay between keystrokes */
delay: number
/** Add modifiers for given keys - not implemented yet */
autoModify: boolean
/** Keyboard layout to use */
keyboardMap: keyboardKey[]
}
export enum DOM_KEY_LOCATION {
STANDARD = 0,
LEFT = 1,
RIGHT = 2,
NUMPAD = 3,
}
export interface keyboardKey {
/** Physical location on a keyboard */
code?: string
/** Character or functional key descriptor */
key?: string
/** Location on the keyboard for keys with multiple representation */
location?: DOM_KEY_LOCATION
/** keyCode for legacy support */
keyCode?: number
/** Does the character in `key` require/imply AltRight to be pressed? */
altGr?: boolean
/** Does the character in `key` require/imply a shiftKey to be pressed? */
shift?: boolean
}
export interface behaviorPlugin {
matches: (
keyDef: keyboardKey,
element: Element,
options: keyboardOptions,
state: keyboardState,
) => boolean
handle: (
keyDef: keyboardKey,
element: Element,
options: keyboardOptions,
state: keyboardState,
) => void
}