@jspsych/plugin-audio-button-response 1.1.3 → 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,161 +1,255 @@
1
- import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
1
+ import { JsPsychPlugin, ParameterType, JsPsych, TrialType } from 'jspsych';
2
+
2
3
  declare const info: {
3
4
  readonly name: "audio-button-response";
5
+ readonly version: string;
4
6
  readonly parameters: {
5
- /** The audio to be played. */
7
+ /** Path to audio file to be played. */
6
8
  readonly stimulus: {
7
9
  readonly type: ParameterType.AUDIO;
8
- readonly pretty_name: "Stimulus";
9
10
  readonly default: any;
10
11
  };
11
- /** Array containing the label(s) for the button(s). */
12
+ /** Labels for the buttons. Each different string in the array will generate a different button. */
12
13
  readonly choices: {
13
14
  readonly type: ParameterType.STRING;
14
- readonly pretty_name: "Choices";
15
15
  readonly default: any;
16
16
  readonly array: true;
17
17
  };
18
- /** The HTML for creating button. Can create own style. Use the "%choice%" string to indicate where the label from the choices parameter should be inserted. */
18
+ /**
19
+ * A function that generates the HTML for each button in the `choices` array. The function gets the string
20
+ * and index of the item in the `choices` array and should return valid HTML. If you want to use different
21
+ * markup for each button, you can do that by using a conditional on either parameter. The default parameter
22
+ * returns a button element with the text label of the choice.
23
+ */
19
24
  readonly button_html: {
20
- readonly type: ParameterType.HTML_STRING;
21
- readonly pretty_name: "Button HTML";
22
- readonly default: "<button class=\"jspsych-btn\">%choice%</button>";
23
- readonly array: true;
25
+ readonly type: ParameterType.FUNCTION;
26
+ readonly default: (choice: string, choice_index: number) => string;
24
27
  };
25
- /** Any content here will be displayed below the stimulus. */
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
30
+ * (e.g., which key to press). */
26
31
  readonly prompt: {
27
32
  readonly type: ParameterType.HTML_STRING;
28
- readonly pretty_name: "Prompt";
29
33
  readonly default: any;
30
34
  };
31
- /** The maximum duration to wait for a response. */
35
+ /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the
36
+ * participant fails to make a response before this timer is reached, the participant's response will be
37
+ * recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial
38
+ * will wait for a response indefinitely */
32
39
  readonly trial_duration: {
33
40
  readonly type: ParameterType.INT;
34
- readonly pretty_name: "Trial duration";
35
41
  readonly default: any;
36
42
  };
37
- /** Vertical margin of button. */
38
- readonly margin_vertical: {
43
+ /** Setting to `'grid'` will make the container element have the CSS property `display: grid` and enable the
44
+ * use of `grid_rows` and `grid_columns`. Setting to `'flex'` will make the container element have the CSS
45
+ * property `display: flex`. You can customize how the buttons are laid out by adding inline CSS in the `button_html` parameter.
46
+ */
47
+ readonly button_layout: {
39
48
  readonly type: ParameterType.STRING;
40
- readonly pretty_name: "Margin vertical";
41
- readonly default: "0px";
49
+ readonly default: "grid";
42
50
  };
43
- /** Horizontal margin of button. */
44
- readonly margin_horizontal: {
45
- readonly type: ParameterType.STRING;
46
- readonly pretty_name: "Margin horizontal";
47
- readonly default: "8px";
51
+ /** The number of rows in the button grid. Only applicable when `button_layout` is set to `'grid'`. If null, the
52
+ * number of rows will be determined automatically based on the number of buttons and the number of columns.
53
+ */
54
+ readonly grid_rows: {
55
+ readonly type: ParameterType.INT;
56
+ readonly default: 1;
57
+ };
58
+ /** The number of columns in the button grid. Only applicable when `button_layout` is set to `'grid'`.
59
+ * If null, the number of columns will be determined automatically based on the number of buttons and the
60
+ * number of rows.
61
+ */
62
+ readonly grid_columns: {
63
+ readonly type: ParameterType.INT;
64
+ readonly default: any;
48
65
  };
49
- /** If true, the trial will end when user makes a response. */
66
+ /** If true, then the trial will end whenever the participant makes a response (assuming they make their
67
+ * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will
68
+ * continue until the value for `trial_duration` is reached. You can set this parameter to `false` to force
69
+ * the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete. */
50
70
  readonly response_ends_trial: {
51
71
  readonly type: ParameterType.BOOL;
52
- readonly pretty_name: "Response ends trial";
53
72
  readonly default: true;
54
73
  };
55
- /** If true, then the trial will end as soon as the audio file finishes playing. */
74
+ /** If true, then the trial will end as soon as the audio file finishes playing. */
56
75
  readonly trial_ends_after_audio: {
57
76
  readonly type: ParameterType.BOOL;
58
- readonly pretty_name: "Trial ends after audio";
59
77
  readonly default: false;
60
78
  };
61
79
  /**
62
- * If true, then responses are allowed while the audio is playing.
63
- * If false, then the audio must finish playing before a response is accepted.
80
+ * If true, then responses are allowed while the audio is playing. If false, then the audio must finish
81
+ * playing before the button choices are enabled and a response is accepted. Once the audio has played
82
+ * all the way through, the buttons are enabled and a response is allowed (including while the audio is
83
+ * being re-played via on-screen playback controls).
64
84
  */
65
85
  readonly response_allowed_while_playing: {
66
86
  readonly type: ParameterType.BOOL;
67
- readonly pretty_name: "Response allowed while playing";
68
87
  readonly default: true;
69
88
  };
89
+ /** How long the button will delay enabling in milliseconds. If `response_allowed_while_playing` is `true`,
90
+ * the timer will start immediately. If it is `false`, the timer will start at the end of the audio. */
91
+ readonly enable_button_after: {
92
+ readonly type: ParameterType.INT;
93
+ readonly default: 0;
94
+ };
95
+ };
96
+ readonly data: {
97
+ /** The response time in milliseconds for the participant to make a response. The time is measured from
98
+ * when the stimulus first began playing until the participant's response.*/
99
+ readonly rt: {
100
+ readonly type: ParameterType.INT;
101
+ };
102
+ /** Indicates which button the participant pressed. The first button in the `choices` array is 0, the second is 1, and so on. */
103
+ readonly response: {
104
+ readonly type: ParameterType.INT;
105
+ };
70
106
  };
71
107
  };
72
108
  type Info = typeof info;
73
109
  /**
74
- * **audio-button-response**
75
- *
76
- * jsPsych plugin for playing an audio file and getting a button response
110
+ * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise
111
+ * timing of the playback. The timing of responses generated is measured against the WebAudio specific clock,
112
+ * improving the measurement of response times. If the browser does not support the WebAudio API, then the audio file is
113
+ * played with HTML5 audio.
114
+
115
+ * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if
116
+ * you are using timeline variables or another dynamic method to specify the audio stimulus, you will need
117
+ * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.
118
+
119
+ * The trial can end when the participant responds, when the audio file has finished playing, or if the participant
120
+ * has failed to respond within a fixed length of time. You can also prevent a button response from being made before the
121
+ * audio has finished playing.
77
122
  *
78
123
  * @author Kristin Diep
79
- * @see {@link https://www.jspsych.org/plugins/jspsych-audio-button-response/ audio-button-response plugin documentation on jspsych.org}
124
+ * @see {@link https://www.jspsych.org/latest/plugins/audio-button-response/ audio-button-response plugin documentation on jspsych.org}
80
125
  */
81
126
  declare class AudioButtonResponsePlugin implements JsPsychPlugin<Info> {
82
127
  private jsPsych;
83
128
  static info: {
84
129
  readonly name: "audio-button-response";
130
+ readonly version: string;
85
131
  readonly parameters: {
86
- /** The audio to be played. */
132
+ /** Path to audio file to be played. */
87
133
  readonly stimulus: {
88
134
  readonly type: ParameterType.AUDIO;
89
- readonly pretty_name: "Stimulus";
90
135
  readonly default: any;
91
136
  };
92
- /** Array containing the label(s) for the button(s). */
137
+ /** Labels for the buttons. Each different string in the array will generate a different button. */
93
138
  readonly choices: {
94
139
  readonly type: ParameterType.STRING;
95
- readonly pretty_name: "Choices";
96
140
  readonly default: any;
97
141
  readonly array: true;
98
142
  };
99
- /** The HTML for creating button. Can create own style. Use the "%choice%" string to indicate where the label from the choices parameter should be inserted. */
143
+ /**
144
+ * A function that generates the HTML for each button in the `choices` array. The function gets the string
145
+ * and index of the item in the `choices` array and should return valid HTML. If you want to use different
146
+ * markup for each button, you can do that by using a conditional on either parameter. The default parameter
147
+ * returns a button element with the text label of the choice.
148
+ */
100
149
  readonly button_html: {
101
- readonly type: ParameterType.HTML_STRING;
102
- readonly pretty_name: "Button HTML";
103
- readonly default: "<button class=\"jspsych-btn\">%choice%</button>";
104
- readonly array: true;
150
+ readonly type: ParameterType.FUNCTION;
151
+ readonly default: (choice: string, choice_index: number) => string;
105
152
  };
106
- /** Any content here will be displayed below the stimulus. */
153
+ /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention
154
+ * is that it can be used to provide a reminder about the action the participant is supposed to take
155
+ * (e.g., which key to press). */
107
156
  readonly prompt: {
108
157
  readonly type: ParameterType.HTML_STRING;
109
- readonly pretty_name: "Prompt";
110
158
  readonly default: any;
111
159
  };
112
- /** The maximum duration to wait for a response. */
160
+ /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the
161
+ * participant fails to make a response before this timer is reached, the participant's response will be
162
+ * recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial
163
+ * will wait for a response indefinitely */
113
164
  readonly trial_duration: {
114
165
  readonly type: ParameterType.INT;
115
- readonly pretty_name: "Trial duration";
116
166
  readonly default: any;
117
167
  };
118
- /** Vertical margin of button. */
119
- readonly margin_vertical: {
168
+ /** Setting to `'grid'` will make the container element have the CSS property `display: grid` and enable the
169
+ * use of `grid_rows` and `grid_columns`. Setting to `'flex'` will make the container element have the CSS
170
+ * property `display: flex`. You can customize how the buttons are laid out by adding inline CSS in the `button_html` parameter.
171
+ */
172
+ readonly button_layout: {
120
173
  readonly type: ParameterType.STRING;
121
- readonly pretty_name: "Margin vertical";
122
- readonly default: "0px";
174
+ readonly default: "grid";
123
175
  };
124
- /** Horizontal margin of button. */
125
- readonly margin_horizontal: {
126
- readonly type: ParameterType.STRING;
127
- readonly pretty_name: "Margin horizontal";
128
- readonly default: "8px";
176
+ /** The number of rows in the button grid. Only applicable when `button_layout` is set to `'grid'`. If null, the
177
+ * number of rows will be determined automatically based on the number of buttons and the number of columns.
178
+ */
179
+ readonly grid_rows: {
180
+ readonly type: ParameterType.INT;
181
+ readonly default: 1;
129
182
  };
130
- /** If true, the trial will end when user makes a response. */
183
+ /** The number of columns in the button grid. Only applicable when `button_layout` is set to `'grid'`.
184
+ * If null, the number of columns will be determined automatically based on the number of buttons and the
185
+ * number of rows.
186
+ */
187
+ readonly grid_columns: {
188
+ readonly type: ParameterType.INT;
189
+ readonly default: any;
190
+ };
191
+ /** If true, then the trial will end whenever the participant makes a response (assuming they make their
192
+ * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will
193
+ * continue until the value for `trial_duration` is reached. You can set this parameter to `false` to force
194
+ * the participant to listen to the stimulus for a fixed amount of time, even if they respond before the time is complete. */
131
195
  readonly response_ends_trial: {
132
196
  readonly type: ParameterType.BOOL;
133
- readonly pretty_name: "Response ends trial";
134
197
  readonly default: true;
135
198
  };
136
- /** If true, then the trial will end as soon as the audio file finishes playing. */
199
+ /** If true, then the trial will end as soon as the audio file finishes playing. */
137
200
  readonly trial_ends_after_audio: {
138
201
  readonly type: ParameterType.BOOL;
139
- readonly pretty_name: "Trial ends after audio";
140
202
  readonly default: false;
141
203
  };
142
204
  /**
143
- * If true, then responses are allowed while the audio is playing.
144
- * If false, then the audio must finish playing before a response is accepted.
205
+ * If true, then responses are allowed while the audio is playing. If false, then the audio must finish
206
+ * playing before the button choices are enabled and a response is accepted. Once the audio has played
207
+ * all the way through, the buttons are enabled and a response is allowed (including while the audio is
208
+ * being re-played via on-screen playback controls).
145
209
  */
146
210
  readonly response_allowed_while_playing: {
147
211
  readonly type: ParameterType.BOOL;
148
- readonly pretty_name: "Response allowed while playing";
149
212
  readonly default: true;
150
213
  };
214
+ /** How long the button will delay enabling in milliseconds. If `response_allowed_while_playing` is `true`,
215
+ * the timer will start immediately. If it is `false`, the timer will start at the end of the audio. */
216
+ readonly enable_button_after: {
217
+ readonly type: ParameterType.INT;
218
+ readonly default: 0;
219
+ };
220
+ };
221
+ readonly data: {
222
+ /** The response time in milliseconds for the participant to make a response. The time is measured from
223
+ * when the stimulus first began playing until the participant's response.*/
224
+ readonly rt: {
225
+ readonly type: ParameterType.INT;
226
+ };
227
+ /** Indicates which button the participant pressed. The first button in the `choices` array is 0, the second is 1, and so on. */
228
+ readonly response: {
229
+ readonly type: ParameterType.INT;
230
+ };
151
231
  };
152
232
  };
153
233
  private audio;
234
+ private params;
235
+ private buttonElements;
236
+ private display;
237
+ private response;
238
+ private context;
239
+ private startTime;
240
+ private trial_complete;
154
241
  constructor(jsPsych: JsPsych);
155
242
  trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void): Promise<unknown>;
156
- simulate(trial: TrialType<Info>, simulation_mode: any, simulation_options: any, load_callback: () => void): void;
243
+ private disable_buttons;
244
+ private enable_buttons_without_delay;
245
+ private enable_buttons_with_delay;
246
+ private enable_buttons;
247
+ private after_response;
248
+ private end_trial;
249
+ simulate(trial: TrialType<Info>, simulation_mode: any, simulation_options: any, load_callback: () => void): Promise<void>;
157
250
  private create_simulation_data;
158
251
  private simulate_data_only;
159
252
  private simulate_visual;
160
253
  }
161
- export default AudioButtonResponsePlugin;
254
+
255
+ export { AudioButtonResponsePlugin as default };