@jspsych/plugin-canvas-keyboard-response 1.1.2 → 2.0.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/README.md +8 -2
- package/dist/index.browser.js +179 -170
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +2 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +177 -168
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +178 -116
- package/dist/index.js +177 -168
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +52 -24
package/dist/index.d.ts
CHANGED
|
@@ -1,116 +1,178 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
readonly
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
readonly
|
|
13
|
-
readonly type: ParameterType.
|
|
14
|
-
readonly
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
readonly
|
|
25
|
-
readonly type: ParameterType.
|
|
26
|
-
readonly
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
readonly
|
|
33
|
-
readonly default: any;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
readonly
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
readonly
|
|
104
|
-
readonly
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
1
|
+
import { JsPsychPlugin, ParameterType, JsPsych, TrialType } from 'jspsych';
|
|
2
|
+
|
|
3
|
+
declare const info: {
|
|
4
|
+
readonly name: "canvas-keyboard-response";
|
|
5
|
+
readonly version: string;
|
|
6
|
+
readonly parameters: {
|
|
7
|
+
/** The function to draw on the canvas. This function automatically takes a canvas element as its only
|
|
8
|
+
* argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.
|
|
9
|
+
* Note that the stimulus function will still generally need to set the correct context itself, using a line
|
|
10
|
+
* like `let ctx = c.getContext("2d")`.
|
|
11
|
+
*/
|
|
12
|
+
readonly stimulus: {
|
|
13
|
+
readonly type: ParameterType.FUNCTION;
|
|
14
|
+
readonly default: any;
|
|
15
|
+
};
|
|
16
|
+
/** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.
|
|
17
|
+
* Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -
|
|
18
|
+
* see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
|
|
19
|
+
* and [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)
|
|
20
|
+
* for more examples. Any key presses that are not listed in the array will be ignored. The default value
|
|
21
|
+
* of `"ALL_KEYS"` means that all keys will be accepted as valid responses. Specifying `"NO_KEYS"` will mean
|
|
22
|
+
* that no responses are allowed.
|
|
23
|
+
*/
|
|
24
|
+
readonly choices: {
|
|
25
|
+
readonly type: ParameterType.KEYS;
|
|
26
|
+
readonly default: "ALL_KEYS";
|
|
27
|
+
};
|
|
28
|
+
/** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention
|
|
29
|
+
* is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
|
|
30
|
+
*/
|
|
31
|
+
readonly prompt: {
|
|
32
|
+
readonly type: ParameterType.HTML_STRING;
|
|
33
|
+
readonly default: any;
|
|
34
|
+
};
|
|
35
|
+
/** How long to display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to
|
|
36
|
+
* `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.
|
|
37
|
+
*/
|
|
38
|
+
readonly stimulus_duration: {
|
|
39
|
+
readonly type: ParameterType.INT;
|
|
40
|
+
readonly default: any;
|
|
41
|
+
};
|
|
42
|
+
/** How long to wait for the participant to make a response before ending the trial in milliseconds. If the
|
|
43
|
+
* participant fails to make a response before this timer is reached, the participant's response will be
|
|
44
|
+
* recorded as null for the trial and the trial will end. If the value of this parameter is null, then the
|
|
45
|
+
* trial will wait for a response indefinitely.
|
|
46
|
+
*/
|
|
47
|
+
readonly trial_duration: {
|
|
48
|
+
readonly type: ParameterType.INT;
|
|
49
|
+
readonly default: any;
|
|
50
|
+
};
|
|
51
|
+
/** If true, then the trial will end whenever the participant makes a response (assuming they make their
|
|
52
|
+
* response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will
|
|
53
|
+
* continue until the value for `trial_duration` is reached. You can use this parameter to force the participant
|
|
54
|
+
* to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
|
|
55
|
+
*/
|
|
56
|
+
readonly response_ends_trial: {
|
|
57
|
+
readonly type: ParameterType.BOOL;
|
|
58
|
+
readonly default: true;
|
|
59
|
+
};
|
|
60
|
+
/** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */
|
|
61
|
+
readonly canvas_size: {
|
|
62
|
+
readonly type: ParameterType.INT;
|
|
63
|
+
readonly array: true;
|
|
64
|
+
readonly default: readonly [500, 500];
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
readonly data: {
|
|
68
|
+
/** Indicates which key the participant pressed. */
|
|
69
|
+
readonly response: {
|
|
70
|
+
readonly type: ParameterType.STRING;
|
|
71
|
+
};
|
|
72
|
+
/** The response time in milliseconds for the participant to make a response. The time is measured from
|
|
73
|
+
* when the stimulus first appears on the screen until the participant's response.
|
|
74
|
+
*/
|
|
75
|
+
readonly rt: {
|
|
76
|
+
readonly type: ParameterType.INT;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
type Info = typeof info;
|
|
81
|
+
/**
|
|
82
|
+
* This plugin can be used to draw a stimulus on a [HTML canvas element](https://www.w3schools.com/html/html5_canvas.asp) and
|
|
83
|
+
* record a keyboard response. The canvas stimulus can be useful for displaying dynamic, parametrically-defined graphics,
|
|
84
|
+
* and for controlling the positioning of multiple graphical elements (shapes, text, images). The stimulus can be
|
|
85
|
+
* displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically
|
|
86
|
+
* if the participant has failed to respond within a fixed length of time.
|
|
87
|
+
*
|
|
88
|
+
* @author Chris Jungerius (modified from Josh de Leeuw)
|
|
89
|
+
* @see {@link https://www.jspsych.org/latest/plugins/canvas-keyboard-response/ canvas-keyboard-response plugin documentation on jspsych.org}
|
|
90
|
+
*/
|
|
91
|
+
declare class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|
92
|
+
private jsPsych;
|
|
93
|
+
static info: {
|
|
94
|
+
readonly name: "canvas-keyboard-response";
|
|
95
|
+
readonly version: string;
|
|
96
|
+
readonly parameters: {
|
|
97
|
+
/** The function to draw on the canvas. This function automatically takes a canvas element as its only
|
|
98
|
+
* argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.
|
|
99
|
+
* Note that the stimulus function will still generally need to set the correct context itself, using a line
|
|
100
|
+
* like `let ctx = c.getContext("2d")`.
|
|
101
|
+
*/
|
|
102
|
+
readonly stimulus: {
|
|
103
|
+
readonly type: ParameterType.FUNCTION;
|
|
104
|
+
readonly default: any;
|
|
105
|
+
};
|
|
106
|
+
/** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.
|
|
107
|
+
* Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -
|
|
108
|
+
* see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
|
|
109
|
+
* and [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)
|
|
110
|
+
* for more examples. Any key presses that are not listed in the array will be ignored. The default value
|
|
111
|
+
* of `"ALL_KEYS"` means that all keys will be accepted as valid responses. Specifying `"NO_KEYS"` will mean
|
|
112
|
+
* that no responses are allowed.
|
|
113
|
+
*/
|
|
114
|
+
readonly choices: {
|
|
115
|
+
readonly type: ParameterType.KEYS;
|
|
116
|
+
readonly default: "ALL_KEYS";
|
|
117
|
+
};
|
|
118
|
+
/** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention
|
|
119
|
+
* is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
|
|
120
|
+
*/
|
|
121
|
+
readonly prompt: {
|
|
122
|
+
readonly type: ParameterType.HTML_STRING;
|
|
123
|
+
readonly default: any;
|
|
124
|
+
};
|
|
125
|
+
/** How long to display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to
|
|
126
|
+
* `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.
|
|
127
|
+
*/
|
|
128
|
+
readonly stimulus_duration: {
|
|
129
|
+
readonly type: ParameterType.INT;
|
|
130
|
+
readonly default: any;
|
|
131
|
+
};
|
|
132
|
+
/** How long to wait for the participant to make a response before ending the trial in milliseconds. If the
|
|
133
|
+
* participant fails to make a response before this timer is reached, the participant's response will be
|
|
134
|
+
* recorded as null for the trial and the trial will end. If the value of this parameter is null, then the
|
|
135
|
+
* trial will wait for a response indefinitely.
|
|
136
|
+
*/
|
|
137
|
+
readonly trial_duration: {
|
|
138
|
+
readonly type: ParameterType.INT;
|
|
139
|
+
readonly default: any;
|
|
140
|
+
};
|
|
141
|
+
/** If true, then the trial will end whenever the participant makes a response (assuming they make their
|
|
142
|
+
* response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will
|
|
143
|
+
* continue until the value for `trial_duration` is reached. You can use this parameter to force the participant
|
|
144
|
+
* to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
|
|
145
|
+
*/
|
|
146
|
+
readonly response_ends_trial: {
|
|
147
|
+
readonly type: ParameterType.BOOL;
|
|
148
|
+
readonly default: true;
|
|
149
|
+
};
|
|
150
|
+
/** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */
|
|
151
|
+
readonly canvas_size: {
|
|
152
|
+
readonly type: ParameterType.INT;
|
|
153
|
+
readonly array: true;
|
|
154
|
+
readonly default: readonly [500, 500];
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
readonly data: {
|
|
158
|
+
/** Indicates which key the participant pressed. */
|
|
159
|
+
readonly response: {
|
|
160
|
+
readonly type: ParameterType.STRING;
|
|
161
|
+
};
|
|
162
|
+
/** The response time in milliseconds for the participant to make a response. The time is measured from
|
|
163
|
+
* when the stimulus first appears on the screen until the participant's response.
|
|
164
|
+
*/
|
|
165
|
+
readonly rt: {
|
|
166
|
+
readonly type: ParameterType.INT;
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
constructor(jsPsych: JsPsych);
|
|
171
|
+
trial(display_element: HTMLElement, trial: TrialType<Info>): void;
|
|
172
|
+
simulate(trial: TrialType<Info>, simulation_mode: any, simulation_options: any, load_callback: () => void): void;
|
|
173
|
+
private simulate_data_only;
|
|
174
|
+
private simulate_visual;
|
|
175
|
+
private create_simulation_data;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { CanvasKeyboardResponsePlugin as default };
|