@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
package/src/utils/tts.ts CHANGED
@@ -1,4 +1,10 @@
1
- import { getNodeRequire } from './nodecompat';
1
+ // Runs a shell command without blocking, so that participants simulated at the same time do not wait for each other
2
+ function run(command: string): Promise<string> {
3
+ const { exec } = process.getBuiltinModule('child_process');
4
+ return new Promise((resolve, reject) => {
5
+ exec(command, { encoding: 'utf8' }, (error, stdout) => (error ? reject(error) : resolve(stdout)));
6
+ });
7
+ }
2
8
 
3
9
  /**
4
10
  * Generates a WebM audio file from text using the platform's native TTS.
@@ -12,13 +18,10 @@ import { getNodeRequire } from './nodecompat';
12
18
  */
13
19
  export async function textToWebmBase64(text: string): Promise<string | null> {
14
20
  try {
15
- const req = await getNodeRequire();
16
- const childProcess: typeof import('child_process') = req('child_process');
17
- const path: typeof import('path') = req('path');
18
- const fs: typeof import('fs') = req('fs');
19
- const os: typeof import('os') = req('os');
21
+ const path = process.getBuiltinModule('path');
22
+ const fs = process.getBuiltinModule('fs');
23
+ const os = process.getBuiltinModule('os');
20
24
 
21
- const { execSync } = childProcess;
22
25
  const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'reactive-tts-'));
23
26
  const wavPath = path.join(dir, 'tts.wav');
24
27
  const webmPath = path.join(dir, 'tts.webm');
