@adriansteffan/reactive 0.2.6 → 0.5.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 (156) hide show
  1. package/README.md +796 -229
  2. package/bin/add.js +56 -0
  3. package/bin/deploy.js +48 -0
  4. package/bin/download.js +28 -0
  5. package/bin/ghsetup.js +21 -0
  6. package/bin/native.js +81 -0
  7. package/bin/setup.js +11 -17
  8. package/bin/study-deploy.js +60 -0
  9. package/bin/undeploy.js +15 -0
  10. package/extras/transcription/compose.yaml +32 -0
  11. package/{template → extras}/transcription/transcribe.py +4 -9
  12. package/package.json +62 -64
  13. package/src/bun-env.d.ts +1 -0
  14. package/src/bun-plugin.ts +22 -0
  15. package/src/components/canvasblock.tsx +209 -537
  16. package/src/components/checkdevice.tsx +64 -84
  17. package/src/components/fullscreenblock.tsx +130 -0
  18. package/src/components/icons.tsx +50 -0
  19. package/src/components/index.ts +9 -11
  20. package/src/components/microphonecheck.tsx +76 -38
  21. package/src/components/plaininput.tsx +48 -41
  22. package/src/components/prolificending.tsx +64 -28
  23. package/src/components/quest.tsx +89 -87
  24. package/src/components/{randomdotkinetogram.tsx → randomdotkinematogram.tsx} +205 -267
  25. package/src/components/{voicerecorder.tsx → recorder.tsx} +81 -106
  26. package/src/components/requestfilepermission.tsx +63 -0
  27. package/src/components/stimulus.tsx +373 -0
  28. package/src/components/storeui.tsx +94 -148
  29. package/src/components/text.tsx +61 -59
  30. package/src/components/tutorial.tsx +45 -47
  31. package/src/components/upload.tsx +133 -309
  32. package/src/components/voicerecording.tsx +90 -94
  33. package/src/core/backend.ts +20 -0
  34. package/src/core/bytecode.ts +178 -0
  35. package/src/core/columns.ts +50 -0
  36. package/src/core/component.ts +238 -0
  37. package/src/core/development.ts +32 -0
  38. package/src/core/experiment.ts +263 -0
  39. package/src/core/files.ts +291 -0
  40. package/src/core/params.ts +166 -0
  41. package/src/core/platform.ts +29 -0
  42. package/src/core/rows.ts +106 -0
  43. package/src/core/simulation.ts +158 -0
  44. package/src/core/slides.ts +178 -0
  45. package/src/core/store.ts +22 -0
  46. package/src/core/timeline.ts +399 -0
  47. package/src/fonts/AtkinsonHyperlegible-Bold.woff2 +0 -0
  48. package/src/fonts/AtkinsonHyperlegible-BoldItalic.woff2 +0 -0
  49. package/src/fonts/AtkinsonHyperlegible-Italic.woff2 +0 -0
  50. package/src/fonts/AtkinsonHyperlegible-Regular.woff2 +0 -0
  51. package/src/index.css +5 -7
  52. package/src/mod.tsx +31 -17
  53. package/src/native.ts +127 -0
  54. package/src/quest.ts +2 -0
  55. package/src/runner/contexts.ts +35 -0
  56. package/src/runner/devpanel.tsx +68 -0
  57. package/src/runner/experimentrunner.tsx +210 -0
  58. package/src/runner/fullscreenguard.tsx +93 -0
  59. package/src/runner/paraminput.tsx +86 -0
  60. package/src/runner/progressbar.tsx +20 -0
  61. package/src/runner/settingsscreen.tsx +517 -0
  62. package/src/{utils → runner}/theme.ts +9 -8
  63. package/src/server.ts +93 -0
  64. package/src/tutorial.ts +3 -0
  65. package/src/utils/array.ts +30 -62
  66. package/src/utils/canvas.ts +66 -0
  67. package/src/utils/ddm.ts +47 -70
  68. package/src/utils/distributions.ts +352 -61
  69. package/src/utils/fullscreen.ts +38 -0
  70. package/src/utils/ids.ts +11 -0
  71. package/src/utils/keys.ts +46 -0
  72. package/src/utils/llm.ts +15 -15
  73. package/src/utils/time.ts +12 -0
  74. package/src/utils/tts.ts +24 -24
  75. package/template/.dockerignore +3 -1
  76. package/template/.env.example +5 -0
  77. package/template/.github/workflows/deploy.yml +25 -0
  78. package/template/.gitignore +14 -0
  79. package/template/Dockerfile +9 -14
  80. package/template/README.md +74 -214
  81. package/template/biome.json +34 -0
  82. package/template/build.ts +20 -0
  83. package/template/bunfig.toml +3 -0
  84. package/template/docker-compose.yaml +4 -33
  85. package/template/index.html +2 -2
  86. package/template/package.json +16 -89
  87. package/template/public/.gitkeep +0 -0
  88. package/template/server.ts +32 -0
  89. package/template/simulate.ts +4 -44
  90. package/template/src/Experiment.tsx +76 -128
  91. package/template/src/bun-env.d.ts +1 -0
  92. package/template/src/index.css +1 -9
  93. package/template/src/main.tsx +25 -10
  94. package/template/tsconfig.json +4 -6
  95. package/.claude/settings.local.json +0 -61
  96. package/.eslintrc.cjs +0 -18
  97. package/.playwright-mcp/console-2026-04-07T14-22-59-060Z.log +0 -1
  98. package/.prettierrc +0 -5
  99. package/Dockerfile +0 -20
  100. package/dist/mod-HDegGPrf.js +0 -87434
  101. package/dist/mod.d.ts +0 -946
  102. package/dist/reactive.es.js +0 -87
  103. package/dist/reactive.umd.js +0 -10255
  104. package/dist/style.css +0 -5
  105. package/dist/web-7BbR1Ad7.js +0 -435
  106. package/dist/web-CATfZO1Q.js +0 -12
  107. package/planned.md +0 -103
  108. package/postcss.config.js +0 -6
  109. package/raw-loader-hooks.mjs +0 -25
  110. package/raw-loader.mjs +0 -5
  111. package/rdk_doc.md +0 -341
  112. package/src/components/enterfullscreen.tsx +0 -230
  113. package/src/components/exitfullscreen.tsx +0 -113
  114. package/src/components/experimentprovider.tsx +0 -69
  115. package/src/components/experimentrunner.tsx +0 -497
  116. package/src/components/mobilefilepermission.tsx +0 -68
  117. package/src/components/settingsscreen.tsx +0 -770
  118. package/src/types/array.d.ts +0 -6
  119. package/src/utils/audiodevice.ts +0 -4
  120. package/src/utils/bytecode.ts +0 -261
  121. package/src/utils/common.ts +0 -291
  122. package/src/utils/ddm.test.ts +0 -233
  123. package/src/utils/distributions.test.ts +0 -209
  124. package/src/utils/nodecompat.ts +0 -11
  125. package/src/utils/overlays.ts +0 -19
  126. package/src/utils/request.ts +0 -25
  127. package/src/utils/simulation.ts +0 -299
  128. package/src/utils/upload.ts +0 -275
  129. package/src/vite-env.d.ts +0 -1
  130. package/template/.env.template +0 -2
  131. package/template/.eslintrc.cjs +0 -18
  132. package/template/.prettierrc +0 -5
  133. package/template/backend/package-lock.json +0 -2544
  134. package/template/backend/package.json +0 -31
  135. package/template/backend/src/backend.ts +0 -131
  136. package/template/backend/tsconfig.json +0 -110
  137. package/template/capacitor.config.ts +0 -15
  138. package/template/electron/main.js +0 -131
  139. package/template/electron/preload.js +0 -9
  140. package/template/electron.vite.config.js +0 -45
  141. package/template/package-lock.json +0 -12467
  142. package/template/postcss.config.js +0 -5
  143. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Bold.ttf +0 -0
  144. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-BoldItalic.ttf +0 -0
  145. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Italic.ttf +0 -0
  146. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Regular.ttf +0 -0
  147. package/template/shared.vite.config.js +0 -39
  148. package/template/src/vite-env.d.ts +0 -2
  149. package/template/tsconfig.node.json +0 -12
  150. package/template/vite.config.js +0 -11
  151. package/tsconfig.json +0 -30
  152. package/tsconfig.node.json +0 -12
  153. package/vite.config.ts +0 -39
  154. /package/{template → extras}/transcription/Dockerfile.cpu +0 -0
  155. /package/{template → extras}/transcription/Dockerfile.gpu +0 -0
  156. /package/{template/public/Atkinson_Hyperlegible → src/fonts}/OFL.txt +0 -0
