@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/dist/index.d.ts CHANGED
@@ -1,116 +1,178 @@
1
- import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
2
- declare const info: {
3
- readonly name: "canvas-keyboard-response";
4
- readonly parameters: {
5
- /** The drawing function to apply to the canvas. Should take the canvas object as argument. */
6
- readonly stimulus: {
7
- readonly type: ParameterType.FUNCTION;
8
- readonly pretty_name: "Stimulus";
9
- readonly default: any;
10
- };
11
- /** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */
12
- readonly choices: {
13
- readonly type: ParameterType.KEYS;
14
- readonly pretty_name: "Choices";
15
- readonly default: "ALL_KEYS";
16
- };
17
- /** Any content here will be displayed below the stimulus. */
18
- readonly prompt: {
19
- readonly type: ParameterType.HTML_STRING;
20
- readonly pretty_name: "Prompt";
21
- readonly default: any;
22
- };
23
- /** How long to show the stimulus. */
24
- readonly stimulus_duration: {
25
- readonly type: ParameterType.INT;
26
- readonly pretty_name: "Stimulus duration";
27
- readonly default: any;
28
- };
29
- /** How long to show trial before it ends. */
30
- readonly trial_duration: {
31
- readonly type: ParameterType.INT;
32
- readonly pretty_name: "Trial duration";
33
- readonly default: any;
34
- };
35
- /** If true, trial will end when subject makes a response. */
36
- readonly response_ends_trial: {
37
- readonly type: ParameterType.BOOL;
38
- readonly pretty_name: "Response ends trial";
39
- readonly default: true;
40
- };
41
- /** Array containing the height (first value) and width (second value) of the canvas element. */
42
- readonly canvas_size: {
43
- readonly type: ParameterType.INT;
44
- readonly array: true;
45
- readonly pretty_name: "Canvas size";
46
- readonly default: readonly [500, 500];
47
- };
48
- };
49
- };
50
- declare type Info = typeof info;
51
- /**
52
- * **canvas-keyboard-response**
53
- *
54
- * jsPsych plugin for displaying a canvas stimulus and getting a keyboard response
55
- *
56
- * @author Chris Jungerius (modified from Josh de Leeuw)
57
- * @see {@link https://www.jspsych.org/plugins/jspsych-canvas-keyboard-response/ canvas-keyboard-response plugin documentation on jspsych.org}
58
- */
59
- declare class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
60
- private jsPsych;
61
- static info: {
62
- readonly name: "canvas-keyboard-response";
63
- readonly parameters: {
64
- /** The drawing function to apply to the canvas. Should take the canvas object as argument. */
65
- readonly stimulus: {
66
- readonly type: ParameterType.FUNCTION;
67
- readonly pretty_name: "Stimulus";
68
- readonly default: any;
69
- };
70
- /** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */
71
- readonly choices: {
72
- readonly type: ParameterType.KEYS;
73
- readonly pretty_name: "Choices";
74
- readonly default: "ALL_KEYS";
75
- };
76
- /** Any content here will be displayed below the stimulus. */
77
- readonly prompt: {
78
- readonly type: ParameterType.HTML_STRING;
79
- readonly pretty_name: "Prompt";
80
- readonly default: any;
81
- };
82
- /** How long to show the stimulus. */
83
- readonly stimulus_duration: {
84
- readonly type: ParameterType.INT;
85
- readonly pretty_name: "Stimulus duration";
86
- readonly default: any;
87
- };
88
- /** How long to show trial before it ends. */
89
- readonly trial_duration: {
90
- readonly type: ParameterType.INT;
91
- readonly pretty_name: "Trial duration";
92
- readonly default: any;
93
- };
94
- /** If true, trial will end when subject makes a response. */
95
- readonly response_ends_trial: {
96
- readonly type: ParameterType.BOOL;
97
- readonly pretty_name: "Response ends trial";
98
- readonly default: true;
99
- };
100
- /** Array containing the height (first value) and width (second value) of the canvas element. */
101
- readonly canvas_size: {
102
- readonly type: ParameterType.INT;
103
- readonly array: true;
104
- readonly pretty_name: "Canvas size";
105
- readonly default: readonly [500, 500];
106
- };
107
- };
108
- };
109
- constructor(jsPsych: JsPsych);
110
- trial(display_element: HTMLElement, trial: TrialType<Info>): void;
111
- simulate(trial: TrialType<Info>, simulation_mode: any, simulation_options: any, load_callback: () => void): void;
112
- private simulate_data_only;
113
- private simulate_visual;
114
- private create_simulation_data;
115
- }
116
- export default CanvasKeyboardResponsePlugin;
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 };