@@ -29,29 +32,27 @@ export async function textToWebmBase64(text: string): Promise<string | null> {
29
32
  if (platform === 'darwin') {
30
33
  let voice = '';
31
34
  try {
32
- const voices = execSync('say -v "?"', { encoding: 'utf8' });
35
+ const voices = await run('say -v "?"');
33
36
  if (voices.includes('Ava')) voice = '-v "Ava (Premium)"';
34
37
  } catch { /* use default */ }
35
- execSync(`say ${voice} -o "${wavPath}" --data-format=LEI16@22050 "${escaped}"`, { stdio: 'ignore' });
38
+ await run(`say ${voice} -o "${wavPath}" --data-format=LEI16@22050 "${escaped}"`);
36
39
  } else if (platform === 'win32') {
37
40
  const ps = `Add-Type -AssemblyName System.Speech; $s = New-Object System.Speech.Synthesis.SpeechSynthesizer; $s.SetOutputToWaveFile('${wavPath.replace(/'/g, "''")}'); $s.Speak('${escaped.replace(/'/g, "''")}'); $s.Dispose()`;
38
- execSync(`powershell -Command "${ps.replace(/"/g, '\\"')}"`, { stdio: 'ignore' });
41
+ await run(`powershell -Command "${ps.replace(/"/g, '\\"')}"`);
39
42
  } else {
40
43
  try {
41
- execSync(`espeak-ng -w "${wavPath}" "${escaped}"`, { stdio: 'ignore' });
44
+ await run(`espeak-ng -w "${wavPath}" "${escaped}"`);
42
45
  } catch {
43
- execSync(`espeak -w "${wavPath}" "${escaped}"`, { stdio: 'ignore' });
46
+ await run(`espeak -w "${wavPath}" "${escaped}"`);
44
47
  }
45
48
  }
46
49
 
47
- execSync(`ffmpeg -i "${wavPath}" -c:a libopus -b:a 24k "${webmPath}" -y`, { stdio: 'ignore' });
50
+ await run(`ffmpeg -i "${wavPath}" -c:a libopus -b:a 24k "${webmPath}" -y`);
48
51
 
49
52
  const webmData = fs.readFileSync(webmPath);
50
53
  const base64 = webmData.toString('base64');
51
54
 
52
- try { fs.unlinkSync(wavPath); } catch { /* ignore */ }
53
- try { fs.unlinkSync(webmPath); } catch { /* ignore */ }
54
- try { fs.rmdirSync(dir); } catch { /* ignore */ }
55
+ fs.rmSync(dir, { recursive: true, force: true });
55
56
 
56
57
  return base64;
57
58
  } catch {
@@ -65,16 +66,15 @@ export async function textToWebmBase64(text: string): Promise<string | null> {
65
66
  */
66
67
  export async function probeAudioDurationMs(base64Audio: string): Promise<number | null> {
67
68
  try {
68
- const req = await getNodeRequire();
69
- const { execSync } = req('child_process') as typeof import('child_process');
70
- const fs = req('fs') as typeof import('fs');
71
- const path = req('path') as typeof import('path');
72
- const os = req('os') as typeof import('os');
69
+ const fs = process.getBuiltinModule('fs');
70
+ const path = process.getBuiltinModule('path');
71
+ const os = process.getBuiltinModule('os');
73
72
 
74
- const tmp = path.join(os.tmpdir(), `reactive-probe-${Date.now()}.webm`);
73
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'reactive-probe-'));
74
+ const tmp = path.join(dir, 'audio.webm');
75
75
  fs.writeFileSync(tmp, Buffer.from(base64Audio, 'base64'));
76
- const out = execSync(`ffprobe -v error -show_entries format=duration -of csv=p=0 "${tmp}"`, { encoding: 'utf8' }).trim();
77
- fs.unlinkSync(tmp);
76
+ const out = (await run(`ffprobe -v error -show_entries format=duration -of csv=p=0 "${tmp}"`)).trim();
77
+ fs.rmSync(dir, { recursive: true, force: true });
78
78
  return Math.round(parseFloat(out) * 1000);
79
79
  } catch {
80
80
  return null;
@@ -1,8 +1,10 @@
1
1
  node_modules
2
- dist-electron
3
2
  dist
4
3
  .git
5
4
  *.log
6
5
  data/
6
+ data_download/
7
7
  android
8
8
  ios
9
+ dist-server
10
+ .env.local
@@ -0,0 +1,5 @@
1
+ # Copy this file to .env.production for the deployed study, and to .env.development for running it on your computer.
2
+ # Git ignores both. Variables starting with PUBLIC_ end up in the experiment's code, all others only reach server.ts.
3
+ PUBLIC_PROLIFIC_CODE=""
4
+ PUBLIC_DISABLE_SETTINGS=FALSE
5
+ PUBLIC_DISABLE_DEV=FALSE
@@ -0,0 +1,25 @@
1
+ # Deploys the study to a study-deploy server on every push to main, if the repository has the secret DEPLOY_TOKEN (see README.md).
2
+ name: Deploy
3
+
4
+ on:
5
+ push:
6
+ branches: [main]
7
+ workflow_dispatch:
8
+
9
+
10
+ concurrency: deploy
11
+
12
+ jobs:
13
+ deploy:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v5
17
+ - uses: oven-sh/setup-bun@v2
18
+ - run: bun install
19
+ - run: |
20
+ if [ -z "$DEPLOY_TOKEN" ]; then echo "There is no DEPLOY_TOKEN secret, so nothing is deployed."; exit 0; fi
21
+ if [ -n "$DOTENV" ]; then echo "$DOTENV" > .env.production; fi
22
+ bun run deploy
23
+ env:
24
+ DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
25
+ DOTENV: ${{ secrets.DOTENV }}
@@ -0,0 +1,14 @@
1
+ node_modules
2
+ dist
3
+ dist-server
4
+ data
5
+ data_download
6
+ android
7
+ ios
8
+ .reactive-cache
9
+ .env
10
+ .env.*
11
+ !.env.example
12
+ *.local
13
+ *.log
14
+ .DS_Store
@@ -1,25 +1,20 @@
1
- FROM node:20-alpine as frontend-builder
1
+ FROM oven/bun:1-alpine AS build
2
2
  WORKDIR /app
3
- COPY package*.json ./
4
3
 
5
- RUN npm install
4
+ COPY package.json bun.lock* ./
5
+ RUN bun install
6
6
 
7
7
  COPY . .
8
- RUN npm run build
8
+ RUN bun run build:production
9
9
 
10
10
 
11
- FROM node:20-alpine
11
+ FROM oven/bun:1-distroless
12
12
  WORKDIR /app
13
13
 
14
- COPY backend/package*.json ./
15
- RUN npm install
16
-
17
- COPY backend/ ./
18
- RUN npm run build
19
- RUN npm install -g pm2
20
-
21
- COPY --from=frontend-builder /app/dist ./static
14
+ COPY --from=build /app/dist-server ./
15
+ COPY --from=build /app/public ./public
22
16
 
23
17
  EXPOSE 8001
24
18
 
25
- CMD ["npx", "pm2-runtime", "./dist/backend.js"]
19
+ # The image's entrypoint is bun
20
+ CMD ["server.js"]
@@ -2,87 +2,93 @@
2
2
 
3
3
  Built with [reactive](https://github.com/adriansteffan/reactive)
4
4
 
5
- ## Prerequisites and Setup
5
+ ## Setup
6
6
 
7
- Regardless of what platform you target with your experiment, you will need a current version of [node.js](https://nodejs.org/en/download/) installed on your system for development.
8
-
9
- To install the needed dependencies, run the following in the root directory:
7
+ Install [Bun](https://bun.sh/), then run in the root directory:
10
8
 
11
9
  ```
12
- npm i && npm i --prefix backend
10
+ bun install
13
11
  ```
14
12
 
15
- You can target multiple platforms at once, just follow the setup processes for all platforms you want to run you study on.
13
+ ### Project layout
14
+
15
+ - `src/Experiment.tsx`: the experiment
16
+ - `public/`: static files, served from the site root (`public/images/cat.png` is available at `/images/cat.png`)
17
+ - `server.ts`: serves the experiment and the route that saves uploaded data, which comes from the library (`uploadRoutes`); add your own routes to `api`, which components reach at `getBackendUrl()` (also in simulations)
18
+ - `.env.production`: the settings for the deployed study, such as the Prolific completion code
19
+ - `.env.development`: the settings for running the study on your computer, read by `bun run dev`, `start`, `build` and `simulate`
20
+ - `.env.example`: the settings to copy into these two files, which git ignores. Variables starting with `PUBLIC_` are compiled into the experiment, where every participant could read them. All others, such as API keys, only reach your routes in `server.ts`. Both are read as `process.env.NAME`, which is `undefined` if it is not set. Avoid `.env` and `.env.local` for them, since Bun reads those on your computer and in deployments alike.
21
+ - `data/`: uploaded data
22
+ - `data_download/`: data downloaded from a study-deploy server
16
23
 
17
24
  ## Target: Web (Online Experiment)
18
25
 
19
- This is the version of the experiment you should use if your testing devices have internet access and don't need any device-specific functionalities (e.g. sensors). The web version will work on all platforms! The specific targets serve as replacements in situations where a stable internet connection might not be given, or privacy directives prevent you from uploading data to a server (and/or you need device-specific functionality).
26
+ This is the version of the experiment you should use if your testing devices have internet access and don't need any device-specific functionalities (e.g. sensors). The web version will work on all platforms!
20
27
 
21
28
  ### Development
22
29
 
23
- The web version of the experiment needs no additional setup for development.
24
-
25
- Run the app in development mode with
26
-
27
30
  ```
28
- npm run dev:all
31
+ bun run dev
29
32
  ```
30
- in the root directory.
31
-
32
- By default, open [http://localhost:5173](http://localhost:5173) to view it in the browser.
33
- The page will reload if you make edits.
34
33
 
34
+ Open [http://localhost:8001](http://localhost:8001). The page updates as you edit.
35
35
 
36
- #### Buidling the frontend locally (to test)
36
+ `bun run start` serves the production version locally, and `bun run typecheck` and `bun run lint` check the code. Linting and formatting use [Biome](https://biomejs.dev/), which has an editor extension.
37
37
 
38
+ ### Deployment
38
39
 
39
- From the `frontend` directory, run
40
+ You will need a server with [Docker](https://docs.docker.com/engine/install/) and Docker Compose 2.24 or newer. In the root directory, start the app with
40
41
 
41
42
  ```
42
- npm run build
43
+ docker compose up -d --build
43
44
  ```
44
45
 
45
- the resulting output can be found in `frontend/dist/`
46
+ and stop it with `docker compose down`. To update, run `git pull` and start it again with the same command.
46
47
 
48
+ The settings page and the `?dev=true` panel are available in the deployed study too. To turn one off, set `PUBLIC_DISABLE_SETTINGS` or `PUBLIC_DISABLE_DEV` to `TRUE` in `.env.production`.
47
49
 
48
- ### Deployment
49
-
50
+ The app listens on port 8001 (see `docker-compose.yaml`). Expose it with a reverse proxy (Apache Virtualhosts or Nginx Server Blocks); [this guide](https://gist.github.com/adriansteffan/48c9bda7237a8a7fcc5bb6987c8e1790) explains how for our setup. Since `.env.production` is not committed, copy it into the clone on the server yourself, and start the app with the same command again whenever it changes.
50
51
 
51
- For deployment, you will need a server with an installation of [docker](https://docs.docker.com/engine/install/)
52
+ Uploaded data is stored in `data/` in the root directory of the cloned repo.
52
53
 
54
+ ### Deploying to a study-deploy server
53
55
 
54
- To build the docker images, run
56
+ If you have access to a [study-deploy](https://github.com/adriansteffan/study-deploy) server, deploy the study with
55
57
 
56
58
  ```
57
- docker compose build
59
+ bun run deploy
58
60
  ```
59
61
 
60
- in the root directory. This might take a while.
62
+ This builds the study with the settings in `.env.production` and uploads it. The first time, it asks for
63
+
64
+ - the server's address and the subdomain the study should get (up to 32 lowercase letters, digits and dashes), and saves both in `package.json` under `studyDeploy`. Commit them, so that GitHub can deploy there too.
65
+ - your token for the server, and saves it in `~/.config/study-deploy/tokens.json` on your computer, for all your studies
61
66
 
62
- #### Running the app
67
+ The study is then served at `https://<subdomain>.<domain>`. Only the user who deployed it first can deploy it again, so collaborators cannot use their own tokens for it. To change the subdomain, edit it in `package.json` and deploy again. The study also stays online under the old one.
63
68
 
64
- After completing the setup, start the webapp with
69
+ Download the data with
65
70
 
66
71
  ```
67
- docker compose up -d
72
+ bun run download
68
73
  ```
69
74
 
70
- and stop it with
75
+ It is saved in `data_download/`, apart from the sessions you ran on your computer. Running it again adds new data and overwrites the files downloaded before.
76
+
77
+ Take the study offline with
71
78
 
72
79
  ```
73
- docker compose down
80
+ bun run undeploy
74
81
  ```
75
82
 
76
- The server will be attached to the ports you specified in the .env files.
77
- Use Virtualhosts (Apache) or Server Blocks (Nginx) with reverse proxy to expose these to the outside. [This guide](https://gist.github.com/adriansteffan/48c9bda7237a8a7fcc5bb6987c8e1790) explains how to do this for our setup.
78
-
79
- #### Updating
83
+ This also deletes its data on the server, so download it first. It asks for confirmation, and only deletes the study under the subdomain in `package.json`.
80
84
 
81
- To update the app, simply stop the running containers, run a `git pull` and build the docker containers once more, and start the containers again.
85
+ GitHub can also deploy on every push to `main`, using `.github/workflows/deploy.yml`. Deploy from your computer once and commit `package.json`. Then, with the [GitHub CLI](https://cli.github.com) installed and logged in, run
82
86
 
83
- #### Where is my data stored?
87
+ ```
88
+ bun run ghsetup
89
+ ```
84
90
 
85
- The server will create a "data" directory in the root directory of the cloned repo,
91
+ This saves your token and the contents of `.env.production` as the repository's secrets `DEPLOY_TOKEN` and `DOTENV`. Run it again whenever you change `.env.production`, since the next push would otherwise deploy the old values. Anyone with write access to the repository can read the secrets, so only do this where you trust every collaborator.
86
92
 
87
93
 
88
94
  ## Simulation
@@ -91,238 +97,92 @@ You can simulate your experiment headlessly to generate synthetic data, test you
91
97
 
92
98
  ### Setup
93
99
 
94
- Define your participant generator and simulation config in `Experiment.tsx`:
100
+ Define your participant generator in the `simulation` field of `defineExperiment` in `Experiment.tsx`:
95
101
 
96
102
  ```tsx
97
- export const simulationConfig = {
98
- participants: {
99
- generator: (i) => ({ id: i, nickname: `participant_${i}` }),
100
- count: 10,
103
+ export default defineExperiment({
104
+ simulation: {
105
+ createParticipants: () => Array.from({ length: 10 }, (_, i) => ({ id: i, nickname: `participant_${i}` })),
101
106
  },
102
- };
107
+ timeline: ({ clicks }) => [ ... ],
108
+ });
103
109
  ```
104
110
 
105
111
  ### Running
106
112
 
107
113
  ```
108
- npm run simulate
114
+ bun run simulate
109
115
  ```
110
116
 
111
- This starts the backend, simulates all participants through the experiment, and shuts down. The simulated data ends up in `backend/data/`.
117
+ This starts the backend, simulates all participants through the experiment, and shuts down. The simulated data ends up in `data/`.
112
118
 
113
119
  ### Customizing participant behavior
114
120
 
115
- Each trial component has default decision functions that model participant behavior. Override them per-trial using the `simulators` property on a timeline item:
121
+ Each trial component has default decision functions that model participant behavior. Override them per trial with `.simulators()`:
116
122
 
117
123
  ```tsx
118
- {
119
- type: 'PlainInput',
120
- props: { content: <p>What is your name?</p> },
121
- simulators: {
122
- respond: (_trialProps, participant) => ({
123
- value: participant.nickname,
124
- participantState: participant,
125
- }),
126
- },
127
- }
124
+ PlainInput.trial('name', { content: <p>What is your name?</p> }).simulators({
125
+ respond: ({ participant }) => ({ value: participant.nickname }),
126
+ }),
128
127
  ```
129
128
 
130
129
  ### Custom components
131
130
 
132
- Register simulations for your custom trial components using `registerSimulation`. See the `CustomTrial` example in `Experiment.tsx` and the [reactive README](https://github.com/adriansteffan/reactive) for details.
131
+ Give your custom components a simulation in their `defineComponent` call. See the `CustomTrial` example in `Experiment.tsx` and the [reactive README](https://github.com/adriansteffan/reactive) for details.
133
132
 
134
- ### Hybrid mode
135
133
 
136
- During development, auto-advance simulated trials while manually interacting with others:
134
+ ## Transcription
137
135
 
138
- Add `?hybridSimulation=true` to the URL:
136
+ Automatically transcribe voice recordings from experiment data using Docker. Requires [Docker](https://docs.docker.com/engine/install/) to be installed. The transcription setup is left out of new projects; add it in the root directory with
139
137
 
140
138
  ```
141
- http://localhost:5173?hybridSimulation=true
139
+ bunx @adriansteffan/reactive add transcription
142
140
  ```
143
141
 
144
- Trials with `simulators` or `simulate: true` defined will auto-advance. Others render normally for human interaction. Hybrid mode is enabled by default during development. For production, set `VITE_DISABLE_HYBRID_SIMULATION=true` to disable it.
145
-
146
-
147
- ## Transcription
148
-
149
- Automatically transcribe voice recordings from experiment data using Docker. Requires [Docker](https://docs.docker.com/engine/install/) to be installed.
142
+ which creates `transcription/` and the scripts below.
150
143
 
151
144
  ### CPU (faster-whisper)
152
145
 
153
146
  ```
154
- npm run transcribe
147
+ bun run transcribe
155
148
  ```
156
149
 
157
150
  ### GPU (qwen-asr, requires NVIDIA GPU)
158
151
 
159
152
  ```
160
- npm run transcribe:gpu
153
+ bun run transcribe:gpu
161
154
  ```
162
155
 
163
156
  ### Options
164
157
 
165
158
  ```
166
- npm run transcribe -- --overwrite # re-transcribe even if transcriptions.csv exists
167
- npm run transcribe -- --model small # use a different model
159
+ bun run transcribe -- --overwrite # re-transcribe even if transcriptions.csv exists
160
+ bun run transcribe -- --model small # use a different model
168
161
  ```
169
162
 
170
- Output: `transcriptions.csv` in each participant's data directory with `filename,text` columns. The model is cached in a Docker volume, so it only downloads once.
171
-
163
+ Output: `transcriptions.<sessionId>.csv` in each session's data directory, wherever it is under `data/` or `data_download/`, with `filename,text` columns. The model is cached in a Docker volume, so it only downloads once.
172
164
 
173
- ## Target: Windows or MacOS
174
165
 
175
- ### Development
166
+ ## Extra components
176
167
 
177
- The desktop version of the experiment needs no additional setup for development.
178
-
179
- Run the app in the development mode with
168
+ Quest (SurveyJS questionnaires) and Tutorial (slide decks) need packages of their own, so they are left out until you add them:
180
169
 
181
170
  ```
182
- npm run electron:dev
171
+ bunx @adriansteffan/reactive add quest tutorial
183
172
  ```
184
- in the root directory.
185
173
 
186
- ### Packaging
174
+ Then import them from `@adriansteffan/reactive/quest` and `@adriansteffan/reactive/tutorial`.
187
175
 
188
- To build platform specific executables, run either
189
176
 
190
- ```
191
- npm run package:mac
192
- ```
193
-
194
- or
195
-
196
- ```
197
- npm run package:win
198
- ```
199
-
200
- There will be a directory called "release" that will contain your executables.
201
-
202
- #### Where is my data stored?
203
-
204
- * Windows:
205
- * On windows, a folder called "data" is created next the executable as soon as the first participant has completed the study
206
-
207
- * MacOS:
208
- * Right click on the application and go to TODO > TODO > TODO, where a folder called "data" is created as soon as the first participant has completed the study
209
-
210
-
211
-
212
- ## Target: Android
213
-
214
- For ease of use, it makes sense to run the web version for most of the development and only switch to the specific device emulators for implementing device-specific features and testing compatibility before packaging.
215
-
216
- ### Setup
217
-
218
- To build and test an Adroid app containing your experiment, you will need an installation of
219
- [Android Studio](https://developer.android.com/studio) and [Java 21 or later](https://www.oracle.com/de/java/technologies/downloads/)
220
-
221
- To set up the android project, run this command in the root directory:
222
- ```
223
- npx cap add android
224
- ````
225
-
226
- Next, find the [path to your local android sdk](https://stackoverflow.com/questions/25176594/android-sdk-location) and create a `local.properties` file in the `android` folder with the following content:
227
-
228
- ```
229
- sdk.dir=SDK_PATH_HERE
230
- ```
177
+ ## Android and iOS apps
231
178
 
232
- If you want to enable file saving for Android versions <= 10, add these lines to the `android/app/main/AndroidManifest.xml`:
179
+ The experiment can also be packaged as an Android or iOS app that stores data on the device, e.g. for studies without a reliable internet connection. To add this, run
233
180
 
234
181
  ```
235
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"> // this line is already there
236
-
237
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
238
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
239
-
240
- <!-- For Android 10+ (API 29+) -->
241
- <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
242
- <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
243
- <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
244
-
245
- <application
246
- android:requestLegacyExternalStorage="true" // add this to the application tag
182
+ bunx @adriansteffan/reactive native
247
183
  ```
248
184
 
249
- For more information, refer to the [Capacitor documentation on Android](https://capacitorjs.com/docs/android)
250
-
251
-
252
- ### Running
253
-
254
- Whenever you have made changes to the code and want to run it on the Android emulator, run:
255
- ```
256
- npm run build
257
- npx cap sync
258
- npx cap run android
259
- ```
260
-
261
- ### Packaging
262
-
263
- From the root directory, run
264
-
265
- ```
266
- npx cap open android
267
- ```
268
-
269
- . Wait for Android Studio to install the project dependencies and then run Build > Generate APKs and Bundles > Generate APKs. Once your build is finished, there will be a popup guiding you to the location of the bundle's app that you can transfer to your Android device.
270
-
271
- #### Where is my data stored?
272
-
273
- In the "Internal Storage" section of the file browser, you will find a "Documents" folder that will contain subfolders with your data as soon as the first participant has finished the experiment.
274
-
275
- ## Target: iOS
276
-
277
- For ease of use, it makes sense to run the web version for most of the development and only switch to the specific device emulators for implementing device-specific features and testing compatibility before packaging.
278
-
279
- ### Setup
280
-
281
- To build an iOS app containing your experiment, you will need a machine running MacOS and an installation of [XCode](https://apps.apple.com/us/app/xcode/id497799835). Furthermore, you will need to install [CocoaPods](https://cocoapods.org/), which is most easily installed with [Homebrew](https://brew.sh/).
282
-
283
- To set up the iOS project, run
284
-
285
- ```
286
- npx cap add ios
287
- ```
288
-
289
- Then, go to `iso > App > App > Info.plist`
290
-
291
- And add these lines next to the other keys:
292
-
293
- ```
294
- <key>UIFileSharingEnabled</key>
295
- <string>YES</string>
296
- <key>LSSupportsOpeningDocumentsInPlace</key>
297
- <string>YES</string>
298
- ```
299
-
300
- For more information, refer to the [Capacitor documentation on iOS](https://capacitorjs.com/docs/ios)
301
-
302
- ### Running
303
-
304
- Whenever you have made changes to the code and want to run it on the iOS emulator, run:
305
-
306
- ```
307
- npm run build
308
- npx cap sync
309
- npx cap run ios
310
- ```
311
-
312
- ### Packaging
313
-
314
- Packaging iOS apps is quite an undertaking, which is why the process is not overly streamlined/documented yet. The best way to get your experiment on an iOS device right now is to run
315
-
316
- ```
317
- npx cap run ios
318
- ```
319
-
320
- which will open the finished project in XCode. From there, follow a guide on how to sign, bundle and install your app/experiment.
321
-
322
- #### Where is my data stored?
323
-
324
- After the first participant is run, a folder with the name of your app will appear under "My iPhone/iPad" in the files app, which contains your data.
325
-
185
+ in the root directory and follow the [setup instructions](https://github.com/adriansteffan/reactive#android-and-ios-apps).
326
186
 
327
187
 
328
188
  ## Authors
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": true
7
+ },
8
+ "formatter": {
9
+ "indentStyle": "space",
10
+ "lineWidth": 100
11
+ },
12
+ "javascript": {
13
+ "formatter": {
14
+ "quoteStyle": "single",
15
+ "jsxQuoteStyle": "single"
16
+ }
17
+ },
18
+ "css": {
19
+ "parser": {
20
+ "tailwindDirectives": true
21
+ }
22
+ },
23
+ "linter": {
24
+ "rules": {
25
+ "preset": "recommended",
26
+ "a11y": "off",
27
+ "complexity": "off",
28
+ "style": "off",
29
+ "suspicious": {
30
+ "noArrayIndexKey": "off"
31
+ }
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,20 @@
1
+ // Bundles the experiment for production: dist/ for Capacitor, dist-server/ for the Docker image
2
+ import fs from 'fs';
3
+ import tailwind from 'bun-plugin-tailwind';
4
+ import publicDir from '@adriansteffan/reactive/bun-plugin';
5
+
6
+ const options = {
7
+ minify: true,
8
+ env: 'PUBLIC_*' as const,
9
+ define: { 'process.env.NODE_ENV': '"production"' },
10
+ plugins: [tailwind, publicDir],
11
+ };
12
+
13
+ fs.rmSync('dist', { recursive: true, force: true });
14
+ fs.rmSync('dist-server', { recursive: true, force: true });
15
+
16
+ await Bun.build({ ...options, entrypoints: ['./index.html'], outdir: 'dist' });
17
+ fs.cpSync('public', 'dist', { recursive: true });
18
+
19
+ // The server bundle includes the frontend, so the image needs no node_modules
20
+ await Bun.build({ ...options, entrypoints: ['./server.ts'], target: 'bun', outdir: 'dist-server' });
@@ -0,0 +1,3 @@
1
+ [serve.static]
2
+ plugins = ["bun-plugin-tailwind", "@adriansteffan/reactive/bun-plugin"]
3
+ env = "PUBLIC_*"