jspsych 7.3.3 → 8.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.
Files changed (58) hide show
  1. package/README.md +1 -1
  2. package/css/jspsych.css +19 -11
  3. package/dist/index.browser.js +3082 -3399
  4. package/dist/index.browser.js.map +1 -1
  5. package/dist/index.browser.min.js +6 -2
  6. package/dist/index.browser.min.js.map +1 -1
  7. package/dist/index.cjs +2464 -3327
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +990 -12
  10. package/dist/index.js +2463 -3325
  11. package/dist/index.js.map +1 -1
  12. package/package.json +6 -5
  13. package/src/ExtensionManager.spec.ts +123 -0
  14. package/src/ExtensionManager.ts +81 -0
  15. package/src/JsPsych.ts +195 -690
  16. package/src/ProgressBar.spec.ts +60 -0
  17. package/src/ProgressBar.ts +60 -0
  18. package/src/index.scss +29 -8
  19. package/src/index.ts +4 -9
  20. package/src/modules/data/DataCollection.ts +1 -1
  21. package/src/modules/data/DataColumn.ts +12 -1
  22. package/src/modules/data/index.ts +92 -103
  23. package/src/modules/extensions.ts +4 -0
  24. package/src/modules/plugin-api/AudioPlayer.ts +101 -0
  25. package/src/modules/plugin-api/KeyboardListenerAPI.ts +1 -1
  26. package/src/modules/plugin-api/MediaAPI.ts +48 -106
  27. package/src/modules/plugin-api/__mocks__/AudioPlayer.ts +38 -0
  28. package/src/modules/plugin-api/index.ts +11 -14
  29. package/src/modules/plugins.ts +26 -27
  30. package/src/modules/randomization.ts +1 -1
  31. package/src/timeline/Timeline.spec.ts +921 -0
  32. package/src/timeline/Timeline.ts +342 -0
  33. package/src/timeline/TimelineNode.ts +174 -0
  34. package/src/timeline/Trial.spec.ts +897 -0
  35. package/src/timeline/Trial.ts +419 -0
  36. package/src/timeline/index.ts +232 -0
  37. package/src/timeline/util.spec.ts +124 -0
  38. package/src/timeline/util.ts +146 -0
  39. package/dist/JsPsych.d.ts +0 -112
  40. package/dist/TimelineNode.d.ts +0 -34
  41. package/dist/migration.d.ts +0 -3
  42. package/dist/modules/data/DataCollection.d.ts +0 -46
  43. package/dist/modules/data/DataColumn.d.ts +0 -15
  44. package/dist/modules/data/index.d.ts +0 -25
  45. package/dist/modules/data/utils.d.ts +0 -3
  46. package/dist/modules/extensions.d.ts +0 -22
  47. package/dist/modules/plugin-api/HardwareAPI.d.ts +0 -15
  48. package/dist/modules/plugin-api/KeyboardListenerAPI.d.ts +0 -34
  49. package/dist/modules/plugin-api/MediaAPI.d.ts +0 -32
  50. package/dist/modules/plugin-api/SimulationAPI.d.ts +0 -44
  51. package/dist/modules/plugin-api/TimeoutAPI.d.ts +0 -17
  52. package/dist/modules/plugin-api/index.d.ts +0 -8
  53. package/dist/modules/plugins.d.ts +0 -136
  54. package/dist/modules/randomization.d.ts +0 -42
  55. package/dist/modules/turk.d.ts +0 -40
  56. package/dist/modules/utils.d.ts +0 -13
  57. package/src/TimelineNode.ts +0 -544
  58. package/src/modules/plugin-api/HardwareAPI.ts +0 -32
