@jspsych/plugin-image-keyboard-response 1.1.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nconst info = <const>{\n name: \"image-keyboard-response\",\n parameters: {\n /** The image to be displayed */\n stimulus: {\n type: ParameterType.IMAGE,\n pretty_name: \"Stimulus\",\n default: undefined,\n },\n /** Set the image height in pixels */\n stimulus_height: {\n type: ParameterType.INT,\n pretty_name: \"Image height\",\n default: null,\n },\n /** Set the image width in pixels */\n stimulus_width: {\n type: ParameterType.INT,\n pretty_name: \"Image width\",\n default: null,\n },\n /** Maintain the aspect ratio after setting width or height */\n maintain_aspect_ratio: {\n type: ParameterType.BOOL,\n pretty_name: \"Maintain aspect ratio\",\n default: true,\n },\n /** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */\n choices: {\n type: ParameterType.KEYS,\n pretty_name: \"Choices\",\n default: \"ALL_KEYS\",\n },\n /** Any content here will be displayed below the stimulus. */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: null,\n },\n /** How long to show the stimulus. */\n stimulus_duration: {\n type: ParameterType.INT,\n pretty_name: \"Stimulus duration\",\n default: null,\n },\n /** How long to show trial before it ends */\n trial_duration: {\n type: ParameterType.INT,\n pretty_name: \"Trial duration\",\n default: null,\n },\n /** If true, trial will end when subject makes a response. */\n response_ends_trial: {\n type: ParameterType.BOOL,\n pretty_name: \"Response ends trial\",\n default: true,\n },\n /**\n * If true, the image will be drawn onto a canvas element (prevents blank screen between consecutive images in some browsers).\n * If false, the image will be shown via an img element.\n */\n render_on_canvas: {\n type: ParameterType.BOOL,\n pretty_name: \"Render on canvas\",\n default: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **image-keyboard-response**\n *\n * jsPsych plugin for displaying an image stimulus and getting a keyboard response\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/plugins/jspsych-image-keyboard-response/ image-keyboard-response plugin documentation on jspsych.org}\n */\nclass ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var height, width;\n if (trial.render_on_canvas) {\n var image_drawn = false;\n // first clear the display element (because the render_on_canvas method appends to display_element instead of overwriting it with .innerHTML)\n if (display_element.hasChildNodes()) {\n // can't loop through child list because the list will be modified by .removeChild()\n while (display_element.firstChild) {\n display_element.removeChild(display_element.firstChild);\n }\n }\n // create canvas element and image\n var canvas = document.createElement(\"canvas\");\n canvas.id = \"jspsych-image-keyboard-response-stimulus\";\n canvas.style.margin = \"0\";\n canvas.style.padding = \"0\";\n var ctx = canvas.getContext(\"2d\");\n var img = new Image();\n img.onload = () => {\n // if image wasn't preloaded, then it will need to be drawn whenever it finishes loading\n if (!image_drawn) {\n getHeightWidth(); // only possible to get width/height after image loads\n ctx.drawImage(img, 0, 0, width, height);\n }\n };\n img.src = trial.stimulus;\n // get/set image height and width - this can only be done after image loads because uses image's naturalWidth/naturalHeight properties\n const getHeightWidth = () => {\n if (trial.stimulus_height !== null) {\n height = trial.stimulus_height;\n if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {\n width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);\n }\n } else {\n height = img.naturalHeight;\n }\n if (trial.stimulus_width !== null) {\n width = trial.stimulus_width;\n if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {\n height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);\n }\n } else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {\n // if stimulus width is null, only use the image's natural width if the width value wasn't set\n // in the if statement above, based on a specified height and maintain_aspect_ratio = true\n width = img.naturalWidth;\n }\n canvas.height = height;\n canvas.width = width;\n };\n getHeightWidth(); // call now, in case image loads immediately (is cached)\n // add canvas and draw image\n display_element.insertBefore(canvas, null);\n if (img.complete && Number.isFinite(width) && Number.isFinite(height)) {\n // if image has loaded and width/height have been set, then draw it now\n // (don't rely on img onload function to draw image when image is in the cache, because that causes a delay in the image presentation)\n ctx.drawImage(img, 0, 0, width, height);\n image_drawn = true;\n }\n // add prompt if there is one\n if (trial.prompt !== null) {\n display_element.insertAdjacentHTML(\"beforeend\", trial.prompt);\n }\n } else {\n // display stimulus as an image element\n var html = '<img src=\"' + trial.stimulus + '\" id=\"jspsych-image-keyboard-response-stimulus\">';\n // add prompt\n if (trial.prompt !== null) {\n html += trial.prompt;\n }\n // update the page content\n display_element.innerHTML = html;\n\n // set image dimensions after image has loaded (so that we have access to naturalHeight/naturalWidth)\n var img = display_element.querySelector(\n \"#jspsych-image-keyboard-response-stimulus\"\n ) as HTMLImageElement;\n if (trial.stimulus_height !== null) {\n height = trial.stimulus_height;\n if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {\n width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);\n }\n } else {\n height = img.naturalHeight;\n }\n if (trial.stimulus_width !== null) {\n width = trial.stimulus_width;\n if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {\n height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);\n }\n } else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {\n // if stimulus width is null, only use the image's natural width if the width value wasn't set\n // in the if statement above, based on a specified height and maintain_aspect_ratio = true\n width = img.naturalWidth;\n }\n img.style.height = height.toString() + \"px\";\n img.style.width = width.toString() + \"px\";\n }\n\n // store response\n var response = {\n rt: null,\n key: null,\n };\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // kill keyboard listeners\n if (typeof keyboardListener !== \"undefined\") {\n this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);\n }\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.key,\n };\n\n // clear the display\n display_element.innerHTML = \"\";\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n };\n\n // function to handle responses by the subject\n var after_response = (info) => {\n // after a valid response, the stimulus will have the CSS class 'responded'\n // which can be used to provide visual feedback that a response was recorded\n display_element.querySelector(\"#jspsych-image-keyboard-response-stimulus\").className +=\n \" responded\";\n\n // only record the first response\n if (response.key == null) {\n response = info;\n }\n\n if (trial.response_ends_trial) {\n end_trial();\n }\n };\n\n // start the response listener\n if (trial.choices != \"NO_KEYS\") {\n var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: after_response,\n valid_responses: trial.choices,\n rt_method: \"performance\",\n persist: false,\n allow_held_key: false,\n });\n }\n\n // hide stimulus if stimulus_duration is set\n if (trial.stimulus_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n display_element.querySelector<HTMLElement>(\n \"#jspsych-image-keyboard-response-stimulus\"\n ).style.visibility = \"hidden\";\n }, trial.stimulus_duration);\n }\n\n // end trial if trial_duration is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n end_trial();\n }, trial.trial_duration);\n } else if (trial.response_ends_trial === false) {\n console.warn(\n \"The experiment may be deadlocked. Try setting a trial duration or set response_ends_trial to true.\"\n );\n }\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 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 this.trial(display_element, trial);\n load_callback();\n\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.pressKey(data.response, data.rt);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\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\nexport default ImageKeyboardResponsePlugin;\n"],"names":["ParameterType"],"mappings":";;;;AAEA,MAAM,IAAI,GAAU;AAClB,IAAA,IAAI,EAAE,yBAAyB;AAC/B,IAAA,UAAU,EAAE;;AAEV,QAAA,QAAQ,EAAE;YACR,IAAI,EAAEA,qBAAa,CAAC,KAAK;AACzB,YAAA,WAAW,EAAE,UAAU;AACvB,YAAA,OAAO,EAAE,SAAS;AACnB,SAAA;;AAED,QAAA,eAAe,EAAE;YACf,IAAI,EAAEA,qBAAa,CAAC,GAAG;AACvB,YAAA,WAAW,EAAE,cAAc;AAC3B,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;;AAED,QAAA,cAAc,EAAE;YACd,IAAI,EAAEA,qBAAa,CAAC,GAAG;AACvB,YAAA,WAAW,EAAE,aAAa;AAC1B,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;;AAED,QAAA,qBAAqB,EAAE;YACrB,IAAI,EAAEA,qBAAa,CAAC,IAAI;AACxB,YAAA,WAAW,EAAE,uBAAuB;AACpC,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;;AAED,QAAA,OAAO,EAAE;YACP,IAAI,EAAEA,qBAAa,CAAC,IAAI;AACxB,YAAA,WAAW,EAAE,SAAS;AACtB,YAAA,OAAO,EAAE,UAAU;AACpB,SAAA;;AAED,QAAA,MAAM,EAAE;YACN,IAAI,EAAEA,qBAAa,CAAC,WA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D,QAAA,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;AACnC,QAAA,aAAa,EAAE,CAAC;AAEhB,QAAA,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE;AACpB,YAAA,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;AACzD,SAAA;KACF;IAEO,sBAAsB,CAAC,KAAsB,EAAE,kBAAkB,EAAA;AACvE,QAAA,MAAM,YAAY,GAAG;YACnB,QAAQ,EAAE,KAAK,CAAC,QAAQ;AACxB,YAAA,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC;AACvE,YAAA,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC;SAC5D,CAAC;AAEF,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,mBAAmB,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;QAE1F,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,+BAA+B,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAEpE,QAAA,OAAO,IAAI,CAAC;KACb;;AAnOM,2BAAI,CAAA,IAAA,GAAG,IAAI;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"image-keyboard-response\",\n version: version,\n parameters: {\n /** The path of the image file to be displayed. */\n stimulus: {\n type: ParameterType.IMAGE,\n default: undefined,\n },\n /** Set the height of the image in pixels. If left null (no value specified), then the image will display at its natural height. */\n stimulus_height: {\n type: ParameterType.INT,\n default: null,\n },\n /** Set the width of the image in pixels. If left null (no value specified), then the image will display at its natural width. */\n stimulus_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** If setting *only* the width or *only* the height and this parameter is true, then the other dimension will be scaled\n * to maintain the image's aspect ratio. */\n maintain_aspect_ratio: {\n type: ParameterType.BOOL,\n default: true,\n },\n /**his array contains the key(s) that the participant is allowed to press in order to respond to the stimulus. Keys should\n * be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) - see\n * [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) and\n * [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)\n * for more examples. Any key presses that are not listed in the array will be ignored. The default value of `\"ALL_KEYS\"`\n * means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean that no responses are allowed. */\n choices: {\n type: ParameterType.KEYS,\n default: \"ALL_KEYS\",\n },\n /**This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can\n * be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press). */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to show the stimulus for in milliseconds. If the value is `null`, then the stimulus will be shown until the\n * participant makes a response. */\n stimulus_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the participant\n * fails to make a response before this timer is reached, the participant's response will be recorded as null for the\n * trial and the trial will end. If the value of this parameter is `null`, then the trial will wait for a response indefinitely. */\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 before\n * the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for\n * `trial_duration` is reached. You can set this parameter to `false` to force the participant to view a stimulus for a\n * fixed amount of time, even if they respond before the time is complete. */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /**\n * If `true`, the image will be drawn onto a canvas element. This prevents a blank screen (white flash) between consecutive image trials in some browsers, like Firefox and Edge.\n * If `false`, the image will be shown via an img element, as in previous versions of jsPsych. If the stimulus is an **animated gif**, you must set this parameter to false, because the canvas rendering method will only present static images.\n */\n render_on_canvas: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The path of the image that was displayed. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** Indicates which key the participant pressed. */\n response: {\n type: ParameterType.STRING,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus\n * first appears on the screen until the participant's response. */\n rt: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin displays an image and records responses generated with the keyboard. The stimulus can be displayed until a\n * response is given, or for a pre-determined amount of time. The trial can be ended automatically if the participant has\n * failed to respond within a fixed length of time.\n *\n * Image 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 image stimulus, you will need to\n * [manually preload](../overview/media-preloading.md#manual-preloading) the images.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/image-keyboard-response/ image-keyboard-response plugin documentation on jspsych.org}\n */\nclass ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var height, width;\n if (trial.render_on_canvas) {\n var image_drawn = false;\n // first clear the display element (because the render_on_canvas method appends to display_element instead of overwriting it with .innerHTML)\n if (display_element.hasChildNodes()) {\n // can't loop through child list because the list will be modified by .removeChild()\n while (display_element.firstChild) {\n display_element.removeChild(display_element.firstChild);\n }\n }\n // create canvas element and image\n var canvas = document.createElement(\"canvas\");\n canvas.id = \"jspsych-image-keyboard-response-stimulus\";\n canvas.style.margin = \"0\";\n canvas.style.padding = \"0\";\n var ctx = canvas.getContext(\"2d\");\n var img = new Image();\n img.onload = () => {\n // if image wasn't preloaded, then it will need to be drawn whenever it finishes loading\n if (!image_drawn) {\n getHeightWidth(); // only possible to get width/height after image loads\n ctx.drawImage(img, 0, 0, width, height);\n }\n };\n img.src = trial.stimulus;\n // get/set image height and width - this can only be done after image loads because uses image's naturalWidth/naturalHeight properties\n const getHeightWidth = () => {\n if (trial.stimulus_height !== null) {\n height = trial.stimulus_height;\n if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {\n width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);\n }\n } else {\n height = img.naturalHeight;\n }\n if (trial.stimulus_width !== null) {\n width = trial.stimulus_width;\n if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {\n height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);\n }\n } else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {\n // if stimulus width is null, only use the image's natural width if the width value wasn't set\n // in the if statement above, based on a specified height and maintain_aspect_ratio = true\n width = img.naturalWidth;\n }\n canvas.height = height;\n canvas.width = width;\n };\n getHeightWidth(); // call now, in case image loads immediately (is cached)\n // add canvas and draw image\n display_element.insertBefore(canvas, null);\n if (img.complete && Number.isFinite(width) && Number.isFinite(height)) {\n // if image has loaded and width/height have been set, then draw it now\n // (don't rely on img onload function to draw image when image is in the cache, because that causes a delay in the image presentation)\n ctx.drawImage(img, 0, 0, width, height);\n image_drawn = true;\n }\n // add prompt if there is one\n if (trial.prompt !== null) {\n display_element.insertAdjacentHTML(\"beforeend\", trial.prompt);\n }\n } else {\n // display stimulus as an image element\n var html = '<img src=\"' + trial.stimulus + '\" id=\"jspsych-image-keyboard-response-stimulus\">';\n // add prompt\n if (trial.prompt !== null) {\n html += trial.prompt;\n }\n // update the page content\n display_element.innerHTML = html;\n\n // set image dimensions after image has loaded (so that we have access to naturalHeight/naturalWidth)\n var img = display_element.querySelector(\n \"#jspsych-image-keyboard-response-stimulus\"\n ) as HTMLImageElement;\n if (trial.stimulus_height !== null) {\n height = trial.stimulus_height;\n if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {\n width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);\n }\n } else {\n height = img.naturalHeight;\n }\n if (trial.stimulus_width !== null) {\n width = trial.stimulus_width;\n if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {\n height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);\n }\n } else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {\n // if stimulus width is null, only use the image's natural width if the width value wasn't set\n // in the if statement above, based on a specified height and maintain_aspect_ratio = true\n width = img.naturalWidth;\n }\n img.style.height = height.toString() + \"px\";\n img.style.width = width.toString() + \"px\";\n }\n\n // store response\n var response = {\n rt: null,\n key: null,\n };\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill keyboard listeners\n if (typeof keyboardListener !== \"undefined\") {\n this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);\n }\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.key,\n };\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n };\n\n // function to handle responses by the subject\n var after_response = (info) => {\n // after a valid response, the stimulus will have the CSS class 'responded'\n // which can be used to provide visual feedback that a response was recorded\n display_element.querySelector(\"#jspsych-image-keyboard-response-stimulus\").className +=\n \" responded\";\n\n // only record the first response\n if (response.key == null) {\n response = info;\n }\n\n if (trial.response_ends_trial) {\n end_trial();\n }\n };\n\n // start the response listener\n if (trial.choices != \"NO_KEYS\") {\n var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: after_response,\n valid_responses: trial.choices,\n rt_method: \"performance\",\n persist: false,\n allow_held_key: false,\n });\n }\n\n // hide stimulus if stimulus_duration is set\n if (trial.stimulus_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n display_element.querySelector<HTMLElement>(\n \"#jspsych-image-keyboard-response-stimulus\"\n ).style.visibility = \"hidden\";\n }, trial.stimulus_duration);\n }\n\n // end trial if trial_duration is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n end_trial();\n }, trial.trial_duration);\n } else if (trial.response_ends_trial === false) {\n console.warn(\n \"The experiment may be deadlocked. Try setting a trial duration or set response_ends_trial to true.\"\n );\n }\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 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 this.trial(display_element, trial);\n load_callback();\n\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.pressKey(data.response, data.rt);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\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\nexport default ImageKeyboardResponsePlugin;\n"],"names":["version","ParameterType","info"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,yBAAA;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,eAAiB,EAAA;AAAA,MACf,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 -1,156 +1,200 @@
1
- import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
2
- declare const info: {
3
- readonly name: "image-keyboard-response";
4
- readonly parameters: {
5
- /** The image to be displayed */
6
- readonly stimulus: {
7
- readonly type: ParameterType.IMAGE;
8
- readonly pretty_name: "Stimulus";
9
- readonly default: any;
10
- };
11
- /** Set the image height in pixels */
12
- readonly stimulus_height: {
13
- readonly type: ParameterType.INT;
14
- readonly pretty_name: "Image height";
15
- readonly default: any;
16
- };
17
- /** Set the image width in pixels */
18
- readonly stimulus_width: {
19
- readonly type: ParameterType.INT;
20
- readonly pretty_name: "Image width";
21
- readonly default: any;
22
- };
23
- /** Maintain the aspect ratio after setting width or height */
24
- readonly maintain_aspect_ratio: {
25
- readonly type: ParameterType.BOOL;
26
- readonly pretty_name: "Maintain aspect ratio";
27
- readonly default: true;
28
- };
29
- /** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */
30
- readonly choices: {
31
- readonly type: ParameterType.KEYS;
32
- readonly pretty_name: "Choices";
33
- readonly default: "ALL_KEYS";
34
- };
35
- /** Any content here will be displayed below the stimulus. */
36
- readonly prompt: {
37
- readonly type: ParameterType.HTML_STRING;
38
- readonly pretty_name: "Prompt";
39
- readonly default: any;
40
- };
41
- /** How long to show the stimulus. */
42
- readonly stimulus_duration: {
43
- readonly type: ParameterType.INT;
44
- readonly pretty_name: "Stimulus duration";
45
- readonly default: any;
46
- };
47
- /** How long to show trial before it ends */
48
- readonly trial_duration: {
49
- readonly type: ParameterType.INT;
50
- readonly pretty_name: "Trial duration";
51
- readonly default: any;
52
- };
53
- /** If true, trial will end when subject makes a response. */
54
- readonly response_ends_trial: {
55
- readonly type: ParameterType.BOOL;
56
- readonly pretty_name: "Response ends trial";
57
- readonly default: true;
58
- };
59
- /**
60
- * If true, the image will be drawn onto a canvas element (prevents blank screen between consecutive images in some browsers).
61
- * If false, the image will be shown via an img element.
62
- */
63
- readonly render_on_canvas: {
64
- readonly type: ParameterType.BOOL;
65
- readonly pretty_name: "Render on canvas";
66
- readonly default: true;
67
- };
68
- };
69
- };
70
- declare type Info = typeof info;
71
- /**
72
- * **image-keyboard-response**
73
- *
74
- * jsPsych plugin for displaying an image stimulus and getting a keyboard response
75
- *
76
- * @author Josh de Leeuw
77
- * @see {@link https://www.jspsych.org/plugins/jspsych-image-keyboard-response/ image-keyboard-response plugin documentation on jspsych.org}
78
- */
79
- declare class ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {
80
- private jsPsych;
81
- static info: {
82
- readonly name: "image-keyboard-response";
83
- readonly parameters: {
84
- /** The image to be displayed */
85
- readonly stimulus: {
86
- readonly type: ParameterType.IMAGE;
87
- readonly pretty_name: "Stimulus";
88
- readonly default: any;
89
- };
90
- /** Set the image height in pixels */
91
- readonly stimulus_height: {
92
- readonly type: ParameterType.INT;
93
- readonly pretty_name: "Image height";
94
- readonly default: any;
95
- };
96
- /** Set the image width in pixels */
97
- readonly stimulus_width: {
98
- readonly type: ParameterType.INT;
99
- readonly pretty_name: "Image width";
100
- readonly default: any;
101
- };
102
- /** Maintain the aspect ratio after setting width or height */
103
- readonly maintain_aspect_ratio: {
104
- readonly type: ParameterType.BOOL;
105
- readonly pretty_name: "Maintain aspect ratio";
106
- readonly default: true;
107
- };
108
- /** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */
109
- readonly choices: {
110
- readonly type: ParameterType.KEYS;
111
- readonly pretty_name: "Choices";
112
- readonly default: "ALL_KEYS";
113
- };
114
- /** Any content here will be displayed below the stimulus. */
115
- readonly prompt: {
116
- readonly type: ParameterType.HTML_STRING;
117
- readonly pretty_name: "Prompt";
118
- readonly default: any;
119
- };
120
- /** How long to show the stimulus. */
121
- readonly stimulus_duration: {
122
- readonly type: ParameterType.INT;
123
- readonly pretty_name: "Stimulus duration";
124
- readonly default: any;
125
- };
126
- /** How long to show trial before it ends */
127
- readonly trial_duration: {
128
- readonly type: ParameterType.INT;
129
- readonly pretty_name: "Trial duration";
130
- readonly default: any;
131
- };
132
- /** If true, trial will end when subject makes a response. */
133
- readonly response_ends_trial: {
134
- readonly type: ParameterType.BOOL;
135
- readonly pretty_name: "Response ends trial";
136
- readonly default: true;
137
- };
138
- /**
139
- * If true, the image will be drawn onto a canvas element (prevents blank screen between consecutive images in some browsers).
140
- * If false, the image will be shown via an img element.
141
- */
142
- readonly render_on_canvas: {
143
- readonly type: ParameterType.BOOL;
144
- readonly pretty_name: "Render on canvas";
145
- readonly default: true;
146
- };
147
- };
148
- };
149
- constructor(jsPsych: JsPsych);
150
- trial(display_element: HTMLElement, trial: TrialType<Info>): void;
151
- simulate(trial: TrialType<Info>, simulation_mode: any, simulation_options: any, load_callback: () => void): void;
152
- private simulate_data_only;
153
- private simulate_visual;
154
- private create_simulation_data;
155
- }
156
- export default ImageKeyboardResponsePlugin;
1
+ import { JsPsychPlugin, ParameterType, JsPsych, TrialType } from 'jspsych';
2
+
3
+ declare const info: {
4
+ readonly name: "image-keyboard-response";
5
+ readonly version: string;
6
+ readonly parameters: {
7
+ /** The path of the image file to be displayed. */
8
+ readonly stimulus: {
9
+ readonly type: ParameterType.IMAGE;
10
+ readonly default: any;
11
+ };
12
+ /** Set the height of the image in pixels. If left null (no value specified), then the image will display at its natural height. */
13
+ readonly stimulus_height: {
14
+ readonly type: ParameterType.INT;
15
+ readonly default: any;
16
+ };
17
+ /** Set the width of the image in pixels. If left null (no value specified), then the image will display at its natural width. */
18
+ readonly stimulus_width: {
19
+ readonly type: ParameterType.INT;
20
+ readonly default: any;
21
+ };
22
+ /** If setting *only* the width or *only* the height and this parameter is true, then the other dimension will be scaled
23
+ * to maintain the image's aspect ratio. */
24
+ readonly maintain_aspect_ratio: {
25
+ readonly type: ParameterType.BOOL;
26
+ readonly default: true;
27
+ };
28
+ /**his array contains the key(s) that the participant is allowed to press in order to respond to the stimulus. Keys should
29
+ * be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) - see
30
+ * [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) and
31
+ * [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)
32
+ * for more examples. Any key presses that are not listed in the array will be ignored. The default value of `"ALL_KEYS"`
33
+ * means that all keys will be accepted as valid responses. Specifying `"NO_KEYS"` will mean that no responses are allowed. */
34
+ readonly choices: {
35
+ readonly type: ParameterType.KEYS;
36
+ readonly default: "ALL_KEYS";
37
+ };
38
+ /**This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can
39
+ * be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press). */
40
+ readonly prompt: {
41
+ readonly type: ParameterType.HTML_STRING;
42
+ readonly default: any;
43
+ };
44
+ /** How long to show the stimulus for in milliseconds. If the value is `null`, then the stimulus will be shown until the
45
+ * participant makes a response. */
46
+ readonly stimulus_duration: {
47
+ readonly type: ParameterType.INT;
48
+ readonly default: any;
49
+ };
50
+ /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the participant
51
+ * fails to make a response before this timer is reached, the participant's response will be recorded as null for the
52
+ * trial and the trial will end. If the value of this parameter is `null`, then the trial will wait for a response indefinitely. */
53
+ readonly trial_duration: {
54
+ readonly type: ParameterType.INT;
55
+ readonly default: any;
56
+ };
57
+ /** If true, then the trial will end whenever the participant makes a response (assuming they make their response before
58
+ * the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for
59
+ * `trial_duration` is reached. You can set this parameter to `false` to force the participant to view a stimulus for a
60
+ * fixed amount of time, even if they respond before the time is complete. */
61
+ readonly response_ends_trial: {
62
+ readonly type: ParameterType.BOOL;
63
+ readonly default: true;
64
+ };
65
+ /**
66
+ * If `true`, the image will be drawn onto a canvas element. This prevents a blank screen (white flash) between consecutive image trials in some browsers, like Firefox and Edge.
67
+ * If `false`, the image will be shown via an img element, as in previous versions of jsPsych. If the stimulus is an **animated gif**, you must set this parameter to false, because the canvas rendering method will only present static images.
68
+ */
69
+ readonly render_on_canvas: {
70
+ readonly type: ParameterType.BOOL;
71
+ readonly default: true;
72
+ };
73
+ };
74
+ readonly data: {
75
+ /** The path of the image that was displayed. */
76
+ readonly stimulus: {
77
+ readonly type: ParameterType.STRING;
78
+ };
79
+ /** Indicates which key the participant pressed. */
80
+ readonly response: {
81
+ readonly type: ParameterType.STRING;
82
+ };
83
+ /** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus
84
+ * first appears on the screen until the participant's response. */
85
+ readonly rt: {
86
+ readonly type: ParameterType.INT;
87
+ };
88
+ };
89
+ };
90
+ type Info = typeof info;
91
+ /**
92
+ * This plugin displays an image and records responses generated with the keyboard. The stimulus can be displayed until a
93
+ * response is given, or for a pre-determined amount of time. The trial can be ended automatically if the participant has
94
+ * failed to respond within a fixed length of time.
95
+ *
96
+ * Image files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using
97
+ * timeline variables or another dynamic method to specify the image stimulus, you will need to
98
+ * [manually preload](../overview/media-preloading.md#manual-preloading) the images.
99
+ *
100
+ * @author Josh de Leeuw
101
+ * @see {@link https://www.jspsych.org/latest/plugins/image-keyboard-response/ image-keyboard-response plugin documentation on jspsych.org}
102
+ */
103
+ declare class ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {
104
+ private jsPsych;
105
+ static info: {
106
+ readonly name: "image-keyboard-response";
107
+ readonly version: string;
108
+ readonly parameters: {
109
+ /** The path of the image file to be displayed. */
110
+ readonly stimulus: {
111
+ readonly type: ParameterType.IMAGE;
112
+ readonly default: any;
113
+ };
114
+ /** Set the height of the image in pixels. If left null (no value specified), then the image will display at its natural height. */
115
+ readonly stimulus_height: {
116
+ readonly type: ParameterType.INT;
117
+ readonly default: any;
118
+ };
119
+ /** Set the width of the image in pixels. If left null (no value specified), then the image will display at its natural width. */
120
+ readonly stimulus_width: {
121
+ readonly type: ParameterType.INT;
122
+ readonly default: any;
123
+ };
124
+ /** If setting *only* the width or *only* the height and this parameter is true, then the other dimension will be scaled
125
+ * to maintain the image's aspect ratio. */
126
+ readonly maintain_aspect_ratio: {
127
+ readonly type: ParameterType.BOOL;
128
+ readonly default: true;
129
+ };
130
+ /**his array contains the key(s) that the participant is allowed to press in order to respond to the stimulus. Keys should
131
+ * be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) - see
132
+ * [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) and
133
+ * [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)
134
+ * for more examples. Any key presses that are not listed in the array will be ignored. The default value of `"ALL_KEYS"`
135
+ * means that all keys will be accepted as valid responses. Specifying `"NO_KEYS"` will mean that no responses are allowed. */
136
+ readonly choices: {
137
+ readonly type: ParameterType.KEYS;
138
+ readonly default: "ALL_KEYS";
139
+ };
140
+ /**This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can
141
+ * be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press). */
142
+ readonly prompt: {
143
+ readonly type: ParameterType.HTML_STRING;
144
+ readonly default: any;
145
+ };
146
+ /** How long to show the stimulus for in milliseconds. If the value is `null`, then the stimulus will be shown until the
147
+ * participant makes a response. */
148
+ readonly stimulus_duration: {
149
+ readonly type: ParameterType.INT;
150
+ readonly default: any;
151
+ };
152
+ /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the participant
153
+ * fails to make a response before this timer is reached, the participant's response will be recorded as null for the
154
+ * trial and the trial will end. If the value of this parameter is `null`, then the trial will wait for a response indefinitely. */
155
+ readonly trial_duration: {
156
+ readonly type: ParameterType.INT;
157
+ readonly default: any;
158
+ };
159
+ /** If true, then the trial will end whenever the participant makes a response (assuming they make their response before
160
+ * the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for
161
+ * `trial_duration` is reached. You can set this parameter to `false` to force the participant to view a stimulus for a
162
+ * fixed amount of time, even if they respond before the time is complete. */
163
+ readonly response_ends_trial: {
164
+ readonly type: ParameterType.BOOL;
165
+ readonly default: true;
166
+ };
167
+ /**
168
+ * If `true`, the image will be drawn onto a canvas element. This prevents a blank screen (white flash) between consecutive image trials in some browsers, like Firefox and Edge.
169
+ * If `false`, the image will be shown via an img element, as in previous versions of jsPsych. If the stimulus is an **animated gif**, you must set this parameter to false, because the canvas rendering method will only present static images.
170
+ */
171
+ readonly render_on_canvas: {
172
+ readonly type: ParameterType.BOOL;
173
+ readonly default: true;
174
+ };
175
+ };
176
+ readonly data: {
177
+ /** The path of the image that was displayed. */
178
+ readonly stimulus: {
179
+ readonly type: ParameterType.STRING;
180
+ };
181
+ /** Indicates which key the participant pressed. */
182
+ readonly response: {
183
+ readonly type: ParameterType.STRING;
184
+ };
185
+ /** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus
186
+ * first appears on the screen until the participant's response. */
187
+ readonly rt: {
188
+ readonly type: ParameterType.INT;
189
+ };
190
+ };
191
+ };
192
+ constructor(jsPsych: JsPsych);
193
+ trial(display_element: HTMLElement, trial: TrialType<Info>): void;
194
+ simulate(trial: TrialType<Info>, simulation_mode: any, simulation_options: any, load_callback: () => void): void;
195
+ private simulate_data_only;
196
+ private simulate_visual;
197
+ private create_simulation_data;
198
+ }
199
+
200
+ export { ImageKeyboardResponsePlugin as default };