@jspsych/plugin-canvas-keyboard-response 2.0.0 → 2.2.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 +74 -51
- 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 +73 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -0
- package/dist/index.js +73 -50
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.spec.ts +18 -0
- package/src/index.ts +30 -1
package/dist/index.browser.js
CHANGED
|
@@ -1,98 +1,112 @@
|
|
|
1
1
|
var jsPsychCanvasKeyboardResponse = (function (jspsych) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
name: "@jspsych/plugin-canvas-keyboard-response",
|
|
6
|
-
version: "2.0.0",
|
|
7
|
-
description: "jsPsych plugin for displaying a canvas stimulus and getting a keyboard response",
|
|
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-canvas-keyboard-response"
|
|
32
|
-
},
|
|
33
|
-
author: "Chris Jungerius, 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/canvas-keyboard-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.2.0";
|
|
47
5
|
|
|
48
6
|
const info = {
|
|
49
7
|
name: "canvas-keyboard-response",
|
|
50
|
-
version
|
|
8
|
+
version,
|
|
51
9
|
parameters: {
|
|
10
|
+
/** The function to draw on the canvas. This function automatically takes a canvas element as its only
|
|
11
|
+
* argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.
|
|
12
|
+
* Note that the stimulus function will still generally need to set the correct context itself, using a line
|
|
13
|
+
* like `let ctx = c.getContext("2d")`.
|
|
14
|
+
*/
|
|
52
15
|
stimulus: {
|
|
53
16
|
type: jspsych.ParameterType.FUNCTION,
|
|
54
17
|
default: void 0
|
|
55
18
|
},
|
|
19
|
+
/** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.
|
|
20
|
+
* Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -
|
|
21
|
+
* see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
|
|
22
|
+
* and [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)
|
|
23
|
+
* for more examples. Any key presses that are not listed in the array will be ignored. The default value
|
|
24
|
+
* of `"ALL_KEYS"` means that all keys will be accepted as valid responses. Specifying `"NO_KEYS"` will mean
|
|
25
|
+
* that no responses are allowed.
|
|
26
|
+
*/
|
|
56
27
|
choices: {
|
|
57
28
|
type: jspsych.ParameterType.KEYS,
|
|
58
29
|
default: "ALL_KEYS"
|
|
59
30
|
},
|
|
31
|
+
/** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention
|
|
32
|
+
* is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
|
|
33
|
+
*/
|
|
60
34
|
prompt: {
|
|
61
35
|
type: jspsych.ParameterType.HTML_STRING,
|
|
62
36
|
default: null
|
|
63
37
|
},
|
|
38
|
+
/** How long to display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to
|
|
39
|
+
* `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.
|
|
40
|
+
*/
|
|
64
41
|
stimulus_duration: {
|
|
65
42
|
type: jspsych.ParameterType.INT,
|
|
66
43
|
default: null
|
|
67
44
|
},
|
|
45
|
+
/** How long to wait for the participant to make a response before ending the trial in milliseconds. If the
|
|
46
|
+
* participant fails to make a response before this timer is reached, the participant's response will be
|
|
47
|
+
* recorded as null for the trial and the trial will end. If the value of this parameter is null, then the
|
|
48
|
+
* trial will wait for a response indefinitely.
|
|
49
|
+
*/
|
|
68
50
|
trial_duration: {
|
|
69
51
|
type: jspsych.ParameterType.INT,
|
|
70
52
|
default: null
|
|
71
53
|
},
|
|
54
|
+
/** If true, then the trial will end whenever the participant makes a response (assuming they make their
|
|
55
|
+
* response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will
|
|
56
|
+
* continue until the value for `trial_duration` is reached. You can use this parameter to force the participant
|
|
57
|
+
* to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
|
|
58
|
+
*/
|
|
72
59
|
response_ends_trial: {
|
|
73
60
|
type: jspsych.ParameterType.BOOL,
|
|
74
61
|
default: true
|
|
75
62
|
},
|
|
63
|
+
/** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */
|
|
76
64
|
canvas_size: {
|
|
77
65
|
type: jspsych.ParameterType.INT,
|
|
78
66
|
array: true,
|
|
79
67
|
default: [500, 500]
|
|
68
|
+
},
|
|
69
|
+
/** If true, the response is not registered until the participant releases the key. The response
|
|
70
|
+
* time (`rt`) still reflects when the key was pressed, and the additional data field
|
|
71
|
+
* `rt_key_duration` records how long the key was held down. Note that when this is true, the
|
|
72
|
+
* trial cannot end until the key is released: with `response_ends_trial: true` the trial ends at
|
|
73
|
+
* the key release, and if the trial ends for another reason (e.g., `trial_duration`) while the
|
|
74
|
+
* key is still held, no response is recorded for the trial.
|
|
75
|
+
*/
|
|
76
|
+
wait_for_key_release: {
|
|
77
|
+
type: jspsych.ParameterType.BOOL,
|
|
78
|
+
default: false
|
|
80
79
|
}
|
|
81
80
|
},
|
|
82
81
|
data: {
|
|
82
|
+
/** Indicates which key the participant pressed. */
|
|
83
83
|
response: {
|
|
84
84
|
type: jspsych.ParameterType.STRING
|
|
85
85
|
},
|
|
86
|
+
/** The response time in milliseconds for the participant to make a response. The time is measured from
|
|
87
|
+
* when the stimulus first appears on the screen until the participant's response.
|
|
88
|
+
*/
|
|
86
89
|
rt: {
|
|
87
90
|
type: jspsych.ParameterType.INT
|
|
91
|
+
},
|
|
92
|
+
/** The duration in milliseconds that the response key was held down, measured from key press to key release. Only recorded when `wait_for_key_release` is true; null otherwise or when no response was made. */
|
|
93
|
+
rt_key_duration: {
|
|
94
|
+
type: jspsych.ParameterType.INT
|
|
88
95
|
}
|
|
96
|
+
},
|
|
97
|
+
// prettier-ignore
|
|
98
|
+
citations: {
|
|
99
|
+
"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 ",
|
|
100
|
+
"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}, } '
|
|
89
101
|
}
|
|
90
102
|
};
|
|
91
103
|
class CanvasKeyboardResponsePlugin {
|
|
92
104
|
constructor(jsPsych) {
|
|
93
105
|
this.jsPsych = jsPsych;
|
|
94
106
|
}
|
|
95
|
-
static
|
|
107
|
+
static {
|
|
108
|
+
this.info = info;
|
|
109
|
+
}
|
|
96
110
|
trial(display_element, trial) {
|
|
97
111
|
var new_html = '<div id="jspsych-canvas-keyboard-response-stimulus"><canvas id="jspsych-canvas-stimulus" height="' + trial.canvas_size[0] + '" width="' + trial.canvas_size[1] + '"></canvas></div>';
|
|
98
112
|
if (trial.prompt !== null) {
|
|
@@ -104,7 +118,8 @@ var jsPsychCanvasKeyboardResponse = (function (jspsych) {
|
|
|
104
118
|
trial.stimulus(c);
|
|
105
119
|
var response = {
|
|
106
120
|
rt: null,
|
|
107
|
-
key: null
|
|
121
|
+
key: null,
|
|
122
|
+
rt_key_duration: null
|
|
108
123
|
};
|
|
109
124
|
const end_trial = () => {
|
|
110
125
|
if (typeof keyboardListener !== "undefined") {
|
|
@@ -112,14 +127,19 @@ var jsPsychCanvasKeyboardResponse = (function (jspsych) {
|
|
|
112
127
|
}
|
|
113
128
|
var trial_data = {
|
|
114
129
|
rt: response.rt,
|
|
115
|
-
response: response.key
|
|
130
|
+
response: response.key,
|
|
131
|
+
rt_key_duration: response.rt_key_duration
|
|
116
132
|
};
|
|
117
133
|
this.jsPsych.finishTrial(trial_data);
|
|
118
134
|
};
|
|
119
135
|
var after_response = (info2) => {
|
|
120
136
|
display_element.querySelector("#jspsych-canvas-keyboard-response-stimulus").className += " responded";
|
|
121
137
|
if (response.key == null) {
|
|
122
|
-
response =
|
|
138
|
+
response = {
|
|
139
|
+
rt: info2.rt,
|
|
140
|
+
key: info2.key,
|
|
141
|
+
rt_key_duration: info2.rt_key_duration ?? null
|
|
142
|
+
};
|
|
123
143
|
}
|
|
124
144
|
if (trial.response_ends_trial) {
|
|
125
145
|
end_trial();
|
|
@@ -131,7 +151,8 @@ var jsPsychCanvasKeyboardResponse = (function (jspsych) {
|
|
|
131
151
|
valid_responses: trial.choices,
|
|
132
152
|
rt_method: "performance",
|
|
133
153
|
persist: false,
|
|
134
|
-
allow_held_key: false
|
|
154
|
+
allow_held_key: false,
|
|
155
|
+
wait_for_key_release: trial.wait_for_key_release
|
|
135
156
|
});
|
|
136
157
|
}
|
|
137
158
|
if (trial.stimulus_duration !== null) {
|
|
@@ -172,8 +193,10 @@ var jsPsychCanvasKeyboardResponse = (function (jspsych) {
|
|
|
172
193
|
create_simulation_data(trial, simulation_options) {
|
|
173
194
|
const default_data = {
|
|
174
195
|
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
|
|
175
|
-
response: this.jsPsych.pluginAPI.getValidKey(trial.choices)
|
|
196
|
+
response: this.jsPsych.pluginAPI.getValidKey(trial.choices),
|
|
197
|
+
rt_key_duration: null
|
|
176
198
|
};
|
|
199
|
+
default_data.rt_key_duration = default_data.rt === null || !trial.wait_for_key_release ? null : this.jsPsych.randomization.sampleExGaussian(150, 30, 1 / 100, true);
|
|
177
200
|
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
178
201
|
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
179
202
|
return data;
|
|
@@ -183,4 +206,4 @@ var jsPsychCanvasKeyboardResponse = (function (jspsych) {
|
|
|
183
206
|
return CanvasKeyboardResponsePlugin;
|
|
184
207
|
|
|
185
208
|
})(jsPsychModule);
|
|
186
|
-
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-canvas-keyboard-response@2.
|
|
209
|
+
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-canvas-keyboard-response@2.2.0/dist/index.browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"canvas-keyboard-response\",\n version: version,\n parameters: {\n /** The function to draw on the canvas. This function automatically takes a canvas element as its only\n * argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.\n * Note that the stimulus function will still generally need to set the correct context itself, using a line\n * like `let ctx = c.getContext(\"2d\")`.\n */\n stimulus: {\n type: ParameterType.FUNCTION,\n default: undefined,\n },\n /** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.\n * Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -\n * see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n * and [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\n * of `\"ALL_KEYS\"` means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean\n * that no responses are allowed.\n */\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\n * is 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 display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to\n * `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.\n */\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\n * 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\n * trial 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\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can use this parameter to force the participant\n * to view a 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 /** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */\n canvas_size: {\n type: ParameterType.INT,\n array: true,\n default: [500, 500],\n },\n },\n data: {\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\n * when the stimulus first appears on the screen until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin can be used to draw a stimulus on a [HTML canvas element](https://www.w3schools.com/html/html5_canvas.asp) and\n * record a keyboard response. The canvas stimulus can be useful for displaying dynamic, parametrically-defined graphics,\n * and for controlling the positioning of multiple graphical elements (shapes, text, images). The stimulus can be\n * displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically\n * if the participant has failed to respond within a fixed length of time.\n *\n * @author Chris Jungerius (modified from Josh de Leeuw)\n * @see {@link https://www.jspsych.org/latest/plugins/canvas-keyboard-response/ canvas-keyboard-response plugin documentation on jspsych.org}\n */\nclass CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html =\n '<div id=\"jspsych-canvas-keyboard-response-stimulus\">' +\n '<canvas id=\"jspsych-canvas-stimulus\" height=\"' +\n trial.canvas_size[0] +\n '\" width=\"' +\n trial.canvas_size[1] +\n '\"></canvas>' +\n \"</div>\";\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n let c = document.getElementById(\"jspsych-canvas-stimulus\");\n c.style.display = \"block\";\n trial.stimulus(c);\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 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-canvas-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-canvas-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 }\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 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 CanvasKeyboardResponsePlugin;\n"],"names":["version","ParameterType","info"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIA,MAAM,IAAc,GAAA;EAAA,EAClB,IAAM,EAAA,0BAAA;EAAA,WACNA,gBAAA;EAAA,EACA,UAAY,EAAA;EAAA,IAMV,QAAU,EAAA;EAAA,MACR,MAAMC,qBAAc,CAAA,QAAA;EAAA,MACpB,OAAS,EAAA,KAAA,CAAA;EAAA,KACX;EAAA,IASA,OAAS,EAAA;EAAA,MACP,MAAMA,qBAAc,CAAA,IAAA;EAAA,MACpB,OAAS,EAAA,UAAA;EAAA,KACX;EAAA,IAIA,MAAQ,EAAA;EAAA,MACN,MAAMA,qBAAc,CAAA,WAAA;EAAA,MACpB,OAAS,EAAA,IAAA;EAAA,KACX;EAAA,IAIA,iBAAmB,EAAA;EAAA,MACjB,MAAMA,qBAAc,CAAA,GAAA;EAAA,MACpB,OAAS,EAAA,IAAA;EAAA,KACX;EAAA,IAMA,cAAgB,EAAA;EAAA,MACd,MAAMA,qBAAc,CAAA,GAAA;EAAA,MACpB,OAAS,EAAA,IAAA;EAAA,KACX;EAAA,IAMA,mBAAqB,EAAA;EAAA,MACnB,MAAMA,qBAAc,CAAA,IAAA;EAAA,MACpB,OAAS,EAAA,IAAA;EA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KAAK,EAAE,CAAA,CAAA;EAAA,KACxD;EAAA,GACF;EAAA,EAEQ,sBAAA,CAAuB,OAAwB,kBAAoB,EAAA;EACzE,IAAA,MAAM,YAAe,GAAA;EAAA,MACnB,EAAA,EAAI,KAAK,OAAQ,CAAA,aAAA,CAAc,iBAAiB,GAAK,EAAA,EAAA,EAAI,CAAI,GAAA,GAAA,EAAK,IAAI,CAAA;EAAA,MACtE,UAAU,IAAK,CAAA,OAAA,CAAQ,SAAU,CAAA,WAAA,CAAY,MAAM,OAAO,CAAA;EAAA,KAC5D,CAAA;EAEA,IAAA,MAAM,OAAO,IAAK,CAAA,OAAA,CAAQ,SAAU,CAAA,mBAAA,CAAoB,cAAc,kBAAkB,CAAA,CAAA;EAExF,IAAA,IAAA,CAAK,OAAQ,CAAA,SAAA,CAAU,+BAAgC,CAAA,KAAA,EAAO,IAAI,CAAA,CAAA;EAElE,IAAO,OAAA,IAAA,CAAA;EAAA,GACT;EACF;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.browser.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-canvas-keyboard-response\",\n \"version\": \"2.2.0\",\n \"description\": \"jsPsych plugin for displaying a canvas stimulus and getting a keyboard response\",\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-canvas-keyboard-response\"\n },\n \"author\": \"Chris Jungerius, 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/canvas-keyboard-response\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.3.4\",\n \"@jspsych/test-utils\": \"^1.3.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"canvas-keyboard-response\",\n version: version,\n parameters: {\n /** The function to draw on the canvas. This function automatically takes a canvas element as its only\n * argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.\n * Note that the stimulus function will still generally need to set the correct context itself, using a line\n * like `let ctx = c.getContext(\"2d\")`.\n */\n stimulus: {\n type: ParameterType.FUNCTION,\n default: undefined,\n },\n /** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.\n * Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -\n * see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n * and [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\n * of `\"ALL_KEYS\"` means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean\n * that no responses are allowed.\n */\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\n * is 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 display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to\n * `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.\n */\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\n * 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\n * trial 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\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can use this parameter to force the participant\n * to view a 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 /** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */\n canvas_size: {\n type: ParameterType.INT,\n array: true,\n default: [500, 500],\n },\n /** If true, the response is not registered until the participant releases the key. The response\n * time (`rt`) still reflects when the key was pressed, and the additional data field\n * `rt_key_duration` records how long the key was held down. Note that when this is true, the\n * trial cannot end until the key is released: with `response_ends_trial: true` the trial ends at\n * the key release, and if the trial ends for another reason (e.g., `trial_duration`) while the\n * key is still held, no response is recorded for the trial.\n */\n wait_for_key_release: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\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\n * when the stimulus first appears on the screen until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The duration in milliseconds that the response key was held down, measured from key press to key release. Only recorded when `wait_for_key_release` is true; null otherwise or when no response was made. */\n rt_key_duration: {\n type: ParameterType.INT,\n },\n },\n // prettier-ignore\n citations: '__CITATIONS__',\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin can be used to draw a stimulus on a [HTML canvas element](https://www.w3schools.com/html/html5_canvas.asp) and\n * record a keyboard response. The canvas stimulus can be useful for displaying dynamic, parametrically-defined graphics,\n * and for controlling the positioning of multiple graphical elements (shapes, text, images). The stimulus can be\n * displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically\n * if the participant has failed to respond within a fixed length of time.\n *\n * @author Chris Jungerius (modified from Josh de Leeuw)\n * @see {@link https://www.jspsych.org/latest/plugins/canvas-keyboard-response/ canvas-keyboard-response plugin documentation on jspsych.org}\n */\nclass CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html =\n '<div id=\"jspsych-canvas-keyboard-response-stimulus\">' +\n '<canvas id=\"jspsych-canvas-stimulus\" height=\"' +\n trial.canvas_size[0] +\n '\" width=\"' +\n trial.canvas_size[1] +\n '\"></canvas>' +\n \"</div>\";\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n let c = document.getElementById(\"jspsych-canvas-stimulus\");\n c.style.display = \"block\";\n trial.stimulus(c);\n // store response\n var response = {\n rt: null,\n key: null,\n rt_key_duration: 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 response: response.key,\n rt_key_duration: response.rt_key_duration,\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-canvas-keyboard-response-stimulus\").className +=\n \" responded\";\n\n // only record the first response\n if (response.key == null) {\n response = {\n rt: info.rt,\n key: info.key,\n rt_key_duration: info.rt_key_duration ?? null,\n };\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 wait_for_key_release: trial.wait_for_key_release,\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-canvas-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 }\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 rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n rt_key_duration: null,\n };\n default_data.rt_key_duration =\n default_data.rt === null || !trial.wait_for_key_release\n ? null\n : this.jsPsych.randomization.sampleExGaussian(150, 30, 1 / 100, true);\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 CanvasKeyboardResponsePlugin;\n"],"names":[],"mappings":";;;EAEE,IAAA,OAAA,GAAW,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IC8FA,SAAA,EAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var jsPsychCanvasKeyboardResponse=function(
|
|
2
|
-
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-canvas-keyboard-response@2.
|
|
1
|
+
var jsPsychCanvasKeyboardResponse=(function(r){"use strict";var c="2.2.0";const p={name:"canvas-keyboard-response",version:c,parameters:{stimulus:{type:r.ParameterType.FUNCTION,default:void 0},choices:{type:r.ParameterType.KEYS,default:"ALL_KEYS"},prompt:{type:r.ParameterType.HTML_STRING,default:null},stimulus_duration:{type:r.ParameterType.INT,default:null},trial_duration:{type:r.ParameterType.INT,default:null},response_ends_trial:{type:r.ParameterType.BOOL,default:!0},canvas_size:{type:r.ParameterType.INT,array:!0,default:[500,500]},wait_for_key_release:{type:r.ParameterType.BOOL,default:!1}},data:{response:{type:r.ParameterType.STRING},rt:{type:r.ParameterType.INT},rt_key_duration:{type:r.ParameterType.INT}},citations:{apa:"de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ",bibtex:'@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } '}};class l{constructor(t){this.jsPsych=t}trial(t,e){var a='<div id="jspsych-canvas-keyboard-response-stimulus"><canvas id="jspsych-canvas-stimulus" height="'+e.canvas_size[0]+'" width="'+e.canvas_size[1]+'"></canvas></div>';e.prompt!==null&&(a+=e.prompt),t.innerHTML=a;let s=document.getElementById("jspsych-canvas-stimulus");s.style.display="block",e.stimulus(s);var i={rt:null,key:null,rt_key_duration:null};const o=()=>{typeof u!="undefined"&&this.jsPsych.pluginAPI.cancelKeyboardResponse(u);var n={rt:i.rt,response:i.key,rt_key_duration:i.rt_key_duration};this.jsPsych.finishTrial(n)};var d=n=>{var y;t.querySelector("#jspsych-canvas-keyboard-response-stimulus").className+=" responded",i.key==null&&(i={rt:n.rt,key:n.key,rt_key_duration:(y=n.rt_key_duration)!=null?y:null}),e.response_ends_trial&&o()};if(e.choices!="NO_KEYS")var u=this.jsPsych.pluginAPI.getKeyboardResponse({callback_function:d,valid_responses:e.choices,rt_method:"performance",persist:!1,allow_held_key:!1,wait_for_key_release:e.wait_for_key_release});e.stimulus_duration!==null&&this.jsPsych.pluginAPI.setTimeout(()=>{t.querySelector("#jspsych-canvas-keyboard-response-stimulus").style.visibility="hidden"},e.stimulus_duration),e.trial_duration!==null&&this.jsPsych.pluginAPI.setTimeout(()=>{o()},e.trial_duration)}simulate(t,e,a,s){e=="data-only"&&(s(),this.simulate_data_only(t,a)),e=="visual"&&this.simulate_visual(t,a,s)}simulate_data_only(t,e){const a=this.create_simulation_data(t,e);this.jsPsych.finishTrial(a)}simulate_visual(t,e,a){const s=this.create_simulation_data(t,e),i=this.jsPsych.getDisplayElement();this.trial(i,t),a(),s.rt!==null&&this.jsPsych.pluginAPI.pressKey(s.response,s.rt)}create_simulation_data(t,e){const a={rt:this.jsPsych.randomization.sampleExGaussian(500,50,.006666666666666667,!0),response:this.jsPsych.pluginAPI.getValidKey(t.choices),rt_key_duration:null};a.rt_key_duration=a.rt===null||!t.wait_for_key_release?null:this.jsPsych.randomization.sampleExGaussian(150,30,.01,!0);const s=this.jsPsych.pluginAPI.mergeSimulationData(a,e);return this.jsPsych.pluginAPI.ensureSimulationDataConsistency(t,s),s}}return l.info=p,l})(jsPsychModule);
|
|
2
|
+
//# sourceMappingURL=https://unpkg.com/@jspsych/plugin-canvas-keyboard-response@2.2.0/dist/index.browser.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.min.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"canvas-keyboard-response\",\n version: version,\n parameters: {\n /** The function to draw on the canvas. This function automatically takes a canvas element as its only\n * argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.\n * Note that the stimulus function will still generally need to set the correct context itself, using a line\n * like `let ctx = c.getContext(\"2d\")`.\n */\n stimulus: {\n type: ParameterType.FUNCTION,\n default: undefined,\n },\n /** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.\n * Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -\n * see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n * and [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\n * of `\"ALL_KEYS\"` means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean\n * that no responses are allowed.\n */\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\n * is 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 display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to\n * `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.\n */\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\n * 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\n * trial 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\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can use this parameter to force the participant\n * to view a 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 /** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */\n canvas_size: {\n type: ParameterType.INT,\n array: true,\n default: [500, 500],\n },\n },\n data: {\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\n * when the stimulus first appears on the screen until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin can be used to draw a stimulus on a [HTML canvas element](https://www.w3schools.com/html/html5_canvas.asp) and\n * record a keyboard response. The canvas stimulus can be useful for displaying dynamic, parametrically-defined graphics,\n * and for controlling the positioning of multiple graphical elements (shapes, text, images). The stimulus can be\n * displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically\n * if the participant has failed to respond within a fixed length of time.\n *\n * @author Chris Jungerius (modified from Josh de Leeuw)\n * @see {@link https://www.jspsych.org/latest/plugins/canvas-keyboard-response/ canvas-keyboard-response plugin documentation on jspsych.org}\n */\nclass CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html =\n '<div id=\"jspsych-canvas-keyboard-response-stimulus\">' +\n '<canvas id=\"jspsych-canvas-stimulus\" height=\"' +\n trial.canvas_size[0] +\n '\" width=\"' +\n trial.canvas_size[1] +\n '\"></canvas>' +\n \"</div>\";\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n let c = document.getElementById(\"jspsych-canvas-stimulus\");\n c.style.display = \"block\";\n trial.stimulus(c);\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 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-canvas-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-canvas-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 }\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 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 CanvasKeyboardResponsePlugin;\n"],"names":["info","version","ParameterType","CanvasKeyboardResponsePlugin","jsPsych","display_element","trial","new_html","c","response","end_trial","keyboardListener","trial_data","after_response","simulation_mode","simulation_options","load_callback","data","default_data"],"mappings":"w+BAIA,MAAMA,EAAc,CAClB,KAAM,2BACN,QAASC,EAAAA,QACT,WAAY,CAMV,SAAU,CACR,KAAMC,EAAAA,cAAc,SACpB,QAAS,MACX,EASA,QAAS,CACP,KAAMA,EAAAA,cAAc,KACpB,QAAS,UACX,EAIA,OAAQ,CACN,KAAMA,EAAAA,cAAc,YACpB,QAAS,IACX,EAIA,kBAAmB,CACjB,KAAMA,gBAAc,IACpB,QAAS,IACX,EAMA,eAAgB,CACd,KAAMA,EAAAA,cAAc,IACpB,QAAS,IACX,EAMA,oBAAqB,CACnB,KAAMA,EAAc,c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,UAAU,WAAW,IAAM,CACtCI,EACF,CAAA,EAAGJ,EAAM,cAAc,CAE3B,CAEA,SACEA,EACAQ,EACAC,EACAC,EACA,CACIF,GAAmB,cACrBE,EACA,EAAA,KAAK,mBAAmBV,EAAOS,CAAkB,GAE/CD,GAAmB,UACrB,KAAK,gBAAgBR,EAAOS,EAAoBC,CAAa,CAEjE,CAEQ,mBAAmBV,EAAwBS,EAAoB,CACrE,MAAME,EAAO,KAAK,uBAAuBX,EAAOS,CAAkB,EAElE,KAAK,QAAQ,YAAYE,CAAI,CAC/B,CAEQ,gBAAgBX,EAAwBS,EAAoBC,EAA2B,CAC7F,MAAMC,EAAO,KAAK,uBAAuBX,EAAOS,CAAkB,EAE5DV,EAAkB,KAAK,QAAQ,oBAErC,KAAK,MAAMA,EAAiBC,CAAK,EACjCU,IAEIC,EAAK,KAAO,MACd,KAAK,QAAQ,UAAU,SAASA,EAAK,SAAUA,EAAK,EAAE,CAE1D,CAEQ,uBAAuBX,EAAwBS,EAAoB,CACzE,MAAMG,EAAe,CACnB,GAAI,KAAK,QAAQ,cAAc,iBAAiB,IAAK,GAAI,oBAAS,EAAI,EACtE,SAAU,KAAK,QAAQ,UAAU,YAAYZ,EAAM,OAAO,CAC5D,EAEMW,EAAO,KAAK,QAAQ,UAAU,oBAAoBC,EAAcH,CAAkB,EAExF,OAAK,KAAA,QAAQ,UAAU,gCAAgCT,EAAOW,CAAI,EAE3DA,CACT,CACF,CA1IMd,OAAAA,EACG,KAAOH"}
|
|
1
|
+
{"version":3,"file":"index.browser.min.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-canvas-keyboard-response\",\n \"version\": \"2.2.0\",\n \"description\": \"jsPsych plugin for displaying a canvas stimulus and getting a keyboard response\",\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-canvas-keyboard-response\"\n },\n \"author\": \"Chris Jungerius, 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/canvas-keyboard-response\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.3.4\",\n \"@jspsych/test-utils\": \"^1.3.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"canvas-keyboard-response\",\n version: version,\n parameters: {\n /** The function to draw on the canvas. This function automatically takes a canvas element as its only\n * argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.\n * Note that the stimulus function will still generally need to set the correct context itself, using a line\n * like `let ctx = c.getContext(\"2d\")`.\n */\n stimulus: {\n type: ParameterType.FUNCTION,\n default: undefined,\n },\n /** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.\n * Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -\n * see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n * and [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\n * of `\"ALL_KEYS\"` means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean\n * that no responses are allowed.\n */\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\n * is 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 display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to\n * `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.\n */\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\n * 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\n * trial 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\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can use this parameter to force the participant\n * to view a 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 /** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */\n canvas_size: {\n type: ParameterType.INT,\n array: true,\n default: [500, 500],\n },\n /** If true, the response is not registered until the participant releases the key. The response\n * time (`rt`) still reflects when the key was pressed, and the additional data field\n * `rt_key_duration` records how long the key was held down. Note that when this is true, the\n * trial cannot end until the key is released: with `response_ends_trial: true` the trial ends at\n * the key release, and if the trial ends for another reason (e.g., `trial_duration`) while the\n * key is still held, no response is recorded for the trial.\n */\n wait_for_key_release: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\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\n * when the stimulus first appears on the screen until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The duration in milliseconds that the response key was held down, measured from key press to key release. Only recorded when `wait_for_key_release` is true; null otherwise or when no response was made. */\n rt_key_duration: {\n type: ParameterType.INT,\n },\n },\n // prettier-ignore\n citations: '__CITATIONS__',\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin can be used to draw a stimulus on a [HTML canvas element](https://www.w3schools.com/html/html5_canvas.asp) and\n * record a keyboard response. The canvas stimulus can be useful for displaying dynamic, parametrically-defined graphics,\n * and for controlling the positioning of multiple graphical elements (shapes, text, images). The stimulus can be\n * displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically\n * if the participant has failed to respond within a fixed length of time.\n *\n * @author Chris Jungerius (modified from Josh de Leeuw)\n * @see {@link https://www.jspsych.org/latest/plugins/canvas-keyboard-response/ canvas-keyboard-response plugin documentation on jspsych.org}\n */\nclass CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html =\n '<div id=\"jspsych-canvas-keyboard-response-stimulus\">' +\n '<canvas id=\"jspsych-canvas-stimulus\" height=\"' +\n trial.canvas_size[0] +\n '\" width=\"' +\n trial.canvas_size[1] +\n '\"></canvas>' +\n \"</div>\";\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n let c = document.getElementById(\"jspsych-canvas-stimulus\");\n c.style.display = \"block\";\n trial.stimulus(c);\n // store response\n var response = {\n rt: null,\n key: null,\n rt_key_duration: 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 response: response.key,\n rt_key_duration: response.rt_key_duration,\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-canvas-keyboard-response-stimulus\").className +=\n \" responded\";\n\n // only record the first response\n if (response.key == null) {\n response = {\n rt: info.rt,\n key: info.key,\n rt_key_duration: info.rt_key_duration ?? null,\n };\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 wait_for_key_release: trial.wait_for_key_release,\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-canvas-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 }\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 rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n rt_key_duration: null,\n };\n default_data.rt_key_duration =\n default_data.rt === null || !trial.wait_for_key_release\n ? null\n : this.jsPsych.randomization.sampleExGaussian(150, 30, 1 / 100, true);\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 CanvasKeyboardResponsePlugin;\n"],"names":["version","_a"],"mappings":"4DACE,IACAA,EAAW,+oBC8FA,UAAA,iuBAAe,ulBAhG5B,IAAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -2,97 +2,112 @@
|
|
|
2
2
|
|
|
3
3
|
var jspsych = require('jspsych');
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
name: "@jspsych/plugin-canvas-keyboard-response",
|
|
7
|
-
version: "2.0.0",
|
|
8
|
-
description: "jsPsych plugin for displaying a canvas stimulus and getting a keyboard response",
|
|
9
|
-
type: "module",
|
|
10
|
-
main: "dist/index.cjs",
|
|
11
|
-
exports: {
|
|
12
|
-
import: "./dist/index.js",
|
|
13
|
-
require: "./dist/index.cjs"
|
|
14
|
-
},
|
|
15
|
-
typings: "dist/index.d.ts",
|
|
16
|
-
unpkg: "dist/index.browser.min.js",
|
|
17
|
-
files: [
|
|
18
|
-
"src",
|
|
19
|
-
"dist"
|
|
20
|
-
],
|
|
21
|
-
source: "src/index.ts",
|
|
22
|
-
scripts: {
|
|
23
|
-
test: "jest --passWithNoTests",
|
|
24
|
-
"test:watch": "npm test -- --watch",
|
|
25
|
-
tsc: "tsc",
|
|
26
|
-
build: "rollup --config",
|
|
27
|
-
"build:watch": "npm run build -- --watch"
|
|
28
|
-
},
|
|
29
|
-
repository: {
|
|
30
|
-
type: "git",
|
|
31
|
-
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
32
|
-
directory: "packages/plugin-canvas-keyboard-response"
|
|
33
|
-
},
|
|
34
|
-
author: "Chris Jungerius, Josh de Leeuw",
|
|
35
|
-
license: "MIT",
|
|
36
|
-
bugs: {
|
|
37
|
-
url: "https://github.com/jspsych/jsPsych/issues"
|
|
38
|
-
},
|
|
39
|
-
homepage: "https://www.jspsych.org/latest/plugins/canvas-keyboard-response",
|
|
40
|
-
peerDependencies: {
|
|
41
|
-
jspsych: ">=7.1.0"
|
|
42
|
-
},
|
|
43
|
-
devDependencies: {
|
|
44
|
-
"@jspsych/config": "^3.0.0",
|
|
45
|
-
"@jspsych/test-utils": "^1.2.0"
|
|
46
|
-
}
|
|
47
|
-
};
|
|
5
|
+
var version = "2.2.0";
|
|
48
6
|
|
|
49
7
|
const info = {
|
|
50
8
|
name: "canvas-keyboard-response",
|
|
51
|
-
version
|
|
9
|
+
version,
|
|
52
10
|
parameters: {
|
|
11
|
+
/** The function to draw on the canvas. This function automatically takes a canvas element as its only
|
|
12
|
+
* argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.
|
|
13
|
+
* Note that the stimulus function will still generally need to set the correct context itself, using a line
|
|
14
|
+
* like `let ctx = c.getContext("2d")`.
|
|
15
|
+
*/
|
|
53
16
|
stimulus: {
|
|
54
17
|
type: jspsych.ParameterType.FUNCTION,
|
|
55
18
|
default: void 0
|
|
56
19
|
},
|
|
20
|
+
/** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.
|
|
21
|
+
* Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -
|
|
22
|
+
* see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
|
|
23
|
+
* and [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)
|
|
24
|
+
* for more examples. Any key presses that are not listed in the array will be ignored. The default value
|
|
25
|
+
* of `"ALL_KEYS"` means that all keys will be accepted as valid responses. Specifying `"NO_KEYS"` will mean
|
|
26
|
+
* that no responses are allowed.
|
|
27
|
+
*/
|
|
57
28
|
choices: {
|
|
58
29
|
type: jspsych.ParameterType.KEYS,
|
|
59
30
|
default: "ALL_KEYS"
|
|
60
31
|
},
|
|
32
|
+
/** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention
|
|
33
|
+
* is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
|
|
34
|
+
*/
|
|
61
35
|
prompt: {
|
|
62
36
|
type: jspsych.ParameterType.HTML_STRING,
|
|
63
37
|
default: null
|
|
64
38
|
},
|
|
39
|
+
/** How long to display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to
|
|
40
|
+
* `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.
|
|
41
|
+
*/
|
|
65
42
|
stimulus_duration: {
|
|
66
43
|
type: jspsych.ParameterType.INT,
|
|
67
44
|
default: null
|
|
68
45
|
},
|
|
46
|
+
/** How long to wait for the participant to make a response before ending the trial in milliseconds. If the
|
|
47
|
+
* participant fails to make a response before this timer is reached, the participant's response will be
|
|
48
|
+
* recorded as null for the trial and the trial will end. If the value of this parameter is null, then the
|
|
49
|
+
* trial will wait for a response indefinitely.
|
|
50
|
+
*/
|
|
69
51
|
trial_duration: {
|
|
70
52
|
type: jspsych.ParameterType.INT,
|
|
71
53
|
default: null
|
|
72
54
|
},
|
|
55
|
+
/** If true, then the trial will end whenever the participant makes a response (assuming they make their
|
|
56
|
+
* response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will
|
|
57
|
+
* continue until the value for `trial_duration` is reached. You can use this parameter to force the participant
|
|
58
|
+
* to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
|
|
59
|
+
*/
|
|
73
60
|
response_ends_trial: {
|
|
74
61
|
type: jspsych.ParameterType.BOOL,
|
|
75
62
|
default: true
|
|
76
63
|
},
|
|
64
|
+
/** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */
|
|
77
65
|
canvas_size: {
|
|
78
66
|
type: jspsych.ParameterType.INT,
|
|
79
67
|
array: true,
|
|
80
68
|
default: [500, 500]
|
|
69
|
+
},
|
|
70
|
+
/** If true, the response is not registered until the participant releases the key. The response
|
|
71
|
+
* time (`rt`) still reflects when the key was pressed, and the additional data field
|
|
72
|
+
* `rt_key_duration` records how long the key was held down. Note that when this is true, the
|
|
73
|
+
* trial cannot end until the key is released: with `response_ends_trial: true` the trial ends at
|
|
74
|
+
* the key release, and if the trial ends for another reason (e.g., `trial_duration`) while the
|
|
75
|
+
* key is still held, no response is recorded for the trial.
|
|
76
|
+
*/
|
|
77
|
+
wait_for_key_release: {
|
|
78
|
+
type: jspsych.ParameterType.BOOL,
|
|
79
|
+
default: false
|
|
81
80
|
}
|
|
82
81
|
},
|
|
83
82
|
data: {
|
|
83
|
+
/** Indicates which key the participant pressed. */
|
|
84
84
|
response: {
|
|
85
85
|
type: jspsych.ParameterType.STRING
|
|
86
86
|
},
|
|
87
|
+
/** The response time in milliseconds for the participant to make a response. The time is measured from
|
|
88
|
+
* when the stimulus first appears on the screen until the participant's response.
|
|
89
|
+
*/
|
|
87
90
|
rt: {
|
|
88
91
|
type: jspsych.ParameterType.INT
|
|
92
|
+
},
|
|
93
|
+
/** The duration in milliseconds that the response key was held down, measured from key press to key release. Only recorded when `wait_for_key_release` is true; null otherwise or when no response was made. */
|
|
94
|
+
rt_key_duration: {
|
|
95
|
+
type: jspsych.ParameterType.INT
|
|
89
96
|
}
|
|
97
|
+
},
|
|
98
|
+
// prettier-ignore
|
|
99
|
+
citations: {
|
|
100
|
+
"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 ",
|
|
101
|
+
"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}, } '
|
|
90
102
|
}
|
|
91
103
|
};
|
|
92
104
|
class CanvasKeyboardResponsePlugin {
|
|
93
105
|
constructor(jsPsych) {
|
|
94
106
|
this.jsPsych = jsPsych;
|
|
95
107
|
}
|
|
108
|
+
static {
|
|
109
|
+
this.info = info;
|
|
110
|
+
}
|
|
96
111
|
trial(display_element, trial) {
|
|
97
112
|
var new_html = '<div id="jspsych-canvas-keyboard-response-stimulus"><canvas id="jspsych-canvas-stimulus" height="' + trial.canvas_size[0] + '" width="' + trial.canvas_size[1] + '"></canvas></div>';
|
|
98
113
|
if (trial.prompt !== null) {
|
|
@@ -104,7 +119,8 @@ class CanvasKeyboardResponsePlugin {
|
|
|
104
119
|
trial.stimulus(c);
|
|
105
120
|
var response = {
|
|
106
121
|
rt: null,
|
|
107
|
-
key: null
|
|
122
|
+
key: null,
|
|
123
|
+
rt_key_duration: null
|
|
108
124
|
};
|
|
109
125
|
const end_trial = () => {
|
|
110
126
|
if (typeof keyboardListener !== "undefined") {
|
|
@@ -112,14 +128,19 @@ class CanvasKeyboardResponsePlugin {
|
|
|
112
128
|
}
|
|
113
129
|
var trial_data = {
|
|
114
130
|
rt: response.rt,
|
|
115
|
-
response: response.key
|
|
131
|
+
response: response.key,
|
|
132
|
+
rt_key_duration: response.rt_key_duration
|
|
116
133
|
};
|
|
117
134
|
this.jsPsych.finishTrial(trial_data);
|
|
118
135
|
};
|
|
119
136
|
var after_response = (info2) => {
|
|
120
137
|
display_element.querySelector("#jspsych-canvas-keyboard-response-stimulus").className += " responded";
|
|
121
138
|
if (response.key == null) {
|
|
122
|
-
response =
|
|
139
|
+
response = {
|
|
140
|
+
rt: info2.rt,
|
|
141
|
+
key: info2.key,
|
|
142
|
+
rt_key_duration: info2.rt_key_duration ?? null
|
|
143
|
+
};
|
|
123
144
|
}
|
|
124
145
|
if (trial.response_ends_trial) {
|
|
125
146
|
end_trial();
|
|
@@ -131,7 +152,8 @@ class CanvasKeyboardResponsePlugin {
|
|
|
131
152
|
valid_responses: trial.choices,
|
|
132
153
|
rt_method: "performance",
|
|
133
154
|
persist: false,
|
|
134
|
-
allow_held_key: false
|
|
155
|
+
allow_held_key: false,
|
|
156
|
+
wait_for_key_release: trial.wait_for_key_release
|
|
135
157
|
});
|
|
136
158
|
}
|
|
137
159
|
if (trial.stimulus_duration !== null) {
|
|
@@ -172,14 +194,15 @@ class CanvasKeyboardResponsePlugin {
|
|
|
172
194
|
create_simulation_data(trial, simulation_options) {
|
|
173
195
|
const default_data = {
|
|
174
196
|
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
|
|
175
|
-
response: this.jsPsych.pluginAPI.getValidKey(trial.choices)
|
|
197
|
+
response: this.jsPsych.pluginAPI.getValidKey(trial.choices),
|
|
198
|
+
rt_key_duration: null
|
|
176
199
|
};
|
|
200
|
+
default_data.rt_key_duration = default_data.rt === null || !trial.wait_for_key_release ? null : this.jsPsych.randomization.sampleExGaussian(150, 30, 1 / 100, true);
|
|
177
201
|
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
178
202
|
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
179
203
|
return data;
|
|
180
204
|
}
|
|
181
205
|
}
|
|
182
|
-
CanvasKeyboardResponsePlugin.info = info;
|
|
183
206
|
|
|
184
207
|
module.exports = CanvasKeyboardResponsePlugin;
|
|
185
208
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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: \"canvas-keyboard-response\",\n version: version,\n parameters: {\n /** The function to draw on the canvas. This function automatically takes a canvas element as its only\n * argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.\n * Note that the stimulus function will still generally need to set the correct context itself, using a line\n * like `let ctx = c.getContext(\"2d\")`.\n */\n stimulus: {\n type: ParameterType.FUNCTION,\n default: undefined,\n },\n /** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.\n * Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -\n * see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n * and [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\n * of `\"ALL_KEYS\"` means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean\n * that no responses are allowed.\n */\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\n * is 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 display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to\n * `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.\n */\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\n * 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\n * trial 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\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can use this parameter to force the participant\n * to view a 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 /** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */\n canvas_size: {\n type: ParameterType.INT,\n array: true,\n default: [500, 500],\n },\n },\n data: {\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\n * when the stimulus first appears on the screen until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin can be used to draw a stimulus on a [HTML canvas element](https://www.w3schools.com/html/html5_canvas.asp) and\n * record a keyboard response. The canvas stimulus can be useful for displaying dynamic, parametrically-defined graphics,\n * and for controlling the positioning of multiple graphical elements (shapes, text, images). The stimulus can be\n * displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically\n * if the participant has failed to respond within a fixed length of time.\n *\n * @author Chris Jungerius (modified from Josh de Leeuw)\n * @see {@link https://www.jspsych.org/latest/plugins/canvas-keyboard-response/ canvas-keyboard-response plugin documentation on jspsych.org}\n */\nclass CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html =\n '<div id=\"jspsych-canvas-keyboard-response-stimulus\">' +\n '<canvas id=\"jspsych-canvas-stimulus\" height=\"' +\n trial.canvas_size[0] +\n '\" width=\"' +\n trial.canvas_size[1] +\n '\"></canvas>' +\n \"</div>\";\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n let c = document.getElementById(\"jspsych-canvas-stimulus\");\n c.style.display = \"block\";\n trial.stimulus(c);\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 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-canvas-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-canvas-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 }\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 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 CanvasKeyboardResponsePlugin;\n"],"names":["version","ParameterType","info"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,0BAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAMV,QAAU,EAAA;AAAA,MACR,MAAMC,qBAAc,CAAA,QAAA;AAAA,MACpB,OAAS,EAAA,KAAA,CAAA;AAAA,KACX;AAAA,IASA,OAAS,EAAA;AAAA,MACP,MAAMA,qBAAc,CAAA,IAAA;AAAA,MACpB,OAAS,EAAA,UAAA;AAAA,KACX;AAAA,IAIA,MAAQ,EAAA;AAAA,MACN,MAAMA,qBAAc,CAAA,WAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAIA,iBAAmB,EAAA;AAAA,MACjB,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAMA,cAAgB,EAAA;AAAA,MACd,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAMA,mBAAqB,EAAA;AAAA,MACnB,MAAMA,qBAAc,CAAA,IAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAEA,WAAa,EAAA;AAAA,MACX,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,KAAO,EAAA,IAAA;AAAA,MACP,OAAA,EAAS,CAAC,GAAA,EAAK,GAAG,CAAA;AAAA,KACpB;A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,EAAI,CAAI,GAAA,GAAA,EAAK,IAAI,CAAA;AAAA,MACtE,UAAU,IAAK,CAAA,OAAA,CAAQ,SAAU,CAAA,WAAA,CAAY,MAAM,OAAO,CAAA;AAAA,KAC5D,CAAA;AAEA,IAAA,MAAM,OAAO,IAAK,CAAA,OAAA,CAAQ,SAAU,CAAA,mBAAA,CAAoB,cAAc,kBAAkB,CAAA,CAAA;AAExF,IAAA,IAAA,CAAK,OAAQ,CAAA,SAAA,CAAU,+BAAgC,CAAA,KAAA,EAAO,IAAI,CAAA,CAAA;AAElE,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACF,CAAA;AA1IM,4BAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-canvas-keyboard-response\",\n \"version\": \"2.2.0\",\n \"description\": \"jsPsych plugin for displaying a canvas stimulus and getting a keyboard response\",\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-canvas-keyboard-response\"\n },\n \"author\": \"Chris Jungerius, 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/canvas-keyboard-response\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.3.4\",\n \"@jspsych/test-utils\": \"^1.3.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"canvas-keyboard-response\",\n version: version,\n parameters: {\n /** The function to draw on the canvas. This function automatically takes a canvas element as its only\n * argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.\n * Note that the stimulus function will still generally need to set the correct context itself, using a line\n * like `let ctx = c.getContext(\"2d\")`.\n */\n stimulus: {\n type: ParameterType.FUNCTION,\n default: undefined,\n },\n /** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.\n * Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -\n * see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n * and [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\n * of `\"ALL_KEYS\"` means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean\n * that no responses are allowed.\n */\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\n * is 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 display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to\n * `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.\n */\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\n * 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\n * trial 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\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can use this parameter to force the participant\n * to view a 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 /** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */\n canvas_size: {\n type: ParameterType.INT,\n array: true,\n default: [500, 500],\n },\n /** If true, the response is not registered until the participant releases the key. The response\n * time (`rt`) still reflects when the key was pressed, and the additional data field\n * `rt_key_duration` records how long the key was held down. Note that when this is true, the\n * trial cannot end until the key is released: with `response_ends_trial: true` the trial ends at\n * the key release, and if the trial ends for another reason (e.g., `trial_duration`) while the\n * key is still held, no response is recorded for the trial.\n */\n wait_for_key_release: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\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\n * when the stimulus first appears on the screen until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The duration in milliseconds that the response key was held down, measured from key press to key release. Only recorded when `wait_for_key_release` is true; null otherwise or when no response was made. */\n rt_key_duration: {\n type: ParameterType.INT,\n },\n },\n // prettier-ignore\n citations: '__CITATIONS__',\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin can be used to draw a stimulus on a [HTML canvas element](https://www.w3schools.com/html/html5_canvas.asp) and\n * record a keyboard response. The canvas stimulus can be useful for displaying dynamic, parametrically-defined graphics,\n * and for controlling the positioning of multiple graphical elements (shapes, text, images). The stimulus can be\n * displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically\n * if the participant has failed to respond within a fixed length of time.\n *\n * @author Chris Jungerius (modified from Josh de Leeuw)\n * @see {@link https://www.jspsych.org/latest/plugins/canvas-keyboard-response/ canvas-keyboard-response plugin documentation on jspsych.org}\n */\nclass CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html =\n '<div id=\"jspsych-canvas-keyboard-response-stimulus\">' +\n '<canvas id=\"jspsych-canvas-stimulus\" height=\"' +\n trial.canvas_size[0] +\n '\" width=\"' +\n trial.canvas_size[1] +\n '\"></canvas>' +\n \"</div>\";\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n let c = document.getElementById(\"jspsych-canvas-stimulus\");\n c.style.display = \"block\";\n trial.stimulus(c);\n // store response\n var response = {\n rt: null,\n key: null,\n rt_key_duration: 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 response: response.key,\n rt_key_duration: response.rt_key_duration,\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-canvas-keyboard-response-stimulus\").className +=\n \" responded\";\n\n // only record the first response\n if (response.key == null) {\n response = {\n rt: info.rt,\n key: info.key,\n rt_key_duration: info.rt_key_duration ?? null,\n };\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 wait_for_key_release: trial.wait_for_key_release,\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-canvas-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 }\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 rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n rt_key_duration: null,\n };\n default_data.rt_key_duration =\n default_data.rt === null || !trial.wait_for_key_release\n ? null\n : this.jsPsych.randomization.sampleExGaussian(150, 30, 1 / 100, true);\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 CanvasKeyboardResponsePlugin;\n"],"names":[],"mappings":";;;;AAEE,IAAA,OAAA,GAAW,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EC8FA,SAAA,EAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -63,6 +63,17 @@ declare const info: {
|
|
|
63
63
|
readonly array: true;
|
|
64
64
|
readonly default: readonly [500, 500];
|
|
65
65
|
};
|
|
66
|
+
/** If true, the response is not registered until the participant releases the key. The response
|
|
67
|
+
* time (`rt`) still reflects when the key was pressed, and the additional data field
|
|
68
|
+
* `rt_key_duration` records how long the key was held down. Note that when this is true, the
|
|
69
|
+
* trial cannot end until the key is released: with `response_ends_trial: true` the trial ends at
|
|
70
|
+
* the key release, and if the trial ends for another reason (e.g., `trial_duration`) while the
|
|
71
|
+
* key is still held, no response is recorded for the trial.
|
|
72
|
+
*/
|
|
73
|
+
readonly wait_for_key_release: {
|
|
74
|
+
readonly type: ParameterType.BOOL;
|
|
75
|
+
readonly default: false;
|
|
76
|
+
};
|
|
66
77
|
};
|
|
67
78
|
readonly data: {
|
|
68
79
|
/** Indicates which key the participant pressed. */
|
|
@@ -75,7 +86,12 @@ declare const info: {
|
|
|
75
86
|
readonly rt: {
|
|
76
87
|
readonly type: ParameterType.INT;
|
|
77
88
|
};
|
|
89
|
+
/** The duration in milliseconds that the response key was held down, measured from key press to key release. Only recorded when `wait_for_key_release` is true; null otherwise or when no response was made. */
|
|
90
|
+
readonly rt_key_duration: {
|
|
91
|
+
readonly type: ParameterType.INT;
|
|
92
|
+
};
|
|
78
93
|
};
|
|
94
|
+
readonly citations: "__CITATIONS__";
|
|
79
95
|
};
|
|
80
96
|
type Info = typeof info;
|
|
81
97
|
/**
|
|
@@ -153,6 +169,17 @@ declare class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
153
169
|
readonly array: true;
|
|
154
170
|
readonly default: readonly [500, 500];
|
|
155
171
|
};
|
|
172
|
+
/** If true, the response is not registered until the participant releases the key. The response
|
|
173
|
+
* time (`rt`) still reflects when the key was pressed, and the additional data field
|
|
174
|
+
* `rt_key_duration` records how long the key was held down. Note that when this is true, the
|
|
175
|
+
* trial cannot end until the key is released: with `response_ends_trial: true` the trial ends at
|
|
176
|
+
* the key release, and if the trial ends for another reason (e.g., `trial_duration`) while the
|
|
177
|
+
* key is still held, no response is recorded for the trial.
|
|
178
|
+
*/
|
|
179
|
+
readonly wait_for_key_release: {
|
|
180
|
+
readonly type: ParameterType.BOOL;
|
|
181
|
+
readonly default: false;
|
|
182
|
+
};
|
|
156
183
|
};
|
|
157
184
|
readonly data: {
|
|
158
185
|
/** Indicates which key the participant pressed. */
|
|
@@ -165,7 +192,12 @@ declare class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
165
192
|
readonly rt: {
|
|
166
193
|
readonly type: ParameterType.INT;
|
|
167
194
|
};
|
|
195
|
+
/** The duration in milliseconds that the response key was held down, measured from key press to key release. Only recorded when `wait_for_key_release` is true; null otherwise or when no response was made. */
|
|
196
|
+
readonly rt_key_duration: {
|
|
197
|
+
readonly type: ParameterType.INT;
|
|
198
|
+
};
|
|
168
199
|
};
|
|
200
|
+
readonly citations: "__CITATIONS__";
|
|
169
201
|
};
|
|
170
202
|
constructor(jsPsych: JsPsych);
|
|
171
203
|
trial(display_element: HTMLElement, trial: TrialType<Info>): void;
|
package/dist/index.js
CHANGED
|
@@ -1,96 +1,111 @@
|
|
|
1
1
|
import { ParameterType } from 'jspsych';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
name: "@jspsych/plugin-canvas-keyboard-response",
|
|
5
|
-
version: "2.0.0",
|
|
6
|
-
description: "jsPsych plugin for displaying a canvas stimulus and getting a keyboard response",
|
|
7
|
-
type: "module",
|
|
8
|
-
main: "dist/index.cjs",
|
|
9
|
-
exports: {
|
|
10
|
-
import: "./dist/index.js",
|
|
11
|
-
require: "./dist/index.cjs"
|
|
12
|
-
},
|
|
13
|
-
typings: "dist/index.d.ts",
|
|
14
|
-
unpkg: "dist/index.browser.min.js",
|
|
15
|
-
files: [
|
|
16
|
-
"src",
|
|
17
|
-
"dist"
|
|
18
|
-
],
|
|
19
|
-
source: "src/index.ts",
|
|
20
|
-
scripts: {
|
|
21
|
-
test: "jest --passWithNoTests",
|
|
22
|
-
"test:watch": "npm test -- --watch",
|
|
23
|
-
tsc: "tsc",
|
|
24
|
-
build: "rollup --config",
|
|
25
|
-
"build:watch": "npm run build -- --watch"
|
|
26
|
-
},
|
|
27
|
-
repository: {
|
|
28
|
-
type: "git",
|
|
29
|
-
url: "git+https://github.com/jspsych/jsPsych.git",
|
|
30
|
-
directory: "packages/plugin-canvas-keyboard-response"
|
|
31
|
-
},
|
|
32
|
-
author: "Chris Jungerius, Josh de Leeuw",
|
|
33
|
-
license: "MIT",
|
|
34
|
-
bugs: {
|
|
35
|
-
url: "https://github.com/jspsych/jsPsych/issues"
|
|
36
|
-
},
|
|
37
|
-
homepage: "https://www.jspsych.org/latest/plugins/canvas-keyboard-response",
|
|
38
|
-
peerDependencies: {
|
|
39
|
-
jspsych: ">=7.1.0"
|
|
40
|
-
},
|
|
41
|
-
devDependencies: {
|
|
42
|
-
"@jspsych/config": "^3.0.0",
|
|
43
|
-
"@jspsych/test-utils": "^1.2.0"
|
|
44
|
-
}
|
|
45
|
-
};
|
|
3
|
+
var version = "2.2.0";
|
|
46
4
|
|
|
47
5
|
const info = {
|
|
48
6
|
name: "canvas-keyboard-response",
|
|
49
|
-
version
|
|
7
|
+
version,
|
|
50
8
|
parameters: {
|
|
9
|
+
/** The function to draw on the canvas. This function automatically takes a canvas element as its only
|
|
10
|
+
* argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.
|
|
11
|
+
* Note that the stimulus function will still generally need to set the correct context itself, using a line
|
|
12
|
+
* like `let ctx = c.getContext("2d")`.
|
|
13
|
+
*/
|
|
51
14
|
stimulus: {
|
|
52
15
|
type: ParameterType.FUNCTION,
|
|
53
16
|
default: void 0
|
|
54
17
|
},
|
|
18
|
+
/** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.
|
|
19
|
+
* Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -
|
|
20
|
+
* see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
|
|
21
|
+
* and [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)
|
|
22
|
+
* for more examples. Any key presses that are not listed in the array will be ignored. The default value
|
|
23
|
+
* of `"ALL_KEYS"` means that all keys will be accepted as valid responses. Specifying `"NO_KEYS"` will mean
|
|
24
|
+
* that no responses are allowed.
|
|
25
|
+
*/
|
|
55
26
|
choices: {
|
|
56
27
|
type: ParameterType.KEYS,
|
|
57
28
|
default: "ALL_KEYS"
|
|
58
29
|
},
|
|
30
|
+
/** This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention
|
|
31
|
+
* is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press).
|
|
32
|
+
*/
|
|
59
33
|
prompt: {
|
|
60
34
|
type: ParameterType.HTML_STRING,
|
|
61
35
|
default: null
|
|
62
36
|
},
|
|
37
|
+
/** How long to display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to
|
|
38
|
+
* `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.
|
|
39
|
+
*/
|
|
63
40
|
stimulus_duration: {
|
|
64
41
|
type: ParameterType.INT,
|
|
65
42
|
default: null
|
|
66
43
|
},
|
|
44
|
+
/** How long to wait for the participant to make a response before ending the trial in milliseconds. If the
|
|
45
|
+
* participant fails to make a response before this timer is reached, the participant's response will be
|
|
46
|
+
* recorded as null for the trial and the trial will end. If the value of this parameter is null, then the
|
|
47
|
+
* trial will wait for a response indefinitely.
|
|
48
|
+
*/
|
|
67
49
|
trial_duration: {
|
|
68
50
|
type: ParameterType.INT,
|
|
69
51
|
default: null
|
|
70
52
|
},
|
|
53
|
+
/** If true, then the trial will end whenever the participant makes a response (assuming they make their
|
|
54
|
+
* response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will
|
|
55
|
+
* continue until the value for `trial_duration` is reached. You can use this parameter to force the participant
|
|
56
|
+
* to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
|
|
57
|
+
*/
|
|
71
58
|
response_ends_trial: {
|
|
72
59
|
type: ParameterType.BOOL,
|
|
73
60
|
default: true
|
|
74
61
|
},
|
|
62
|
+
/** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */
|
|
75
63
|
canvas_size: {
|
|
76
64
|
type: ParameterType.INT,
|
|
77
65
|
array: true,
|
|
78
66
|
default: [500, 500]
|
|
67
|
+
},
|
|
68
|
+
/** If true, the response is not registered until the participant releases the key. The response
|
|
69
|
+
* time (`rt`) still reflects when the key was pressed, and the additional data field
|
|
70
|
+
* `rt_key_duration` records how long the key was held down. Note that when this is true, the
|
|
71
|
+
* trial cannot end until the key is released: with `response_ends_trial: true` the trial ends at
|
|
72
|
+
* the key release, and if the trial ends for another reason (e.g., `trial_duration`) while the
|
|
73
|
+
* key is still held, no response is recorded for the trial.
|
|
74
|
+
*/
|
|
75
|
+
wait_for_key_release: {
|
|
76
|
+
type: ParameterType.BOOL,
|
|
77
|
+
default: false
|
|
79
78
|
}
|
|
80
79
|
},
|
|
81
80
|
data: {
|
|
81
|
+
/** Indicates which key the participant pressed. */
|
|
82
82
|
response: {
|
|
83
83
|
type: ParameterType.STRING
|
|
84
84
|
},
|
|
85
|
+
/** The response time in milliseconds for the participant to make a response. The time is measured from
|
|
86
|
+
* when the stimulus first appears on the screen until the participant's response.
|
|
87
|
+
*/
|
|
85
88
|
rt: {
|
|
86
89
|
type: ParameterType.INT
|
|
90
|
+
},
|
|
91
|
+
/** The duration in milliseconds that the response key was held down, measured from key press to key release. Only recorded when `wait_for_key_release` is true; null otherwise or when no response was made. */
|
|
92
|
+
rt_key_duration: {
|
|
93
|
+
type: ParameterType.INT
|
|
87
94
|
}
|
|
95
|
+
},
|
|
96
|
+
// prettier-ignore
|
|
97
|
+
citations: {
|
|
98
|
+
"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 ",
|
|
99
|
+
"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}, } '
|
|
88
100
|
}
|
|
89
101
|
};
|
|
90
102
|
class CanvasKeyboardResponsePlugin {
|
|
91
103
|
constructor(jsPsych) {
|
|
92
104
|
this.jsPsych = jsPsych;
|
|
93
105
|
}
|
|
106
|
+
static {
|
|
107
|
+
this.info = info;
|
|
108
|
+
}
|
|
94
109
|
trial(display_element, trial) {
|
|
95
110
|
var new_html = '<div id="jspsych-canvas-keyboard-response-stimulus"><canvas id="jspsych-canvas-stimulus" height="' + trial.canvas_size[0] + '" width="' + trial.canvas_size[1] + '"></canvas></div>';
|
|
96
111
|
if (trial.prompt !== null) {
|
|
@@ -102,7 +117,8 @@ class CanvasKeyboardResponsePlugin {
|
|
|
102
117
|
trial.stimulus(c);
|
|
103
118
|
var response = {
|
|
104
119
|
rt: null,
|
|
105
|
-
key: null
|
|
120
|
+
key: null,
|
|
121
|
+
rt_key_duration: null
|
|
106
122
|
};
|
|
107
123
|
const end_trial = () => {
|
|
108
124
|
if (typeof keyboardListener !== "undefined") {
|
|
@@ -110,14 +126,19 @@ class CanvasKeyboardResponsePlugin {
|
|
|
110
126
|
}
|
|
111
127
|
var trial_data = {
|
|
112
128
|
rt: response.rt,
|
|
113
|
-
response: response.key
|
|
129
|
+
response: response.key,
|
|
130
|
+
rt_key_duration: response.rt_key_duration
|
|
114
131
|
};
|
|
115
132
|
this.jsPsych.finishTrial(trial_data);
|
|
116
133
|
};
|
|
117
134
|
var after_response = (info2) => {
|
|
118
135
|
display_element.querySelector("#jspsych-canvas-keyboard-response-stimulus").className += " responded";
|
|
119
136
|
if (response.key == null) {
|
|
120
|
-
response =
|
|
137
|
+
response = {
|
|
138
|
+
rt: info2.rt,
|
|
139
|
+
key: info2.key,
|
|
140
|
+
rt_key_duration: info2.rt_key_duration ?? null
|
|
141
|
+
};
|
|
121
142
|
}
|
|
122
143
|
if (trial.response_ends_trial) {
|
|
123
144
|
end_trial();
|
|
@@ -129,7 +150,8 @@ class CanvasKeyboardResponsePlugin {
|
|
|
129
150
|
valid_responses: trial.choices,
|
|
130
151
|
rt_method: "performance",
|
|
131
152
|
persist: false,
|
|
132
|
-
allow_held_key: false
|
|
153
|
+
allow_held_key: false,
|
|
154
|
+
wait_for_key_release: trial.wait_for_key_release
|
|
133
155
|
});
|
|
134
156
|
}
|
|
135
157
|
if (trial.stimulus_duration !== null) {
|
|
@@ -170,14 +192,15 @@ class CanvasKeyboardResponsePlugin {
|
|
|
170
192
|
create_simulation_data(trial, simulation_options) {
|
|
171
193
|
const default_data = {
|
|
172
194
|
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
|
|
173
|
-
response: this.jsPsych.pluginAPI.getValidKey(trial.choices)
|
|
195
|
+
response: this.jsPsych.pluginAPI.getValidKey(trial.choices),
|
|
196
|
+
rt_key_duration: null
|
|
174
197
|
};
|
|
198
|
+
default_data.rt_key_duration = default_data.rt === null || !trial.wait_for_key_release ? null : this.jsPsych.randomization.sampleExGaussian(150, 30, 1 / 100, true);
|
|
175
199
|
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
176
200
|
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
177
201
|
return data;
|
|
178
202
|
}
|
|
179
203
|
}
|
|
180
|
-
CanvasKeyboardResponsePlugin.info = info;
|
|
181
204
|
|
|
182
205
|
export { CanvasKeyboardResponsePlugin as default };
|
|
183
206
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"canvas-keyboard-response\",\n version: version,\n parameters: {\n /** The function to draw on the canvas. This function automatically takes a canvas element as its only\n * argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.\n * Note that the stimulus function will still generally need to set the correct context itself, using a line\n * like `let ctx = c.getContext(\"2d\")`.\n */\n stimulus: {\n type: ParameterType.FUNCTION,\n default: undefined,\n },\n /** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.\n * Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -\n * see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n * and [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\n * of `\"ALL_KEYS\"` means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean\n * that no responses are allowed.\n */\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\n * is 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 display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to\n * `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.\n */\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\n * 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\n * trial 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\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can use this parameter to force the participant\n * to view a 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 /** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */\n canvas_size: {\n type: ParameterType.INT,\n array: true,\n default: [500, 500],\n },\n },\n data: {\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\n * when the stimulus first appears on the screen until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin can be used to draw a stimulus on a [HTML canvas element](https://www.w3schools.com/html/html5_canvas.asp) and\n * record a keyboard response. The canvas stimulus can be useful for displaying dynamic, parametrically-defined graphics,\n * and for controlling the positioning of multiple graphical elements (shapes, text, images). The stimulus can be\n * displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically\n * if the participant has failed to respond within a fixed length of time.\n *\n * @author Chris Jungerius (modified from Josh de Leeuw)\n * @see {@link https://www.jspsych.org/latest/plugins/canvas-keyboard-response/ canvas-keyboard-response plugin documentation on jspsych.org}\n */\nclass CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html =\n '<div id=\"jspsych-canvas-keyboard-response-stimulus\">' +\n '<canvas id=\"jspsych-canvas-stimulus\" height=\"' +\n trial.canvas_size[0] +\n '\" width=\"' +\n trial.canvas_size[1] +\n '\"></canvas>' +\n \"</div>\";\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n let c = document.getElementById(\"jspsych-canvas-stimulus\");\n c.style.display = \"block\";\n trial.stimulus(c);\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 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-canvas-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-canvas-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 }\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 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 CanvasKeyboardResponsePlugin;\n"],"names":["version","info"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,0BAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAMV,QAAU,EAAA;AAAA,MACR,MAAM,aAAc,CAAA,QAAA;AAAA,MACpB,OAAS,EAAA,KAAA,CAAA;AAAA,KACX;AAAA,IASA,OAAS,EAAA;AAAA,MACP,MAAM,aAAc,CAAA,IAAA;AAAA,MACpB,OAAS,EAAA,UAAA;AAAA,KACX;AAAA,IAIA,MAAQ,EAAA;AAAA,MACN,MAAM,aAAc,CAAA,WAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAIA,iBAAmB,EAAA;AAAA,MACjB,MAAM,aAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAMA,cA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CAAA;AAEd,IAAI,IAAA,IAAA,CAAK,OAAO,IAAM,EAAA;AACpB,MAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,QAAA,CAAS,IAAK,CAAA,QAAA,EAAU,KAAK,EAAE,CAAA,CAAA;AAAA,KACxD;AAAA,GACF;AAAA,EAEQ,sBAAA,CAAuB,OAAwB,kBAAoB,EAAA;AACzE,IAAA,MAAM,YAAe,GAAA;AAAA,MACnB,EAAA,EAAI,KAAK,OAAQ,CAAA,aAAA,CAAc,iBAAiB,GAAK,EAAA,EAAA,EAAI,CAAI,GAAA,GAAA,EAAK,IAAI,CAAA;AAAA,MACtE,UAAU,IAAK,CAAA,OAAA,CAAQ,SAAU,CAAA,WAAA,CAAY,MAAM,OAAO,CAAA;AAAA,KAC5D,CAAA;AAEA,IAAA,MAAM,OAAO,IAAK,CAAA,OAAA,CAAQ,SAAU,CAAA,mBAAA,CAAoB,cAAc,kBAAkB,CAAA,CAAA;AAExF,IAAA,IAAA,CAAK,OAAQ,CAAA,SAAA,CAAU,+BAAgC,CAAA,KAAA,EAAO,IAAI,CAAA,CAAA;AAElE,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACF,CAAA;AA1IM,4BAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-canvas-keyboard-response\",\n \"version\": \"2.2.0\",\n \"description\": \"jsPsych plugin for displaying a canvas stimulus and getting a keyboard response\",\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-canvas-keyboard-response\"\n },\n \"author\": \"Chris Jungerius, 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/canvas-keyboard-response\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.3.4\",\n \"@jspsych/test-utils\": \"^1.3.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"canvas-keyboard-response\",\n version: version,\n parameters: {\n /** The function to draw on the canvas. This function automatically takes a canvas element as its only\n * argument, e.g. `function(c) {...}` or `function drawStim(c) {...}`, where `c` refers to the canvas element.\n * Note that the stimulus function will still generally need to set the correct context itself, using a line\n * like `let ctx = c.getContext(\"2d\")`.\n */\n stimulus: {\n type: ParameterType.FUNCTION,\n default: undefined,\n },\n /** This array contains the key(s) that the participant is allowed to press in order to respond to the stimulus.\n * Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) -\n * see [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n * and [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\n * of `\"ALL_KEYS\"` means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean\n * that no responses are allowed.\n */\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\n * is 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 display the stimulus in milliseconds. The visibility CSS property of the stimulus will be set to\n * `hidden` after this time has elapsed. If this is null, then the stimulus will remain visible until the trial ends.\n */\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\n * 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\n * trial 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\n * response before the cutoff specified by the `trial_duration` parameter). If false, then the trial will\n * continue until the value for `trial_duration` is reached. You can use this parameter to force the participant\n * to view a 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 /** Array that defines the size of the canvas element in pixels. First value is height, second value is width. */\n canvas_size: {\n type: ParameterType.INT,\n array: true,\n default: [500, 500],\n },\n /** If true, the response is not registered until the participant releases the key. The response\n * time (`rt`) still reflects when the key was pressed, and the additional data field\n * `rt_key_duration` records how long the key was held down. Note that when this is true, the\n * trial cannot end until the key is released: with `response_ends_trial: true` the trial ends at\n * the key release, and if the trial ends for another reason (e.g., `trial_duration`) while the\n * key is still held, no response is recorded for the trial.\n */\n wait_for_key_release: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\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\n * when the stimulus first appears on the screen until the participant's response.\n */\n rt: {\n type: ParameterType.INT,\n },\n /** The duration in milliseconds that the response key was held down, measured from key press to key release. Only recorded when `wait_for_key_release` is true; null otherwise or when no response was made. */\n rt_key_duration: {\n type: ParameterType.INT,\n },\n },\n // prettier-ignore\n citations: '__CITATIONS__',\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin can be used to draw a stimulus on a [HTML canvas element](https://www.w3schools.com/html/html5_canvas.asp) and\n * record a keyboard response. The canvas stimulus can be useful for displaying dynamic, parametrically-defined graphics,\n * and for controlling the positioning of multiple graphical elements (shapes, text, images). The stimulus can be\n * displayed until a response is given, or for a pre-determined amount of time. The trial can be ended automatically\n * if the participant has failed to respond within a fixed length of time.\n *\n * @author Chris Jungerius (modified from Josh de Leeuw)\n * @see {@link https://www.jspsych.org/latest/plugins/canvas-keyboard-response/ canvas-keyboard-response plugin documentation on jspsych.org}\n */\nclass CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html =\n '<div id=\"jspsych-canvas-keyboard-response-stimulus\">' +\n '<canvas id=\"jspsych-canvas-stimulus\" height=\"' +\n trial.canvas_size[0] +\n '\" width=\"' +\n trial.canvas_size[1] +\n '\"></canvas>' +\n \"</div>\";\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n let c = document.getElementById(\"jspsych-canvas-stimulus\");\n c.style.display = \"block\";\n trial.stimulus(c);\n // store response\n var response = {\n rt: null,\n key: null,\n rt_key_duration: 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 response: response.key,\n rt_key_duration: response.rt_key_duration,\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-canvas-keyboard-response-stimulus\").className +=\n \" responded\";\n\n // only record the first response\n if (response.key == null) {\n response = {\n rt: info.rt,\n key: info.key,\n rt_key_duration: info.rt_key_duration ?? null,\n };\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 wait_for_key_release: trial.wait_for_key_release,\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-canvas-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 }\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 rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n rt_key_duration: null,\n };\n default_data.rt_key_duration =\n default_data.rt === null || !trial.wait_for_key_release\n ? null\n : this.jsPsych.randomization.sampleExGaussian(150, 30, 1 / 100, true);\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 CanvasKeyboardResponsePlugin;\n"],"names":[],"mappings":";;AAEE,IAAA,OAAA,GAAW,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EC8FA,SAAA,EAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jspsych/plugin-canvas-keyboard-response",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "jsPsych plugin for displaying a canvas stimulus and getting a keyboard response",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"jspsych": ">=7.1.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@jspsych/config": "^3.
|
|
41
|
-
"@jspsych/test-utils": "^1.
|
|
40
|
+
"@jspsych/config": "^3.3.4",
|
|
41
|
+
"@jspsych/test-utils": "^1.3.0"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/index.spec.ts
CHANGED
|
@@ -27,6 +27,24 @@ describe("canvas-keyboard-response simulation", () => {
|
|
|
27
27
|
|
|
28
28
|
expect(getData().values()[0].rt).toBeGreaterThan(0);
|
|
29
29
|
expect(typeof getData().values()[0].response).toBe("string");
|
|
30
|
+
expect(getData().values()[0].rt_key_duration).toBe(null);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("data mode records rt_key_duration when wait_for_key_release is true", async () => {
|
|
34
|
+
const timeline = [
|
|
35
|
+
{
|
|
36
|
+
type: canvasKeyboardResponse,
|
|
37
|
+
stimulus: drawRect,
|
|
38
|
+
wait_for_key_release: true,
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const { expectFinished, getData } = await simulateTimeline(timeline);
|
|
43
|
+
|
|
44
|
+
await expectFinished();
|
|
45
|
+
|
|
46
|
+
expect(getData().values()[0].rt).toBeGreaterThan(0);
|
|
47
|
+
expect(typeof getData().values()[0].rt_key_duration).toBe("number");
|
|
30
48
|
});
|
|
31
49
|
|
|
32
50
|
// can't run this until we mock canvas elements.
|
package/src/index.ts
CHANGED
|
@@ -65,6 +65,17 @@ const info = <const>{
|
|
|
65
65
|
array: true,
|
|
66
66
|
default: [500, 500],
|
|
67
67
|
},
|
|
68
|
+
/** If true, the response is not registered until the participant releases the key. The response
|
|
69
|
+
* time (`rt`) still reflects when the key was pressed, and the additional data field
|
|
70
|
+
* `rt_key_duration` records how long the key was held down. Note that when this is true, the
|
|
71
|
+
* trial cannot end until the key is released: with `response_ends_trial: true` the trial ends at
|
|
72
|
+
* the key release, and if the trial ends for another reason (e.g., `trial_duration`) while the
|
|
73
|
+
* key is still held, no response is recorded for the trial.
|
|
74
|
+
*/
|
|
75
|
+
wait_for_key_release: {
|
|
76
|
+
type: ParameterType.BOOL,
|
|
77
|
+
default: false,
|
|
78
|
+
},
|
|
68
79
|
},
|
|
69
80
|
data: {
|
|
70
81
|
/** Indicates which key the participant pressed. */
|
|
@@ -77,7 +88,13 @@ const info = <const>{
|
|
|
77
88
|
rt: {
|
|
78
89
|
type: ParameterType.INT,
|
|
79
90
|
},
|
|
91
|
+
/** The duration in milliseconds that the response key was held down, measured from key press to key release. Only recorded when `wait_for_key_release` is true; null otherwise or when no response was made. */
|
|
92
|
+
rt_key_duration: {
|
|
93
|
+
type: ParameterType.INT,
|
|
94
|
+
},
|
|
80
95
|
},
|
|
96
|
+
// prettier-ignore
|
|
97
|
+
citations: '__CITATIONS__',
|
|
81
98
|
};
|
|
82
99
|
|
|
83
100
|
type Info = typeof info;
|
|
@@ -120,6 +137,7 @@ class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
120
137
|
var response = {
|
|
121
138
|
rt: null,
|
|
122
139
|
key: null,
|
|
140
|
+
rt_key_duration: null,
|
|
123
141
|
};
|
|
124
142
|
|
|
125
143
|
// function to end trial when it is time
|
|
@@ -133,6 +151,7 @@ class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
133
151
|
var trial_data = {
|
|
134
152
|
rt: response.rt,
|
|
135
153
|
response: response.key,
|
|
154
|
+
rt_key_duration: response.rt_key_duration,
|
|
136
155
|
};
|
|
137
156
|
|
|
138
157
|
// move on to the next trial
|
|
@@ -148,7 +167,11 @@ class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
148
167
|
|
|
149
168
|
// only record the first response
|
|
150
169
|
if (response.key == null) {
|
|
151
|
-
response =
|
|
170
|
+
response = {
|
|
171
|
+
rt: info.rt,
|
|
172
|
+
key: info.key,
|
|
173
|
+
rt_key_duration: info.rt_key_duration ?? null,
|
|
174
|
+
};
|
|
152
175
|
}
|
|
153
176
|
|
|
154
177
|
if (trial.response_ends_trial) {
|
|
@@ -164,6 +187,7 @@ class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
164
187
|
rt_method: "performance",
|
|
165
188
|
persist: false,
|
|
166
189
|
allow_held_key: false,
|
|
190
|
+
wait_for_key_release: trial.wait_for_key_release,
|
|
167
191
|
});
|
|
168
192
|
}
|
|
169
193
|
|
|
@@ -222,7 +246,12 @@ class CanvasKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
222
246
|
const default_data = {
|
|
223
247
|
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
|
|
224
248
|
response: this.jsPsych.pluginAPI.getValidKey(trial.choices),
|
|
249
|
+
rt_key_duration: null,
|
|
225
250
|
};
|
|
251
|
+
default_data.rt_key_duration =
|
|
252
|
+
default_data.rt === null || !trial.wait_for_key_release
|
|
253
|
+
? null
|
|
254
|
+
: this.jsPsych.randomization.sampleExGaussian(150, 30, 1 / 100, true);
|
|
226
255
|
|
|
227
256
|
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
228
257
|
|