@@ -1,8 +0,0 @@
1
- import { JsPsych } from "../../JsPsych";
2
- import { HardwareAPI } from "./HardwareAPI";
3
- import { KeyboardListenerAPI } from "./KeyboardListenerAPI";
4
- import { MediaAPI } from "./MediaAPI";
5
- import { SimulationAPI } from "./SimulationAPI";
6
- import { TimeoutAPI } from "./TimeoutAPI";
7
- export declare function createJointPluginAPIObject(jsPsych: JsPsych): KeyboardListenerAPI & TimeoutAPI & MediaAPI & HardwareAPI & SimulationAPI;
8
- export declare type PluginAPI = ReturnType<typeof createJointPluginAPIObject>;
@@ -1,136 +0,0 @@
1
- /**
2
- Flatten the type output to improve type hints shown in editors.
3
- Borrowed from type-fest
4
- */
5
- declare type Simplify<T> = {
6
- [KeyType in keyof T]: T[KeyType];
7
- };
8
- /**
9
- Create a type that makes the given keys required. The remaining keys are kept as is.
10
- Borrowed from type-fest
11
- */
12
- declare type SetRequired<BaseType, Keys extends keyof BaseType> = Simplify<Omit<BaseType, Keys> & Required<Pick<BaseType, Keys>>>;
13
- /**
14
- * Parameter types for plugins
15
- */
16
- export declare enum ParameterType {
17
- BOOL = 0,
18
- STRING = 1,
19
- INT = 2,
20
- FLOAT = 3,
21
- FUNCTION = 4,
22
- KEY = 5,
23
- KEYS = 6,
24
- SELECT = 7,
25
- HTML_STRING = 8,
26
- IMAGE = 9,
27
- AUDIO = 10,
28
- VIDEO = 11,
29
- OBJECT = 12,
30
- COMPLEX = 13,
31
- TIMELINE = 14
32
- }
33
- declare type ParameterTypeMap = {
34
- [ParameterType.BOOL]: boolean;
35
- [ParameterType.STRING]: string;
36
- [ParameterType.INT]: number;
37
- [ParameterType.FLOAT]: number;
38
- [ParameterType.FUNCTION]: (...args: any[]) => any;
39
- [ParameterType.KEY]: string;
40
- [ParameterType.KEYS]: string[] | "ALL_KEYS" | "NO_KEYS";
41
- [ParameterType.SELECT]: any;
42
- [ParameterType.HTML_STRING]: string;
43
- [ParameterType.IMAGE]: string;
44
- [ParameterType.AUDIO]: string;
45
- [ParameterType.VIDEO]: string;
46
- [ParameterType.OBJECT]: object;
47
- [ParameterType.COMPLEX]: any;
48
- [ParameterType.TIMELINE]: any;
49
- };
50
- export interface ParameterInfo {
51
- type: ParameterType;
52
- array?: boolean;
53
- pretty_name?: string;
54
- default?: any;
55
- preload?: boolean;
56
- }
57
- export interface ParameterInfos {
58
- [key: string]: ParameterInfo;
59
- }
60
- declare type InferredParameter<I extends ParameterInfo> = I["array"] extends true ? Array<ParameterTypeMap[I["type"]]> : ParameterTypeMap[I["type"]];
61
- declare type RequiredParameterNames<I extends ParameterInfos> = {
62
- [K in keyof I]: I[K]["default"] extends undefined ? K : never;
63
- }[keyof I];
64
- declare type InferredParameters<I extends ParameterInfos> = SetRequired<{
65
- [Property in keyof I]?: InferredParameter<I[Property]>;
66
- }, RequiredParameterNames<I>>;
67
- export declare const universalPluginParameters: {
68
- /**
69
- * Data to add to this trial (key-value pairs)
70
- */
71
- readonly data: {
72
- readonly type: ParameterType.OBJECT;
73
- readonly pretty_name: "Data";
74
- readonly default: {};
75
- };
76
- /**
77
- * Function to execute when trial begins
78
- */
79
- readonly on_start: {
80
- readonly type: ParameterType.FUNCTION;
81
- readonly pretty_name: "On start";
82
- readonly default: () => void;
83
- };
84
- /**
85
- * Function to execute when trial is finished
86
- */
87
- readonly on_finish: {
88
- readonly type: ParameterType.FUNCTION;
89
- readonly pretty_name: "On finish";
90
- readonly default: () => void;
91
- };
92
- /**
93
- * Function to execute after the trial has loaded
94
- */
95
- readonly on_load: {
96
- readonly type: ParameterType.FUNCTION;
97
- readonly pretty_name: "On load";
98
- readonly default: () => void;
99
- };
100
- /**
101
- * Length of gap between the end of this trial and the start of the next trial
102
- */
103
- readonly post_trial_gap: {
104
- readonly type: ParameterType.INT;
105
- readonly pretty_name: "Post trial gap";
106
- readonly default: any;
107
- };
108
- /**
109
- * A list of CSS classes to add to the jsPsych display element for the duration of this trial
110
- */
111
- readonly css_classes: {
112
- readonly type: ParameterType.STRING;
113
- readonly pretty_name: "Custom CSS classes";
114
- readonly default: any;
115
- };
116
- /**
117
- * Options to control simulation mode for the trial.
118
- */
119
- readonly simulation_options: {
120
- readonly type: ParameterType.COMPLEX;
121
- readonly default: any;
122
- };
123
- };
124
- export declare type UniversalPluginParameters = InferredParameters<typeof universalPluginParameters>;
125
- export interface PluginInfo {
126
- name: string;
127
- parameters: {
128
- [key: string]: ParameterInfo;
129
- };
130
- }
131
- export interface JsPsychPlugin<I extends PluginInfo> {
132
- trial(display_element: HTMLElement, trial: TrialType<I>, on_load?: () => void): void | Promise<any>;
133
- }
134
- export declare type TrialType<I extends PluginInfo> = InferredParameters<I["parameters"]> & UniversalPluginParameters;
135
- export declare type PluginParameters<I extends PluginInfo> = InferredParameters<I["parameters"]>;
136
- export {};
@@ -1,42 +0,0 @@
1
- /**
2
- * Uses the `seedrandom` package to replace Math.random() with a seedable PRNG.
3
- *
4
- * @param seed An optional seed. If none is given, a random seed will be generated.
5
- * @returns The seed value.
6
- */
7
- export declare function setSeed(seed?: string): string;
8
- export declare function repeat(array: any, repetitions: any, unpack?: boolean): any;
9
- export declare function shuffle(array: Array<any>): any[];
10
- export declare function shuffleNoRepeats(arr: Array<any>, equalityTest: (a: any, b: any) => boolean): any[];
11
- export declare function shuffleAlternateGroups(arr_groups: any, random_group_order?: boolean): any[];
12
- export declare function sampleWithoutReplacement(arr: any, size: any): any[];
13
- export declare function sampleWithReplacement(arr: any, size: any, weights?: any): any[];
14
- export declare function factorial(factors: Record<string, any>, repetitions?: number, unpack?: boolean): any;
15
- export declare function randomID(length?: number): string;
16
- /**
17
- * Generate a random integer from `lower` to `upper`, inclusive of both end points.
18
- * @param lower The lowest value it is possible to generate
19
- * @param upper The highest value it is possible to generate
20
- * @returns A random integer
21
- */
22
- export declare function randomInt(lower: number, upper: number): number;
23
- /**
24
- * Generates a random sample from a Bernoulli distribution.
25
- * @param p The probability of sampling 1.
26
- * @returns 0, with probability 1-p, or 1, with probability p.
27
- */
28
- export declare function sampleBernoulli(p: number): 0 | 1;
29
- export declare function sampleNormal(mean: number, standard_deviation: number): number;
30
- export declare function sampleExponential(rate: number): number;
31
- export declare function sampleExGaussian(mean: number, standard_deviation: number, rate: number, positive?: boolean): number;
32
- /**
33
- * Generate one or more random words.
34
- *
35
- * This is a wrapper function for the {@link https://www.npmjs.com/package/random-words `random-words` npm package}.
36
- *
37
- * @param opts An object with optional properties `min`, `max`, `exactly`,
38
- * `join`, `maxLength`, `wordsPerString`, `separator`, and `formatter`.
39
- *
40
- * @returns An array of words or a single string, depending on parameter choices.
41
- */
42
- export declare function randomWords(opts: any): any;
@@ -1,40 +0,0 @@
1
- interface turkInformation {
2
- /**
3
- * Is the experiment being loaded in preview mode on Mechanical Turk?
4
- */
5
- previewMode: boolean;
6
- /**
7
- * Is the experiment being loaded outside of the Mechanical Turk environment?
8
- */
9
- outsideTurk: boolean;
10
- /**
11
- * The HIT ID.
12
- */
13
- hitId: string;
14
- /**
15
- * The Assignment ID.
16
- */
17
- assignmentId: string;
18
- /**
19
- * The worker ID.
20
- */
21
- workerId: string;
22
- /**
23
- * URL for submission of the HIT.
24
- */
25
- turkSubmitTo: string;
26
- }
27
- /**
28
- * Gets information about the Mechanical Turk Environment, HIT, Assignment, and Worker
29
- * by parsing the URL variables that Mechanical Turk generates.
30
- * @returns An object containing information about the Mechanical Turk Environment, HIT, Assignment, and Worker.
31
- */
32
- export declare function turkInfo(): turkInformation;
33
- /**
34
- * Send data to Mechnical Turk for storage.
35
- * @param data An object containing `key:value` pairs to send to Mechanical Turk. Values
36
- * cannot contain nested objects, arrays, or functions.
37
- * @returns Nothing
38
- */
39
- export declare function submitToTurk(data: any): void;
40
- export {};
@@ -1,13 +0,0 @@
1
- /**
2
- * Finds all of the unique items in an array.
3
- * @param arr The array to extract unique values from
4
- * @returns An array with one copy of each unique item in `arr`
5
- */
6
- export declare function unique(arr: Array<any>): any[];
7
- export declare function deepCopy(obj: any): any;
8
- /**
9
- * Merges two objects, recursively.
10
- * @param obj1 Object to merge
11
- * @param obj2 Object to merge
12
- */
13
- export declare function deepMerge(obj1: any, obj2: any): any;