@jspsych/plugin-image-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.
@@ -1,285 +1,276 @@
1
1
  var jsPsychImageKeyboardResponse = (function (jspsych) {
2
2
  'use strict';
3
3
 
4
+ var _package = {
5
+ name: "@jspsych/plugin-image-keyboard-response",
6
+ version: "2.0.0",
7
+ description: "jsPsych plugin for displaying a 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",
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-image-keyboard-response"
32
+ },
33
+ author: "Josh de Leeuw",
34
+ license: "MIT",
35
+ bugs: {
36
+ url: "https://github.com/jspsych/jsPsych/issues"
37
+ },
38
+ homepage: "https://www.jspsych.org/latest/plugins/image-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
+ };
47
+
4
48
  const info = {
5
- name: "image-keyboard-response",
6
- parameters: {
7
- /** The image to be displayed */
8
- stimulus: {
9
- type: jspsych.ParameterType.IMAGE,
10
- pretty_name: "Stimulus",
11
- default: undefined,
12
- },
13
- /** Set the image height in pixels */
14
- stimulus_height: {
15
- type: jspsych.ParameterType.INT,
16
- pretty_name: "Image height",
17
- default: null,
18
- },
19
- /** Set the image width in pixels */
20
- stimulus_width: {
21
- type: jspsych.ParameterType.INT,
22
- pretty_name: "Image width",
23
- default: null,
24
- },
25
- /** Maintain the aspect ratio after setting width or height */
26
- maintain_aspect_ratio: {
27
- type: jspsych.ParameterType.BOOL,
28
- pretty_name: "Maintain aspect ratio",
29
- default: true,
30
- },
31
- /** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */
32
- choices: {
33
- type: jspsych.ParameterType.KEYS,
34
- pretty_name: "Choices",
35
- default: "ALL_KEYS",
36
- },
37
- /** Any content here will be displayed below the stimulus. */
38
- prompt: {
39
- type: jspsych.ParameterType.HTML_STRING,
40
- pretty_name: "Prompt",
41
- default: null,
42
- },
43
- /** How long to show the stimulus. */
44
- stimulus_duration: {
45
- type: jspsych.ParameterType.INT,
46
- pretty_name: "Stimulus duration",
47
- default: null,
48
- },
49
- /** How long to show trial before it ends */
50
- trial_duration: {
51
- type: jspsych.ParameterType.INT,
52
- pretty_name: "Trial duration",
53
- default: null,
54
- },
55
- /** If true, trial will end when subject makes a response. */
56
- response_ends_trial: {
57
- type: jspsych.ParameterType.BOOL,
58
- pretty_name: "Response ends trial",
59
- default: true,
60
- },
61
- /**
62
- * If true, the image will be drawn onto a canvas element (prevents blank screen between consecutive images in some browsers).
63
- * If false, the image will be shown via an img element.
64
- */
65
- render_on_canvas: {
66
- type: jspsych.ParameterType.BOOL,
67
- pretty_name: "Render on canvas",
68
- default: true,
69
- },
49
+ name: "image-keyboard-response",
50
+ version: _package.version,
51
+ parameters: {
52
+ stimulus: {
53
+ type: jspsych.ParameterType.IMAGE,
54
+ default: void 0
55
+ },
56
+ stimulus_height: {
57
+ type: jspsych.ParameterType.INT,
58
+ default: null
59
+ },
60
+ stimulus_width: {
61
+ type: jspsych.ParameterType.INT,
62
+ default: null
63
+ },
64
+ maintain_aspect_ratio: {
65
+ type: jspsych.ParameterType.BOOL,
66
+ default: true
67
+ },
68
+ choices: {
69
+ type: jspsych.ParameterType.KEYS,
70
+ default: "ALL_KEYS"
71
+ },
72
+ prompt: {
73
+ type: jspsych.ParameterType.HTML_STRING,
74
+ default: null
75
+ },
76
+ stimulus_duration: {
77
+ type: jspsych.ParameterType.INT,
78
+ default: null
79
+ },
80
+ trial_duration: {
81
+ type: jspsych.ParameterType.INT,
82
+ default: null
83
+ },
84
+ response_ends_trial: {
85
+ type: jspsych.ParameterType.BOOL,
86
+ default: true
70
87
  },
88
+ render_on_canvas: {
89
+ type: jspsych.ParameterType.BOOL,
90
+ default: true
91
+ }
92
+ },
93
+ data: {
94
+ stimulus: {
95
+ type: jspsych.ParameterType.STRING
96
+ },
97
+ response: {
98
+ type: jspsych.ParameterType.STRING
99
+ },
100
+ rt: {
101
+ type: jspsych.ParameterType.INT
102
+ }
103
+ }
71
104
  };
72
- /**
73
- * **image-keyboard-response**
74
- *
75
- * jsPsych plugin for displaying an image stimulus and getting a keyboard response
76
- *
77
- * @author Josh de Leeuw
78
- * @see {@link https://www.jspsych.org/plugins/jspsych-image-keyboard-response/ image-keyboard-response plugin documentation on jspsych.org}
79
- */
80
105
  class ImageKeyboardResponsePlugin {
81
- constructor(jsPsych) {
82
- this.jsPsych = jsPsych;
83
- }
84
- trial(display_element, trial) {
85
- var height, width;
86
- if (trial.render_on_canvas) {
87
- var image_drawn = false;
88
- // first clear the display element (because the render_on_canvas method appends to display_element instead of overwriting it with .innerHTML)
89
- if (display_element.hasChildNodes()) {
90
- // can't loop through child list because the list will be modified by .removeChild()
91
- while (display_element.firstChild) {
92
- display_element.removeChild(display_element.firstChild);
93
- }
94
- }
95
- // create canvas element and image
96
- var canvas = document.createElement("canvas");
97
- canvas.id = "jspsych-image-keyboard-response-stimulus";
98
- canvas.style.margin = "0";
99
- canvas.style.padding = "0";
100
- var ctx = canvas.getContext("2d");
101
- var img = new Image();
102
- img.onload = () => {
103
- // if image wasn't preloaded, then it will need to be drawn whenever it finishes loading
104
- if (!image_drawn) {
105
- getHeightWidth(); // only possible to get width/height after image loads
106
- ctx.drawImage(img, 0, 0, width, height);
107
- }
108
- };
109
- img.src = trial.stimulus;
110
- // get/set image height and width - this can only be done after image loads because uses image's naturalWidth/naturalHeight properties
111
- const getHeightWidth = () => {
112
- if (trial.stimulus_height !== null) {
113
- height = trial.stimulus_height;
114
- if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {
115
- width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);
116
- }
117
- }
118
- else {
119
- height = img.naturalHeight;
120
- }
121
- if (trial.stimulus_width !== null) {
122
- width = trial.stimulus_width;
123
- if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {
124
- height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);
125
- }
126
- }
127
- else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {
128
- // if stimulus width is null, only use the image's natural width if the width value wasn't set
129
- // in the if statement above, based on a specified height and maintain_aspect_ratio = true
130
- width = img.naturalWidth;
131
- }
132
- canvas.height = height;
133
- canvas.width = width;
134
- };
135
- getHeightWidth(); // call now, in case image loads immediately (is cached)
136
- // add canvas and draw image
137
- display_element.insertBefore(canvas, null);
138
- if (img.complete && Number.isFinite(width) && Number.isFinite(height)) {
139
- // if image has loaded and width/height have been set, then draw it now
140
- // (don't rely on img onload function to draw image when image is in the cache, because that causes a delay in the image presentation)
141
- ctx.drawImage(img, 0, 0, width, height);
142
- image_drawn = true;
143
- }
144
- // add prompt if there is one
145
- if (trial.prompt !== null) {
146
- display_element.insertAdjacentHTML("beforeend", trial.prompt);
147
- }
106
+ constructor(jsPsych) {
107
+ this.jsPsych = jsPsych;
108
+ }
109
+ static info = info;
110
+ trial(display_element, trial) {
111
+ var height, width;
112
+ if (trial.render_on_canvas) {
113
+ var image_drawn = false;
114
+ if (display_element.hasChildNodes()) {
115
+ while (display_element.firstChild) {
116
+ display_element.removeChild(display_element.firstChild);
148
117
  }
149
- else {
150
- // display stimulus as an image element
151
- var html = '<img src="' + trial.stimulus + '" id="jspsych-image-keyboard-response-stimulus">';
152
- // add prompt
153
- if (trial.prompt !== null) {
154
- html += trial.prompt;
155
- }
156
- // update the page content
157
- display_element.innerHTML = html;
158
- // set image dimensions after image has loaded (so that we have access to naturalHeight/naturalWidth)
159
- var img = display_element.querySelector("#jspsych-image-keyboard-response-stimulus");
160
- if (trial.stimulus_height !== null) {
161
- height = trial.stimulus_height;
162
- if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {
163
- width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);
164
- }
165
- }
166
- else {
167
- height = img.naturalHeight;
168
- }
169
- if (trial.stimulus_width !== null) {
170
- width = trial.stimulus_width;
171
- if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {
172
- height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);
173
- }
174
- }
175
- else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {
176
- // if stimulus width is null, only use the image's natural width if the width value wasn't set
177
- // in the if statement above, based on a specified height and maintain_aspect_ratio = true
178
- width = img.naturalWidth;
179
- }
180
- img.style.height = height.toString() + "px";
181
- img.style.width = width.toString() + "px";
118
+ }
119
+ var canvas = document.createElement("canvas");
120
+ canvas.id = "jspsych-image-keyboard-response-stimulus";
121
+ canvas.style.margin = "0";
122
+ canvas.style.padding = "0";
123
+ var ctx = canvas.getContext("2d");
124
+ var img = new Image();
125
+ img.onload = () => {
126
+ if (!image_drawn) {
127
+ getHeightWidth();
128
+ ctx.drawImage(img, 0, 0, width, height);
182
129
  }
183
- // store response
184
- var response = {
185
- rt: null,
186
- key: null,
187
- };
188
- // function to end trial when it is time
189
- const end_trial = () => {
190
- // kill any remaining setTimeout handlers
191
- this.jsPsych.pluginAPI.clearAllTimeouts();
192
- // kill keyboard listeners
193
- if (typeof keyboardListener !== "undefined") {
194
- this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
195
- }
196
- // gather the data to store for the trial
197
- var trial_data = {
198
- rt: response.rt,
199
- stimulus: trial.stimulus,
200
- response: response.key,
201
- };
202
- // clear the display
203
- display_element.innerHTML = "";
204
- // move on to the next trial
205
- this.jsPsych.finishTrial(trial_data);
206
- };
207
- // function to handle responses by the subject
208
- var after_response = (info) => {
209
- // after a valid response, the stimulus will have the CSS class 'responded'
210
- // which can be used to provide visual feedback that a response was recorded
211
- display_element.querySelector("#jspsych-image-keyboard-response-stimulus").className +=
212
- " responded";
213
- // only record the first response
214
- if (response.key == null) {
215
- response = info;
216
- }
217
- if (trial.response_ends_trial) {
218
- end_trial();
219
- }
220
- };
221
- // start the response listener
222
- if (trial.choices != "NO_KEYS") {
223
- var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({
224
- callback_function: after_response,
225
- valid_responses: trial.choices,
226
- rt_method: "performance",
227
- persist: false,
228
- allow_held_key: false,
229
- });
130
+ };
131
+ img.src = trial.stimulus;
132
+ const getHeightWidth = () => {
133
+ if (trial.stimulus_height !== null) {
134
+ height = trial.stimulus_height;
135
+ if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {
136
+ width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);
137
+ }
138
+ } else {
139
+ height = img.naturalHeight;
230
140
  }
231
- // hide stimulus if stimulus_duration is set
232
- if (trial.stimulus_duration !== null) {
233
- this.jsPsych.pluginAPI.setTimeout(() => {
234
- display_element.querySelector("#jspsych-image-keyboard-response-stimulus").style.visibility = "hidden";
235
- }, trial.stimulus_duration);
141
+ if (trial.stimulus_width !== null) {
142
+ width = trial.stimulus_width;
143
+ if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {
144
+ height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);
145
+ }
146
+ } else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {
147
+ width = img.naturalWidth;
236
148
  }
237
- // end trial if trial_duration is set
238
- if (trial.trial_duration !== null) {
239
- this.jsPsych.pluginAPI.setTimeout(() => {
240
- end_trial();
241
- }, trial.trial_duration);
149
+ canvas.height = height;
150
+ canvas.width = width;
151
+ };
152
+ getHeightWidth();
153
+ display_element.insertBefore(canvas, null);
154
+ if (img.complete && Number.isFinite(width) && Number.isFinite(height)) {
155
+ ctx.drawImage(img, 0, 0, width, height);
156
+ image_drawn = true;
157
+ }
158
+ if (trial.prompt !== null) {
159
+ display_element.insertAdjacentHTML("beforeend", trial.prompt);
160
+ }
161
+ } else {
162
+ var html = '<img src="' + trial.stimulus + '" id="jspsych-image-keyboard-response-stimulus">';
163
+ if (trial.prompt !== null) {
164
+ html += trial.prompt;
165
+ }
166
+ display_element.innerHTML = html;
167
+ var img = display_element.querySelector(
168
+ "#jspsych-image-keyboard-response-stimulus"
169
+ );
170
+ if (trial.stimulus_height !== null) {
171
+ height = trial.stimulus_height;
172
+ if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {
173
+ width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);
242
174
  }
243
- else if (trial.response_ends_trial === false) {
244
- console.warn("The experiment may be deadlocked. Try setting a trial duration or set response_ends_trial to true.");
175
+ } else {
176
+ height = img.naturalHeight;
177
+ }
178
+ if (trial.stimulus_width !== null) {
179
+ width = trial.stimulus_width;
180
+ if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {
181
+ height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);
245
182
  }
183
+ } else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {
184
+ width = img.naturalWidth;
185
+ }
186
+ img.style.height = height.toString() + "px";
187
+ img.style.width = width.toString() + "px";
246
188
  }
247
- simulate(trial, simulation_mode, simulation_options, load_callback) {
248
- if (simulation_mode == "data-only") {
249
- load_callback();
250
- this.simulate_data_only(trial, simulation_options);
251
- }
252
- if (simulation_mode == "visual") {
253
- this.simulate_visual(trial, simulation_options, load_callback);
254
- }
189
+ var response = {
190
+ rt: null,
191
+ key: null
192
+ };
193
+ const end_trial = () => {
194
+ if (typeof keyboardListener !== "undefined") {
195
+ this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
196
+ }
197
+ var trial_data = {
198
+ rt: response.rt,
199
+ stimulus: trial.stimulus,
200
+ response: response.key
201
+ };
202
+ this.jsPsych.finishTrial(trial_data);
203
+ };
204
+ var after_response = (info2) => {
205
+ display_element.querySelector("#jspsych-image-keyboard-response-stimulus").className += " responded";
206
+ if (response.key == null) {
207
+ response = info2;
208
+ }
209
+ if (trial.response_ends_trial) {
210
+ end_trial();
211
+ }
212
+ };
213
+ if (trial.choices != "NO_KEYS") {
214
+ var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({
215
+ callback_function: after_response,
216
+ valid_responses: trial.choices,
217
+ rt_method: "performance",
218
+ persist: false,
219
+ allow_held_key: false
220
+ });
255
221
  }
256
- simulate_data_only(trial, simulation_options) {
257
- const data = this.create_simulation_data(trial, simulation_options);
258
- this.jsPsych.finishTrial(data);
222
+ if (trial.stimulus_duration !== null) {
223
+ this.jsPsych.pluginAPI.setTimeout(() => {
224
+ display_element.querySelector(
225
+ "#jspsych-image-keyboard-response-stimulus"
226
+ ).style.visibility = "hidden";
227
+ }, trial.stimulus_duration);
259
228
  }
260
- simulate_visual(trial, simulation_options, load_callback) {
261
- const data = this.create_simulation_data(trial, simulation_options);
262
- const display_element = this.jsPsych.getDisplayElement();
263
- this.trial(display_element, trial);
264
- load_callback();
265
- if (data.rt !== null) {
266
- this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
267
- }
229
+ if (trial.trial_duration !== null) {
230
+ this.jsPsych.pluginAPI.setTimeout(() => {
231
+ end_trial();
232
+ }, trial.trial_duration);
233
+ } else if (trial.response_ends_trial === false) {
234
+ console.warn(
235
+ "The experiment may be deadlocked. Try setting a trial duration or set response_ends_trial to true."
236
+ );
237
+ }
238
+ }
239
+ simulate(trial, simulation_mode, simulation_options, load_callback) {
240
+ if (simulation_mode == "data-only") {
241
+ load_callback();
242
+ this.simulate_data_only(trial, simulation_options);
243
+ }
244
+ if (simulation_mode == "visual") {
245
+ this.simulate_visual(trial, simulation_options, load_callback);
268
246
  }
269
- create_simulation_data(trial, simulation_options) {
270
- const default_data = {
271
- stimulus: trial.stimulus,
272
- rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
273
- response: this.jsPsych.pluginAPI.getValidKey(trial.choices),
274
- };
275
- const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
276
- this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
277
- return data;
247
+ }
248
+ simulate_data_only(trial, simulation_options) {
249
+ const data = this.create_simulation_data(trial, simulation_options);
250
+ this.jsPsych.finishTrial(data);
251
+ }
252
+ simulate_visual(trial, simulation_options, load_callback) {
253
+ const data = this.create_simulation_data(trial, simulation_options);
254
+ const display_element = this.jsPsych.getDisplayElement();
255
+ this.trial(display_element, trial);
256
+ load_callback();
257
+ if (data.rt !== null) {
258
+ this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
278
259
  }
260
+ }
261
+ create_simulation_data(trial, simulation_options) {
262
+ const default_data = {
263
+ stimulus: trial.stimulus,
264
+ rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
265
+ response: this.jsPsych.pluginAPI.getValidKey(trial.choices)
266
+ };
267
+ const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
268
+ this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
269
+ return data;
270
+ }
279
271
  }
280
- ImageKeyboardResponsePlugin.info = info;
281
272
 
282
273
  return ImageKeyboardResponsePlugin;
283
274
 
284
275
  })(jsPsychModule);
285
- //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-image-keyboard-response@1.1.3/dist/index.browser.js.map
276
+ //# sourceMappingURL=https://unpkg.com/@jspsych/plugin-image-keyboard-response@2.0.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\nconst info = <const>{\n name: \"image-keyboard-response\",\n parameters: {\n /** The image to be displayed */\n stimulus: {\n type: ParameterType.IMAGE,\n pretty_name: \"Stimulus\",\n default: undefined,\n },\n /** Set the image height in pixels */\n stimulus_height: {\n type: ParameterType.INT,\n pretty_name: \"Image height\",\n default: null,\n },\n /** Set the image width in pixels */\n stimulus_width: {\n type: ParameterType.INT,\n pretty_name: \"Image width\",\n default: null,\n },\n /** Maintain the aspect ratio after setting width or height */\n maintain_aspect_ratio: {\n type: ParameterType.BOOL,\n pretty_name: \"Maintain aspect ratio\",\n default: true,\n },\n /** Array containing the key(s) the subject is allowed to press to respond to the stimulus. */\n choices: {\n type: ParameterType.KEYS,\n pretty_name: \"Choices\",\n default: \"ALL_KEYS\",\n },\n /** Any content here will be displayed below the stimulus. */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: null,\n },\n /** How long to show the stimulus. */\n stimulus_duration: {\n type: ParameterType.INT,\n pretty_name: \"Stimulus duration\",\n default: null,\n },\n /** How long to show trial before it ends */\n trial_duration: {\n type: ParameterType.INT,\n pretty_name: \"Trial duration\",\n default: null,\n },\n /** If true, trial will end when subject makes a response. */\n response_ends_trial: {\n type: ParameterType.BOOL,\n pretty_name: \"Response ends trial\",\n default: true,\n },\n /**\n * If true, the image will be drawn onto a canvas element (prevents blank screen between consecutive images in some browsers).\n * If false, the image will be shown via an img element.\n */\n render_on_canvas: {\n type: ParameterType.BOOL,\n pretty_name: \"Render on canvas\",\n default: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **image-keyboard-response**\n *\n * jsPsych plugin for displaying an image stimulus and getting a keyboard response\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/plugins/jspsych-image-keyboard-response/ image-keyboard-response plugin documentation on jspsych.org}\n */\nclass ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var height, width;\n if (trial.render_on_canvas) {\n var image_drawn = false;\n // first clear the display element (because the render_on_canvas method appends to display_element instead of overwriting it with .innerHTML)\n if (display_element.hasChildNodes()) {\n // can't loop through child list because the list will be modified by .removeChild()\n while (display_element.firstChild) {\n display_element.removeChild(display_element.firstChild);\n }\n }\n // create canvas element and image\n var canvas = document.createElement(\"canvas\");\n canvas.id = \"jspsych-image-keyboard-response-stimulus\";\n canvas.style.margin = \"0\";\n canvas.style.padding = \"0\";\n var ctx = canvas.getContext(\"2d\");\n var img = new Image();\n img.onload = () => {\n // if image wasn't preloaded, then it will need to be drawn whenever it finishes loading\n if (!image_drawn) {\n getHeightWidth(); // only possible to get width/height after image loads\n ctx.drawImage(img, 0, 0, width, height);\n }\n };\n img.src = trial.stimulus;\n // get/set image height and width - this can only be done after image loads because uses image's naturalWidth/naturalHeight properties\n const getHeightWidth = () => {\n if (trial.stimulus_height !== null) {\n height = trial.stimulus_height;\n if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {\n width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);\n }\n } else {\n height = img.naturalHeight;\n }\n if (trial.stimulus_width !== null) {\n width = trial.stimulus_width;\n if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {\n height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);\n }\n } else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {\n // if stimulus width is null, only use the image's natural width if the width value wasn't set\n // in the if statement above, based on a specified height and maintain_aspect_ratio = true\n width = img.naturalWidth;\n }\n canvas.height = height;\n canvas.width = width;\n };\n getHeightWidth(); // call now, in case image loads immediately (is cached)\n // add canvas and draw image\n display_element.insertBefore(canvas, null);\n if (img.complete && Number.isFinite(width) && Number.isFinite(height)) {\n // if image has loaded and width/height have been set, then draw it now\n // (don't rely on img onload function to draw image when image is in the cache, because that causes a delay in the image presentation)\n ctx.drawImage(img, 0, 0, width, height);\n image_drawn = true;\n }\n // add prompt if there is one\n if (trial.prompt !== null) {\n display_element.insertAdjacentHTML(\"beforeend\", trial.prompt);\n }\n } else {\n // display stimulus as an image element\n var html = '<img src=\"' + trial.stimulus + '\" id=\"jspsych-image-keyboard-response-stimulus\">';\n // add prompt\n if (trial.prompt !== null) {\n html += trial.prompt;\n }\n // update the page content\n display_element.innerHTML = html;\n\n // set image dimensions after image has loaded (so that we have access to naturalHeight/naturalWidth)\n var img = display_element.querySelector(\n \"#jspsych-image-keyboard-response-stimulus\"\n ) as HTMLImageElement;\n if (trial.stimulus_height !== null) {\n height = trial.stimulus_height;\n if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {\n width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);\n }\n } else {\n height = img.naturalHeight;\n }\n if (trial.stimulus_width !== null) {\n width = trial.stimulus_width;\n if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {\n height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);\n }\n } else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {\n // if stimulus width is null, only use the image's natural width if the width value wasn't set\n // in the if statement above, based on a specified height and maintain_aspect_ratio = true\n width = img.naturalWidth;\n }\n img.style.height = height.toString() + \"px\";\n img.style.width = width.toString() + \"px\";\n }\n\n // store response\n var response = {\n rt: null,\n key: null,\n };\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // kill keyboard listeners\n if (typeof keyboardListener !== \"undefined\") {\n this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);\n }\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.key,\n };\n\n // clear the display\n display_element.innerHTML = \"\";\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n };\n\n // function to handle responses by the subject\n var after_response = (info) => {\n // after a valid response, the stimulus will have the CSS class 'responded'\n // which can be used to provide visual feedback that a response was recorded\n display_element.querySelector(\"#jspsych-image-keyboard-response-stimulus\").className +=\n \" responded\";\n\n // only record the first response\n if (response.key == null) {\n response = info;\n }\n\n if (trial.response_ends_trial) {\n end_trial();\n }\n };\n\n // start the response listener\n if (trial.choices != \"NO_KEYS\") {\n var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: after_response,\n valid_responses: trial.choices,\n rt_method: \"performance\",\n persist: false,\n allow_held_key: false,\n });\n }\n\n // hide stimulus if stimulus_duration is set\n if (trial.stimulus_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n display_element.querySelector<HTMLElement>(\n \"#jspsych-image-keyboard-response-stimulus\"\n ).style.visibility = \"hidden\";\n }, trial.stimulus_duration);\n }\n\n // end trial if trial_duration is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n end_trial();\n }, trial.trial_duration);\n } else if (trial.response_ends_trial === false) {\n console.warn(\n \"The experiment may be deadlocked. Try setting a trial duration or set response_ends_trial to true.\"\n );\n }\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.pressKey(data.response, data.rt);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n}\n\nexport default ImageKeyboardResponsePlugin;\n"],"names":["ParameterType"],"mappings":";;;EAEA,MAAM,IAAI,GAAU;EAClB,IAAA,IAAI,EAAE,yBAAyB;EAC/B,IAAA,UAAU,EAAE;;EAEV,QAAA,QAAQ,EAAE;cACR,IAAI,EAAEA,qBAAa,CAAC,KAAK;EACzB,YAAA,WAAW,EAAE,UAAU;EACvB,YAAA,OAAO,EAAE,SAAS;EACnB,SAAA;;EAED,QAAA,eAAe,EAAE;cACf,IAAI,EAAEA,qBAAa,CAAC,GAAG;EACvB,YAAA,WAAW,EAAE,cAAc;EAC3B,YAAA,OAAO,EAAE,IAAI;EACd,SAAA;;EAED,QAAA,cAAc,EAAE;cACd,IAAI,EAAEA,qBAAa,CAAC,GAAG;EACvB,YAAA,WAAW,EAAE,aAAa;EAC1B,YAAA,OAAO,EAAE,IAAI;EACd,SAAA;;EAED,QAAA,qBAAqB,EAAE;cACrB,IAAI,EAAEA,qBAAa,CAAC,IAAI;EACxB,YAAA,WAAW,EAAE,uBAAuB;EACpC,YAAA,OAAO,EAAE,IAAI;EACd,SAAA;;EAED,QAAA,OAAO,EAAE;cACP,IAAI,EAAEA,qBAAa,CAAC,IAAI;EACxB,YAAA,WAAW,EAAE,SAAS;EACtB,YAAA,OAAO,EAAE,UAAU;EACpB,SAAA;;EAED,QAAA,MAAM,EAAE;cACN,IAAI,EAAEA,qBAAa,CAAC,WAAW;EAC/B,YAAA,WAAW,EAAE,QAAQ;EACrB,YAAA,OAAO,EAAE,IAAI;EACd,SAAA;;EAED,QAAA,iBAAiB,EAAE;cACjB,IAAI,EAAEA,qBAAa,CAAC,GAAG;EACvB,YAAA,WAAW,EAAE,mBAAmB;EAChC,YAAA,OAAO,EAAE,IAAI;EACd,SAAA;;EAED,QAAA,cAAc,EAAE;cACd,IAAI,EAAEA,qBAAa,CAAC,GAAG;EACvB,YAAA,WAAW,EAAE,gBAAgB;EAC7B,Y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AAkB,EAAA;EACvE,QAAA,MAAM,YAAY,GAAG;cACnB,QAAQ,EAAE,KAAK,CAAC,QAAQ;EACxB,YAAA,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC;EACvE,YAAA,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC;WAC5D,CAAC;EAEF,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,mBAAmB,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;UAE1F,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,+BAA+B,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;EAEpE,QAAA,OAAO,IAAI,CAAC;OACb;;EAnOM,2BAAI,CAAA,IAAA,GAAG,IAAI;;;;;;;;"}
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: \"image-keyboard-response\",\n version: version,\n parameters: {\n /** The path of the image file to be displayed. */\n stimulus: {\n type: ParameterType.IMAGE,\n default: undefined,\n },\n /** Set the height of the image in pixels. If left null (no value specified), then the image will display at its natural height. */\n stimulus_height: {\n type: ParameterType.INT,\n default: null,\n },\n /** Set the width of the image in pixels. If left null (no value specified), then the image will display at its natural width. */\n stimulus_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** If setting *only* the width or *only* the height and this parameter is true, then the other dimension will be scaled\n * to maintain the image's aspect ratio. */\n maintain_aspect_ratio: {\n type: ParameterType.BOOL,\n default: true,\n },\n /**his array contains the key(s) that the participant is allowed to press in order to respond to the stimulus. Keys should\n * be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) - see\n * [this page](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) and\n * [this page (event.key column)](https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/)\n * for more examples. Any key presses that are not listed in the array will be ignored. The default value of `\"ALL_KEYS\"`\n * means that all keys will be accepted as valid responses. Specifying `\"NO_KEYS\"` will mean that no responses are allowed. */\n choices: {\n type: ParameterType.KEYS,\n default: \"ALL_KEYS\",\n },\n /**This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can\n * be used to provide a reminder about the action the participant is supposed to take (e.g., which key to press). */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** How long to show the stimulus for in milliseconds. If the value is `null`, then the stimulus will be shown until the\n * participant makes a response. */\n stimulus_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** How long to wait for the participant to make a response before ending the trial in milliseconds. If the participant\n * fails to make a response before this timer is reached, the participant's response will be recorded as null for the\n * trial and the trial will end. If the value of this parameter is `null`, then the trial will wait for a response indefinitely. */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /** If true, then the trial will end whenever the participant makes a response (assuming they make their response before\n * the cutoff specified by the `trial_duration` parameter). If false, then the trial will continue until the value for\n * `trial_duration` is reached. You can set this parameter to `false` to force the participant to view a stimulus for a\n * fixed amount of time, even if they respond before the time is complete. */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n /**\n * If `true`, the image will be drawn onto a canvas element. This prevents a blank screen (white flash) between consecutive image trials in some browsers, like Firefox and Edge.\n * If `false`, the image will be shown via an img element, as in previous versions of jsPsych. If the stimulus is an **animated gif**, you must set this parameter to false, because the canvas rendering method will only present static images.\n */\n render_on_canvas: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** The path of the image that was displayed. */\n stimulus: {\n type: ParameterType.STRING,\n },\n /** Indicates which key the participant pressed. */\n response: {\n type: ParameterType.STRING,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus\n * first appears on the screen until the participant's response. */\n rt: {\n type: ParameterType.INT,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin displays an image and records responses generated with the keyboard. The stimulus can be displayed until a\n * response is given, or for a pre-determined amount of time. The trial can be ended automatically if the participant has\n * failed to respond within a fixed length of time.\n *\n * Image files can be automatically preloaded by jsPsych using the [`preload` plugin](preload.md). However, if you are using\n * timeline variables or another dynamic method to specify the image stimulus, you will need to\n * [manually preload](../overview/media-preloading.md#manual-preloading) the images.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/image-keyboard-response/ image-keyboard-response plugin documentation on jspsych.org}\n */\nclass ImageKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var height, width;\n if (trial.render_on_canvas) {\n var image_drawn = false;\n // first clear the display element (because the render_on_canvas method appends to display_element instead of overwriting it with .innerHTML)\n if (display_element.hasChildNodes()) {\n // can't loop through child list because the list will be modified by .removeChild()\n while (display_element.firstChild) {\n display_element.removeChild(display_element.firstChild);\n }\n }\n // create canvas element and image\n var canvas = document.createElement(\"canvas\");\n canvas.id = \"jspsych-image-keyboard-response-stimulus\";\n canvas.style.margin = \"0\";\n canvas.style.padding = \"0\";\n var ctx = canvas.getContext(\"2d\");\n var img = new Image();\n img.onload = () => {\n // if image wasn't preloaded, then it will need to be drawn whenever it finishes loading\n if (!image_drawn) {\n getHeightWidth(); // only possible to get width/height after image loads\n ctx.drawImage(img, 0, 0, width, height);\n }\n };\n img.src = trial.stimulus;\n // get/set image height and width - this can only be done after image loads because uses image's naturalWidth/naturalHeight properties\n const getHeightWidth = () => {\n if (trial.stimulus_height !== null) {\n height = trial.stimulus_height;\n if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {\n width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);\n }\n } else {\n height = img.naturalHeight;\n }\n if (trial.stimulus_width !== null) {\n width = trial.stimulus_width;\n if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {\n height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);\n }\n } else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {\n // if stimulus width is null, only use the image's natural width if the width value wasn't set\n // in the if statement above, based on a specified height and maintain_aspect_ratio = true\n width = img.naturalWidth;\n }\n canvas.height = height;\n canvas.width = width;\n };\n getHeightWidth(); // call now, in case image loads immediately (is cached)\n // add canvas and draw image\n display_element.insertBefore(canvas, null);\n if (img.complete && Number.isFinite(width) && Number.isFinite(height)) {\n // if image has loaded and width/height have been set, then draw it now\n // (don't rely on img onload function to draw image when image is in the cache, because that causes a delay in the image presentation)\n ctx.drawImage(img, 0, 0, width, height);\n image_drawn = true;\n }\n // add prompt if there is one\n if (trial.prompt !== null) {\n display_element.insertAdjacentHTML(\"beforeend\", trial.prompt);\n }\n } else {\n // display stimulus as an image element\n var html = '<img src=\"' + trial.stimulus + '\" id=\"jspsych-image-keyboard-response-stimulus\">';\n // add prompt\n if (trial.prompt !== null) {\n html += trial.prompt;\n }\n // update the page content\n display_element.innerHTML = html;\n\n // set image dimensions after image has loaded (so that we have access to naturalHeight/naturalWidth)\n var img = display_element.querySelector(\n \"#jspsych-image-keyboard-response-stimulus\"\n ) as HTMLImageElement;\n if (trial.stimulus_height !== null) {\n height = trial.stimulus_height;\n if (trial.stimulus_width == null && trial.maintain_aspect_ratio) {\n width = img.naturalWidth * (trial.stimulus_height / img.naturalHeight);\n }\n } else {\n height = img.naturalHeight;\n }\n if (trial.stimulus_width !== null) {\n width = trial.stimulus_width;\n if (trial.stimulus_height == null && trial.maintain_aspect_ratio) {\n height = img.naturalHeight * (trial.stimulus_width / img.naturalWidth);\n }\n } else if (!(trial.stimulus_height !== null && trial.maintain_aspect_ratio)) {\n // if stimulus width is null, only use the image's natural width if the width value wasn't set\n // in the if statement above, based on a specified height and maintain_aspect_ratio = true\n width = img.naturalWidth;\n }\n img.style.height = height.toString() + \"px\";\n img.style.width = width.toString() + \"px\";\n }\n\n // store response\n var response = {\n rt: null,\n key: null,\n };\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill keyboard listeners\n if (typeof keyboardListener !== \"undefined\") {\n this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);\n }\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.key,\n };\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n };\n\n // function to handle responses by the subject\n var after_response = (info) => {\n // after a valid response, the stimulus will have the CSS class 'responded'\n // which can be used to provide visual feedback that a response was recorded\n display_element.querySelector(\"#jspsych-image-keyboard-response-stimulus\").className +=\n \" responded\";\n\n // only record the first response\n if (response.key == null) {\n response = info;\n }\n\n if (trial.response_ends_trial) {\n end_trial();\n }\n };\n\n // start the response listener\n if (trial.choices != \"NO_KEYS\") {\n var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: after_response,\n valid_responses: trial.choices,\n rt_method: \"performance\",\n persist: false,\n allow_held_key: false,\n });\n }\n\n // hide stimulus if stimulus_duration is set\n if (trial.stimulus_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n display_element.querySelector<HTMLElement>(\n \"#jspsych-image-keyboard-response-stimulus\"\n ).style.visibility = \"hidden\";\n }, trial.stimulus_duration);\n }\n\n // end trial if trial_duration is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n end_trial();\n }, trial.trial_duration);\n } else if (trial.response_ends_trial === false) {\n console.warn(\n \"The experiment may be deadlocked. Try setting a trial duration or set response_ends_trial to true.\"\n );\n }\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.pressKey(data.response, data.rt);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n}\n\nexport default ImageKeyboardResponsePlugin;\n"],"names":["version","ParameterType","info"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIA,MAAM,IAAc,GAAA;EAAA,EAClB,IAAM,EAAA,yBAAA;EAAA,WACNA,gBAAA;EAAA,EACA,UAAY,EAAA;EAAA,IAEV,QAAU,EAAA;EAAA,MACR,MAAMC,qBAAc,CAAA,KAAA;EAAA,MACpB,OAAS,EAAA,KAAA,CAAA;EAAA,KACX;EAAA,IAEA,eAAiB,EAAA;EAAA,MACf,MAAMA,qBAAc,CAAA,GAAA;EAAA,MACpB,OAAS,EAAA,IAAA;EAAA,KACX;EAAA,IAEA,cAAgB,EAAA;EAAA,MACd,MAAMA,qBAAc,CAAA,GAAA;EAAA,MACpB,OAAS,EAAA,IAAA;EAAA,KACX;EAAA,IAGA,qBAAuB,EAAA;EAAA,MACrB,MAAMA,qBAAc,CAAA,IAAA;EAAA,MACpB,OAAS,EAAA,IAAA;EAAA,KACX;EAAA,IAOA,OAAS,EAAA;EAAA,MACP,M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