@@ -1,233 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { simulateDDMTrial, mapDDMChoice } from './ddm';
3
- import { seedDistributions } from './distributions';
4
-
5
- beforeEach(() => {
6
- seedDistributions(42);
7
- });
8
-
9
- const baseParams = {
10
- driftRate: 0.003,
11
- boundaries: 0.1 as const,
12
- startingPoint: 0,
13
- noiseLevel: 0.003,
14
- timeLimit: 2000,
15
- stimOffset: 2000,
16
- postStimStrategy: { type: 'continue' as const },
17
- };
18
-
19
- describe('simulateDDMTrial', () => {
20
- it('returns a valid result shape', () => {
21
- const result = simulateDDMTrial(baseParams);
22
- expect([0, 1, null]).toContain(result.choice);
23
- expect(result.rt).toBeGreaterThan(0);
24
- expect(typeof result.finalEvidence).toBe('number');
25
- expect(result.isContaminated).toBe(false);
26
- });
27
-
28
- it('is reproducible with the same seed', () => {
29
- seedDistributions(99);
30
- const a = simulateDDMTrial(baseParams);
31
- seedDistributions(99);
32
- const b = simulateDDMTrial(baseParams);
33
- expect(a).toEqual(b);
34
- });
35
-
36
- it('rt includes sensory and motor delays', () => {
37
- const result = simulateDDMTrial({
38
- ...baseParams,
39
- driftRate: 1, // very high drift for instant decision
40
- sensoryDelay: 100,
41
- motorDelay: 50,
42
- });
43
- expect(result.rt).toBeGreaterThanOrEqual(150);
44
- });
45
-
46
- it('clamps sensory and motor delays to >= 0', () => {
47
- const result = simulateDDMTrial({
48
- ...baseParams,
49
- driftRate: 1,
50
- sensoryDelay: { type: 'normal', mean: -1000, sd: 1 },
51
- motorDelay: { type: 'normal', mean: -1000, sd: 1 },
52
- });
53
- expect(result.rt).toBeGreaterThanOrEqual(0);
54
- });
55
-
56
- it('clamps noise level to >= 0', () => {
57
- // Should not throw even with a negative noise param
58
- const result = simulateDDMTrial({
59
- ...baseParams,
60
- noiseLevel: { type: 'normal', mean: -10, sd: 0.1 },
61
- });
62
- expect(result).toBeDefined();
63
- });
64
-
65
- it('returns null choice on timeout', () => {
66
- const result = simulateDDMTrial({
67
- ...baseParams,
68
- driftRate: 0,
69
- noiseLevel: 0, // no noise, no drift — never reaches boundary
70
- timeLimit: 100,
71
- });
72
- expect(result.choice).toBeNull();
73
- expect(result.rt).toBe(100);
74
- });
75
-
76
- it('supports asymmetric boundaries', () => {
77
- const result = simulateDDMTrial({
78
- ...baseParams,
79
- boundaries: [-0.05, 0.2], // lower closer, upper farther
80
- driftRate: 0,
81
- noiseLevel: 0.01,
82
- });
83
- expect([0, 1, null]).toContain(result.choice);
84
- });
85
-
86
- it('contamination returns isContaminated with valid rt', () => {
87
- const result = simulateDDMTrial({ ...baseParams, contaminationRate: 1.0 });
88
- expect(result.isContaminated).toBe(true);
89
- expect(result.rt).toBeGreaterThanOrEqual(0);
90
- expect(result.rt).toBeLessThanOrEqual(baseParams.timeLimit);
91
- });
92
-
93
- it('contamination sets finalEvidence to startingPoint', () => {
94
- const result = simulateDDMTrial({
95
- ...baseParams,
96
- startingPoint: 0.05,
97
- contaminationRate: 1.0,
98
- });
99
- expect(result.isContaminated).toBe(true);
100
- expect(result.finalEvidence).toBe(0.05);
101
- });
102
- });
103
-
104
- describe('snapshot strategy', () => {
105
- it('forces choice at stimOffset based on boundary proximity', () => {
106
- const result = simulateDDMTrial({
107
- ...baseParams,
108
- driftRate: 0.01, // positive drift, evidence moves toward upper
109
- stimOffset: 50,
110
- postStimStrategy: { type: 'snapshot' },
111
- });
112
- expect([0, 1]).toContain(result.choice);
113
- expect(result.isContaminated).toBe(false);
114
- });
115
-
116
- it('rt reflects stimOffset timing, not timeLimit', () => {
117
- const result = simulateDDMTrial({
118
- ...baseParams,
119
- driftRate: 0.0001, // slow drift, won't hit boundary before stimOffset
120
- noiseLevel: 0.0001,
121
- sensoryDelay: 0,
122
- motorDelay: 100,
123
- stimOffset: 200,
124
- timeLimit: 5000,
125
- postStimStrategy: { type: 'snapshot' },
126
- });
127
- // rt should be around stimOffset + motorDelay, not timeLimit
128
- expect(result.rt).toBeLessThan(5000);
129
- expect(result.rt).toBeGreaterThanOrEqual(200);
130
- });
131
- });
132
-
133
- describe('continue strategy', () => {
134
- it('defaults to zero drift after stimOffset', () => {
135
- // With zero drift and no noise after stimOffset, evidence should freeze
136
- const result = simulateDDMTrial({
137
- ...baseParams,
138
- driftRate: 0,
139
- noiseLevel: 0,
140
- stimOffset: 10,
141
- timeLimit: 100,
142
- postStimStrategy: { type: 'continue' },
143
- });
144
- expect(result.choice).toBeNull(); // no drift, no noise — timeout
145
- });
146
-
147
- });
148
-
149
- describe('collapse strategy', () => {
150
- it('eventually forces a decision', () => {
151
- const result = simulateDDMTrial({
152
- ...baseParams,
153
- driftRate: 0,
154
- noiseLevel: 0.001,
155
- stimOffset: 0,
156
- timeLimit: 10000,
157
- postStimStrategy: {
158
- type: 'collapse',
159
- collapseDef: { rate: 0.001 },
160
- },
161
- });
162
- // Boundaries collapse, must eventually reach evidence
163
- expect([0, 1]).toContain(result.choice);
164
- });
165
-
166
- it('respects collapse delay', () => {
167
- const fast = simulateDDMTrial({
168
- ...baseParams,
169
- driftRate: 0,
170
- noiseLevel: 0.0001,
171
- stimOffset: 0,
172
- timeLimit: 10000,
173
- postStimStrategy: {
174
- type: 'collapse',
175
- collapseDef: { rate: 0.001, delay: 0 },
176
- },
177
- });
178
- const delayed = simulateDDMTrial({
179
- ...baseParams,
180
- driftRate: 0,
181
- noiseLevel: 0.0001,
182
- stimOffset: 0,
183
- timeLimit: 10000,
184
- postStimStrategy: {
185
- type: 'collapse',
186
- collapseDef: { rate: 0.001, delay: 500 },
187
- },
188
- });
189
- // Delayed collapse should take longer (or at least not be faster)
190
- expect(delayed.rt).toBeGreaterThanOrEqual(fast.rt);
191
- });
192
- });
193
-
194
- describe('mapDDMChoice', () => {
195
- it('returns null for null choice', () => {
196
- expect(mapDDMChoice(null, ['a', 'b'])).toBeNull();
197
- });
198
-
199
- it('returns null for empty validKeys', () => {
200
- expect(mapDDMChoice(1, [])).toBeNull();
201
- });
202
-
203
- it('maps choice 1 to correct key', () => {
204
- const key = mapDDMChoice(1, ['a', 'b'], 'a');
205
- expect(key).toBe('a');
206
- });
207
-
208
- it('maps choice 0 to incorrect key', () => {
209
- const key = mapDDMChoice(0, ['a', 'b'], 'a');
210
- expect(key).toBe('b');
211
- });
212
-
213
- it('handles case-insensitive correctResponse', () => {
214
- const key = mapDDMChoice(1, ['A', 'b'], 'a');
215
- expect(key?.toLowerCase()).toBe('a');
216
- });
217
-
218
- it('handles array correctResponse', () => {
219
- const key = mapDDMChoice(1, ['a', 'b', 'c'], ['a', 'b']);
220
- expect(['a', 'b']).toContain(key);
221
- });
222
-
223
- it('returns random key when no correctResponse', () => {
224
- const key = mapDDMChoice(1, ['a', 'b']);
225
- expect(['a', 'b']).toContain(key);
226
- });
227
-
228
- it('falls back to any key when no matching keys for choice', () => {
229
- // choice 0 (incorrect), but all keys are correct — no wrong keys available
230
- const key = mapDDMChoice(0, ['a'], 'a');
231
- expect(key).toBe('a');
232
- });
233
- });
@@ -1,209 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { sobol, halton, seedDistributions, normal, uniform, poisson, sampleParticipants } from './distributions';
3
-
4
- // Known Sobol sequence values (1D, Van der Corput base 2, skipping the zero point)
5
- // Reference: https://en.wikipedia.org/wiki/Van_der_Corput_sequence
6
- const SOBOL_1D_EXPECTED = [0.5, 0.75, 0.25, 0.375, 0.875, 0.625, 0.125, 0.1875];
7
-
8
- // Known Halton sequence values (base 2 and 3, skipping the zero point)
9
- // Reference: https://en.wikipedia.org/wiki/Halton_sequence
10
- const HALTON_2D_EXPECTED = [
11
- [0.5, 1 / 3],
12
- [0.25, 2 / 3],
13
- [0.75, 1 / 9],
14
- [0.125, 4 / 9],
15
- [0.625, 7 / 9],
16
- ];
17
-
18
- describe('sobol', () => {
19
- it('produces known 1D Van der Corput values', () => {
20
- const result = sobol(8, [{ distribution: 'uniform', min: 0, max: 1 }]) as number[];
21
- expect(result).toHaveLength(8);
22
- for (let i = 0; i < SOBOL_1D_EXPECTED.length; i++) {
23
- expect(result[i]).toBeCloseTo(SOBOL_1D_EXPECTED[i], 10);
24
- }
25
- });
26
-
27
- it('produces known 2D values', () => {
28
- const result = sobol(4, [
29
- { distribution: 'uniform', min: 0, max: 1 },
30
- { distribution: 'uniform', min: 0, max: 1 },
31
- ]) as number[][];
32
- // First 2D Sobol points (after skipping zero): [0.5, 0.5], [0.75, 0.25], [0.25, 0.75]
33
- expect(result[0]).toEqual([expect.closeTo(0.5, 10), expect.closeTo(0.5, 10)]);
34
- expect(result[1]).toEqual([expect.closeTo(0.75, 10), expect.closeTo(0.25, 10)]);
35
- expect(result[2]).toEqual([expect.closeTo(0.25, 10), expect.closeTo(0.75, 10)]);
36
- });
37
-
38
- it('scales uniform dimensions correctly', () => {
39
- const result = sobol(3, [{ distribution: 'uniform', min: 200, max: 800 }]) as number[];
40
- // 0.5 * 600 + 200 = 500, 0.75 * 600 + 200 = 650, 0.25 * 600 + 200 = 350
41
- expect(result[0]).toBeCloseTo(500, 10);
42
- expect(result[1]).toBeCloseTo(650, 10);
43
- expect(result[2]).toBeCloseTo(350, 10);
44
- });
45
-
46
- it('produces correct count of points', () => {
47
- const result = sobol(100, [{ distribution: 'uniform', min: 0, max: 1 }]) as number[];
48
- expect(result).toHaveLength(100);
49
- });
50
-
51
- it('returns flat array for 1D, nested for multi-D', () => {
52
- const r1 = sobol(3, [{ distribution: 'uniform', min: 0, max: 1 }]);
53
- expect(typeof r1[0]).toBe('number');
54
-
55
- const r2 = sobol(3, [
56
- { distribution: 'uniform', min: 0, max: 1 },
57
- { distribution: 'uniform', min: 0, max: 1 },
58
- ]);
59
- expect(Array.isArray(r2[0])).toBe(true);
60
- });
61
-
62
- it('all 1D values are in [0, 1] for unit range', () => {
63
- const result = sobol(1000, [{ distribution: 'uniform', min: 0, max: 1 }]) as number[];
64
- for (const v of result) {
65
- expect(v).toBeGreaterThanOrEqual(0);
66
- expect(v).toBeLessThan(1);
67
- }
68
- });
69
-
70
- it('produces no duplicate points in 2D', () => {
71
- const result = sobol(100, [
72
- { distribution: 'uniform', min: 0, max: 1 },
73
- { distribution: 'uniform', min: 0, max: 1 },
74
- ]) as number[][];
75
- const keys = new Set(result.map(([a, b]) => `${a},${b}`));
76
- expect(keys.size).toBe(100);
77
- });
78
-
79
- it('is deterministic (same call twice gives same result)', () => {
80
- const a = sobol(50, [{ distribution: 'uniform', min: 0, max: 1 }]);
81
- const b = sobol(50, [{ distribution: 'uniform', min: 0, max: 1 }]);
82
- expect(a).toEqual(b);
83
- });
84
-
85
- it('throws for dimensions > 21', () => {
86
- const specs = Array.from({ length: 22 }, () => ({ distribution: 'uniform' as const, min: 0, max: 1 }));
87
- expect(() => sobol(10, specs)).toThrow('1-21 dimensions');
88
- });
89
- });
90
-
91
- describe('halton', () => {
92
- it('produces known 2D values (bases 2, 3)', () => {
93
- const result = halton(5, [
94
- { distribution: 'uniform', min: 0, max: 1 },
95
- { distribution: 'uniform', min: 0, max: 1 },
96
- ]) as number[][];
97
- for (let i = 0; i < HALTON_2D_EXPECTED.length; i++) {
98
- expect(result[i][0]).toBeCloseTo(HALTON_2D_EXPECTED[i][0], 10);
99
- expect(result[i][1]).toBeCloseTo(HALTON_2D_EXPECTED[i][1], 10);
100
- }
101
- });
102
-
103
- it('is deterministic', () => {
104
- const a = halton(50, [{ distribution: 'uniform', min: 0, max: 1 }]);
105
- const b = halton(50, [{ distribution: 'uniform', min: 0, max: 1 }]);
106
- expect(a).toEqual(b);
107
- });
108
- });
109
-
110
- describe('normal distribution spec', () => {
111
- it('produces values centered around the mean', () => {
112
- const result = sobol(1000, [{ distribution: 'normal', mean: 500, sd: 100 }]) as number[];
113
- const avg = result.reduce((a, b) => a + b, 0) / result.length;
114
- expect(avg).toBeCloseTo(500, 0);
115
- });
116
-
117
- it('median is close to mean (symmetric distribution)', () => {
118
- const result = sobol(1000, [{ distribution: 'normal', mean: 500, sd: 100 }]) as number[];
119
- const sorted = [...result].sort((a, b) => a - b);
120
- const median = sorted[500];
121
- expect(median).toBeCloseTo(500, 0);
122
- });
123
- });
124
-
125
- describe('poisson distribution spec', () => {
126
- it('produces non-negative integers', () => {
127
- const result = sobol(100, [{ distribution: 'poisson', mean: 5 }]) as number[];
128
- for (const v of result) {
129
- expect(v).toBeGreaterThanOrEqual(0);
130
- expect(Number.isInteger(v)).toBe(true);
131
- }
132
- });
133
-
134
- it('mean is close to lambda', () => {
135
- const result = sobol(1000, [{ distribution: 'poisson', mean: 5 }]) as number[];
136
- const avg = result.reduce((a, b) => a + b, 0) / result.length;
137
- expect(avg).toBeCloseTo(5, 0);
138
- });
139
- });
140
-
141
- describe('sampleParticipants', () => {
142
- it('returns objects with the correct keys', () => {
143
- const result = sampleParticipants('sobol', 5, {
144
- rtMean: { distribution: 'normal', mean: 500, sd: 100 },
145
- threshold: { distribution: 'uniform', min: 0.3, max: 0.7 },
146
- });
147
- expect(result).toHaveLength(5);
148
- for (const p of result) {
149
- expect(p).toHaveProperty('rtMean');
150
- expect(p).toHaveProperty('threshold');
151
- expect(typeof p.rtMean).toBe('number');
152
- expect(typeof p.threshold).toBe('number');
153
- }
154
- });
155
-
156
- it('sobol produces deterministic results', () => {
157
- const a = sampleParticipants('sobol', 10, { x: { distribution: 'uniform', min: 0, max: 1 } });
158
- const b = sampleParticipants('sobol', 10, { x: { distribution: 'uniform', min: 0, max: 1 } });
159
- expect(a).toEqual(b);
160
- });
161
-
162
- it('halton produces deterministic results', () => {
163
- const a = sampleParticipants('halton', 10, { x: { distribution: 'uniform', min: 0, max: 1 } });
164
- const b = sampleParticipants('halton', 10, { x: { distribution: 'uniform', min: 0, max: 1 } });
165
- expect(a).toEqual(b);
166
- });
167
-
168
- it('random method produces valid values', () => {
169
- const result = sampleParticipants('random', 50, {
170
- score: { distribution: 'poisson', mean: 5 },
171
- });
172
- expect(result).toHaveLength(50);
173
- for (const p of result) {
174
- expect(Number.isInteger(p.score)).toBe(true);
175
- expect(p.score).toBeGreaterThanOrEqual(0);
176
- }
177
- });
178
-
179
- it('works with a single dimension', () => {
180
- const result = sampleParticipants('sobol', 3, {
181
- rt: { distribution: 'uniform', min: 200, max: 800 },
182
- });
183
- expect(result[0].rt).toBeCloseTo(500, 10);
184
- expect(result[1].rt).toBeCloseTo(650, 10);
185
- expect(result[2].rt).toBeCloseTo(350, 10);
186
- });
187
- });
188
-
189
- describe('seedDistributions', () => {
190
- it('makes pseudorandom samplers reproducible', () => {
191
- seedDistributions(42);
192
- const a = [normal(0, 1), uniform(0, 10), poisson(5)];
193
-
194
- seedDistributions(42);
195
- const b = [normal(0, 1), uniform(0, 10), poisson(5)];
196
-
197
- expect(a).toEqual(b);
198
- });
199
-
200
- it('different seeds produce different sequences', () => {
201
- seedDistributions(1);
202
- const a = normal(0, 1);
203
-
204
- seedDistributions(2);
205
- const b = normal(0, 1);
206
-
207
- expect(a).not.toBe(b);
208
- });
209
- });
@@ -1,11 +0,0 @@
1
- // Creates a require() function for loading Node builtins (fs, path, etc.) at runtime.
2
- // Needed because these files are bundled as ESM by Vite, where require doesn't exist.
3
- // Only initialized when called (simulation time), not on import (safe in browser).
4
- let _require: ((id: string) => any) | null = null;
5
- export async function getNodeRequire(): Promise<(id: string) => any> {
6
- if (!_require) {
7
- const mod = await import(/* @vite-ignore */ 'module') as any;
8
- _require = mod.createRequire(import.meta.url);
9
- }
10
- return _require!;
11
- }
@@ -1,19 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { ComponentType } from 'react';
3
- import { Store } from './common';
4
-
5
- export interface OverlayProps {
6
- store: Store;
7
- updateStore: (mergeIn: Store) => void;
8
- data: any[];
9
- }
10
-
11
- const registry: ComponentType<OverlayProps>[] = [];
12
-
13
- export function registerOverlay(component: ComponentType<OverlayProps>) {
14
- if (!registry.includes(component)) registry.push(component);
15
- }
16
-
17
- export function getOverlays() {
18
- return [...registry];
19
- }
@@ -1,25 +0,0 @@
1
- const BACKEND_ROUTE = "/backend";
2
-
3
- export async function post(endpoint: string, body: object | FormData) {
4
- if (body instanceof FormData) {
5
- return await fetch(`${BACKEND_ROUTE}${endpoint}`, {
6
- method: 'POST',
7
- body,
8
- });
9
- } else {
10
- return fetch(`${BACKEND_ROUTE}${endpoint}`, {
11
- method: 'POST',
12
- headers: { 'Content-Type': 'application/json' },
13
- body: JSON.stringify(body),
14
- });
15
- }
16
- }
17
-
18
- export async function get(endpoint: string) {
19
- const res = await fetch(`${BACKEND_ROUTE}${endpoint}`);
20
- return res;
21
- }
22
-
23
- export async function getJson(endpoint: string) {
24
- return await (await get(endpoint)).json();
25
- }