@jspsych/plugin-audio-slider-response 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js +154 -159
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +2 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +47 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +47 -45
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.min.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":["getAllProperties","object","properties","key","autoBind","self","include","exclude","filter","match","pattern","descriptor","info","version","ParameterType","AudioSliderResponsePlugin","jsPsych","html","j","label_width_perc","percent_of_range","percent_dist_from_center","offset","next_disabled_attribute","enable_button","endTime","rt","trialdata","display_element","trial","on_load","__async","resolve","simulation_mode","simulation_options","load_callback","default_data","data","respond","el"],"mappings":"4JAGA,MAAMA,EAAmBC,GAAU,CAClC,MAAMC,EAAa,IAAI,IAEvB,EACC,WAAWC,KAAO,QAAQ,QAAQF,CAAM,EACvCC,EAAW,IAAI,CAACD,EAAQE,CAAG,CAAC,SAEpBF,EAAS,QAAQ,eAAeA,CAAM,IAAMA,IAAW,OAAO,WAExE,OAAOC,CACR,MAEAE,EAAiB,CAACC,EAAM,CAAC,QAAAC,EAAS,QAAAC,CAAO,EAAI,CAAA,IAAO,CACnD,MAAMC,EAASL,GAAO,CACrB,MAAMM,EAAQC,GAAW,OAAOA,GAAY,SAAWP,IAAQO,EAAUA,EAAQ,KAAKP,CAAG,EAEzF,OAAIG,EAC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D,EAAcF,CAAkB,EAExF,OAAA,KAAK,QAAQ,UAAU,gCAAgCL,EAAOQ,CAAI,EAE3DA,CACT,CAEQ,mBAAmBR,EAAwBK,EAAoB,CACrE,MAAMG,EAAO,KAAK,uBAAuBR,EAAOK,CAAkB,EAElE,KAAK,QAAQ,YAAYG,CAAI,CAC/B,CAEQ,gBAAgBR,EAAwBK,EAAoBC,EAA2B,CAC7F,MAAME,EAAO,KAAK,uBAAuBR,EAAOK,CAAkB,EAE5DN,EAAkB,KAAK,QAAQ,kBAAkB,EAEjDU,EAAU,IAAM,CACpB,GAAID,EAAK,KAAO,KAAM,CACpB,MAAME,EAAKX,EAAgB,cAAgC,qBAAqB,EAEhF,WAAW,IAAM,CACf,KAAK,QAAQ,UAAU,YAAYW,CAAE,EACrCA,EAAG,cAAgBF,EAAK,QAC1B,EAAGA,EAAK,GAAK,CAAC,EAEd,KAAK,QAAQ,UAAU,YAAYT,EAAgB,cAAc,QAAQ,EAAGS,EAAK,EAAE,CACrF,CACF,EAEA,KAAK,MAAMT,EAAiBC,EAAO,IAAM,CACvCM,EAAAA,EAEKN,EAAM,+BAGTS,EAAQ,EAFR,KAAK,MAAM,iBAAiB,QAASA,CAAO,CAIhD,CAAC,CACH,CACF,CAtSMvB,OAAAA,EACG,KAAOH"}
|
|
1
|
+
{"version":3,"file":"index.browser.min.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.0\",\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 // 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":["getAllProperties","object","properties","key","autoBind","self","include","exclude","filter","match","pattern","descriptor","version"],"mappings":"4JAGA,MAAMA,EAAmBC,GAAU,CAClC,MAAMC,EAAa,IAAI,IAEvB,EACC,WAAWC,KAAO,QAAQ,QAAQF,CAAM,EACvCC,EAAW,IAAI,CAACD,EAAQE,CAAG,CAAC,SAEpBF,EAAS,QAAQ,eAAeA,CAAM,IAAMA,IAAW,OAAO,WAExE,OAAOC,CACR,MAEAE,EAAiB,CAACC,EAAM,CAAC,QAAAC,EAAS,QAAAC,CAAO,EAAI,CAAA,IAAO,CACnD,MAAMC,EAASL,GAAO,CACrB,MAAMM,EAAQC,GAAW,OAAOA,GAAY,SAAWP,IAAQO,EAAUA,EAAQ,KAAKP,CAAG,EAEzF,OAAIG,EACIA,EAAQ,KAAKG,CAAK,EAGtBF,EACI,CAACA,EAAQ,KAAKE,CAAK,EAGpB,EACT,EAEC,SAAW,CAACR,EAAQE,CAAG,IAAKH,EAAiBK,EAAK,YAAY,SAAS,EAAG,CACzE,GAAIF,IAAQ,eAAiB,CAACK,EAAOL,CAAG,EACvC,SAGD,MAAMQ,EAAa,QAAQ,yBAAyBV,EAAQE,CAAG,EAC3DQ,GAAc,OAAOA,EAAW,OAAU,aAC7CN,EAAKF,CAAG,EAAIE,EAAKF,CAAG,EAAE,KAAKE,CAAI,EAElC,CAEC,OAAOA,CACR,SCxCEO,EAAW,2qCCsHA,UAAA,iuBAAe","x_google_ignoreList":[0]}
|
package/dist/index.cjs
CHANGED
|
@@ -3,126 +3,125 @@
|
|
|
3
3
|
var autoBind = require('auto-bind');
|
|
4
4
|
var jspsych = require('jspsych');
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
name: "@jspsych/plugin-audio-slider-response",
|
|
8
|
-
version: "2.0.1",
|
|
9
|
-
description: "",
|
|
10
|
-
type: "module",
|
|
11
|
-
main: "dist/index.cjs",
|
|
12
|
-
exports: {
|
|
13
|
-
import: "./dist/index.js",
|
|
14
|
-
require: "./dist/index.cjs"
|
|
15
|
-
},
|
|
16
|
-
typings: "dist/index.d.ts",
|
|
17
|
-
unpkg: "dist/index.browser.min.js",
|
|
18
|
-
files: [
|
|
19
|
-
"src",
|
|
20
|
-
"dist"
|
|
21
|
-
],
|
|
22
|
-
source: "src/index.ts",
|
|
23
|
-
scripts: {
|
|
24
|
-
test: "jest --passWithNoTests",
|
|
25
|
-
"test:watch": "npm test -- --watch",
|
|
26
|
-
tsc: "tsc",
|
|
27
|
-
build: "rollup --config",
|
|
28
|
-
"build:watch": "npm run build -- --watch"
|
|
29
|
-
},
|
|
30
|
-
repository: {
|
|
31
|
-
type: "git",
|
|
32
|
-
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
33
|
-
directory: "packages/plugin-audio-slider-response"
|
|
34
|
-
},
|
|
35
|
-
author: "Josh de Leeuw",
|
|
36
|
-
license: "MIT",
|
|
37
|
-
bugs: {
|
|
38
|
-
url: "https://github.com/jspsych/jsPsych/issues"
|
|
39
|
-
},
|
|
40
|
-
homepage: "https://www.jspsych.org/latest/plugins/audio-slider-response",
|
|
41
|
-
peerDependencies: {
|
|
42
|
-
jspsych: ">=7.1.0"
|
|
43
|
-
},
|
|
44
|
-
devDependencies: {
|
|
45
|
-
"@jspsych/config": "^3.0.0",
|
|
46
|
-
"@jspsych/test-utils": "^1.2.0"
|
|
47
|
-
}
|
|
48
|
-
};
|
|
6
|
+
var version = "2.1.0";
|
|
49
7
|
|
|
50
8
|
const info = {
|
|
51
9
|
name: "audio-slider-response",
|
|
52
|
-
version
|
|
10
|
+
version,
|
|
53
11
|
parameters: {
|
|
12
|
+
/** Audio file to be played. */
|
|
54
13
|
stimulus: {
|
|
55
14
|
type: jspsych.ParameterType.AUDIO,
|
|
56
15
|
default: void 0
|
|
57
16
|
},
|
|
17
|
+
/** Sets the minimum value of the slider. */
|
|
58
18
|
min: {
|
|
59
19
|
type: jspsych.ParameterType.INT,
|
|
60
20
|
default: 0
|
|
61
21
|
},
|
|
22
|
+
/** Sets the maximum value of the slider */
|
|
62
23
|
max: {
|
|
63
24
|
type: jspsych.ParameterType.INT,
|
|
64
25
|
default: 100
|
|
65
26
|
},
|
|
27
|
+
/** Sets the starting value of the slider */
|
|
66
28
|
slider_start: {
|
|
67
29
|
type: jspsych.ParameterType.INT,
|
|
68
30
|
default: 50
|
|
69
31
|
},
|
|
32
|
+
/** Sets the step of the slider. This is the smallest amount by which the slider can change. */
|
|
70
33
|
step: {
|
|
71
34
|
type: jspsych.ParameterType.INT,
|
|
72
35
|
default: 1
|
|
73
36
|
},
|
|
37
|
+
/** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the
|
|
38
|
+
* slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the
|
|
39
|
+
* other two will be at 33% and 67% of the slider width.
|
|
40
|
+
*/
|
|
74
41
|
labels: {
|
|
75
42
|
type: jspsych.ParameterType.HTML_STRING,
|
|
76
43
|
default: [],
|
|
77
44
|
array: true
|
|
78
45
|
},
|
|
46
|
+
/** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */
|
|
79
47
|
slider_width: {
|
|
80
48
|
type: jspsych.ParameterType.INT,
|
|
81
49
|
default: null
|
|
82
50
|
},
|
|
51
|
+
/** Label of the button to end the trial. */
|
|
83
52
|
button_label: {
|
|
84
53
|
type: jspsych.ParameterType.STRING,
|
|
85
54
|
default: "Continue",
|
|
86
55
|
array: false
|
|
87
56
|
},
|
|
57
|
+
/** If true, the participant must move the slider before clicking the continue button. */
|
|
88
58
|
require_movement: {
|
|
89
59
|
type: jspsych.ParameterType.BOOL,
|
|
90
60
|
default: false
|
|
91
61
|
},
|
|
62
|
+
/** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is
|
|
63
|
+
* that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
|
|
64
|
+
*/
|
|
92
65
|
prompt: {
|
|
93
66
|
type: jspsych.ParameterType.HTML_STRING,
|
|
94
67
|
default: null
|
|
95
68
|
},
|
|
69
|
+
/** How long to wait for the participant to make a response before ending the trial in milliseconds. If
|
|
70
|
+
* the participant fails to make a response before this timer is reached, the participant's response will be
|
|
71
|
+
* recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial
|
|
72
|
+
* will wait for a response indefinitely.
|
|
73
|
+
*/
|
|
96
74
|
trial_duration: {
|
|
97
75
|
type: jspsych.ParameterType.INT,
|
|
98
76
|
default: null
|
|
99
77
|
},
|
|
78
|
+
/** If true, then the trial will end whenever the participant makes a response (assuming they make their response
|
|
79
|
+
* before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the
|
|
80
|
+
* value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to
|
|
81
|
+
* the stimulus for a fixed amount of time, even if they respond before the time is complete.
|
|
82
|
+
*/
|
|
100
83
|
response_ends_trial: {
|
|
101
84
|
type: jspsych.ParameterType.BOOL,
|
|
102
85
|
default: true
|
|
103
86
|
},
|
|
87
|
+
/** If true, then the trial will end as soon as the audio file finishes playing. */
|
|
104
88
|
trial_ends_after_audio: {
|
|
105
89
|
type: jspsych.ParameterType.BOOL,
|
|
106
90
|
default: false
|
|
107
91
|
},
|
|
92
|
+
/** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before
|
|
93
|
+
* the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,
|
|
94
|
+
* the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).
|
|
95
|
+
*/
|
|
108
96
|
response_allowed_while_playing: {
|
|
109
97
|
type: jspsych.ParameterType.BOOL,
|
|
110
98
|
default: true
|
|
111
99
|
}
|
|
112
100
|
},
|
|
113
101
|
data: {
|
|
102
|
+
/** The numeric value of the slider. */
|
|
114
103
|
response: {
|
|
115
104
|
type: jspsych.ParameterType.INT
|
|
116
105
|
},
|
|
106
|
+
/** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first
|
|
107
|
+
* began playing until the participant's response.
|
|
108
|
+
*/
|
|
117
109
|
rt: {
|
|
118
110
|
type: jspsych.ParameterType.INT
|
|
119
111
|
},
|
|
112
|
+
/** The path of the audio file that was played. */
|
|
120
113
|
stimulus: {
|
|
121
114
|
type: jspsych.ParameterType.STRING
|
|
122
115
|
},
|
|
116
|
+
/** The starting value of the slider. */
|
|
123
117
|
slider_start: {
|
|
124
118
|
type: jspsych.ParameterType.INT
|
|
125
119
|
}
|
|
120
|
+
},
|
|
121
|
+
// prettier-ignore
|
|
122
|
+
citations: {
|
|
123
|
+
"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 ",
|
|
124
|
+
"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}, } '
|
|
126
125
|
}
|
|
127
126
|
};
|
|
128
127
|
class AudioSliderResponsePlugin {
|
|
@@ -236,6 +235,9 @@ class AudioSliderResponsePlugin {
|
|
|
236
235
|
};
|
|
237
236
|
autoBind(this);
|
|
238
237
|
}
|
|
238
|
+
static {
|
|
239
|
+
this.info = info;
|
|
240
|
+
}
|
|
239
241
|
async trial(display_element, trial, on_load) {
|
|
240
242
|
this.params = trial;
|
|
241
243
|
this.display = display_element;
|
|
@@ -250,6 +252,7 @@ class AudioSliderResponsePlugin {
|
|
|
250
252
|
this.trial_complete = resolve;
|
|
251
253
|
});
|
|
252
254
|
}
|
|
255
|
+
// to enable slider after audio ends
|
|
253
256
|
enable_slider() {
|
|
254
257
|
document.querySelector("#jspsych-audio-slider-response-response").disabled = false;
|
|
255
258
|
if (!this.params.require_movement) {
|
|
@@ -303,7 +306,6 @@ class AudioSliderResponsePlugin {
|
|
|
303
306
|
});
|
|
304
307
|
}
|
|
305
308
|
}
|
|
306
|
-
AudioSliderResponsePlugin.info = info;
|
|
307
309
|
|
|
308
310
|
module.exports = AudioSliderResponsePlugin;
|
|
309
311
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,uBAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAEV,QAAU,EAAA;AAAA,MACR,MAAMC,qBAAc,CAAA,KAAA;AAAA,MACpB,OAAS,EAAA,KAAA,CAAA;AAAA,KACX;AAAA,IAEA,GAAK,EAAA;AAAA,MACH,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,CAAA;AAAA,KACX;AAAA,IAEA,GAAK,EAAA;AAAA,MACH,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,GAAA;AAAA,KACX;AAAA,IAEA,YAAc,EAAA;AAAA,MACZ,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,EAAA;AAAA,KACX;AAAA,IAEA,IAAM,EAAA;AAAA,MACJ,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,CAAA;AAAA,KACX;AAAA,IAKA,MAAQ,EAAA;AAAA,MACN,MAAMA,qBAAc,CAAA,WAAA;AAAA,MACpB,SAAS,EAAC;AAAA,MACV,KAAO,EAAA,IAA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CAAM,eAAiB,EAAA,KAAA,EAAO,MAAM;AACvC,MAAc,aAAA,EAAA,CAAA;AAEd,MAAI,IAAA,CAAC,MAAM,8BAAgC,EAAA;AACzC,QAAK,IAAA,CAAA,KAAA,CAAM,gBAAiB,CAAA,OAAA,EAAS,OAAO,CAAA,CAAA;AAAA,OACvC,MAAA;AACL,QAAQ,OAAA,EAAA,CAAA;AAAA,OACV;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAtSM,yBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-audio-slider-response\",\n \"version\": \"2.1.0\",\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 // 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":[],"mappings":";;;;;AAEE,IAAW,OAAA,GAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ECsHA,SAAA,EAAA;AAAA;;GAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -113,6 +113,7 @@ declare const info: {
|
|
|
113
113
|
readonly type: ParameterType.INT;
|
|
114
114
|
};
|
|
115
115
|
};
|
|
116
|
+
readonly citations: "__CITATIONS__";
|
|
116
117
|
};
|
|
117
118
|
type Info = typeof info;
|
|
118
119
|
/**
|
|
@@ -245,6 +246,7 @@ declare class AudioSliderResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
245
246
|
readonly type: ParameterType.INT;
|
|
246
247
|
};
|
|
247
248
|
};
|
|
249
|
+
readonly citations: "__CITATIONS__";
|
|
248
250
|
};
|
|
249
251
|
private audio;
|
|
250
252
|
private context;
|
package/dist/index.js
CHANGED
|
@@ -1,126 +1,125 @@
|
|
|
1
1
|
import autoBind from 'auto-bind';
|
|
2
2
|
import { ParameterType } from 'jspsych';
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
name: "@jspsych/plugin-audio-slider-response",
|
|
6
|
-
version: "2.0.1",
|
|
7
|
-
description: "",
|
|
8
|
-
type: "module",
|
|
9
|
-
main: "dist/index.cjs",
|
|
10
|
-
exports: {
|
|
11
|
-
import: "./dist/index.js",
|
|
12
|
-
require: "./dist/index.cjs"
|
|
13
|
-
},
|
|
14
|
-
typings: "dist/index.d.ts",
|
|
15
|
-
unpkg: "dist/index.browser.min.js",
|
|
16
|
-
files: [
|
|
17
|
-
"src",
|
|
18
|
-
"dist"
|
|
19
|
-
],
|
|
20
|
-
source: "src/index.ts",
|
|
21
|
-
scripts: {
|
|
22
|
-
test: "jest --passWithNoTests",
|
|
23
|
-
"test:watch": "npm test -- --watch",
|
|
24
|
-
tsc: "tsc",
|
|
25
|
-
build: "rollup --config",
|
|
26
|
-
"build:watch": "npm run build -- --watch"
|
|
27
|
-
},
|
|
28
|
-
repository: {
|
|
29
|
-
type: "git",
|
|
30
|
-
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
31
|
-
directory: "packages/plugin-audio-slider-response"
|
|
32
|
-
},
|
|
33
|
-
author: "Josh de Leeuw",
|
|
34
|
-
license: "MIT",
|
|
35
|
-
bugs: {
|
|
36
|
-
url: "https://github.com/jspsych/jsPsych/issues"
|
|
37
|
-
},
|
|
38
|
-
homepage: "https://www.jspsych.org/latest/plugins/audio-slider-response",
|
|
39
|
-
peerDependencies: {
|
|
40
|
-
jspsych: ">=7.1.0"
|
|
41
|
-
},
|
|
42
|
-
devDependencies: {
|
|
43
|
-
"@jspsych/config": "^3.0.0",
|
|
44
|
-
"@jspsych/test-utils": "^1.2.0"
|
|
45
|
-
}
|
|
46
|
-
};
|
|
4
|
+
var version = "2.1.0";
|
|
47
5
|
|
|
48
6
|
const info = {
|
|
49
7
|
name: "audio-slider-response",
|
|
50
|
-
version
|
|
8
|
+
version,
|
|
51
9
|
parameters: {
|
|
10
|
+
/** Audio file to be played. */
|
|
52
11
|
stimulus: {
|
|
53
12
|
type: ParameterType.AUDIO,
|
|
54
13
|
default: void 0
|
|
55
14
|
},
|
|
15
|
+
/** Sets the minimum value of the slider. */
|
|
56
16
|
min: {
|
|
57
17
|
type: ParameterType.INT,
|
|
58
18
|
default: 0
|
|
59
19
|
},
|
|
20
|
+
/** Sets the maximum value of the slider */
|
|
60
21
|
max: {
|
|
61
22
|
type: ParameterType.INT,
|
|
62
23
|
default: 100
|
|
63
24
|
},
|
|
25
|
+
/** Sets the starting value of the slider */
|
|
64
26
|
slider_start: {
|
|
65
27
|
type: ParameterType.INT,
|
|
66
28
|
default: 50
|
|
67
29
|
},
|
|
30
|
+
/** Sets the step of the slider. This is the smallest amount by which the slider can change. */
|
|
68
31
|
step: {
|
|
69
32
|
type: ParameterType.INT,
|
|
70
33
|
default: 1
|
|
71
34
|
},
|
|
35
|
+
/** Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the
|
|
36
|
+
* slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the
|
|
37
|
+
* other two will be at 33% and 67% of the slider width.
|
|
38
|
+
*/
|
|
72
39
|
labels: {
|
|
73
40
|
type: ParameterType.HTML_STRING,
|
|
74
41
|
default: [],
|
|
75
42
|
array: true
|
|
76
43
|
},
|
|
44
|
+
/** Set the width of the slider in pixels. If left null, then the width will be equal to the widest element in the display. */
|
|
77
45
|
slider_width: {
|
|
78
46
|
type: ParameterType.INT,
|
|
79
47
|
default: null
|
|
80
48
|
},
|
|
49
|
+
/** Label of the button to end the trial. */
|
|
81
50
|
button_label: {
|
|
82
51
|
type: ParameterType.STRING,
|
|
83
52
|
default: "Continue",
|
|
84
53
|
array: false
|
|
85
54
|
},
|
|
55
|
+
/** If true, the participant must move the slider before clicking the continue button. */
|
|
86
56
|
require_movement: {
|
|
87
57
|
type: ParameterType.BOOL,
|
|
88
58
|
default: false
|
|
89
59
|
},
|
|
60
|
+
/** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is
|
|
61
|
+
* that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
|
|
62
|
+
*/
|
|
90
63
|
prompt: {
|
|
91
64
|
type: ParameterType.HTML_STRING,
|
|
92
65
|
default: null
|
|
93
66
|
},
|
|
67
|
+
/** How long to wait for the participant to make a response before ending the trial in milliseconds. If
|
|
68
|
+
* the participant fails to make a response before this timer is reached, the participant's response will be
|
|
69
|
+
* recorded as null for the trial and the trial will end. If the value of this parameter is null, then the trial
|
|
70
|
+
* will wait for a response indefinitely.
|
|
71
|
+
*/
|
|
94
72
|
trial_duration: {
|
|
95
73
|
type: ParameterType.INT,
|
|
96
74
|
default: null
|
|
97
75
|
},
|
|
76
|
+
/** If true, then the trial will end whenever the participant makes a response (assuming they make their response
|
|
77
|
+
* before the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the
|
|
78
|
+
* value for `trial_duration` is reached. You can set this parameter to `false` to force the participant to listen to
|
|
79
|
+
* the stimulus for a fixed amount of time, even if they respond before the time is complete.
|
|
80
|
+
*/
|
|
98
81
|
response_ends_trial: {
|
|
99
82
|
type: ParameterType.BOOL,
|
|
100
83
|
default: true
|
|
101
84
|
},
|
|
85
|
+
/** If true, then the trial will end as soon as the audio file finishes playing. */
|
|
102
86
|
trial_ends_after_audio: {
|
|
103
87
|
type: ParameterType.BOOL,
|
|
104
88
|
default: false
|
|
105
89
|
},
|
|
90
|
+
/** If true, then responses are allowed while the audio is playing. If false, then the audio must finish playing before
|
|
91
|
+
* the slider is enabled and the trial can end via the next button click. Once the audio has played all the way through,
|
|
92
|
+
* the slider is enabled and a response is allowed (including while the audio is being re-played via on-screen playback controls).
|
|
93
|
+
*/
|
|
106
94
|
response_allowed_while_playing: {
|
|
107
95
|
type: ParameterType.BOOL,
|
|
108
96
|
default: true
|
|
109
97
|
}
|
|
110
98
|
},
|
|
111
99
|
data: {
|
|
100
|
+
/** The numeric value of the slider. */
|
|
112
101
|
response: {
|
|
113
102
|
type: ParameterType.INT
|
|
114
103
|
},
|
|
104
|
+
/** The time in milliseconds for the participant to make a response. The time is measured from when the stimulus first
|
|
105
|
+
* began playing until the participant's response.
|
|
106
|
+
*/
|
|
115
107
|
rt: {
|
|
116
108
|
type: ParameterType.INT
|
|
117
109
|
},
|
|
110
|
+
/** The path of the audio file that was played. */
|
|
118
111
|
stimulus: {
|
|
119
112
|
type: ParameterType.STRING
|
|
120
113
|
},
|
|
114
|
+
/** The starting value of the slider. */
|
|
121
115
|
slider_start: {
|
|
122
116
|
type: ParameterType.INT
|
|
123
117
|
}
|
|
118
|
+
},
|
|
119
|
+
// prettier-ignore
|
|
120
|
+
citations: {
|
|
121
|
+
"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 ",
|
|
122
|
+
"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}, } '
|
|
124
123
|
}
|
|
125
124
|
};
|
|
126
125
|
class AudioSliderResponsePlugin {
|
|
@@ -234,6 +233,9 @@ class AudioSliderResponsePlugin {
|
|
|
234
233
|
};
|
|
235
234
|
autoBind(this);
|
|
236
235
|
}
|
|
236
|
+
static {
|
|
237
|
+
this.info = info;
|
|
238
|
+
}
|
|
237
239
|
async trial(display_element, trial, on_load) {
|
|
238
240
|
this.params = trial;
|
|
239
241
|
this.display = display_element;
|
|
@@ -248,6 +250,7 @@ class AudioSliderResponsePlugin {
|
|
|
248
250
|
this.trial_complete = resolve;
|
|
249
251
|
});
|
|
250
252
|
}
|
|
253
|
+
// to enable slider after audio ends
|
|
251
254
|
enable_slider() {
|
|
252
255
|
document.querySelector("#jspsych-audio-slider-response-response").disabled = false;
|
|
253
256
|
if (!this.params.require_movement) {
|
|
@@ -301,7 +304,6 @@ class AudioSliderResponsePlugin {
|
|
|
301
304
|
});
|
|
302
305
|
}
|
|
303
306
|
}
|
|
304
|
-
AudioSliderResponsePlugin.info = info;
|
|
305
307
|
|
|
306
308
|
export { AudioSliderResponsePlugin as default };
|
|
307
309
|
//# sourceMappingURL=index.js.map
|