@jspsych/plugin-audio-slider-response 2.0.1 → 2.1.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.
@@ -49,142 +49,241 @@ var jsPsychAudioSliderResponse = (function (jspsych) {
49
49
 
50
50
  var autoBind$1 = /*@__PURE__*/getDefaultExportFromCjs(autoBind);
51
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
- };
52
+ var version = "2.1.1";
95
53
 
96
54
  const info = {
97
55
  name: "audio-slider-response",
98
- version: _package.version,
56
+ version,
99
57
  parameters: {
58
+ /** Audio file to be played. */
100
59
  stimulus: {
101
60
  type: jspsych.ParameterType.AUDIO,
102
61
  default: void 0
103
62
  },
63
+ /** Sets the minimum value of the slider. */
104
64
  min: {
105
65
  type: jspsych.ParameterType.INT,
106
66
  default: 0
107
67
  },
68
+ /** Sets the maximum value of the slider */
108
69
  max: {
109
70
  type: jspsych.ParameterType.INT,
110
71
  default: 100
111
72
  },
73
+ /** Sets the starting value of the slider */
112
74
  slider_start: {
113
75
  type: jspsych.ParameterType.INT,
114
76
  default: 50
115
77
  },
78
+ /** Sets the step of the slider. This is the smallest amount by which the slider can change. */
116
79
  step: {
117
80
  type: jspsych.ParameterType.INT,
118
81
  default: 1
119
82
  },
83
+ /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the
84
+ * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the
85
+ * other two will be at 33% and 67% of the slider width.
86
+ */
120
87
  labels: {
121
88
  type: jspsych.ParameterType.HTML_STRING,
122
89
  default: [],
123
90
  array: true
124
91
  },
92
+ /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */
125
93
  slider_width: {
126
94
  type: jspsych.ParameterType.INT,
127
95
  default: null
128
96
  },
97
+ /** Label of the button to end the trial. */
129
98
  button_label: {
130
99
  type: jspsych.ParameterType.STRING,
131
100
  default: "Continue",
132
101
  array: false
133
102
  },
103
+ /** If true, the participant must move the slider before clicking the continue button. */
134
104
  require_movement: {
135
105
  type: jspsych.ParameterType.BOOL,
136
106
  default: false
137
107
  },
108
+ /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is
109
+ * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
110
+ */
138
111
  prompt: {
139
112
  type: jspsych.ParameterType.HTML_STRING,
140
113
  default: null
141
114
  },
115
+ /** How long to wait for the participant to make a response before ending the trial in milliseconds. If
116
+ * the participant fails to make a response before this timer is reached, the participant's response will be
117
+ * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial
118
+ * will wait for a response indefinitely.
119
+ */
142
120
  trial_duration: {
143
121
  type: jspsych.ParameterType.INT,
144
122
  default: null
145
123
  },
124
+ /** If true, then the trial will end whenever the participant makes a response (assuming they make their response
125
+ * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the
126
+ * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to
127
+ * the stimulus for a fixed amount of time, even if they respond before the time is complete.
128
+ */
146
129
  response_ends_trial: {
147
130
  type: jspsych.ParameterType.BOOL,
148
131
  default: true
149
132
  },
133
+ /** If true, then the trial will end as soon as the audio file finishes playing. */
150
134
  trial_ends_after_audio: {
151
135
  type: jspsych.ParameterType.BOOL,
152
136
  default: false
153
137
  },
138
+ /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before
139
+ * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,
140
+ * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).
141
+ */
154
142
  response_allowed_while_playing: {
155
143
  type: jspsych.ParameterType.BOOL,
156
144
  default: true
157
145
  }
158
146
  },
159
147
  data: {
148
+ /** The numeric value of the slider. */
160
149
  response: {
161
150
  type: jspsych.ParameterType.INT
162
151
  },
152
+ /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first
153
+ * began playing until the participant's response.
154
+ */
163
155
  rt: {
164
156
  type: jspsych.ParameterType.INT
165
157
  },
158
+ /** The path of the audio file that was played. */
166
159
  stimulus: {
167
160
  type: jspsych.ParameterType.STRING
168
161
  },
162
+ /** The starting value of the slider. */
169
163
  slider_start: {
170
164
  type: jspsych.ParameterType.INT
171
165
  }
166
+ },
167
+ // prettier-ignore
168
+ citations: {
169
+ "apa": "de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ",
170
+ "bibtex": '@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '
172
171
  }
173
172
  };
