@jspsych/plugin-html-keyboard-response 1.1.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js +163 -156
- 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 +161 -154
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +84 -30
- package/dist/index.js +161 -154
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.spec.ts +7 -6
- package/src/index.ts +44 -23
package/dist/index.cjs
CHANGED
|
@@ -2,170 +2,177 @@
|
|
|
2
2
|
|
|
3
3
|
var jspsych = require('jspsych');
|
|
4
4
|
|
|
5
|
+
var _package = {
|
|
6
|
+
name: "@jspsych/plugin-html-keyboard-response",
|
|
7
|
+
version: "2.0.0",
|
|
8
|
+
description: "jsPsych plugin for displaying a 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",
|
|
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-html-keyboard-response"
|
|
33
|
+
},
|
|
34
|
+
author: "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/html-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
|
+
};
|
|
48
|
+
|
|
5
49
|
const info = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
type: jspsych.ParameterType.HTML_STRING,
|
|
29
|
-
pretty_name: "Prompt",
|
|
30
|
-
default: null,
|
|
31
|
-
},
|
|
32
|
-
/**
|
|
33
|
-
* How long to show the stimulus.
|
|
34
|
-
*/
|
|
35
|
-
stimulus_duration: {
|
|
36
|
-
type: jspsych.ParameterType.INT,
|
|
37
|
-
pretty_name: "Stimulus duration",
|
|
38
|
-
default: null,
|
|
39
|
-
},
|
|
40
|
-
/**
|
|
41
|
-
* How long to show trial before it ends.
|
|
42
|
-
*/
|
|
43
|
-
trial_duration: {
|
|
44
|
-
type: jspsych.ParameterType.INT,
|
|
45
|
-
pretty_name: "Trial duration",
|
|
46
|
-
default: null,
|
|
47
|
-
},
|
|
48
|
-
/**
|
|
49
|
-
* If true, trial will end when subject makes a response.
|
|
50
|
-
*/
|
|
51
|
-
response_ends_trial: {
|
|
52
|
-
type: jspsych.ParameterType.BOOL,
|
|
53
|
-
pretty_name: "Response ends trial",
|
|
54
|
-
default: true,
|
|
55
|
-
},
|
|
50
|
+
name: "html-keyboard-response",
|
|
51
|
+
version: _package.version,
|
|
52
|
+
parameters: {
|
|
53
|
+
stimulus: {
|
|
54
|
+
type: jspsych.ParameterType.HTML_STRING,
|
|
55
|
+
default: void 0
|
|
56
|
+
},
|
|
57
|
+
choices: {
|
|
58
|
+
type: jspsych.ParameterType.KEYS,
|
|
59
|
+
default: "ALL_KEYS"
|
|
60
|
+
},
|
|
61
|
+
prompt: {
|
|
62
|
+
type: jspsych.ParameterType.HTML_STRING,
|
|
63
|
+
default: null
|
|
64
|
+
},
|
|
65
|
+
stimulus_duration: {
|
|
66
|
+
type: jspsych.ParameterType.INT,
|
|
67
|
+
default: null
|
|
68
|
+
},
|
|
69
|
+
trial_duration: {
|
|
70
|
+
type: jspsych.ParameterType.INT,
|
|
71
|
+
default: null
|
|
56
72
|
},
|
|
73
|
+
response_ends_trial: {
|
|
74
|
+
type: jspsych.ParameterType.BOOL,
|
|
75
|
+
default: true
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
data: {
|
|
79
|
+
response: {
|
|
80
|
+
type: jspsych.ParameterType.STRING
|
|
81
|
+
},
|
|
82
|
+
rt: {
|
|
83
|
+
type: jspsych.ParameterType.INT
|
|
84
|
+
},
|
|
85
|
+
stimulus: {
|
|
86
|
+
type: jspsych.ParameterType.STRING
|
|
87
|
+
}
|
|
88
|
+
}
|
|
57
89
|
};
|
|
58
|
-
/**
|
|
59
|
-
* **html-keyboard-response**
|
|
60
|
-
*
|
|
61
|
-
* jsPsych plugin for displaying a stimulus and getting a keyboard response
|
|
62
|
-
*
|
|
63
|
-
* @author Josh de Leeuw
|
|
64
|
-
* @see {@link https://www.jspsych.org/plugins/jspsych-html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}
|
|
65
|
-
*/
|
|
66
90
|
class HtmlKeyboardResponsePlugin {
|
|
67
|
-
|
|
68
|
-
|
|
91
|
+
constructor(jsPsych) {
|
|
92
|
+
this.jsPsych = jsPsych;
|
|
93
|
+
}
|
|
94
|
+
trial(display_element, trial) {
|
|
95
|
+
var new_html = '<div id="jspsych-html-keyboard-response-stimulus">' + trial.stimulus + "</div>";
|
|
96
|
+
if (trial.prompt !== null) {
|
|
97
|
+
new_html += trial.prompt;
|
|
98
|
+
}
|
|
99
|
+
display_element.innerHTML = new_html;
|
|
100
|
+
var response = {
|
|
101
|
+
rt: null,
|
|
102
|
+
key: null
|
|
103
|
+
};
|
|
104
|
+
const end_trial = () => {
|
|
105
|
+
if (typeof keyboardListener !== "undefined") {
|
|
106
|
+
this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
|
|
107
|
+
}
|
|
108
|
+
var trial_data = {
|
|
109
|
+
rt: response.rt,
|
|
110
|
+
stimulus: trial.stimulus,
|
|
111
|
+
response: response.key
|
|
112
|
+
};
|
|
113
|
+
this.jsPsych.finishTrial(trial_data);
|
|
114
|
+
};
|
|
115
|
+
var after_response = (info2) => {
|
|
116
|
+
display_element.querySelector("#jspsych-html-keyboard-response-stimulus").className += " responded";
|
|
117
|
+
if (response.key == null) {
|
|
118
|
+
response = info2;
|
|
119
|
+
}
|
|
120
|
+
if (trial.response_ends_trial) {
|
|
121
|
+
end_trial();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
if (trial.choices != "NO_KEYS") {
|
|
125
|
+
var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
126
|
+
callback_function: after_response,
|
|
127
|
+
valid_responses: trial.choices,
|
|
128
|
+
rt_method: "performance",
|
|
129
|
+
persist: false,
|
|
130
|
+
allow_held_key: false
|
|
131
|
+
});
|
|
69
132
|
}
|
|
70
|
-
trial
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// draw
|
|
77
|
-
display_element.innerHTML = new_html;
|
|
78
|
-
// store response
|
|
79
|
-
var response = {
|
|
80
|
-
rt: null,
|
|
81
|
-
key: null,
|
|
82
|
-
};
|
|
83
|
-
// function to end trial when it is time
|
|
84
|
-
const end_trial = () => {
|
|
85
|
-
// kill any remaining setTimeout handlers
|
|
86
|
-
this.jsPsych.pluginAPI.clearAllTimeouts();
|
|
87
|
-
// kill keyboard listeners
|
|
88
|
-
if (typeof keyboardListener !== "undefined") {
|
|
89
|
-
this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
|
|
90
|
-
}
|
|
91
|
-
// gather the data to store for the trial
|
|
92
|
-
var trial_data = {
|
|
93
|
-
rt: response.rt,
|
|
94
|
-
stimulus: trial.stimulus,
|
|
95
|
-
response: response.key,
|
|
96
|
-
};
|
|
97
|
-
// clear the display
|
|
98
|
-
display_element.innerHTML = "";
|
|
99
|
-
// move on to the next trial
|
|
100
|
-
this.jsPsych.finishTrial(trial_data);
|
|
101
|
-
};
|
|
102
|
-
// function to handle responses by the subject
|
|
103
|
-
var after_response = (info) => {
|
|
104
|
-
// after a valid response, the stimulus will have the CSS class 'responded'
|
|
105
|
-
// which can be used to provide visual feedback that a response was recorded
|
|
106
|
-
display_element.querySelector("#jspsych-html-keyboard-response-stimulus").className +=
|
|
107
|
-
" responded";
|
|
108
|
-
// only record the first response
|
|
109
|
-
if (response.key == null) {
|
|
110
|
-
response = info;
|
|
111
|
-
}
|
|
112
|
-
if (trial.response_ends_trial) {
|
|
113
|
-
end_trial();
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
// start the response listener
|
|
117
|
-
if (trial.choices != "NO_KEYS") {
|
|
118
|
-
var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({
|
|
119
|
-
callback_function: after_response,
|
|
120
|
-
valid_responses: trial.choices,
|
|
121
|
-
rt_method: "performance",
|
|
122
|
-
persist: false,
|
|
123
|
-
allow_held_key: false,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
// hide stimulus if stimulus_duration is set
|
|
127
|
-
if (trial.stimulus_duration !== null) {
|
|
128
|
-
this.jsPsych.pluginAPI.setTimeout(() => {
|
|
129
|
-
display_element.querySelector("#jspsych-html-keyboard-response-stimulus").style.visibility = "hidden";
|
|
130
|
-
}, trial.stimulus_duration);
|
|
131
|
-
}
|
|
132
|
-
// end trial if trial_duration is set
|
|
133
|
-
if (trial.trial_duration !== null) {
|
|
134
|
-
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
|
135
|
-
}
|
|
133
|
+
if (trial.stimulus_duration !== null) {
|
|
134
|
+
this.jsPsych.pluginAPI.setTimeout(() => {
|
|
135
|
+
display_element.querySelector(
|
|
136
|
+
"#jspsych-html-keyboard-response-stimulus"
|
|
137
|
+
).style.visibility = "hidden";
|
|
138
|
+
}, trial.stimulus_duration);
|
|
136
139
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
load_callback();
|
|
140
|
-
this.simulate_data_only(trial, simulation_options);
|
|
141
|
-
}
|
|
142
|
-
if (simulation_mode == "visual") {
|
|
143
|
-
this.simulate_visual(trial, simulation_options, load_callback);
|
|
144
|
-
}
|
|
140
|
+
if (trial.trial_duration !== null) {
|
|
141
|
+
this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
|
|
145
142
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
};
|
|
152
|
-
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
153
|
-
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
154
|
-
return data;
|
|
143
|
+
}
|
|
144
|
+
simulate(trial, simulation_mode, simulation_options, load_callback) {
|
|
145
|
+
if (simulation_mode == "data-only") {
|
|
146
|
+
load_callback();
|
|
147
|
+
this.simulate_data_only(trial, simulation_options);
|
|
155
148
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.jsPsych.finishTrial(data);
|
|
149
|
+
if (simulation_mode == "visual") {
|
|
150
|
+
this.simulate_visual(trial, simulation_options, load_callback);
|
|
159
151
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
152
|
+
}
|
|
153
|
+
create_simulation_data(trial, simulation_options) {
|
|
154
|
+
const default_data = {
|
|
155
|
+
stimulus: trial.stimulus,
|
|
156
|
+
rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
|
|
157
|
+
response: this.jsPsych.pluginAPI.getValidKey(trial.choices)
|
|
158
|
+
};
|
|
159
|
+
const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
|
|
160
|
+
this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
|
|
161
|
+
return data;
|
|
162
|
+
}
|
|
163
|
+
simulate_data_only(trial, simulation_options) {
|
|
164
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
165
|
+
this.jsPsych.finishTrial(data);
|
|
166
|
+
}
|
|
167
|
+
simulate_visual(trial, simulation_options, load_callback) {
|
|
168
|
+
const data = this.create_simulation_data(trial, simulation_options);
|
|
169
|
+
const display_element = this.jsPsych.getDisplayElement();
|
|
170
|
+
this.trial(display_element, trial);
|
|
171
|
+
load_callback();
|
|
172
|
+
if (data.rt !== null) {
|
|
173
|
+
this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
|
|
168
174
|
}
|
|
175
|
+
}
|
|
169
176
|
}
|
|
170
177
|
HtmlKeyboardResponsePlugin.info = info;
|
|
171
178
|
|
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\nconst info = <const>{\n name: \"html-keyboard-response\",\n parameters: {\n /**\n * The HTML string to be displayed.\n */\n stimulus: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Stimulus\",\n default: undefined,\n },\n /**\n * Array containing the key(s) the subject is allowed to press to respond to the stimulus.\n */\n choices: {\n type: ParameterType.KEYS,\n pretty_name: \"Choices\",\n default: \"ALL_KEYS\",\n },\n /**\n * Any content here will be displayed below the stimulus.\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: null,\n },\n /**\n * How long to show the stimulus.\n */\n stimulus_duration: {\n type: ParameterType.INT,\n pretty_name: \"Stimulus duration\",\n default: null,\n },\n /**\n * How long to show trial before it ends.\n */\n trial_duration: {\n type: ParameterType.INT,\n pretty_name: \"Trial duration\",\n default: null,\n },\n /**\n * If true, trial will end when subject makes a response.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n pretty_name: \"Response ends trial\",\n default: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **html-keyboard-response**\n *\n * jsPsych plugin for displaying a stimulus and getting a keyboard response\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/plugins/jspsych-html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}\n */\nclass HtmlKeyboardResponsePlugin 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 = '<div id=\"jspsych-html-keyboard-response-stimulus\">' + trial.stimulus + \"</div>\";\n\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n\n // store response\n var response = {\n rt: null,\n key: null,\n };\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // kill keyboard listeners\n if (typeof keyboardListener !== \"undefined\") {\n this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);\n }\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.key,\n };\n\n // clear the display\n display_element.innerHTML = \"\";\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n };\n\n // function to handle responses by the subject\n var after_response = (info) => {\n // after a valid response, the stimulus will have the CSS class 'responded'\n // which can be used to provide visual feedback that a response was recorded\n display_element.querySelector(\"#jspsych-html-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-html-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(end_trial, 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 create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n 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\nexport default HtmlKeyboardResponsePlugin;\n"],"names":["ParameterType"],"mappings":";;;;AAEA,MAAM,IAAI,GAAU;AAClB,IAAA,IAAI,EAAE,wBAAwB;AAC9B,IAAA,UAAU,EAAE;AACV;;AAEG;AACH,QAAA,QAAQ,EAAE;YACR,IAAI,EAAEA,qBAAa,CAAC,WAAW;AAC/B,YAAA,WAAW,EAAE,UAAU;AACvB,YAAA,OAAO,EAAE,SAAS;AACnB,SAAA;AACD;;AAEG;AACH,QAAA,OAAO,EAAE;YACP,IAAI,EAAEA,qBAAa,CAAC,IAAI;AACxB,YAAA,WAAW,EAAE,SAAS;AACtB,YAAA,OAAO,EAAE,UAAU;AACpB,SAAA;AACD;;AAEG;AACH,QAAA,MAAM,EAAE;YACN,IAAI,EAAEA,qBAAa,CAAC,WAAW;AAC/B,YAAA,WAAW,EAAE,QAAQ;AACrB,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACD;;AAEG;AACH,QAAA,iBAAiB,EAAE;YACjB,IAAI,EAAEA,qBAAa,CAAC,GAAG;AACvB,YAAA,WAAW,EAAE,mBAAmB;AAChC,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACD;;AAEG;AACH,QAAA,cAAc,EAAE;YACd,IAAI,EAAEA,qBAAa,CAAC,GAAG;AACvB,YAAA,WAAW,EAAE,gBAAgB;AAC7B,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACD;;AAEG;AACH,QAAA,mBAAmB,EAAE;YACnB,IAAI,EAAEA,qBAAa,CAAC,IAAI;AACxB,YAAA,WAAW,EAAE,qBAAqB;AAClC,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACF,KAAA;CACF,CAAC;AAIF;;;;;;;AAOG;AACH,MAAM,0BAA0B,CAA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AAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;AACzD,SAAA;KACF;;AAtIM,0BAAI,CAAA,IAAA,GAAG,IAAI;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"html-keyboard-response\",\n version: version,\n parameters: {\n /**\n * The string to be displayed.\n */\n stimulus: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /**\n * This array contains the key(s) that the participant is allowed to press in order to respond\n * to the stimulus. Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) - see\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values this page}\n * and\n * {@link https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/ this page (event.key column)}\n * for more examples. Any key presses that are not listed in the\n * array will be ignored. The default value of `\"ALL_KEYS\"` means that all keys will be accepted as valid responses.\n * Specifying `\"NO_KEYS\"` will mean that no responses are allowed.\n */\n choices: {\n type: ParameterType.KEYS,\n default: \"ALL_KEYS\",\n },\n /**\n * This string can contain HTML markup. Any content here will be displayed below the stimulus.\n * The intention is that it can be used to provide a reminder about the action the participant\n * is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /**\n * How long to display the stimulus in milliseconds. The visibility CSS property of the stimulus\n * will be set to `hidden` after this time has elapsed. If this is null, then the stimulus will\n * remain visible until the trial ends.\n */\n stimulus_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /**\n * How long to wait for the participant to make a response before ending the trial in milliseconds.\n * If the participant fails to make a response before this timer is reached, the participant's response\n * will be recorded as null for the trial and the trial will end. If the value of this parameter is null,\n * then the trial will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\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 set this parameter to false to force\n * the participant 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 },\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 when the stimulus first appears on the screen until the participant's response. */\n rt: {\n type: ParameterType.INT,\n },\n /** The HTML content that was displayed on the screen. */\n stimulus: {\n type: ParameterType.STRING,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin displays HTML content and records responses generated with the keyboard.\n * The stimulus can be displayed until a response is given, or for a pre-determined amount of time.\n * The trial can be ended automatically if the participant has failed to respond within a fixed length of time.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}\n */\nclass HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html = '<div id=\"jspsych-html-keyboard-response-stimulus\">' + trial.stimulus + \"</div>\";\n\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n\n // store response\n var response = {\n rt: null,\n key: null,\n };\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill keyboard listeners\n if (typeof keyboardListener !== \"undefined\") {\n this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);\n }\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.key,\n };\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n };\n\n // function to handle responses by the subject\n var after_response = (info) => {\n // after a valid response, the stimulus will have the CSS class 'responded'\n // which can be used to provide visual feedback that a response was recorded\n display_element.querySelector(\"#jspsych-html-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-html-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(end_trial, 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 create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n 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\nexport default HtmlKeyboardResponsePlugin;\n"],"names":["version","ParameterType","info"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,wBAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAIV,QAAU,EAAA;AAAA,MACR,MAAMC,qBAAc,CAAA,WAAA;AAAA,MACpB,OAAS,EAAA,KAAA,CAAA;AAAA,KACX;AAAA,IAWA,OAAS,EAAA;AAAA,MACP,MAAMA,qBAAc,CAAA,IAAA;AAAA,MACpB,OAAS,EAAA,UAAA;AAAA,KACX;AAAA,IAMA,MAAQ,EAAA;AAAA,MACN,MAAMA,qBAAc,CAAA,WAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAMA,iBAAmB,EAAA;AAAA,MACjB,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAOA,cAAgB,EAAA;AAAA,MACd,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAOA,mBAAqB,EAAA;AAAA,MACnB,MAAMA,qBAAc,CAAA,IAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,GACF;AAAA,EACA,IAAM,EAAA;AAAA,IAEJ,QAAU,EAAA;AAAA,MACR,MAAMA,qBAAc,CAAA,MAAA;AAAA,KACtB;AAAA,IAEA,EAAI,EAAA;AAAA,MACF,MAAMA,qBAAc,CAAA,GAAA;AAAA,KACtB;AAAA,IAEA,QAAU,EAAA;AAAA,MACR,MAAMA,qBAAc,CAAA,MAAA;AAAA,KACtB;AAAA,GACF;AACF,CAAA,CAAA;AA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BAAA,CACG,IAAO,GAAA,IAAA;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,120 +1,173 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsPsychPlugin, ParameterType, JsPsych, TrialType } from 'jspsych';
|
|
2
|
+
|
|
2
3
|
declare const info: {
|
|
3
4
|
readonly name: "html-keyboard-response";
|
|
5
|
+
readonly version: string;
|
|
4
6
|
readonly parameters: {
|
|
5
7
|
/**
|
|
6
|
-
* The
|
|
8
|
+
* The string to be displayed.
|
|
7
9
|
*/
|
|
8
10
|
readonly stimulus: {
|
|
9
11
|
readonly type: ParameterType.HTML_STRING;
|
|
10
|
-
readonly pretty_name: "Stimulus";
|
|
11
12
|
readonly default: any;
|
|
12
13
|
};
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
+
* This array contains the key(s) that the participant is allowed to press in order to respond
|
|
16
|
+
* to the stimulus. Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) - see
|
|
17
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values this page}
|
|
18
|
+
* and
|
|
19
|
+
* {@link https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/ this page (event.key column)}
|
|
20
|
+
* for more examples. Any key presses that are not listed in the
|
|
21
|
+
* array will be ignored. The default value of `"ALL_KEYS"` means that all keys will be accepted as valid responses.
|
|
22
|
+
* Specifying `"NO_KEYS"` will mean that no responses are allowed.
|
|
15
23
|
*/
|
|
16
24
|
readonly choices: {
|
|
17
25
|
readonly type: ParameterType.KEYS;
|
|
18
|
-
readonly pretty_name: "Choices";
|
|
19
26
|
readonly default: "ALL_KEYS";
|
|
20
27
|
};
|
|
21
28
|
/**
|
|
22
|
-
* Any content here will be displayed below the stimulus.
|
|
29
|
+
* This string can contain HTML markup. Any content here will be displayed below the stimulus.
|
|
30
|
+
* The intention is that it can be used to provide a reminder about the action the participant
|
|
31
|
+
* is supposed to take (e.g., which key to press).
|
|
23
32
|
*/
|
|
24
33
|
readonly prompt: {
|
|
25
34
|
readonly type: ParameterType.HTML_STRING;
|
|
26
|
-
readonly pretty_name: "Prompt";
|
|
27
35
|
readonly default: any;
|
|
28
36
|
};
|
|
29
37
|
/**
|
|
30
|
-
* How long to
|
|
38
|
+
* How long to display the stimulus in milliseconds. The visibility CSS property of the stimulus
|
|
39
|
+
* will be set to `hidden` after this time has elapsed. If this is null, then the stimulus will
|
|
40
|
+
* remain visible until the trial ends.
|
|
31
41
|
*/
|
|
32
42
|
readonly stimulus_duration: {
|
|
33
43
|
readonly type: ParameterType.INT;
|
|
34
|
-
readonly pretty_name: "Stimulus duration";
|
|
35
44
|
readonly default: any;
|
|
36
45
|
};
|
|
37
46
|
/**
|
|
38
|
-
* How long to
|
|
47
|
+
* How long to wait for the participant to make a response before ending the trial in milliseconds.
|
|
48
|
+
* If the participant fails to make a response before this timer is reached, the participant's response
|
|
49
|
+
* will be recorded as null for the trial and the trial will end. If the value of this parameter is null,
|
|
50
|
+
* then the trial will wait for a response indefinitely.
|
|
39
51
|
*/
|
|
40
52
|
readonly trial_duration: {
|
|
41
53
|
readonly type: ParameterType.INT;
|
|
42
|
-
readonly pretty_name: "Trial duration";
|
|
43
54
|
readonly default: any;
|
|
44
55
|
};
|
|
45
56
|
/**
|
|
46
|
-
* If true, trial will end
|
|
57
|
+
* If true, then the trial will end whenever the participant makes a response (assuming they make their
|
|
58
|
+
* response before the cutoff specified by the trial_duration parameter). If false, then the trial will
|
|
59
|
+
* continue until the value for trial_duration is reached. You can set this parameter to false to force
|
|
60
|
+
* the participant to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
|
|
47
61
|
*/
|
|
48
62
|
readonly response_ends_trial: {
|
|
49
63
|
readonly type: ParameterType.BOOL;
|
|
50
|
-
readonly pretty_name: "Response ends trial";
|
|
51
64
|
readonly default: true;
|
|
52
65
|
};
|
|
53
66
|
};
|
|
67
|
+
readonly data: {
|
|
68
|
+
/** Indicates which key the participant pressed. */
|
|
69
|
+
readonly response: {
|
|
70
|
+
readonly type: ParameterType.STRING;
|
|
71
|
+
};
|
|
72
|
+
/** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus first appears on the screen until the participant's response. */
|
|
73
|
+
readonly rt: {
|
|
74
|
+
readonly type: ParameterType.INT;
|
|
75
|
+
};
|
|
76
|
+
/** The HTML content that was displayed on the screen. */
|
|
77
|
+
readonly stimulus: {
|
|
78
|
+
readonly type: ParameterType.STRING;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
54
81
|
};
|
|
55
82
|
type Info = typeof info;
|
|
56
83
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
84
|
+
* This plugin displays HTML content and records responses generated with the keyboard.
|
|
85
|
+
* The stimulus can be displayed until a response is given, or for a pre-determined amount of time.
|
|
86
|
+
* The trial can be ended automatically if the participant has failed to respond within a fixed length of time.
|
|
60
87
|
*
|
|
61
88
|
* @author Josh de Leeuw
|
|
62
|
-
* @see {@link https://www.jspsych.org/plugins/
|
|
89
|
+
* @see {@link https://www.jspsych.org/latest/plugins/html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}
|
|
63
90
|
*/
|
|
64
91
|
declare class HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|
65
92
|
private jsPsych;
|
|
66
93
|
static info: {
|
|
67
94
|
readonly name: "html-keyboard-response";
|
|
95
|
+
readonly version: string;
|
|
68
96
|
readonly parameters: {
|
|
69
97
|
/**
|
|
70
|
-
* The
|
|
98
|
+
* The string to be displayed.
|
|
71
99
|
*/
|
|
72
100
|
readonly stimulus: {
|
|
73
101
|
readonly type: ParameterType.HTML_STRING;
|
|
74
|
-
readonly pretty_name: "Stimulus";
|
|
75
102
|
readonly default: any;
|
|
76
103
|
};
|
|
77
104
|
/**
|
|
78
|
-
*
|
|
105
|
+
* This array contains the key(s) that the participant is allowed to press in order to respond
|
|
106
|
+
* to the stimulus. Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) - see
|
|
107
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values this page}
|
|
108
|
+
* and
|
|
109
|
+
* {@link https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/ this page (event.key column)}
|
|
110
|
+
* for more examples. Any key presses that are not listed in the
|
|
111
|
+
* array will be ignored. The default value of `"ALL_KEYS"` means that all keys will be accepted as valid responses.
|
|
112
|
+
* Specifying `"NO_KEYS"` will mean that no responses are allowed.
|
|
79
113
|
*/
|
|
80
114
|
readonly choices: {
|
|
81
115
|
readonly type: ParameterType.KEYS;
|
|
82
|
-
readonly pretty_name: "Choices";
|
|
83
116
|
readonly default: "ALL_KEYS";
|
|
84
117
|
};
|
|
85
118
|
/**
|
|
86
|
-
* Any content here will be displayed below the stimulus.
|
|
119
|
+
* This string can contain HTML markup. Any content here will be displayed below the stimulus.
|
|
120
|
+
* The intention is that it can be used to provide a reminder about the action the participant
|
|
121
|
+
* is supposed to take (e.g., which key to press).
|
|
87
122
|
*/
|
|
88
123
|
readonly prompt: {
|
|
89
124
|
readonly type: ParameterType.HTML_STRING;
|
|
90
|
-
readonly pretty_name: "Prompt";
|
|
91
125
|
readonly default: any;
|
|
92
126
|
};
|
|
93
127
|
/**
|
|
94
|
-
* How long to
|
|
128
|
+
* How long to display the stimulus in milliseconds. The visibility CSS property of the stimulus
|
|
129
|
+
* will be set to `hidden` after this time has elapsed. If this is null, then the stimulus will
|
|
130
|
+
* remain visible until the trial ends.
|
|
95
131
|
*/
|
|
96
132
|
readonly stimulus_duration: {
|
|
97
133
|
readonly type: ParameterType.INT;
|
|
98
|
-
readonly pretty_name: "Stimulus duration";
|
|
99
134
|
readonly default: any;
|
|
100
135
|
};
|
|
101
136
|
/**
|
|
102
|
-
* How long to
|
|
137
|
+
* How long to wait for the participant to make a response before ending the trial in milliseconds.
|
|
138
|
+
* If the participant fails to make a response before this timer is reached, the participant's response
|
|
139
|
+
* will be recorded as null for the trial and the trial will end. If the value of this parameter is null,
|
|
140
|
+
* then the trial will wait for a response indefinitely.
|
|
103
141
|
*/
|
|
104
142
|
readonly trial_duration: {
|
|
105
143
|
readonly type: ParameterType.INT;
|
|
106
|
-
readonly pretty_name: "Trial duration";
|
|
107
144
|
readonly default: any;
|
|
108
145
|
};
|
|
109
146
|
/**
|
|
110
|
-
* If true, trial will end
|
|
147
|
+
* If true, then the trial will end whenever the participant makes a response (assuming they make their
|
|
148
|
+
* response before the cutoff specified by the trial_duration parameter). If false, then the trial will
|
|
149
|
+
* continue until the value for trial_duration is reached. You can set this parameter to false to force
|
|
150
|
+
* the participant to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
|
|
111
151
|
*/
|
|
112
152
|
readonly response_ends_trial: {
|
|
113
153
|
readonly type: ParameterType.BOOL;
|
|
114
|
-
readonly pretty_name: "Response ends trial";
|
|
115
154
|
readonly default: true;
|
|
116
155
|
};
|
|
117
156
|
};
|
|
157
|
+
readonly data: {
|
|
158
|
+
/** Indicates which key the participant pressed. */
|
|
159
|
+
readonly response: {
|
|
160
|
+
readonly type: ParameterType.STRING;
|
|
161
|
+
};
|
|
162
|
+
/** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus first appears on the screen until the participant's response. */
|
|
163
|
+
readonly rt: {
|
|
164
|
+
readonly type: ParameterType.INT;
|
|
165
|
+
};
|
|
166
|
+
/** The HTML content that was displayed on the screen. */
|
|
167
|
+
readonly stimulus: {
|
|
168
|
+
readonly type: ParameterType.STRING;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
118
171
|
};
|
|
119
172
|
constructor(jsPsych: JsPsych);
|
|
120
173
|
trial(display_element: HTMLElement, trial: TrialType<Info>): void;
|
|
@@ -123,4 +176,5 @@ declare class HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {
|
|
|
123
176
|
private simulate_data_only;
|
|
124
177
|
private simulate_visual;
|
|
125
178
|
}
|
|
126
|
-
|
|
179
|
+
|
|
180
|
+
export { HtmlKeyboardResponsePlugin as default };
|