@jspsych/plugin-audio-slider-response 1.1.3 → 2.0.1

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.
@@ -1,356 +1,364 @@
1
1
  var jsPsychAudioSliderResponse = (function (jspsych) {
2
- 'use strict';
2
+ 'use strict';
3
3
 
4
- const info = {
5
- name: "audio-slider-response",
6
- parameters: {
7
- /** The audio file to be played. */
8
- stimulus: {
9
- type: jspsych.ParameterType.AUDIO,
10
- pretty_name: "Stimulus",
11
- default: undefined,
12
- },
13
- /** Sets the minimum value of the slider. */
14
- min: {
15
- type: jspsych.ParameterType.INT,
16
- pretty_name: "Min slider",
17
- default: 0,
18
- },
19
- /** Sets the maximum value of the slider */
20
- max: {
21
- type: jspsych.ParameterType.INT,
22
- pretty_name: "Max slider",
23
- default: 100,
24
- },
25
- /** Sets the starting value of the slider */
26
- slider_start: {
27
- type: jspsych.ParameterType.INT,
28
- pretty_name: "Slider starting value",
29
- default: 50,
30
- },
31
- /** Sets the step of the slider */
32
- step: {
33
- type: jspsych.ParameterType.INT,
34
- pretty_name: "Step",
35
- default: 1,
36
- },
37
- /** Array containing the labels for the slider. Labels will be displayed at equidistant locations along the slider. */
38
- labels: {
39
- type: jspsych.ParameterType.HTML_STRING,
40
- pretty_name: "Labels",
41
- default: [],
42
- array: true,
43
- },
44
- /** Width of the slider in pixels. */
45
- slider_width: {
46
- type: jspsych.ParameterType.INT,
47
- pretty_name: "Slider width",
48
- default: null,
49
- },
50
- /** Label of the button to advance. */
51
- button_label: {
52
- type: jspsych.ParameterType.STRING,
53
- pretty_name: "Button label",
54
- default: "Continue",
55
- array: false,
56
- },
57
- /** If true, the participant will have to move the slider before continuing. */
58
- require_movement: {
59
- type: jspsych.ParameterType.BOOL,
60
- pretty_name: "Require movement",
61
- default: false,
62
- },
63
- /** Any content here will be displayed below the slider. */
64
- prompt: {
65
- type: jspsych.ParameterType.HTML_STRING,
66
- pretty_name: "Prompt",
67
- default: null,
68
- },
69
- /** How long to show the trial. */
70
- trial_duration: {
71
- type: jspsych.ParameterType.INT,
72
- pretty_name: "Trial duration",
73
- default: null,
74
- },
75
- /** If true, trial will end when user makes a response. */
76
- response_ends_trial: {
77
- type: jspsych.ParameterType.BOOL,
78
- pretty_name: "Response ends trial",
79
- default: true,
80
- },
81
- /** If true, then the trial will end as soon as the audio file finishes playing. */
82
- trial_ends_after_audio: {
83
- type: jspsych.ParameterType.BOOL,
84
- pretty_name: "Trial ends after audio",
85
- default: false,
86
- },
87
- /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before a response is accepted. */
88
- response_allowed_while_playing: {
89
- type: jspsych.ParameterType.BOOL,
90
- pretty_name: "Response allowed while playing",
91
- default: true,
92
- },
93
- },
94
- };
95
- /**
96
- * **audio-slider-response**
97
- *
98
- * jsPsych plugin for playing audio and getting a slider response
99
- *
100
- * @author Josh de Leeuw
101
- * @see {@link https://www.jspsych.org/plugins/jspsych-audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}
102
- */
103
- class AudioSliderResponsePlugin {
104
- constructor(jsPsych) {
105
- this.jsPsych = jsPsych;
106
- }
107
- trial(display_element, trial, on_load) {
108
- // hold the .resolve() function from the Promise that ends the trial
109
- let trial_complete;
110
- // half of the thumb width value from jspsych.css, used to adjust the label positions
111
- var half_thumb_width = 7.5;
112
- // setup stimulus
113
- var context = this.jsPsych.pluginAPI.audioContext();
114
- // record webaudio context start time
115
- var startTime;
116
- // for storing data related to response
117
- var response;
118
- // load audio file
119
- this.jsPsych.pluginAPI
120
- .getAudioBuffer(trial.stimulus)
121
- .then((buffer) => {
122
- if (context !== null) {
123
- this.audio = context.createBufferSource();
124
- this.audio.buffer = buffer;
125
- this.audio.connect(context.destination);
126
- }
127
- else {
128
- this.audio = buffer;
129
- this.audio.currentTime = 0;
130
- }
131
- setupTrial();
132
- })
133
- .catch((err) => {
134
- console.error(`Failed to load audio file "${trial.stimulus}". Try checking the file path. We recommend using the preload plugin to load audio files.`);
135
- console.error(err);
136
- });
137
- const setupTrial = () => {
138
- // set up end event if trial needs it
139
- if (trial.trial_ends_after_audio) {
140
- this.audio.addEventListener("ended", end_trial);
141
- }
142
- // enable slider after audio ends if necessary
143
- if (!trial.response_allowed_while_playing && !trial.trial_ends_after_audio) {
144
- this.audio.addEventListener("ended", enable_slider);
145
- }
146
- var html = '<div id="jspsych-audio-slider-response-wrapper" style="margin: 100px 0px;">';
147
- html +=
148
- '<div class="jspsych-audio-slider-response-container" style="position:relative; margin: 0 auto 3em auto; width:';
149
- if (trial.slider_width !== null) {
150
- html += trial.slider_width + "px;";
151
- }
152
- else {
153
- html += "auto;";
154
- }
155
- html += '">';
156
- html +=
157
- '<input type="range" class="jspsych-slider" value="' +
158
- trial.slider_start +
159
- '" min="' +
160
- trial.min +
161
- '" max="' +
162
- trial.max +
163
- '" step="' +
164
- trial.step +
165
- '" id="jspsych-audio-slider-response-response"';
166
- if (!trial.response_allowed_while_playing) {
167
- html += " disabled";
168
- }
169
- html += "></input><div>";
170
- for (var j = 0; j < trial.labels.length; j++) {
171
- var label_width_perc = 100 / (trial.labels.length - 1);
172
- var percent_of_range = j * (100 / (trial.labels.length - 1));
173
- var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;
174
- var offset = (percent_dist_from_center * half_thumb_width) / 100;
175
- html +=
176
- '<div style="border: 1px solid transparent; display: inline-block; position: absolute; ' +
177
- "left:calc(" +
178
- percent_of_range +
179
- "% - (" +
180
- label_width_perc +
181
- "% / 2) - " +
182
- offset +
183
- "px); text-align: center; width: " +
184
- label_width_perc +
185
- '%;">';
186
- html += '<span style="text-align: center; font-size: 80%;">' + trial.labels[j] + "</span>";
187
- html += "</div>";
188
- }
189
- html += "</div>";
190
- html += "</div>";
191
- html += "</div>";
192
- if (trial.prompt !== null) {
193
- html += trial.prompt;
194
- }
195
- // add submit button
196
- var next_disabled_attribute = "";
197
- if (trial.require_movement || !trial.response_allowed_while_playing) {
198
- next_disabled_attribute = "disabled";
199
- }
200
- html +=
201
- '<button id="jspsych-audio-slider-response-next" class="jspsych-btn" ' +
202
- next_disabled_attribute +
203
- ">" +
204
- trial.button_label +
205
- "</button>";
206
- display_element.innerHTML = html;
207
- response = {
208
- rt: null,
209
- response: null,
210
- };
211
- if (!trial.response_allowed_while_playing) {
212
- display_element.querySelector("#jspsych-audio-slider-response-response").disabled = true;
213
- display_element.querySelector("#jspsych-audio-slider-response-next").disabled = true;
214
- }
215
- if (trial.require_movement) {
216
- const enable_button = () => {
217
- display_element.querySelector("#jspsych-audio-slider-response-next").disabled = false;
218
- };
219
- display_element
220
- .querySelector("#jspsych-audio-slider-response-response")
221
- .addEventListener("mousedown", enable_button);
222
- display_element
223
- .querySelector("#jspsych-audio-slider-response-response")
224
- .addEventListener("touchstart", enable_button);
225
- display_element
226
- .querySelector("#jspsych-audio-slider-response-response")
227
- .addEventListener("change", enable_button);
228
- }
229
- display_element
230
- .querySelector("#jspsych-audio-slider-response-next")
231
- .addEventListener("click", () => {
232
- // measure response time
233
- var endTime = performance.now();
234
- var rt = Math.round(endTime - startTime);
235
- if (context !== null) {
236
- endTime = context.currentTime;
237
- rt = Math.round((endTime - startTime) * 1000);
238
- }
239
- response.rt = rt;
240
- response.response = display_element.querySelector("#jspsych-audio-slider-response-response").valueAsNumber;
241
- if (trial.response_ends_trial) {
242
- end_trial();
243
- }
244
- else {
245
- display_element.querySelector("#jspsych-audio-slider-response-next").disabled = true;
246
- }
247
- });
248
- startTime = performance.now();
249
- // start audio
250
- if (context !== null) {
251
- startTime = context.currentTime;
252
- this.audio.start(startTime);
253
- }
254
- else {
255
- this.audio.play();
256
- }
257
- // end trial if trial_duration is set
258
- if (trial.trial_duration !== null) {
259
- this.jsPsych.pluginAPI.setTimeout(() => {
260
- end_trial();
261
- }, trial.trial_duration);
262
- }
263
- on_load();
264
- };
265
- // function to enable slider after audio ends
266
- function enable_slider() {
267
- document.querySelector("#jspsych-audio-slider-response-response").disabled =
268
- false;
269
- if (!trial.require_movement) {
270
- document.querySelector("#jspsych-audio-slider-response-next").disabled =
271
- false;
272
- }
273
- }
274
- const end_trial = () => {
275
- // kill any remaining setTimeout handlers
276
- this.jsPsych.pluginAPI.clearAllTimeouts();
277
- // stop the audio file if it is playing
278
- // remove end event listeners if they exist
279
- if (context !== null) {
280
- this.audio.stop();
281
- }
282
- else {
283
- this.audio.pause();
284
- }
285
- this.audio.removeEventListener("ended", end_trial);
286
- this.audio.removeEventListener("ended", enable_slider);
287
- // save data
288
- var trialdata = {
289
- rt: response.rt,
290
- stimulus: trial.stimulus,
291
- slider_start: trial.slider_start,
292
- response: response.response,
293
- };
294
- display_element.innerHTML = "";
295
- // next trial
296
- this.jsPsych.finishTrial(trialdata);
297
- trial_complete();
298
- };
299
- return new Promise((resolve) => {
300
- trial_complete = resolve;
301
- });
302
- }
303
- simulate(trial, simulation_mode, simulation_options, load_callback) {
304
- if (simulation_mode == "data-only") {
305
- load_callback();
306
- this.simulate_data_only(trial, simulation_options);
307
- }
308
- if (simulation_mode == "visual") {
309
- this.simulate_visual(trial, simulation_options, load_callback);
310
- }
311
- }
312
- create_simulation_data(trial, simulation_options) {
313
- const default_data = {
314
- stimulus: trial.stimulus,
315
- slider_start: trial.slider_start,
316
- response: this.jsPsych.randomization.randomInt(trial.min, trial.max),
317
- rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
318
- };
319
- const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
320
- this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
321
- return data;
322
- }
323
- simulate_data_only(trial, simulation_options) {
324
- const data = this.create_simulation_data(trial, simulation_options);
325
- this.jsPsych.finishTrial(data);
326
- }
327
- simulate_visual(trial, simulation_options, load_callback) {
328
- const data = this.create_simulation_data(trial, simulation_options);
329
- const display_element = this.jsPsych.getDisplayElement();
330
- const respond = () => {
331
- if (data.rt !== null) {
332
- const el = display_element.querySelector("input[type='range']");
333
- setTimeout(() => {
334
- this.jsPsych.pluginAPI.clickTarget(el);
335
- el.valueAsNumber = data.response;
336
- }, data.rt / 2);
337
- this.jsPsych.pluginAPI.clickTarget(display_element.querySelector("button"), data.rt);
338
- }
339
- };
340
- this.trial(display_element, trial, () => {
341
- load_callback();
342
- if (!trial.response_allowed_while_playing) {
343
- this.audio.addEventListener("ended", respond);
344
- }
345
- else {
346
- respond();
347
- }
348
- });
349
- }
350
- }
351
- AudioSliderResponsePlugin.info = info;
4
+ function getDefaultExportFromCjs (x) {
5
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
6
+ }
352
7
 
353
- return AudioSliderResponsePlugin;
8
+ // Gets all non-builtin properties up the prototype chain
9
+ const getAllProperties = object => {
10
+ const properties = new Set();
11
+
12
+ do {
13
+ for (const key of Reflect.ownKeys(object)) {
14
+ properties.add([object, key]);
15
+ }
16
+ } while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);
17
+
18
+ return properties;
19
+ };
20
+
21
+ var autoBind = (self, {include, exclude} = {}) => {
22
+ const filter = key => {
23
+ const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);
24
+
25
+ if (include) {
26
+ return include.some(match);
27
+ }
28
+
29
+ if (exclude) {
30
+ return !exclude.some(match);
31
+ }
32
+
33
+ return true;
34
+ };
35
+
36
+ for (const [object, key] of getAllProperties(self.constructor.prototype)) {
37
+ if (key === 'constructor' || !filter(key)) {
38
+ continue;
39
+ }
40
+
41
+ const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
42
+ if (descriptor && typeof descriptor.value === 'function') {
43
+ self[key] = self[key].bind(self);
44
+ }
45
+ }
46
+
47
+ return self;
48
+ };
49
+
50
+ var autoBind$1 = /*@__PURE__*/getDefaultExportFromCjs(autoBind);
51
+
52
+ var _package = {
53
+ name: "@jspsych/plugin-audio-slider-response",
54
+ version: "2.0.1",
55
+ description: "",
56
+ type: "module",
57
+ main: "dist/index.cjs",
58
+ exports: {
59
+ import: "./dist/index.js",
60
+ require: "./dist/index.cjs"
61
+ },
62
+ typings: "dist/index.d.ts",
63
+ unpkg: "dist/index.browser.min.js",
64
+ files: [
65
+ "src",
66
+ "dist"
67
+ ],
68
+ source: "src/index.ts",
69
+ scripts: {
70
+ test: "jest --passWithNoTests",
71
+ "test:watch": "npm test -- --watch",
72
+ tsc: "tsc",
73
+ build: "rollup --config",
74
+ "build:watch": "npm run build -- --watch"
75
+ },
76
+ repository: {
77
+ type: "git",
78
+ url: "git+https://github.com/jspsych/jsPsych.git",
79
+ directory: "packages/plugin-audio-slider-response"
80
+ },
81
+ author: "Josh de Leeuw",
82
+ license: "MIT",
83
+ bugs: {
84
+ url: "https://github.com/jspsych/jsPsych/issues"
85
+ },
86
+ homepage: "https://www.jspsych.org/latest/plugins/audio-slider-response",
87
+ peerDependencies: {
88
+ jspsych: ">=7.1.0"
89
+ },
90
+ devDependencies: {
91
+ "@jspsych/config": "^3.0.0",
92
+ "@jspsych/test-utils": "^1.2.0"
93
+ }
94
+ };
95
+
96
+ const info = {
97
+ name: "audio-slider-response",
98
+ version: _package.version,
99
+ parameters: {
100
+ stimulus: {
101
+ type: jspsych.ParameterType.AUDIO,
102
+ default: void 0
103
+ },
104
+ min: {
105
+ type: jspsych.ParameterType.INT,
106
+ default: 0
107
+ },
108
+ max: {
109
+ type: jspsych.ParameterType.INT,
110
+ default: 100
111
+ },
112
+ slider_start: {
113
+ type: jspsych.ParameterType.INT,
114
+ default: 50
115
+ },
116
+ step: {
117
+ type: jspsych.ParameterType.INT,
118
+ default: 1
119
+ },
120
+ labels: {
121
+ type: jspsych.ParameterType.HTML_STRING,
122
+ default: [],
123
+ array: true
124
+ },
125
+ slider_width: {
126
+ type: jspsych.ParameterType.INT,
127
+ default: null
128
+ },
129
+ button_label: {
130
+ type: jspsych.ParameterType.STRING,
131
+ default: "Continue",
132
+ array: false
133
+ },
134
+ require_movement: {
135
+ type: jspsych.ParameterType.BOOL,
136
+ default: false
137
+ },
138
+ prompt: {
139
+ type: jspsych.ParameterType.HTML_STRING,
140
+ default: null
141
+ },
142
+ trial_duration: {
143
+ type: jspsych.ParameterType.INT,
144
+ default: null
145
+ },
146
+ response_ends_trial: {
147
+ type: jspsych.ParameterType.BOOL,
148
+ default: true
149
+ },
150
+ trial_ends_after_audio: {
151
+ type: jspsych.ParameterType.BOOL,
152
+ default: false
153
+ },
154
+ response_allowed_while_playing: {
155
+ type: jspsych.ParameterType.BOOL,
156
+ default: true
157
+ }
158
+ },
159
+ data: {
160
+ response: {
161
+ type: jspsych.ParameterType.INT
162
+ },
163
+ rt: {
164
+ type: jspsych.ParameterType.INT
165
+ },
166
+ stimulus: {
167
+ type: jspsych.ParameterType.STRING
168
+ },
169
+ slider_start: {
170
+ type: jspsych.ParameterType.INT
171
+ }
172
+ }
173
+ };
174
+ class AudioSliderResponsePlugin {
175
+ constructor(jsPsych) {
176
+ this.jsPsych = jsPsych;
177
+ autoBind$1(this);
178
+ }
179
+ static info = info;
180
+ audio;
181
+ context;
182
+ params;
183
+ display;
184
+ response = { rt: null, response: null };
185
+ startTime;
186
+ half_thumb_width;
187
+ trial_complete;
188
+ async trial(display_element, trial, on_load) {
189
+ this.params = trial;
190
+ this.display = display_element;
191
+ this.response;
192
+ this.half_thumb_width = 7.5;
193
+ this.trial_complete;
194
+ this.context = this.jsPsych.pluginAPI.audioContext();
195
+ this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);
196
+ this.setupTrial();
197
+ on_load();
198
+ return new Promise((resolve) => {
199
+ this.trial_complete = resolve;
200
+ });
201
+ }
202
+ enable_slider() {
203
+ document.querySelector("#jspsych-audio-slider-response-response").disabled = false;
204
+ if (!this.params.require_movement) {
205
+ document.querySelector("#jspsych-audio-slider-response-next").disabled = false;
206
+ }
207
+ }
208
+ setupTrial = () => {
209
+ if (this.params.trial_ends_after_audio) {
210
+ this.audio.addEventListener("ended", this.end_trial);
211
+ }
212
+ if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {
213
+ this.audio.addEventListener("ended", this.enable_slider);
214
+ }
215
+ var html = '<div id="jspsych-audio-slider-response-wrapper" style="margin: 100px 0px;">';
216
+ html += '<div class="jspsych-audio-slider-response-container" style="position:relative; margin: 0 auto 3em auto; width:';
217
+ if (this.params.slider_width !== null) {
218
+ html += this.params.slider_width + "px;";
219
+ } else {
220
+ html += "auto;";
221
+ }
222
+ html += '">';
223
+ html += '<input type="range" class="jspsych-slider" value="' + this.params.slider_start + '" min="' + this.params.min + '" max="' + this.params.max + '" step="' + this.params.step + '" id="jspsych-audio-slider-response-response"';
224
+ if (!this.params.response_allowed_while_playing) {
225
+ html += " disabled";
226
+ }
227
+ html += "></input><div>";
228
+ for (var j = 0; j < this.params.labels.length; j++) {
229
+ var label_width_perc = 100 / (this.params.labels.length - 1);
230
+ var percent_of_range = j * (100 / (this.params.labels.length - 1));
231
+ var percent_dist_from_center = (percent_of_range - 50) / 50 * 100;
232
+ var offset = percent_dist_from_center * this.half_thumb_width / 100;
233
+ html += '<div style="border: 1px solid transparent; display: inline-block; position: absolute; left:calc(' + percent_of_range + "% - (" + label_width_perc + "% / 2) - " + offset + "px); text-align: center; width: " + label_width_perc + '%;">';
234
+ html += '<span style="text-align: center; font-size: 80%;">' + this.params.labels[j] + "</span>";
235
+ html += "</div>";
236
+ }
237
+ html += "</div>";
238
+ html += "</div>";
239
+ html += "</div>";
240
+ if (this.params.prompt !== null) {
241
+ html += this.params.prompt;
242
+ }
243
+ var next_disabled_attribute = "";
244
+ if (this.params.require_movement || !this.params.response_allowed_while_playing) {
245
+ next_disabled_attribute = "disabled";
246
+ }
247
+ html += '<button id="jspsych-audio-slider-response-next" class="jspsych-btn" ' + next_disabled_attribute + ">" + this.params.button_label + "</button>";
248
+ this.display.innerHTML = html;
249
+ this.response = {
250
+ rt: null,
251
+ response: null
252
+ };
253
+ if (!this.params.response_allowed_while_playing) {
254
+ this.display.querySelector(
255
+ "#jspsych-audio-slider-response-response"
256
+ ).disabled = true;
257
+ this.display.querySelector("#jspsych-audio-slider-response-next").disabled = true;
258
+ }
259
+ if (this.params.require_movement) {
260
+ const enable_button = () => {
261
+ this.display.querySelector(
262
+ "#jspsych-audio-slider-response-next"
263
+ ).disabled = false;
264
+ };
265
+ this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("mousedown", enable_button);
266
+ this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("touchstart", enable_button);
267
+ this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("change", enable_button);
268
+ }
269
+ this.display.querySelector("#jspsych-audio-slider-response-next").addEventListener("click", () => {
270
+ var endTime = performance.now();
271
+ var rt = Math.round(endTime - this.startTime);
272
+ if (this.context !== null) {
273
+ endTime = this.context.currentTime;
274
+ rt = Math.round((endTime - this.startTime) * 1e3);
275
+ }
276
+ this.response.rt = rt;
277
+ this.response.response = this.display.querySelector(
278
+ "#jspsych-audio-slider-response-response"
279
+ ).valueAsNumber;
280
+ if (this.params.response_ends_trial) {
281
+ this.end_trial();
282
+ } else {
283
+ this.display.querySelector(
284
+ "#jspsych-audio-slider-response-next"
285
+ ).disabled = true;
286
+ }
287
+ });
288
+ this.startTime = performance.now();
289
+ if (this.context !== null) {
290
+ this.startTime = this.context.currentTime;
291
+ }
292
+ this.audio.play();
293
+ if (this.params.trial_duration !== null) {
294
+ this.jsPsych.pluginAPI.setTimeout(() => {
295
+ this.end_trial();
296
+ }, this.params.trial_duration);
297
+ }
298
+ };
299
+ end_trial = () => {
300
+ this.jsPsych.pluginAPI.clearAllTimeouts();
301
+ this.audio.stop();
302
+ this.audio.removeEventListener("ended", this.end_trial);
303
+ this.audio.removeEventListener("ended", this.enable_slider);
304
+ var trialdata = {
305
+ rt: this.response.rt,
306
+ stimulus: this.params.stimulus,
307
+ slider_start: this.params.slider_start,
308
+ response: this.response.response
309
+ };
310
+ this.display.innerHTML = "";
311
+ this.trial_complete(trialdata);
312
+ };
313
+ simulate(trial, simulation_mode, simulation_options, load_callback) {
314
+ if (simulation_mode == "data-only") {
315
+ load_callback();
316
+ this.simulate_data_only(trial, simulation_options);
317
+ }
318
+ if (simulation_mode == "visual") {
319
+ this.simulate_visual(trial, simulation_options, load_callback);
320
+ }
321
+ }
322
+ create_simulation_data(trial, simulation_options) {
323
+ const default_data = {
324
+ stimulus: trial.stimulus,
325
+ slider_start: trial.slider_start,
326
+ response: this.jsPsych.randomization.randomInt(trial.min, trial.max),
327
+ rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true)
328
+ };
329
+ const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
330
+ this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
331
+ return data;
332
+ }
333
+ simulate_data_only(trial, simulation_options) {
334
+ const data = this.create_simulation_data(trial, simulation_options);
335
+ this.jsPsych.finishTrial(data);
336
+ }
337
+ simulate_visual(trial, simulation_options, load_callback) {
338
+ const data = this.create_simulation_data(trial, simulation_options);
339
+ const display_element = this.jsPsych.getDisplayElement();
340
+ const respond = () => {
341
+ if (data.rt !== null) {
342
+ const el = display_element.querySelector("input[type='range']");
343
+ setTimeout(() => {
344
+ this.jsPsych.pluginAPI.clickTarget(el);
345
+ el.valueAsNumber = data.response;
346
+ }, data.rt / 2);
347
+ this.jsPsych.pluginAPI.clickTarget(display_element.querySelector("button"), data.rt);
348
+ }
349
+ };
350
+ this.trial(display_element, trial, () => {
351
+ load_callback();
352
+ if (!trial.response_allowed_while_playing) {
353
+ this.audio.addEventListener("ended", respond);
354
+ } else {
355
+ respond();
356
+ }
357
+ });
358
+ }
359
+ }
360
+
361
+ return AudioSliderResponsePlugin;
354
362
 
355
363
  })(jsPsychModule);
356
- //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-audio-slider-response@1.1.3/dist/index.browser.js.map
364
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-audio-slider-response@2.0.1/dist/index.browser.js.map