174
173
  class AudioSliderResponsePlugin {
175
174
  constructor(jsPsych) {
176
175
  this.jsPsych = jsPsych;
176
+ this.response = { rt: null, response: null };
177
+ this.setupTrial = () => {
178
+ if (this.params.trial_ends_after_audio) {
179
+ this.audio.addEventListener("ended", this.end_trial);
180
+ }
181
+ if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {
182
+ this.audio.addEventListener("ended", this.enable_slider);
183
+ }
184
+ var html = '<div id="jspsych-audio-slider-response-wrapper" style="margin: 100px 0px;">';
185
+ html += '<div class="jspsych-audio-slider-response-container" style="position:relative; margin: 0 auto 3em auto; width:';
186
+ if (this.params.slider_width !== null) {
187
+ html += this.params.slider_width + "px;";
188
+ } else {
189
+ html += "auto;";
190
+ }
191
+ html += '">';
192
+ 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"';
193
+ if (!this.params.response_allowed_while_playing) {
194
+ html += " disabled";
195
+ }
196
+ html += "></input><div>";
197
+ for (var j = 0; j < this.params.labels.length; j++) {
198
+ var label_width_perc = 100 / (this.params.labels.length - 1);
199
+ var percent_of_range = j * (100 / (this.params.labels.length - 1));
200
+ var percent_dist_from_center = (percent_of_range - 50) / 50 * 100;
201
+ var offset = percent_dist_from_center * this.half_thumb_width / 100;
202
+ 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 + '%;">';
203
+ html += '<span style="text-align: center; font-size: 80%;">' + this.params.labels[j] + "</span>";
204
+ html += "</div>";
205
+ }
206
+ html += "</div>";
207
+ html += "</div>";
208
+ html += "</div>";
209
+ if (this.params.prompt !== null) {
210
+ html += this.params.prompt;
211
+ }
212
+ var next_disabled_attribute = "";
213
+ if (this.params.require_movement || !this.params.response_allowed_while_playing) {
214
+ next_disabled_attribute = "disabled";
215
+ }
216
+ html += '<button id="jspsych-audio-slider-response-next" class="jspsych-btn" ' + next_disabled_attribute + ">" + this.params.button_label + "</button>";
217
+ this.display.innerHTML = html;
218
+ this.response = {
219
+ rt: null,
220
+ response: null
221
+ };
222
+ if (!this.params.response_allowed_while_playing) {
223
+ this.display.querySelector(
224
+ "#jspsych-audio-slider-response-response"
225
+ ).disabled = true;
226
+ this.display.querySelector("#jspsych-audio-slider-response-next").disabled = true;
227
+ }
228
+ if (this.params.require_movement) {
229
+ const enable_button = () => {
230
+ this.display.querySelector(
231
+ "#jspsych-audio-slider-response-next"
232
+ ).disabled = false;
233
+ };
234
+ this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("mousedown", enable_button);
235
+ this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("touchstart", enable_button);
236
+ this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("change", enable_button);
237
+ }
238
+ this.display.querySelector("#jspsych-audio-slider-response-next").addEventListener("click", () => {
239
+ var endTime = performance.now();
240
+ var rt = Math.round(endTime - this.startTime);
241
+ if (this.context !== null) {
242
+ endTime = this.context.currentTime;
243
+ rt = Math.round((endTime - this.startTime) * 1e3);
244
+ }
245
+ this.response.rt = rt;
246
+ this.response.response = this.display.querySelector(
247
+ "#jspsych-audio-slider-response-response"
248
+ ).valueAsNumber;
249
+ if (this.params.response_ends_trial) {
250
+ this.end_trial();
251
+ } else {
252
+ this.display.querySelector(
253
+ "#jspsych-audio-slider-response-next"
254
+ ).disabled = true;
255
+ }
256
+ });
257
+ this.startTime = performance.now();
258
+ if (this.context !== null) {
259
+ this.startTime = this.context.currentTime;
260
+ }
261
+ this.audio.play();
262
+ if (this.params.trial_duration !== null) {
263
+ this.jsPsych.pluginAPI.setTimeout(() => {
264
+ this.end_trial();
265
+ }, this.params.trial_duration);
266
+ }
267
+ };
268
+ this.end_trial = () => {
269
+ this.jsPsych.pluginAPI.clearAllTimeouts();
270
+ this.audio.removeEventListener("ended", this.end_trial);
271
+ this.audio.removeEventListener("ended", this.enable_slider);
272
+ this.audio.stop();
273
+ var trialdata = {
274
+ rt: this.response.rt,
275
+ stimulus: this.params.stimulus,
276
+ slider_start: this.params.slider_start,
277
+ response: this.response.response
278
+ };
279
+ this.display.innerHTML = "";
280
+ this.trial_complete(trialdata);
281
+ };
177
282
  autoBind$1(this);
178
283
  }
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;
284
+ static {
285
+ this.info = info;
286
+ }
188
287
  async trial(display_element, trial, on_load) {
189
288
  this.params = trial;
190
289
  this.display = display_element;
@@ -199,117 +298,13 @@ var jsPsychAudioSliderResponse = (function (jspsych) {
199
298
  this.trial_complete = resolve;
200
299
  });
201
300
  }
301
+ // to enable slider after audio ends
202
302
  enable_slider() {
203
303
  document.querySelector("#jspsych-audio-slider-response-response").disabled = false;
204
304
  if (!this.params.require_movement) {
205
305
  document.querySelector("#jspsych-audio-slider-response-next").disabled = false;
206
306
  }
207
307
  }
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
308
  simulate(trial, simulation_mode, simulation_options, load_callback) {
314
309
  if (simulation_mode == "data-only") {
315
310
  load_callback();
@@ -361,4 +356,4 @@ var jsPsychAudioSliderResponse = (function (jspsych) {
361
356
  return AudioSliderResponsePlugin;
362
357
 
363
358
  })(jsPsychModule);
364
- //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-audio-slider-response@2.0.1/dist/index.browser.js.map
359
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-audio-slider-response@2.1.1/dist/index.browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.js","sources":["../../../node_modules/auto-bind/index.js","../src/index.ts"],"sourcesContent":["'use strict';\n\n// Gets all non-builtin properties up the prototype chain\nconst getAllProperties = object => {\n\tconst properties = new Set();\n\n\tdo {\n\t\tfor (const key of Reflect.ownKeys(object)) {\n\t\t\tproperties.add([object, key]);\n\t\t}\n\t} while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);\n\n\treturn properties;\n};\n\nmodule.exports = (self, {include, exclude} = {}) => {\n\tconst filter = key => {\n\t\tconst match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);\n\n\t\tif (include) {\n\t\t\treturn include.some(match);\n\t\t}\n\n\t\tif (exclude) {\n\t\t\treturn !exclude.some(match);\n\t\t}\n\n\t\treturn true;\n\t};\n\n\tfor (const [object, key] of getAllProperties(self.constructor.prototype)) {\n\t\tif (key === 'constructor' || !filter(key)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(object, key);\n\t\tif (descriptor && typeof descriptor.value === 'function') {\n\t\t\tself[key] = self[key].bind(self);\n\t\t}\n\t}\n\n\treturn self;\n};\n","import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If\n * the participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need\n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n //record start time\n this.startTime = performance.now();\n // record webaudio context start time\n if (this.context !== null) {\n this.startTime = this.context.currentTime;\n }\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_slider);\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\n };\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":["version","ParameterType","autoBind"],"mapp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AA,CAAA;CAAA,OACrF;CAAA,KACF,CAAA;CAEA,IAAK,IAAA,CAAA,KAAA,CAAM,eAAiB,EAAA,KAAA,EAAO,MAAM;CACvC,MAAc,aAAA,EAAA,CAAA;CAEd,MAAI,IAAA,CAAC,MAAM,8BAAgC,EAAA;CACzC,QAAK,IAAA,CAAA,KAAA,CAAM,gBAAiB,CAAA,OAAA,EAAS,OAAO,CAAA,CAAA;CAAA,OACvC,MAAA;CACL,QAAQ,OAAA,EAAA,CAAA;CAAA,OACV;CAAA,KACD,CAAA,CAAA;CAAA,GACH;CACF;;;;;;;;"}
1
+ {"version":3,"file":"index.browser.js","sources":["../../../node_modules/auto-bind/index.js","../package.json","../src/index.ts"],"sourcesContent":["'use strict';\n\n// Gets all non-builtin properties up the prototype chain\nconst getAllProperties = object => {\n\tconst properties = new Set();\n\n\tdo {\n\t\tfor (const key of Reflect.ownKeys(object)) {\n\t\t\tproperties.add([object, key]);\n\t\t}\n\t} while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);\n\n\treturn properties;\n};\n\nmodule.exports = (self, {include, exclude} = {}) => {\n\tconst filter = key => {\n\t\tconst match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key);\n\n\t\tif (include) {\n\t\t\treturn include.some(match);\n\t\t}\n\n\t\tif (exclude) {\n\t\t\treturn !exclude.some(match);\n\t\t}\n\n\t\treturn true;\n\t};\n\n\tfor (const [object, key] of getAllProperties(self.constructor.prototype)) {\n\t\tif (key === 'constructor' || !filter(key)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(object, key);\n\t\tif (descriptor && typeof descriptor.value === 'function') {\n\t\t\tself[key] = self[key].bind(self);\n\t\t}\n\t}\n\n\treturn self;\n};\n","{\n \"name\": \"@jspsych/plugin-audio-slider-response\",\n \"version\": \"2.1.1\",\n \"description\": \"\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest --passWithNoTests\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-audio-slider-response\"\n },\n \"author\": \"Josh de Leeuw\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/audio-slider-response\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.2.0\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import autoBind from \"auto-bind\";\nimport { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { AudioPlayerInterface } from \"../../jspsych/src/modules/plugin-api/AudioPlayer\";\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"audio-slider-response\",\n version: version,\n parameters: {\n /** Audio file to be played. */\n stimulus: {\n type: ParameterType.AUDIO,\n default: undefined,\n },\n /** Sets the minimum value of the slider. */\n min: {\n type: ParameterType.INT,\n default: 0,\n },\n /** Sets the maximum value of the slider */\n max: {\n type: ParameterType.INT,\n default: 100,\n },\n /** Sets the starting value of the slider */\n slider_start: {\n type: ParameterType.INT,\n default: 50,\n },\n /** Sets the step of the slider. This is the smallest amount by which the slider can change. */\n step: {\n type: ParameterType.INT,\n default: 1,\n },\n /** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the\n * slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the\n * other two will be at 33% and 67% of the slider width.\n */\n labels: {\n type: ParameterType.HTML_STRING,\n default: [],\n array: true,\n },\n /** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */\n slider_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to end the trial. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n array: false,\n },\n /** If true, the participant must move the slider before clicking the continue button. */\n require_movement: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is\n * that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If\n * the participant fails to make a response before this timer is reached, the participant's response will be\n * recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial\n * will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response\n * before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the\n * value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to\n * the stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /** If true, then the trial will end as soon as the audio file finishes playing. */\n trial_ends_after_audio: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before\n * the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,\n * the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).\n */\n response_allowed_while_playing: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The numeric value of the slider. */\n response: {\n type: ParameterType.INT,\n },\n /** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first\n * began playing until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The path of the audio file that was played. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** The starting value of the slider. */\n slider_start: {\n type: ParameterType.INT,\n },\n },\n // prettier-ignore\n citations: '__CITATIONS__',\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin plays an audio file and allows the participant to respond by dragging a slider.\n *\n * If the browser supports it, audio files are played using the WebAudio API. This allows for reasonably precise timing of the\n * playback. The timing of responses generated is measured against the WebAudio specific clock, improving the measurement of\n * response times. If the browser does not support the WebAudio API, then the audio file is played with HTML5 audio.\n *\n * Audio files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the audio stimulus, then you will need\n * to [manually preload](../overview/media-preloading.md#manual-preloading) the audio.\n *\n * The trial can end when the participant responds, or if the participant has failed to respond within a fixed length of time. You can also prevent the slider response from being made before the audio has finished playing.\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/audio-slider-response/ audio-slider-response plugin documentation on jspsych.org}\n */\nclass AudioSliderResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n private audio: AudioPlayerInterface;\n private context: AudioContext;\n private params: TrialType<Info>;\n private display: HTMLElement;\n private response: { rt: number; response: number } = { rt: null, response: null };\n private startTime: number;\n private half_thumb_width: number;\n private trial_complete: (trial_data: {\n rt: number;\n slider_start: number;\n response: number;\n }) => void;\n\n constructor(private jsPsych: JsPsych) {\n autoBind(this);\n }\n\n async trial(display_element: HTMLElement, trial: TrialType<Info>, on_load: () => void) {\n this.params = trial;\n this.display = display_element;\n // for storing data related to response\n this.response;\n // half of the thumb width value from jspsych.css, used to adjust the label positions\n this.half_thumb_width = 7.5;\n // hold the .resolve() function from the Promise that ends the trial\n this.trial_complete;\n\n // setup stimulus\n this.context = this.jsPsych.pluginAPI.audioContext();\n\n // load audio file\n this.audio = await this.jsPsych.pluginAPI.getAudioPlayer(trial.stimulus);\n\n this.setupTrial();\n\n on_load();\n\n return new Promise((resolve) => {\n this.trial_complete = resolve;\n });\n }\n\n // to enable slider after audio ends\n private enable_slider() {\n document.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-response\").disabled =\n false;\n if (!this.params.require_movement) {\n document.querySelector<HTMLButtonElement>(\"#jspsych-audio-slider-response-next\").disabled =\n false;\n }\n }\n\n private setupTrial = () => {\n // set up end event if trial needs it\n if (this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.end_trial);\n }\n\n // enable slider after audio ends if necessary\n if (!this.params.response_allowed_while_playing && !this.params.trial_ends_after_audio) {\n this.audio.addEventListener(\"ended\", this.enable_slider);\n }\n\n var html = '<div id=\"jspsych-audio-slider-response-wrapper\" style=\"margin: 100px 0px;\">';\n html +=\n '<div class=\"jspsych-audio-slider-response-container\" style=\"position:relative; margin: 0 auto 3em auto; width:';\n if (this.params.slider_width !== null) {\n html += this.params.slider_width + \"px;\";\n } else {\n html += \"auto;\";\n }\n html += '\">';\n html +=\n '<input type=\"range\" class=\"jspsych-slider\" value=\"' +\n this.params.slider_start +\n '\" min=\"' +\n this.params.min +\n '\" max=\"' +\n this.params.max +\n '\" step=\"' +\n this.params.step +\n '\" id=\"jspsych-audio-slider-response-response\"';\n if (!this.params.response_allowed_while_playing) {\n html += \" disabled\";\n }\n html += \"></input><div>\";\n for (var j = 0; j < this.params.labels.length; j++) {\n var label_width_perc = 100 / (this.params.labels.length - 1);\n var percent_of_range = j * (100 / (this.params.labels.length - 1));\n var percent_dist_from_center = ((percent_of_range - 50) / 50) * 100;\n var offset = (percent_dist_from_center * this.half_thumb_width) / 100;\n html +=\n '<div style=\"border: 1px solid transparent; display: inline-block; position: absolute; ' +\n \"left:calc(\" +\n percent_of_range +\n \"% - (\" +\n label_width_perc +\n \"% / 2) - \" +\n offset +\n \"px); text-align: center; width: \" +\n label_width_perc +\n '%;\">';\n html +=\n '<span style=\"text-align: center; font-size: 80%;\">' + this.params.labels[j] + \"</span>\";\n html += \"</div>\";\n }\n html += \"</div>\";\n html += \"</div>\";\n html += \"</div>\";\n\n if (this.params.prompt !== null) {\n html += this.params.prompt;\n }\n\n // add submit button\n var next_disabled_attribute = \"\";\n if (this.params.require_movement || !this.params.response_allowed_while_playing) {\n next_disabled_attribute = \"disabled\";\n }\n html +=\n '<button id=\"jspsych-audio-slider-response-next\" class=\"jspsych-btn\" ' +\n next_disabled_attribute +\n \">\" +\n this.params.button_label +\n \"</button>\";\n\n this.display.innerHTML = html;\n\n this.response = {\n rt: null,\n response: null,\n };\n\n if (!this.params.response_allowed_while_playing) {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).disabled = true;\n this.display.querySelector<HTMLInputElement>(\"#jspsych-audio-slider-response-next\").disabled =\n true;\n }\n\n if (this.params.require_movement) {\n const enable_button = () => {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = false;\n };\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"mousedown\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"touchstart\", enable_button);\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-response\")\n .addEventListener(\"change\", enable_button);\n }\n\n this.display\n .querySelector(\"#jspsych-audio-slider-response-next\")\n .addEventListener(\"click\", () => {\n // measure response time\n var endTime = performance.now();\n var rt = Math.round(endTime - this.startTime);\n if (this.context !== null) {\n endTime = this.context.currentTime;\n rt = Math.round((endTime - this.startTime) * 1000);\n }\n this.response.rt = rt;\n this.response.response = this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-response\"\n ).valueAsNumber;\n\n if (this.params.response_ends_trial) {\n this.end_trial();\n } else {\n this.display.querySelector<HTMLInputElement>(\n \"#jspsych-audio-slider-response-next\"\n ).disabled = true;\n }\n });\n\n //record start time\n this.startTime = performance.now();\n // record webaudio context start time\n if (this.context !== null) {\n this.startTime = this.context.currentTime;\n }\n\n // start audio\n this.audio.play();\n\n // end trial if trial_duration is set\n if (this.params.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n this.end_trial();\n }, this.params.trial_duration);\n }\n };\n\n private end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // remove end event listeners if they exist\n this.audio.removeEventListener(\"ended\", this.end_trial);\n this.audio.removeEventListener(\"ended\", this.enable_slider);\n\n // stop the audio file if it is playing\n this.audio.stop();\n\n // save data\n var trialdata = {\n rt: this.response.rt,\n stimulus: this.params.stimulus,\n slider_start: this.params.slider_start,\n response: this.response.response,\n };\n\n this.display.innerHTML = \"\";\n\n // next trial\n this.trial_complete(trialdata);\n };\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n slider_start: trial.slider_start,\n response: this.jsPsych.randomization.randomInt(trial.min, trial.max),\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n const respond = () => {\n if (data.rt !== null) {\n const el = display_element.querySelector<HTMLInputElement>(\"input[type='range']\");\n\n setTimeout(() => {\n this.jsPsych.pluginAPI.clickTarget(el);\n el.valueAsNumber = data.response;\n }, data.rt / 2);\n\n this.jsPsych.pluginAPI.clickTarget(display_element.querySelector(\"button\"), data.rt);\n }\n };\n\n this.trial(display_element, trial, () => {\n load_callback();\n\n if (!trial.response_allowed_while_playing) {\n this.audio.addEventListener(\"ended\", respond);\n } else {\n respond();\n }\n });\n }\n}\n\nexport default AudioSliderResponsePlugin;\n"],"names":[],"mappings":";;;;;;;CAEA;CACA,MAAM,gBAAgB,GAAG,MAAM,IAAI;CACnC,CAAC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAE,CAAA;;CAE7B,CAAC,GAAG;CACJ,EAAE,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;CAC7C,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;CAChC,GAAA;CACA,EAAE,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,MAAM,KAAK,MAAM,CAAC,SAAS,EAAA;;CAElF,CAAC,OAAO,UAAU,CAAA;CAClB,CAAC,CAAA;;KAED,QAAc,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK;CACpD,CAAC,MAAM,MAAM,GAAG,GAAG,IAAI;CACvB,EAAE,MAAM,KAAK,GAAG,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,GAAG,GAAG,KAAK,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;;CAE5F,EAAE,IAAI,OAAO,EAAE;CACf,GAAG,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;CAC7B,GAAA;;CAEA,EAAE,IAAI,OAAO,EAAE;CACf,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;CAC9B,GAAA;;CAEA,EAAE,OAAO,IAAI,CAAA;CACb,EAAE,CAAA;;CAEF,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE;CAC3E,EAAE,IAAI,GAAG,KAAK,aAAa,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;CAC7C,GAAG,SAAA;CACH,GAAA;;CAEA,EAAE,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAClE,EAAE,IAAI,UAAU,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,EAAE;CAC5D,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;CACnC,GAAA;CACA,EAAA;;CAEA,CAAC,OAAO,IAAI,CAAA;CACZ,CAAC,CAAA;;;;CCxCC,IAAW,OAAA,GAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GCsHA,SAAA,EAAA;CAAA;;IAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_google_ignoreList":[0]}
@@ -1,2 +1,2 @@
1
- var jsPsychAudioSliderResponse=function(a){"use strict";function m(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}const c=i=>{const s=new Set;do for(const e of Reflect.ownKeys(i))s.add([i,e]);while((i=Reflect.getPrototypeOf(i))&&i!==Object.prototype);return s};var y=(i,{include:s,exclude:e}={})=>{const r=t=>{const n=l=>typeof l=="string"?t===l:l.test(t);return s?s.some(n):e?!e.some(n):!0};for(const[t,n]of c(i.constructor.prototype)){if(n==="constructor"||!r(n))continue;const l=Reflect.getOwnPropertyDescriptor(t,n);l&&typeof l.value=="function"&&(i[n]=i[n].bind(i))}return i},_=m(y),g={name:"@jspsych/plugin-audio-slider-response",version:"2.0.1",description:"",type:"module",main:"dist/index.cjs",exports:{import:"./dist/index.js",require:"./dist/index.cjs"},typings:"dist/index.d.ts",unpkg:"dist/index.browser.min.js",files:["src","dist"],source:"src/index.ts",scripts:{test:"jest --passWithNoTests","test:watch":"npm test -- --watch",tsc:"tsc",build:"rollup --config","build:watch":"npm run build -- --watch"},repository:{type:"git",url:"git+https://github.com/jspsych/jsPsych.git",directory:"packages/plugin-audio-slider-response"},author:"Josh de Leeuw",license:"MIT",bugs:{url:"https://github.com/jspsych/jsPsych/issues"},homepage:"https://www.jspsych.org/latest/plugins/audio-slider-response",peerDependencies:{jspsych:">=7.1.0"},devDependencies:{"@jspsych/config":"^3.0.0","@jspsych/test-utils":"^1.2.0"}},v=(i,s,e)=>new Promise((r,t)=>{var n=p=>{try{d(e.next(p))}catch(o){t(o)}},l=p=>{try{d(e.throw(p))}catch(o){t(o)}},d=p=>p.done?r(p.value):Promise.resolve(p.value).then(n,l);d((e=e.apply(i,s)).next())});const P={name:"audio-slider-response",version:g.version,parameters:{stimulus:{type:a.ParameterType.AUDIO,default:void 0},min:{type:a.ParameterType.INT,default:0},max:{type:a.ParameterType.INT,default:100},slider_start:{type:a.ParameterType.INT,default:50},step:{type:a.ParameterType.INT,default:1},labels:{type:a.ParameterType.HTML_STRING,default:[],array:!0},slider_width:{type:a.ParameterType.INT,default:null},button_label:{type:a.ParameterType.STRING,default:"Continue",array:!1},require_movement:{type:a.ParameterType.BOOL,default:!1},prompt:{type:a.ParameterType.HTML_STRING,default:null},trial_duration:{type:a.ParameterType.INT,default:null},response_ends_trial:{type:a.ParameterType.BOOL,default:!0},trial_ends_after_audio:{type:a.ParameterType.BOOL,default:!1},response_allowed_while_playing:{type:a.ParameterType.BOOL,default:!0}},data:{response:{type:a.ParameterType.INT},rt:{type:a.ParameterType.INT},stimulus:{type:a.ParameterType.STRING},slider_start:{type:a.ParameterType.INT}}};class u{constructor(s){this.jsPsych=s,this.response={rt:null,response:null},this.setupTrial=()=>{this.params.trial_ends_after_audio&&this.audio.addEventListener("ended",this.end_trial),!this.params.response_allowed_while_playing&&!this.params.trial_ends_after_audio&&this.audio.addEventListener("ended",this.enable_slider);var e='<div id="jspsych-audio-slider-response-wrapper" style="margin: 100px 0px;">';e+='<div class="jspsych-audio-slider-response-container" style="position:relative; margin: 0 auto 3em auto; width:',this.params.slider_width!==null?e+=this.params.slider_width+"px;":e+="auto;",e+='">',e+='<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"',this.params.response_allowed_while_playing||(e+=" disabled"),e+="></input><div>";for(var r=0;r<this.params.labels.length;r++){var t=100/(this.params.labels.length-1),n=r*(100/(this.params.labels.length-1)),l=(n-50)/50*100,d=l*this.half_thumb_width/100;e+='<div style="border: 1px solid transparent; display: inline-block; position: absolute; left:calc('+n+"% - ("+t+"% / 2) - "+d+"px); text-align: center; width: "+t+'%;">',e+='<span style="text-align: center; font-size: 80%;">'+this.params.labels[r]+"</span>",e+="</div>"}e+="</div>",e+="</div>",e+="</div>",this.params.prompt!==null&&(e+=this.params.prompt);var p="";if((this.params.require_movement||!this.params.response_allowed_while_playing)&&(p="disabled"),e+='<button id="jspsych-audio-slider-response-next" class="jspsych-btn" '+p+">"+this.params.button_label+"</button>",this.display.innerHTML=e,this.response={rt:null,response:null},this.params.response_allowed_while_playing||(this.display.querySelector("#jspsych-audio-slider-response-response").disabled=!0,this.display.querySelector("#jspsych-audio-slider-response-next").disabled=!0),this.params.require_movement){const o=()=>{this.display.querySelector("#jspsych-audio-slider-response-next").disabled=!1};this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("mousedown",o),this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("touchstart",o),this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("change",o)}this.display.querySelector("#jspsych-audio-slider-response-next").addEventListener("click",()=>{var o=performance.now(),h=Math.round(o-this.startTime);this.context!==null&&(o=this.context.currentTime,h=Math.round((o-this.startTime)*1e3)),this.response.rt=h,this.response.response=this.display.querySelector("#jspsych-audio-slider-response-response").valueAsNumber,this.params.response_ends_trial?this.end_trial():this.display.querySelector("#jspsych-audio-slider-response-next").disabled=!0}),this.startTime=performance.now(),this.context!==null&&(this.startTime=this.context.currentTime),this.audio.play(),this.params.trial_duration!==null&&this.jsPsych.pluginAPI.setTimeout(()=>{this.end_trial()},this.params.trial_duration)},this.end_trial=()=>{this.jsPsych.pluginAPI.clearAllTimeouts(),this.audio.stop(),this.audio.removeEventListener("ended",this.end_trial),this.audio.removeEventListener("ended",this.enable_slider);var e={rt:this.response.rt,stimulus:this.params.stimulus,slider_start:this.params.slider_start,response:this.response.response};this.display.innerHTML="",this.trial_complete(e)},_(this)}trial(s,e,r){return v(this,null,function*(){return this.params=e,this.display=s,this.response,this.half_thumb_width=7.5,this.trial_complete,this.context=this.jsPsych.pluginAPI.audioContext(),this.audio=yield this.jsPsych.pluginAPI.getAudioPlayer(e.stimulus),this.setupTrial(),r(),new Promise(t=>{this.trial_complete=t})})}enable_slider(){document.querySelector("#jspsych-audio-slider-response-response").disabled=!1,this.params.require_movement||(document.querySelector("#jspsych-audio-slider-response-next").disabled=!1)}simulate(s,e,r,t){e=="data-only"&&(t(),this.simulate_data_only(s,r)),e=="visual"&&this.simulate_visual(s,r,t)}create_simulation_data(s,e){const r={stimulus:s.stimulus,slider_start:s.slider_start,response:this.jsPsych.randomization.randomInt(s.min,s.max),rt:this.jsPsych.randomization.sampleExGaussian(500,50,.006666666666666667,!0)},t=this.jsPsych.pluginAPI.mergeSimulationData(r,e);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(s,t),t}simulate_data_only(s,e){const r=this.create_simulation_data(s,e);this.jsPsych.finishTrial(r)}simulate_visual(s,e,r){const t=this.create_simulation_data(s,e),n=this.jsPsych.getDisplayElement(),l=()=>{if(t.rt!==null){const d=n.querySelector("input[type='range']");setTimeout(()=>{this.jsPsych.pluginAPI.clickTarget(d),d.valueAsNumber=t.response},t.rt/2),this.jsPsych.pluginAPI.clickTarget(n.querySelector("button"),t.rt)}};this.trial(n,s,()=>{r(),s.response_allowed_while_playing?l():this.audio.addEventListener("ended",l)})}}return u.info=P,u}(jsPsychModule);
2
- //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-audio-slider-response@2.0.1/dist/index.browser.min.js.map
1
+ var jsPsychAudioSliderResponse=function(i){"use strict";function m(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}const y=r=>{const t=new Set;do for(const e of Reflect.ownKeys(r))t.add([r,e]);while((r=Reflect.getPrototypeOf(r))&&r!==Object.prototype);return t};var c=(r,{include:t,exclude:e}={})=>{const a=s=>{const n=l=>typeof l=="string"?s===l:l.test(s);return t?t.some(n):e?!e.some(n):!0};for(const[s,n]of y(r.constructor.prototype)){if(n==="constructor"||!a(n))continue;const l=Reflect.getOwnPropertyDescriptor(s,n);l&&typeof l.value=="function"&&(r[n]=r[n].bind(r))}return r},_=m(c),v="2.1.1",f=(r,t,e)=>new Promise((a,s)=>{var n=p=>{try{d(e.next(p))}catch(o){s(o)}},l=p=>{try{d(e.throw(p))}catch(o){s(o)}},d=p=>p.done?a(p.value):Promise.resolve(p.value).then(n,l);d((e=e.apply(r,t)).next())});const P={name:"audio-slider-response",version:v,parameters:{stimulus:{type:i.ParameterType.AUDIO,default:void 0},min:{type:i.ParameterType.INT,default:0},max:{type:i.ParameterType.INT,default:100},slider_start:{type:i.ParameterType.INT,default:50},step:{type:i.ParameterType.INT,default:1},labels:{type:i.ParameterType.HTML_STRING,default:[],array:!0},slider_width:{type:i.ParameterType.INT,default:null},button_label:{type:i.ParameterType.STRING,default:"Continue",array:!1},require_movement:{type:i.ParameterType.BOOL,default:!1},prompt:{type:i.ParameterType.HTML_STRING,default:null},trial_duration:{type:i.ParameterType.INT,default:null},response_ends_trial:{type:i.ParameterType.BOOL,default:!0},trial_ends_after_audio:{type:i.ParameterType.BOOL,default:!1},response_allowed_while_playing:{type:i.ParameterType.BOOL,default:!0}},data:{response:{type:i.ParameterType.INT},rt:{type:i.ParameterType.INT},stimulus:{type:i.ParameterType.STRING},slider_start:{type:i.ParameterType.INT}},citations:{apa:"de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ",bibtex:'@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '}};class u{constructor(t){this.jsPsych=t,this.response={rt:null,response:null},this.setupTrial=()=>{this.params.trial_ends_after_audio&&this.audio.addEventListener("ended",this.end_trial),!this.params.response_allowed_while_playing&&!this.params.trial_ends_after_audio&&this.audio.addEventListener("ended",this.enable_slider);var e='<div id="jspsych-audio-slider-response-wrapper" style="margin: 100px 0px;">';e+='<div class="jspsych-audio-slider-response-container" style="position:relative; margin: 0 auto 3em auto; width:',this.params.slider_width!==null?e+=this.params.slider_width+"px;":e+="auto;",e+='">',e+='<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"',this.params.response_allowed_while_playing||(e+=" disabled"),e+="></input><div>";for(var a=0;a<this.params.labels.length;a++){var s=100/(this.params.labels.length-1),n=a*(100/(this.params.labels.length-1)),l=(n-50)/50*100,d=l*this.half_thumb_width/100;e+='<div style="border: 1px solid transparent; display: inline-block; position: absolute; left:calc('+n+"% - ("+s+"% / 2) - "+d+"px); text-align: center; width: "+s+'%;">',e+='<span style="text-align: center; font-size: 80%;">'+this.params.labels[a]+"</span>",e+="</div>"}e+="</div>",e+="</div>",e+="</div>",this.params.prompt!==null&&(e+=this.params.prompt);var p="";if((this.params.require_movement||!this.params.response_allowed_while_playing)&&(p="disabled"),e+='<button id="jspsych-audio-slider-response-next" class="jspsych-btn" '+p+">"+this.params.button_label+"</button>",this.display.innerHTML=e,this.response={rt:null,response:null},this.params.response_allowed_while_playing||(this.display.querySelector("#jspsych-audio-slider-response-response").disabled=!0,this.display.querySelector("#jspsych-audio-slider-response-next").disabled=!0),this.params.require_movement){const o=()=>{this.display.querySelector("#jspsych-audio-slider-response-next").disabled=!1};this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("mousedown",o),this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("touchstart",o),this.display.querySelector("#jspsych-audio-slider-response-response").addEventListener("change",o)}this.display.querySelector("#jspsych-audio-slider-response-next").addEventListener("click",()=>{var o=performance.now(),h=Math.round(o-this.startTime);this.context!==null&&(o=this.context.currentTime,h=Math.round((o-this.startTime)*1e3)),this.response.rt=h,this.response.response=this.display.querySelector("#jspsych-audio-slider-response-response").valueAsNumber,this.params.response_ends_trial?this.end_trial():this.display.querySelector("#jspsych-audio-slider-response-next").disabled=!0}),this.startTime=performance.now(),this.context!==null&&(this.startTime=this.context.currentTime),this.audio.play(),this.params.trial_duration!==null&&this.jsPsych.pluginAPI.setTimeout(()=>{this.end_trial()},this.params.trial_duration)},this.end_trial=()=>{this.jsPsych.pluginAPI.clearAllTimeouts(),this.audio.removeEventListener("ended",this.end_trial),this.audio.removeEventListener("ended",this.enable_slider),this.audio.stop();var e={rt:this.response.rt,stimulus:this.params.stimulus,slider_start:this.params.slider_start,response:this.response.response};this.display.innerHTML="",this.trial_complete(e)},_(this)}trial(t,e,a){return f(this,null,function*(){return this.params=e,this.display=t,this.response,this.half_thumb_width=7.5,this.trial_complete,this.context=this.jsPsych.pluginAPI.audioContext(),this.audio=yield this.jsPsych.pluginAPI.getAudioPlayer(e.stimulus),this.setupTrial(),a(),new Promise(s=>{this.trial_complete=s})})}enable_slider(){document.querySelector("#jspsych-audio-slider-response-response").disabled=!1,this.params.require_movement||(document.querySelector("#jspsych-audio-slider-response-next").disabled=!1)}simulate(t,e,a,s){e=="data-only"&&(s(),this.simulate_data_only(t,a)),e=="visual"&&this.simulate_visual(t,a,s)}create_simulation_data(t,e){const a={stimulus:t.stimulus,slider_start:t.slider_start,response:this.jsPsych.randomization.randomInt(t.min,t.max),rt:this.jsPsych.randomization.sampleExGaussian(500,50,.006666666666666667,!0)},s=this.jsPsych.pluginAPI.mergeSimulationData(a,e);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(t,s),s}simulate_data_only(t,e){const a=this.create_simulation_data(t,e);this.jsPsych.finishTrial(a)}simulate_visual(t,e,a){const s=this.create_simulation_data(t,e),n=this.jsPsych.getDisplayElement(),l=()=>{if(s.rt!==null){const d=n.querySelector("input[type='range']");setTimeout(()=>{this.jsPsych.pluginAPI.clickTarget(d),d.valueAsNumber=s.response},s.rt/2),this.jsPsych.pluginAPI.clickTarget(n.querySelector("button"),s.rt)}};this.trial(n,t,()=>{a(),t.response_allowed_while_playing?l():this.audio.addEventListener("ended",l)})}}return u.info=P,u}(jsPsychModule);
2
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-audio-slider-response@2.1.1/dist/index.browser.min.js.map