@adriansteffan/reactive 0.2.7 → 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.
- package/README.md +796 -229
- package/bin/add.js +56 -0
- package/bin/deploy.js +48 -0
- package/bin/download.js +28 -0
- package/bin/ghsetup.js +21 -0
- package/bin/native.js +81 -0
- package/bin/setup.js +11 -17
- package/bin/study-deploy.js +60 -0
- package/bin/undeploy.js +15 -0
- package/extras/transcription/compose.yaml +32 -0
- package/{template → extras}/transcription/transcribe.py +4 -9
- package/package.json +62 -64
- package/src/bun-env.d.ts +1 -0
- package/src/bun-plugin.ts +22 -0
- package/src/components/canvasblock.tsx +209 -537
- package/src/components/checkdevice.tsx +64 -84
- package/src/components/fullscreenblock.tsx +130 -0
- package/src/components/icons.tsx +50 -0
- package/src/components/index.ts +9 -11
- package/src/components/microphonecheck.tsx +76 -38
- package/src/components/plaininput.tsx +45 -40
- package/src/components/prolificending.tsx +64 -28
- package/src/components/quest.tsx +89 -87
- package/src/components/{randomdotkinetogram.tsx → randomdotkinematogram.tsx} +205 -267
- package/src/components/{voicerecorder.tsx → recorder.tsx} +81 -106
- package/src/components/requestfilepermission.tsx +63 -0
- package/src/components/stimulus.tsx +373 -0
- package/src/components/storeui.tsx +94 -148
- package/src/components/text.tsx +61 -59
- package/src/components/tutorial.tsx +45 -47
- package/src/components/upload.tsx +133 -309
- package/src/components/voicerecording.tsx +90 -94
- package/src/core/backend.ts +20 -0
- package/src/core/bytecode.ts +178 -0
- package/src/core/columns.ts +50 -0
- package/src/core/component.ts +238 -0
- package/src/core/development.ts +32 -0
- package/src/core/experiment.ts +263 -0
- package/src/core/files.ts +291 -0
- package/src/core/params.ts +166 -0
- package/src/core/platform.ts +29 -0
- package/src/core/rows.ts +106 -0
- package/src/core/simulation.ts +158 -0
- package/src/core/slides.ts +178 -0
- package/src/core/store.ts +22 -0
- package/src/core/timeline.ts +399 -0
- package/src/fonts/AtkinsonHyperlegible-Bold.woff2 +0 -0
- package/src/fonts/AtkinsonHyperlegible-BoldItalic.woff2 +0 -0
- package/src/fonts/AtkinsonHyperlegible-Italic.woff2 +0 -0
- package/src/fonts/AtkinsonHyperlegible-Regular.woff2 +0 -0
- package/src/index.css +5 -7
- package/src/mod.tsx +31 -17
- package/src/native.ts +127 -0
- package/src/quest.ts +2 -0
- package/src/runner/contexts.ts +35 -0
- package/src/runner/devpanel.tsx +68 -0
- package/src/runner/experimentrunner.tsx +210 -0
- package/src/runner/fullscreenguard.tsx +93 -0
- package/src/runner/paraminput.tsx +86 -0
- package/src/runner/progressbar.tsx +20 -0
- package/src/runner/settingsscreen.tsx +517 -0
- package/src/{utils → runner}/theme.ts +9 -8
- package/src/server.ts +93 -0
- package/src/tutorial.ts +3 -0
- package/src/utils/array.ts +30 -62
- package/src/utils/canvas.ts +66 -0
- package/src/utils/ddm.ts +47 -70
- package/src/utils/distributions.ts +352 -61
- package/src/utils/fullscreen.ts +38 -0
- package/src/utils/ids.ts +11 -0
- package/src/utils/keys.ts +46 -0
- package/src/utils/llm.ts +15 -15
- package/src/utils/time.ts +12 -0
- package/src/utils/tts.ts +24 -24
- package/template/.dockerignore +3 -1
- package/template/.env.example +5 -0
- package/template/.github/workflows/deploy.yml +25 -0
- package/template/.gitignore +14 -0
- package/template/Dockerfile +9 -14
- package/template/README.md +74 -214
- package/template/biome.json +34 -0
- package/template/build.ts +20 -0
- package/template/bunfig.toml +3 -0
- package/template/docker-compose.yaml +4 -33
- package/template/index.html +2 -2
- package/template/package.json +16 -89
- package/template/public/.gitkeep +0 -0
- package/template/server.ts +32 -0
- package/template/simulate.ts +4 -44
- package/template/src/Experiment.tsx +76 -128
- package/template/src/bun-env.d.ts +1 -0
- package/template/src/index.css +1 -9
- package/template/src/main.tsx +25 -10
- package/template/tsconfig.json +4 -6
- package/.claude/settings.local.json +0 -61
- package/.eslintrc.cjs +0 -18
- package/.playwright-mcp/console-2026-04-07T14-22-59-060Z.log +0 -1
- package/.playwright-mcp/console-2026-09-20T12-17-32-043Z.log +0 -1
- package/.playwright-mcp/page-2026-09-20T12-17-32-084Z.yml +0 -10
- package/.prettierrc +0 -5
- package/Dockerfile +0 -20
- package/dist/mod-BTpABl23.js +0 -87435
- package/dist/mod.d.ts +0 -947
- package/dist/reactive.es.js +0 -87
- package/dist/reactive.umd.js +0 -10255
- package/dist/style.css +0 -5
- package/dist/web-DV4cj_8Q.js +0 -435
- package/dist/web-DprbPn6i.js +0 -12
- package/planned.md +0 -103
- package/postcss.config.js +0 -6
- package/raw-loader-hooks.mjs +0 -25
- package/raw-loader.mjs +0 -5
- package/rdk_doc.md +0 -341
- package/src/components/enterfullscreen.tsx +0 -230
- package/src/components/exitfullscreen.tsx +0 -113
- package/src/components/experimentprovider.tsx +0 -69
- package/src/components/experimentrunner.tsx +0 -497
- package/src/components/mobilefilepermission.tsx +0 -68
- package/src/components/settingsscreen.tsx +0 -770
- package/src/types/array.d.ts +0 -6
- package/src/utils/audiodevice.ts +0 -4
- package/src/utils/bytecode.ts +0 -261
- package/src/utils/common.ts +0 -291
- package/src/utils/ddm.test.ts +0 -233
- package/src/utils/distributions.test.ts +0 -209
- package/src/utils/nodecompat.ts +0 -11
- package/src/utils/overlays.ts +0 -19
- package/src/utils/request.ts +0 -25
- package/src/utils/simulation.ts +0 -299
- package/src/utils/upload.ts +0 -275
- package/src/vite-env.d.ts +0 -1
- package/template/.env.template +0 -2
- package/template/.eslintrc.cjs +0 -18
- package/template/.prettierrc +0 -5
- package/template/backend/package-lock.json +0 -2544
- package/template/backend/package.json +0 -31
- package/template/backend/src/backend.ts +0 -131
- package/template/backend/tsconfig.json +0 -110
- package/template/capacitor.config.ts +0 -15
- package/template/electron/main.js +0 -131
- package/template/electron/preload.js +0 -9
- package/template/electron.vite.config.js +0 -45
- package/template/package-lock.json +0 -12467
- package/template/postcss.config.js +0 -5
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Bold.ttf +0 -0
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-BoldItalic.ttf +0 -0
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Italic.ttf +0 -0
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Regular.ttf +0 -0
- package/template/shared.vite.config.js +0 -39
- package/template/src/vite-env.d.ts +0 -2
- package/template/tsconfig.node.json +0 -12
- package/template/vite.config.js +0 -11
- package/tsconfig.json +0 -30
- package/tsconfig.node.json +0 -12
- package/vite.config.ts +0 -39
- /package/{template → extras}/transcription/Dockerfile.cpu +0 -0
- /package/{template → extras}/transcription/Dockerfile.gpu +0 -0
- /package/{template/public/Atkinson_Hyperlegible → src/fonts}/OFL.txt +0 -0
package/src/types/array.d.ts
DELETED
package/src/utils/audiodevice.ts
DELETED
package/src/utils/bytecode.ts
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
export type Store = Record<string, any>;
|
|
2
|
-
|
|
3
|
-
type BaseTrialData = {
|
|
4
|
-
index: number;
|
|
5
|
-
trialNumber: number;
|
|
6
|
-
start: number;
|
|
7
|
-
end: number;
|
|
8
|
-
duration: number;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type ComponentResultData = BaseTrialData & {
|
|
12
|
-
type: string;
|
|
13
|
-
name: string;
|
|
14
|
-
/** Per-trial override for which CSV file(s) this trial's data goes into. When set on a timeline item, overrides the component type's default from the flattener registry. */
|
|
15
|
-
csv?: string | string[];
|
|
16
|
-
responseData?: any;
|
|
17
|
-
metadata?: Record<string, any>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type CanvasResultData = BaseTrialData & {
|
|
21
|
-
metadata?: Record<string, any>;
|
|
22
|
-
key: string | null;
|
|
23
|
-
reactionTime: number | null;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type TrialResult = ComponentResultData | CanvasResultData;
|
|
27
|
-
|
|
28
|
-
export interface MarkerItem {
|
|
29
|
-
type: 'MARKER';
|
|
30
|
-
id: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type ConditionalFunction = (data?: TrialResult[], store?: Store) => boolean;
|
|
34
|
-
|
|
35
|
-
export type StoreUpdateFunction = (data?: TrialResult[], store?: Store) => Record<string, any>;
|
|
36
|
-
|
|
37
|
-
export interface IfGotoItem {
|
|
38
|
-
type: 'IF_GOTO';
|
|
39
|
-
cond: ConditionalFunction;
|
|
40
|
-
marker: string;
|
|
41
|
-
}
|
|
42
|
-
export interface UpdateStoreItem {
|
|
43
|
-
type: 'UPDATE_STORE';
|
|
44
|
-
fun: StoreUpdateFunction;
|
|
45
|
-
}
|
|
46
|
-
export interface IfBlockItem {
|
|
47
|
-
type: 'IF_BLOCK';
|
|
48
|
-
cond: ConditionalFunction;
|
|
49
|
-
timeline: TimelineItem[];
|
|
50
|
-
}
|
|
51
|
-
export interface WhileBlockItem {
|
|
52
|
-
type: 'WHILE_BLOCK';
|
|
53
|
-
cond: ConditionalFunction;
|
|
54
|
-
timeline: TimelineItem[];
|
|
55
|
-
}
|
|
56
|
-
export type ControlFlowItem =
|
|
57
|
-
| MarkerItem
|
|
58
|
-
| IfGotoItem
|
|
59
|
-
| UpdateStoreItem
|
|
60
|
-
| IfBlockItem
|
|
61
|
-
| WhileBlockItem;
|
|
62
|
-
export type TimelineItem = ControlFlowItem | any;
|
|
63
|
-
|
|
64
|
-
export interface ExecuteContentInstruction {
|
|
65
|
-
type: 'ExecuteContent';
|
|
66
|
-
content: any;
|
|
67
|
-
}
|
|
68
|
-
export interface IfGotoInstruction {
|
|
69
|
-
type: 'IfGoto';
|
|
70
|
-
cond: (store: Store, data: TrialResult[]) => boolean;
|
|
71
|
-
marker: string;
|
|
72
|
-
}
|
|
73
|
-
export interface UpdateStoreInstruction {
|
|
74
|
-
type: 'UpdateStore';
|
|
75
|
-
fun: (store: Store, data: TrialResult[]) => Store;
|
|
76
|
-
}
|
|
77
|
-
export type UnifiedBytecodeInstruction =
|
|
78
|
-
| ExecuteContentInstruction
|
|
79
|
-
| IfGotoInstruction
|
|
80
|
-
| UpdateStoreInstruction;
|
|
81
|
-
|
|
82
|
-
function prefixUserMarkers(marker: string): string {
|
|
83
|
-
return `user_${marker}`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function compileTimeline(timeline: TimelineItem[]): {
|
|
87
|
-
instructions: UnifiedBytecodeInstruction[];
|
|
88
|
-
markers: { [key: string]: number };
|
|
89
|
-
} {
|
|
90
|
-
const instructions: UnifiedBytecodeInstruction[] = [];
|
|
91
|
-
const markers: { [key: string]: number } = {};
|
|
92
|
-
let uniqueMarkerCounterForThisRun = 0;
|
|
93
|
-
|
|
94
|
-
function getUniqueMarker(prefix: string): string {
|
|
95
|
-
return `${prefix}_auto_${uniqueMarkerCounterForThisRun++}`;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function adaptCondition(
|
|
99
|
-
userCondition: ConditionalFunction,
|
|
100
|
-
): (store: Store, data: TrialResult[]) => boolean {
|
|
101
|
-
return (runtimeStore: Store, runtimeData: TrialResult[]): boolean => {
|
|
102
|
-
return userCondition(runtimeData, runtimeStore);
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function adaptUpdate(
|
|
107
|
-
userUpdateFunction: StoreUpdateFunction,
|
|
108
|
-
): (store: Store, data: TrialResult[]) => Store {
|
|
109
|
-
return (runtimeStore: Store, runtimeData: TrialResult[]): Store => {
|
|
110
|
-
const updates = userUpdateFunction(runtimeData, runtimeStore);
|
|
111
|
-
if (typeof updates === 'object' && updates !== null) {
|
|
112
|
-
return {
|
|
113
|
-
...runtimeStore,
|
|
114
|
-
...updates,
|
|
115
|
-
};
|
|
116
|
-
} else {
|
|
117
|
-
console.warn('Store update function did not return an object. Store remains unchanged.', {
|
|
118
|
-
data: runtimeData,
|
|
119
|
-
store: runtimeStore,
|
|
120
|
-
});
|
|
121
|
-
return runtimeStore;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function processTimeline(items: TimelineItem[]) {
|
|
127
|
-
for (const item of items) {
|
|
128
|
-
let isControlFlow = false;
|
|
129
|
-
|
|
130
|
-
if (typeof item === 'object' && item !== null && 'type' in item) {
|
|
131
|
-
const itemType = item.type;
|
|
132
|
-
|
|
133
|
-
switch (itemType) {
|
|
134
|
-
case 'MARKER': {
|
|
135
|
-
const markerItem = item as MarkerItem;
|
|
136
|
-
markers[prefixUserMarkers(markerItem.id)] = instructions.length;
|
|
137
|
-
isControlFlow = true;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
case 'IF_GOTO': {
|
|
141
|
-
const ifGotoItem = item as IfGotoItem;
|
|
142
|
-
const runtimeConditionFunc = adaptCondition(ifGotoItem.cond);
|
|
143
|
-
instructions.push({
|
|
144
|
-
type: 'IfGoto',
|
|
145
|
-
cond: runtimeConditionFunc,
|
|
146
|
-
marker: prefixUserMarkers(ifGotoItem.marker),
|
|
147
|
-
});
|
|
148
|
-
isControlFlow = true;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
case 'UPDATE_STORE': {
|
|
152
|
-
const updateStoreItem = item as UpdateStoreItem;
|
|
153
|
-
const runtimeUpdateFunc = adaptUpdate(updateStoreItem.fun);
|
|
154
|
-
instructions.push({
|
|
155
|
-
type: 'UpdateStore',
|
|
156
|
-
fun: runtimeUpdateFunc,
|
|
157
|
-
});
|
|
158
|
-
isControlFlow = true;
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
case 'IF_BLOCK': {
|
|
162
|
-
const ifBlockItem = item as IfBlockItem;
|
|
163
|
-
const endMarker = getUniqueMarker('if_end');
|
|
164
|
-
const runtimeConditionFunc = adaptCondition(ifBlockItem.cond);
|
|
165
|
-
instructions.push({
|
|
166
|
-
type: 'IfGoto',
|
|
167
|
-
cond: (store, data) => !runtimeConditionFunc(store, data),
|
|
168
|
-
marker: endMarker,
|
|
169
|
-
});
|
|
170
|
-
processTimeline(ifBlockItem.timeline);
|
|
171
|
-
markers[endMarker] = instructions.length;
|
|
172
|
-
isControlFlow = true;
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
case 'WHILE_BLOCK': {
|
|
176
|
-
const whileBlockItem = item as WhileBlockItem;
|
|
177
|
-
const startMarker = getUniqueMarker('while_start');
|
|
178
|
-
const endMarker = getUniqueMarker('while_end');
|
|
179
|
-
const runtimeConditionFunc = adaptCondition(whileBlockItem.cond);
|
|
180
|
-
markers[startMarker] = instructions.length;
|
|
181
|
-
instructions.push({
|
|
182
|
-
type: 'IfGoto',
|
|
183
|
-
cond: (store, data) => !runtimeConditionFunc(store, data),
|
|
184
|
-
marker: endMarker,
|
|
185
|
-
});
|
|
186
|
-
processTimeline(whileBlockItem.timeline);
|
|
187
|
-
instructions.push({
|
|
188
|
-
type: 'IfGoto',
|
|
189
|
-
cond: () => true,
|
|
190
|
-
marker: startMarker,
|
|
191
|
-
});
|
|
192
|
-
markers[endMarker] = instructions.length;
|
|
193
|
-
isControlFlow = true;
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (!isControlFlow) {
|
|
200
|
-
instructions.push({
|
|
201
|
-
type: 'ExecuteContent',
|
|
202
|
-
content: item,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
processTimeline(timeline);
|
|
209
|
-
|
|
210
|
-
return { instructions, markers };
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Walks bytecode from `fromPointer`, processing IfGoto and UpdateStore instructions,
|
|
215
|
-
* and returns the pointer of the next ExecuteContent (or past-end if none found).
|
|
216
|
-
*/
|
|
217
|
-
export function applyMetadata<T extends Record<string, any>>(
|
|
218
|
-
trialData: T,
|
|
219
|
-
content: { metadata?: any; nestMetadata?: boolean },
|
|
220
|
-
data: TrialResult[],
|
|
221
|
-
store: Store,
|
|
222
|
-
): T {
|
|
223
|
-
const metadata = typeof content.metadata === 'function' ? content.metadata(data, store) : content.metadata;
|
|
224
|
-
if (content.nestMetadata) return { ...trialData, metadata };
|
|
225
|
-
if (metadata) return { ...metadata, ...trialData };
|
|
226
|
-
return trialData;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export function advanceToNextContent(
|
|
230
|
-
bytecode: { instructions: UnifiedBytecodeInstruction[]; markers: Record<string, number> },
|
|
231
|
-
fromPointer: number,
|
|
232
|
-
getStore: () => Store,
|
|
233
|
-
getData: () => TrialResult[],
|
|
234
|
-
onUpdateStore: (newStore: Store) => void,
|
|
235
|
-
): number {
|
|
236
|
-
let pointer = fromPointer;
|
|
237
|
-
while (pointer < bytecode.instructions.length) {
|
|
238
|
-
const instr = bytecode.instructions[pointer];
|
|
239
|
-
switch (instr.type) {
|
|
240
|
-
case 'ExecuteContent':
|
|
241
|
-
return pointer;
|
|
242
|
-
case 'IfGoto':
|
|
243
|
-
if (instr.cond(getStore(), getData())) {
|
|
244
|
-
const target = bytecode.markers[instr.marker];
|
|
245
|
-
if (target !== undefined) {
|
|
246
|
-
pointer = target;
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
pointer++;
|
|
251
|
-
break;
|
|
252
|
-
case 'UpdateStore':
|
|
253
|
-
onUpdateStore(instr.fun(getStore(), getData()));
|
|
254
|
-
pointer++;
|
|
255
|
-
break;
|
|
256
|
-
default:
|
|
257
|
-
pointer++;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return pointer;
|
|
261
|
-
}
|
package/src/utils/common.ts
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { Capacitor } from '@capacitor/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function now(){
|
|
5
|
-
return Math.round(performance.now());
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function isFullscreen(): boolean {
|
|
9
|
-
const domFs = !!(
|
|
10
|
-
document.fullscreenElement ||
|
|
11
|
-
(document as any).webkitFullscreenElement ||
|
|
12
|
-
(document as any).mozFullScreenElement ||
|
|
13
|
-
(document as any).msFullscreenElement
|
|
14
|
-
);
|
|
15
|
-
if (!domFs) return false;
|
|
16
|
-
// On macOS Chrome, `fullscreenElement` can stay set after ESC exit. When truly
|
|
17
|
-
// in fullscreen, no browser chrome is visible, so outerHeight === innerHeight.
|
|
18
|
-
return Math.abs(window.outerHeight - window.innerHeight) < 5;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function isDesktop() {
|
|
22
|
-
return (window as any).electronAPI !== undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Generic type for all data structures
|
|
26
|
-
export interface TrialData {
|
|
27
|
-
index: number;
|
|
28
|
-
trialNumber: number;
|
|
29
|
-
type: string;
|
|
30
|
-
name: string;
|
|
31
|
-
/** Populated from the timeline item's csv field. Overrides the component type's default CSV target from the flattener registry. */
|
|
32
|
-
csv?: string | string[];
|
|
33
|
-
responseData: any;
|
|
34
|
-
start: number;
|
|
35
|
-
end: number;
|
|
36
|
-
duration: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface FileUpload {
|
|
40
|
-
filename: string;
|
|
41
|
-
content: string;
|
|
42
|
-
encoding?: 'base64' | 'utf8';
|
|
43
|
-
/** Internal flag: file was already eagerly uploaded, skip in upload but include in download. */
|
|
44
|
-
_alreadyUploaded?: boolean;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface ExperimentConfig {
|
|
48
|
-
showProgressBar: boolean;
|
|
49
|
-
theme?: import('./theme').Theme;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface Store {
|
|
53
|
-
[key: string]: any;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface BaseComponentProps {
|
|
57
|
-
next: (data?: object, actualStartTime?: number, actualStopTime?: number) => void;
|
|
58
|
-
data: TrialData[];
|
|
59
|
-
store?: Store;
|
|
60
|
-
updateStore: (mergeIn: Store) => void;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function selectPrevTrialData(data: any[], type?: string): any | undefined {
|
|
64
|
-
if (!type) return data.at(-1);
|
|
65
|
-
for (let i = data.length - 1; i >= 0; i--) {
|
|
66
|
-
if (data[i].type === type) return data[i];
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
type ParamType = 'string' | 'number' | 'boolean' | 'array' | 'json';
|
|
72
|
-
|
|
73
|
-
type ParamValue<T extends ParamType> = T extends 'number'
|
|
74
|
-
? number
|
|
75
|
-
: T extends 'boolean'
|
|
76
|
-
? boolean
|
|
77
|
-
: T extends 'array' | 'json'
|
|
78
|
-
? any
|
|
79
|
-
: string;
|
|
80
|
-
|
|
81
|
-
const sharedRegistry: any[] = [];
|
|
82
|
-
|
|
83
|
-
export function getParam<T extends ParamType>(
|
|
84
|
-
name: string,
|
|
85
|
-
defaultValue: ParamValue<T>,
|
|
86
|
-
type: T = 'string' as T,
|
|
87
|
-
description?: string,
|
|
88
|
-
uiDefault?: string,
|
|
89
|
-
): ParamValue<T> {
|
|
90
|
-
let registryEntry = sharedRegistry.find((p) => p.name === name);
|
|
91
|
-
|
|
92
|
-
if (!registryEntry) {
|
|
93
|
-
registryEntry = {
|
|
94
|
-
name,
|
|
95
|
-
defaultValue: uiDefault !== undefined ? uiDefault : defaultValue,
|
|
96
|
-
type,
|
|
97
|
-
description,
|
|
98
|
-
value: undefined,
|
|
99
|
-
};
|
|
100
|
-
sharedRegistry.push(registryEntry);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const conversions: Record<ParamType, (v: string) => any> = {
|
|
104
|
-
string: (v) => v,
|
|
105
|
-
number: (v) => {
|
|
106
|
-
const num = Number(v);
|
|
107
|
-
return isNaN(num) ? defaultValue : num;
|
|
108
|
-
},
|
|
109
|
-
boolean: (v) => v.toLowerCase() === 'true',
|
|
110
|
-
array: (v) => {
|
|
111
|
-
try {
|
|
112
|
-
return JSON.parse(v);
|
|
113
|
-
} catch {
|
|
114
|
-
return defaultValue;
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
json: (v) => {
|
|
118
|
-
try {
|
|
119
|
-
return JSON.parse(v);
|
|
120
|
-
} catch {
|
|
121
|
-
return defaultValue;
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const convertValue = (value: any): ParamValue<T> => {
|
|
127
|
-
if (
|
|
128
|
-
(type === 'string' && typeof value === 'string') ||
|
|
129
|
-
(type === 'number' && typeof value === 'number') ||
|
|
130
|
-
(type === 'boolean' && typeof value === 'boolean') ||
|
|
131
|
-
(type === 'array' && Array.isArray(value)) ||
|
|
132
|
-
(type === 'json' && typeof value === 'object' && value !== null)
|
|
133
|
-
) {
|
|
134
|
-
return value as ParamValue<T>;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (typeof value === 'string') {
|
|
138
|
-
if (value.toLowerCase() === 'undefined') return defaultValue;
|
|
139
|
-
return conversions[type](value);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return defaultValue;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// First, check for the parameter in the base64-encoded JSON
|
|
146
|
-
const searchParams = typeof window !== 'undefined' ? new URLSearchParams(window.location.search) : new URLSearchParams();
|
|
147
|
-
const encodedJson = searchParams.get('_b');
|
|
148
|
-
if (encodedJson) {
|
|
149
|
-
try {
|
|
150
|
-
const jsonString = atob(encodedJson);
|
|
151
|
-
const decodedParams = JSON.parse(jsonString);
|
|
152
|
-
if (name in decodedParams) {
|
|
153
|
-
const convertedValue = convertValue(decodedParams[name]);
|
|
154
|
-
registryEntry.value = convertedValue;
|
|
155
|
-
return convertedValue;
|
|
156
|
-
}
|
|
157
|
-
} catch {
|
|
158
|
-
// Silently fail if decoding or parsing fails, fallthrough to lower case
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Next, check for the parameter directly in the URL
|
|
163
|
-
const value = searchParams.get(name);
|
|
164
|
-
if (value === undefined || value === null) {
|
|
165
|
-
// If no value found, register default value
|
|
166
|
-
return defaultValue;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const convertedValue = convertValue(value);
|
|
170
|
-
registryEntry.value = convertedValue;
|
|
171
|
-
return convertedValue;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const timelineRepresentation: { type: string; name?: string }[] = [];
|
|
175
|
-
|
|
176
|
-
// Param class that uses the same shared registry
|
|
177
|
-
export class Param {
|
|
178
|
-
static getRegistry() {
|
|
179
|
-
return [...sharedRegistry];
|
|
180
|
-
}
|
|
181
|
-
static getTimelineRepresentation() {
|
|
182
|
-
return [...timelineRepresentation];
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export type Platform = 'desktop' | 'mobile' | 'web';
|
|
187
|
-
|
|
188
|
-
export const getPlatform = (): Platform => {
|
|
189
|
-
if ((window as any).electronAPI) {
|
|
190
|
-
return 'desktop';
|
|
191
|
-
} else if (Capacitor.isNativePlatform()) {
|
|
192
|
-
return 'mobile';
|
|
193
|
-
} else {
|
|
194
|
-
return 'web';
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const providedComponentParams: Record<string, any> = {};
|
|
199
|
-
|
|
200
|
-
export function registerExperimentParams(experiment: any[]) {
|
|
201
|
-
experiment.forEach((item) => {
|
|
202
|
-
const params = providedComponentParams[item.type];
|
|
203
|
-
if (params) {
|
|
204
|
-
for (const param of params) {
|
|
205
|
-
if(!item.hideSettings || (item.hideSettings !== true && !item.hideSettings.includes(param.name))){
|
|
206
|
-
if (!sharedRegistry.some((p) => p.name === param.name)) {
|
|
207
|
-
sharedRegistry.push(param);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export function registerComponentParams(
|
|
216
|
-
type: string,
|
|
217
|
-
params: { name: string; defaultValue: any; type: string; description?: string }[],
|
|
218
|
-
) {
|
|
219
|
-
providedComponentParams[type] = params;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export function prepareTimeline(experiment: any[], options: { subset?: boolean } = {}): any[] {
|
|
223
|
-
registerExperimentParams(experiment);
|
|
224
|
-
|
|
225
|
-
if (!options.subset) return experiment;
|
|
226
|
-
|
|
227
|
-
timelineRepresentation.length = 0;
|
|
228
|
-
experiment.forEach((item) => {
|
|
229
|
-
timelineRepresentation.push({
|
|
230
|
-
type: item.type ?? 'NoTypeSpecified',
|
|
231
|
-
name: item.name,
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
const include = getParam('includeSubset', undefined);
|
|
236
|
-
const exclude = getParam('excludeSubset', undefined);
|
|
237
|
-
|
|
238
|
-
let experimentFiltered = [...experiment];
|
|
239
|
-
|
|
240
|
-
if (include) {
|
|
241
|
-
const includeItems = include.split(',');
|
|
242
|
-
experimentFiltered = experimentFiltered.filter((item, index) => {
|
|
243
|
-
const positionMatch = includeItems.some((val: string) => {
|
|
244
|
-
const num = parseInt(val, 10);
|
|
245
|
-
return !isNaN(num) && num - 1 === index;
|
|
246
|
-
});
|
|
247
|
-
const nameMatch = item.name && includeItems.includes(item.name);
|
|
248
|
-
return positionMatch || nameMatch;
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (exclude) {
|
|
253
|
-
const excludeItems = exclude.split(',');
|
|
254
|
-
experimentFiltered = experimentFiltered.filter((item, index) => {
|
|
255
|
-
const positionMatch = excludeItems.some((val: string) => {
|
|
256
|
-
const num = parseInt(val, 10);
|
|
257
|
-
return !isNaN(num) && num - 1 === index;
|
|
258
|
-
});
|
|
259
|
-
const nameMatch = item.name && excludeItems.includes(item.name);
|
|
260
|
-
return !(positionMatch || nameMatch);
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return experimentFiltered;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
export function canvasCountdown(seconds: number) {
|
|
269
|
-
if (seconds <= 0) {
|
|
270
|
-
return [];
|
|
271
|
-
}
|
|
272
|
-
return Array.from({ length: seconds }, (_, i) => {
|
|
273
|
-
const number = seconds - i;
|
|
274
|
-
|
|
275
|
-
return {
|
|
276
|
-
draw: (ctx: CanvasRenderingContext2D, w: number, h: number) => {
|
|
277
|
-
ctx.save();
|
|
278
|
-
|
|
279
|
-
ctx.fillStyle = 'black';
|
|
280
|
-
ctx.font = `bold ${Math.min(w, h) * 0.02 * 2}px sans-serif`; // Make countdown text larger
|
|
281
|
-
ctx.textAlign = 'center';
|
|
282
|
-
ctx.textBaseline = 'middle';
|
|
283
|
-
ctx.fillText(number.toString(), w / 2, h / 2);
|
|
284
|
-
|
|
285
|
-
ctx.restore();
|
|
286
|
-
},
|
|
287
|
-
displayDuration: 1000,
|
|
288
|
-
ignoreData: true,
|
|
289
|
-
};
|
|
290
|
-
});
|
|
291
|
-
}
|