@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/bin/add.js ADDED
@@ -0,0 +1,56 @@
1
+ // Adds extras to the experiment project in the current directory, e.g. `add quest tutorial`
2
+ import { cpSync, existsSync, readFileSync, writeFileSync } from 'fs';
3
+ import { join, dirname } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { spawnSync } from 'child_process';
6
+
7
+ // Extra components and the packages they need
8
+ const components = {
9
+ quest: ['survey-core', 'survey-react-ui'],
10
+ tutorial: ['motion'],
11
+ };
12
+ const extras = [...Object.keys(components), 'transcription'];
13
+
14
+ const projectPath = process.cwd();
15
+ const projectPackagePath = join(projectPath, 'package.json');
16
+ if (!existsSync(projectPackagePath)) {
17
+ console.error('Run this command in the root directory of your experiment project.');
18
+ process.exit(1);
19
+ }
20
+
21
+ const names = process.argv.slice(3);
22
+ if (names.length === 0 || names.some((name) => !extras.includes(name))) {
23
+ console.error(`Usage: bunx @adriansteffan/reactive add <${extras.join('|')}> ...`);
24
+ process.exit(1);
25
+ }
26
+
27
+ const libraryPath = join(dirname(fileURLToPath(import.meta.url)), '..');
28
+
29
+ const added = names.filter((name) => name in components);
30
+ if (added.length > 0) {
31
+ // At the versions the library declares as its peer dependencies
32
+ const peers = JSON.parse(readFileSync(join(libraryPath, 'package.json'), 'utf8')).peerDependencies;
33
+ const packages = added.flatMap((name) => components[name]).map((name) => `${name}@${peers[name]}`);
34
+ console.log(`> bun add ${packages.join(' ')}`);
35
+ const result = spawnSync('bun', ['add', ...packages], { cwd: projectPath, stdio: 'inherit' });
36
+ if (result.status !== 0) process.exit(result.status ?? 1);
37
+ console.log(`\nImport them from ${added.map((name) => `@adriansteffan/reactive/${name}`).join(' and ')}.`);
38
+ }
39
+
40
+ if (names.includes('transcription')) {
41
+ const target = join(projectPath, 'transcription');
42
+ if (existsSync(target)) {
43
+ console.log('transcription/ already exists and was left as it is.');
44
+ } else {
45
+ cpSync(join(libraryPath, 'extras', 'transcription'), target, { recursive: true });
46
+ }
47
+ // Read after `bun add`, which changes package.json too
48
+ const project = JSON.parse(readFileSync(projectPackagePath, 'utf8'));
49
+ project.scripts = {
50
+ ...project.scripts,
51
+ transcribe: 'docker compose -f transcription/compose.yaml run --rm transcribe',
52
+ 'transcribe:gpu': 'docker compose -f transcription/compose.yaml run --rm transcribe-gpu',
53
+ };
54
+ writeFileSync(projectPackagePath, `${JSON.stringify(project, null, 2)}\n`);
55
+ console.log('\nAdded transcription/ and the scripts transcribe and transcribe:gpu, see "Transcription" in README.md.');
56
+ }
package/bin/deploy.js ADDED
@@ -0,0 +1,48 @@
1
+ // Builds the study in the current directory and uploads it to a study-deploy server
2
+ import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'fs';
3
+ import { join, sep } from 'path';
4
+ import { spawnSync } from 'child_process';
5
+ import { zipSync } from 'fflate';
6
+ import { ask, getToken, readProject, request } from './study-deploy.js';
7
+
8
+ const project = readProject();
9
+ const notSetUp = 'package.json does not say where to deploy. Run `bun run deploy` in a terminal once, and it asks.';
10
+ const address = project.studyDeploy?.server ?? (await ask('Server (e.g. https://deploy.exp.example.org): ', notSetUp));
11
+ const url = address.includes('://') ? address : `https://${address}`;
12
+ if (!URL.canParse(url)) {
13
+ console.error(`${address} is not a valid address.`);
14
+ process.exit(1);
15
+ }
16
+ const server = new URL(url).origin;
17
+ const name = project.studyDeploy?.name ?? (await ask('Subdomain for the study: ', notSetUp));
18
+
19
+ const token = await getToken(server);
20
+
21
+ const build = spawnSync('bun', ['run', 'build:production'], { stdio: 'inherit' });
22
+ if (build.status !== 0) process.exit(build.status ?? 1);
23
+
24
+ // The server's files at the top level, and public/ next to them
25
+ const files = {};
26
+ for (const [dir, prefix] of [['dist-server', ''], ['public', 'public/']]) {
27
+ for (const file of readdirSync(dir, { recursive: true })) {
28
+ const source = join(dir, file);
29
+ if (statSync(source).isFile()) files[prefix + file.split(sep).join('/')] = readFileSync(source);
30
+ }
31
+ }
32
+
33
+ // Bun reads .env when the server starts, which is how variables without the PUBLIC_ prefix reach it
34
+ if (existsSync('.env.production')) files['.env'] = readFileSync('.env.production');
35
+ else console.log('There is no .env.production, so the study is deployed without any settings or keys.');
36
+
37
+ const response = await request(server, `/deploy/${name}`, token, { method: 'POST', body: zipSync(files) });
38
+ console.log((await response.text()).trim());
39
+
40
+ // Saved once the server has accepted them. 409 and 500 are about the study, not where it is deployed.
41
+ if (response.ok || response.status === 409 || response.status === 500) {
42
+ if (project.studyDeploy?.server !== server || project.studyDeploy?.name !== name) {
43
+ project.studyDeploy = { server, name };
44
+ writeFileSync('package.json', `${JSON.stringify(project, null, 2)}\n`);
45
+ console.log('Saved the server and subdomain in package.json. Commit it, so that GitHub can deploy there too.');
46
+ }
47
+ }
48
+ if (!response.ok) process.exit(1);
@@ -0,0 +1,28 @@
1
+ // Downloads the data of the deployed study into data_download
2
+ import { spawn } from 'child_process';
3
+ import { once } from 'events';
4
+ import { mkdirSync } from 'fs';
5
+ import { Readable } from 'stream';
6
+ import { pipeline } from 'stream/promises';
7
+ import { deployedStudy, getToken, request } from './study-deploy.js';
8
+
9
+ const { server, name } = deployedStudy();
10
+ const response = await request(server, `/data/${name}`, await getToken(server));
11
+ if (!response.ok) {
12
+ console.error((await response.text()).trim());
13
+ process.exit(1);
14
+ }
15
+
16
+ const folder = 'data_download';
17
+ mkdirSync(folder, { recursive: true });
18
+ const tar = spawn('tar', ['-xf', '-', '-C', folder], { stdio: ['pipe', 'inherit', 'inherit'] });
19
+ const closed = once(tar, 'close');
20
+ try {
21
+ await pipeline(Readable.fromWeb(response.body), tar.stdin);
22
+ const [code] = await closed;
23
+ if (code !== 0) throw new Error(`tar exited with code ${code}`);
24
+ } catch (error) {
25
+ console.error(`The download is incomplete: ${error.message}`);
26
+ process.exit(1);
27
+ }
28
+ console.log(`Saved the data in ${folder}/`);
package/bin/ghsetup.js ADDED
@@ -0,0 +1,21 @@
1
+ // Saves the token and .env.production as secrets of the study's GitHub repository, for .github/workflows/deploy.yml
2
+ import { existsSync, readFileSync } from 'fs';
3
+ import { spawnSync } from 'child_process';
4
+ import { deployedStudy, tokens } from './study-deploy.js';
5
+
6
+ const token = process.env.DEPLOY_TOKEN || tokens[deployedStudy().server];
7
+ if (!token) {
8
+ console.error('Run `bun run deploy` first, which asks for your token.');
9
+ process.exit(1);
10
+ }
11
+
12
+ function setSecret(name, value) {
13
+ // Passed on standard input, because other users of the computer can see arguments
14
+ const result = spawnSync('gh', ['secret', 'set', name], { input: value, stdio: ['pipe', 'inherit', 'inherit'] });
15
+ if (result.error) console.error('This needs the GitHub CLI, see https://cli.github.com.');
16
+ if (result.status !== 0) process.exit(1);
17
+ }
18
+
19
+ setSecret('DEPLOY_TOKEN', token);
20
+ if (existsSync('.env.production')) setSecret('DOTENV', readFileSync('.env.production'));
21
+ console.log('GitHub now deploys on every push to main. Commit package.json first if you have not.');
package/bin/native.js ADDED
@@ -0,0 +1,81 @@
1
+ // Adds Android and iOS support to the experiment project in the current directory
2
+ import { existsSync, readFileSync, writeFileSync } from 'fs';
3
+ import { join, dirname } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+ import { spawnSync } from 'child_process';
6
+
7
+ const projectPath = process.cwd();
8
+ const projectPackagePath = join(projectPath, 'package.json');
9
+
10
+ if (!existsSync(projectPackagePath)) {
11
+ console.error('Run this command in the root directory of your experiment project.');
12
+ process.exit(1);
13
+ }
14
+
15
+ const project = JSON.parse(readFileSync(projectPackagePath, 'utf8'));
16
+ const library = JSON.parse(
17
+ readFileSync(join(dirname(fileURLToPath(import.meta.url)), '../package.json'), 'utf8'),
18
+ );
19
+
20
+ function run(args) {
21
+ console.log(`> bun ${args.join(' ')}`);
22
+ const result = spawnSync('bun', args, { cwd: projectPath, stdio: 'inherit' });
23
+ if (result.status !== 0) process.exit(result.status ?? 1);
24
+ }
25
+
26
+ // At the versions the library declares as its peer dependencies
27
+ const peers = library.peerDependencies;
28
+ const capacitorVersion = peers['@capacitor/core'];
29
+ const nativePlugins = ['@capacitor/core', '@capacitor/filesystem', '@capacitor/status-bar', '@adriansteffan/immersive-mode'].map(
30
+ (name) => `${name}@${peers[name]}`,
31
+ );
32
+
33
+ run(['add', ...nativePlugins, `@capacitor/android@${capacitorVersion}`, `@capacitor/ios@${capacitorVersion}`]);
34
+ run(['add', '--dev', `@capacitor/cli@${capacitorVersion}`]);
35
+
36
+ const configPath = join(projectPath, 'capacitor.config.ts');
37
+ if (!existsSync(configPath)) {
38
+ const appId = `com.${project.name.toLowerCase().replace(/[^a-z0-9]/g, '')}.app`;
39
+ writeFileSync(
40
+ configPath,
41
+ `import type { CapacitorConfig } from '@capacitor/cli';
42
+
43
+ const config: CapacitorConfig = {
44
+ appId: '${appId}',
45
+ appName: '${project.name}',
46
+ webDir: 'dist',
47
+ server: {
48
+ hostname: 'localhost',
49
+ androidScheme: 'https',
50
+ cleartext: true,
51
+ allowNavigation: ['*'],
52
+ },
53
+ };
54
+
55
+ export default config;
56
+ `,
57
+ );
58
+ console.log('Created capacitor.config.ts');
59
+ }
60
+
61
+ const mainPath = join(projectPath, 'src', 'main.tsx');
62
+ const mainSource = existsSync(mainPath) ? readFileSync(mainPath, 'utf8') : null;
63
+ if (mainSource === null) {
64
+ console.log('Could not find src/main.tsx. Add this line to your entry file:\n import "@adriansteffan/reactive/native";');
65
+ } else if (!mainSource.includes('@adriansteffan/reactive/native')) {
66
+ const lines = mainSource.split('\n');
67
+ const lastImport = lines.findLastIndex((line) => line.startsWith('import '));
68
+ lines.splice(lastImport + 1, 0, 'import "@adriansteffan/reactive/native";');
69
+ writeFileSync(mainPath, lines.join('\n'));
70
+ console.log('Added the native integration to src/main.tsx');
71
+ }
72
+
73
+ console.log(`
74
+ Android and iOS support added. Create the native projects with
75
+
76
+ bunx cap add android
77
+ bunx cap add ios
78
+
79
+ and see "Android and iOS apps" in the reactive README for the remaining setup:
80
+ https://github.com/adriansteffan/reactive#android-and-ios-apps
81
+ `);
package/bin/setup.js CHANGED
@@ -10,7 +10,6 @@ const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = dirname(__filename);
11
11
 
12
12
  const version = createRequire(import.meta.url)(join(__dirname, '../package.json')).version;
13
- console.log(version)
14
13
 
15
14
  const rl = readline.createInterface({
16
15
  input: process.stdin,
@@ -47,6 +46,7 @@ function copyDir(src, dest, ignoreEntries = []) {
47
46
  }
48
47
 
49
48
  async function main() {
49
+ console.log(version);
50
50
  try {
51
51
 
52
52
  const projectName = await question('Please enter your project name: ');
@@ -66,7 +66,7 @@ async function main() {
66
66
  process.exit(1);
67
67
  }
68
68
 
69
- copyDir(templatePath, projectPath, ['package.json','capacitor.config.js','node_modules']);
69
+ copyDir(templatePath, projectPath, ['package.json','node_modules']);
70
70
 
71
71
  const templatePackageJsonPath = join(templatePath, 'package.json');
72
72
  if (!existsSync(templatePackageJsonPath)) {
@@ -79,25 +79,13 @@ async function main() {
79
79
 
80
80
  writeFileSync(join(projectPath, 'package.json'), packageJsonContent);
81
81
 
82
-
83
- const templateCapacitorPath = join(templatePath, 'capacitor.config.ts');
84
- if (!existsSync(templateCapacitorPath)) {
85
- console.error('Template capacitor.config.ts not found');
86
- process.exit(1);
87
- }
88
-
89
- let capacitorContent = readFileSync(templateCapacitorPath, 'utf8');
90
- capacitorContent = capacitorContent.replace(/PROJECT_NAME/g, projectName);
91
-
92
- writeFileSync(join(projectPath, 'capacitor.config.ts'), capacitorContent);
93
-
94
82
  console.log(`
95
83
  Project ${projectName} created successfully!
96
84
 
97
85
  To get started:
98
86
  cd ${projectName}
99
- npm i && npm i --prefix backend
100
- npm run dev:all
87
+ bun install
88
+ bun run dev
101
89
  `);
102
90
 
103
91
  } catch (error) {
@@ -109,4 +97,10 @@ To get started:
109
97
  }
110
98
  }
111
99
 
112
- main();
100
+ const command = process.argv[2];
101
+ if (['native', 'add', 'deploy', 'download', 'undeploy', 'ghsetup'].includes(command)) {
102
+ rl.close();
103
+ await import(`./${command}.js`);
104
+ } else {
105
+ main();
106
+ }
@@ -0,0 +1,60 @@
1
+ // Shared by the commands that talk to a study-deploy server
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
3
+ import { homedir } from 'os';
4
+ import { dirname, join } from 'path';
5
+ import { createInterface } from 'readline/promises';
6
+
7
+ // Kept per server, so that a changed address in package.json cannot make a command send a token elsewhere
8
+ const tokensPath = join(homedir(), '.config', 'study-deploy', 'tokens.json');
9
+ export const tokens = existsSync(tokensPath) ? JSON.parse(readFileSync(tokensPath, 'utf8')) : {};
10
+
11
+ export function readProject() {
12
+ if (!existsSync('package.json')) {
13
+ console.error('Run this command in the root directory of your experiment project.');
14
+ process.exit(1);
15
+ }
16
+ return JSON.parse(readFileSync('package.json', 'utf8'));
17
+ }
18
+
19
+ /** Where the study is deployed, from package.json. */
20
+ export function deployedStudy() {
21
+ const { studyDeploy } = readProject();
22
+ if (!studyDeploy) {
23
+ console.error('This study has not been deployed with `bun run deploy` yet.');
24
+ process.exit(1);
25
+ }
26
+ return studyDeploy;
27
+ }
28
+
29
+ export async function ask(question, missing) {
30
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
31
+ const answer = process.stdin.isTTY ? (await rl.question(question)).trim() : '';
32
+ rl.close();
33
+ if (!answer) {
34
+ console.error(missing);
35
+ process.exit(1);
36
+ }
37
+ return answer;
38
+ }
39
+
40
+ export async function getToken(server) {
41
+ return process.env.DEPLOY_TOKEN || tokens[server] || (await ask(`Your token for ${server}: `, 'Set DEPLOY_TOKEN.'));
42
+ }
43
+
44
+ /** Sends a request and saves its token, or forgets the token if the server rejected it, so that the next command asks again. */
45
+ export async function request(server, path, token, options) {
46
+ let response;
47
+ try {
48
+ response = await fetch(server + path, { ...options, headers: { Authorization: `Bearer ${token}` } });
49
+ } catch (error) {
50
+ console.error(`Could not reach ${server} (${error.cause?.code ?? error.message})`);
51
+ process.exit(1);
52
+ }
53
+ if (!process.env.DEPLOY_TOKEN) {
54
+ if (response.status === 401) delete tokens[server];
55
+ else tokens[server] = token;
56
+ mkdirSync(dirname(tokensPath), { recursive: true });
57
+ writeFileSync(tokensPath, `${JSON.stringify(tokens, null, 2)}\n`, { mode: 0o600 });
58
+ }
59
+ return response;
60
+ }
@@ -0,0 +1,15 @@
1
+ // Takes the deployed study offline and deletes everything the server keeps for it
2
+ import { ask, deployedStudy, getToken, request } from './study-deploy.js';
3
+
4
+ const { server, name } = deployedStudy();
5
+ console.log(`This takes ${name} offline and deletes all its data on ${server}. Run \`bun run download\` first if you still need it.`);
6
+ const unconfirmed = 'Nothing was deleted.';
7
+ if ((await ask(`Type ${name} to confirm: `, unconfirmed)) !== name) {
8
+ console.error(unconfirmed);
9
+ process.exit(1);
10
+ }
11
+
12
+ const response = await request(server, `/deploy/${name}`, await getToken(server), { method: 'DELETE' });
13
+ console.log((await response.text()).trim());
14
+ if (!response.ok) process.exit(1);
15
+ console.log('If GitHub deploys this study, run `gh secret delete DEPLOY_TOKEN`, or the next push brings it back.');
@@ -0,0 +1,32 @@
1
+ services:
2
+ transcribe:
3
+ build:
4
+ context: .
5
+ dockerfile: Dockerfile.cpu
6
+ volumes:
7
+ - ../data:/data/data
8
+ - ../data_download:/data/data_download
9
+ - model-cache:/root/.cache/huggingface
10
+ environment:
11
+ - DATA_DIR=/data
12
+
13
+ transcribe-gpu:
14
+ build:
15
+ context: .
16
+ dockerfile: Dockerfile.gpu
17
+ volumes:
18
+ - ../data:/data/data
19
+ - ../data_download:/data/data_download
20
+ - model-cache:/root/.cache/huggingface
21
+ environment:
22
+ - DATA_DIR=/data
23
+ deploy:
24
+ resources:
25
+ reservations:
26
+ devices:
27
+ - driver: nvidia
28
+ count: 1
29
+ capabilities: [gpu]
30
+
31
+ volumes:
32
+ model-cache:
@@ -6,15 +6,10 @@ import argparse
6
6
 
7
7
 
8
8
  def find_participant_dirs(data_dir):
9
- """Return participant directories that contain .webm audio files."""
10
- dirs = []
11
- for entry in sorted(os.listdir(data_dir)):
12
- full = os.path.join(data_dir, entry)
13
- if not os.path.isdir(full):
14
- continue
15
- if any(f.endswith(".webm") for f in os.listdir(full)):
16
- dirs.append(full)
17
- return dirs
9
+ """Return the directories under data_dir, at any depth, that contain .webm audio files."""
10
+ return sorted(
11
+ root for root, _, files in os.walk(data_dir) if any(f.endswith(".webm") for f in files)
12
+ )
18
13
 
19
14
 
20
15
  def find_audio_files(participant_dir):
package/package.json CHANGED
@@ -1,95 +1,93 @@
1
1
  {
2
2
  "name": "@adriansteffan/reactive",
3
- "version": "0.2.6",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
- "dev": "vite",
7
- "build": "tsc && vite build",
8
- "test": "vitest --silent=false",
9
- "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
10
- "preview": "vite preview"
6
+ "test": "bun test",
7
+ "typecheck": "bun check",
8
+ "lint": "biome lint --error-on-warnings"
11
9
  },
12
10
  "bin": {
13
11
  "create-reactive-experiment": "bin/setup.js",
14
- "@adriansteffan/reactive": "bin/setup.js"
12
+ "reactive": "bin/setup.js"
15
13
  },
16
- "main": "./dist/reactive.umd.js",
17
- "module": "./dist/reactive.es.js",
18
- "types": "./dist/mod.d.ts",
14
+ "files": [
15
+ "src",
16
+ "bin",
17
+ "extras",
18
+ "template",
19
+ "template/.gitignore"
20
+ ],
19
21
  "exports": {
20
- ".": {
21
- "import": "./dist/reactive.es.js",
22
- "require": "./dist/reactive.umd.js",
23
- "types": "./dist/mod.d.ts"
24
- },
25
- "./style.css": "./dist/style.css",
26
- "./array": {
27
- "import": "./dist/reactive.es.js",
28
- "require": "./dist/reactive.umd.js",
29
- "types": "./dist/mod.d.ts"
30
- },
31
- "./raw-loader": "./raw-loader.mjs",
32
- "./raw-loader-hooks": "./raw-loader-hooks.mjs"
22
+ ".": "./src/mod.tsx",
23
+ "./style.css": "./src/index.css",
24
+ "./bun-plugin": "./src/bun-plugin.ts",
25
+ "./native": "./src/native.ts",
26
+ "./server": "./src/server.ts",
27
+ "./quest": "./src/quest.ts",
28
+ "./tutorial": "./src/tutorial.ts"
33
29
  },
30
+ "sideEffects": [
31
+ "*.css",
32
+ "./src/utils/array.ts",
33
+ "./src/native.ts"
34
+ ],
34
35
  "author": "Adrian Steffan",
35
36
  "license": "MIT",
36
37
  "bugs": {
37
38
  "url": "https://github.com/adriansteffan/reactive/issues"
38
39
  },
39
40
  "dependencies": {
41
+ "fflate": "^0.8.3"
42
+ },
43
+ "peerDependencies": {
40
44
  "@adriansteffan/immersive-mode": "^0.0.1",
41
45
  "@capacitor/core": "^7.0.1",
42
46
  "@capacitor/filesystem": "^7.0.0",
43
- "@capacitor/share": "^7.0.0",
44
47
  "@capacitor/status-bar": "^7.0.0",
45
- "@stdlib/random-base-mt19937": "^0.2.3",
46
- "@stdlib/random-base-normal": "^0.2.2",
47
- "@stdlib/random-base-poisson": "^0.2.2",
48
- "@stdlib/random-base-uniform": "^0.2.3",
49
- "@stdlib/stats-base-dists-normal-quantile": "^0.3.1",
50
- "@stdlib/stats-base-dists-poisson-quantile": "^0.2.3",
51
- "@tanstack/react-query": "^5.61.3",
52
- "@tanstack/react-query-devtools": "^5.61.3",
53
- "@zip.js/zip.js": "^2.7.53",
54
- "halton": "^1.0.0",
55
48
  "motion": "^12.38.0",
56
49
  "react": "^18.2.0",
57
50
  "react-dom": "^18.2.0",
58
- "react-icons": "^5.1.0",
59
- "react-toastify": "^10.0.6",
51
+ "survey-core": "^2.4.1",
60
52
  "survey-react-ui": "^2.4.1",
61
- "uuid": "^11.0.3"
62
- },
63
- "peerDependencies": {
64
53
  "tailwindcss": "^4.0.9"
65
54
  },
55
+ "peerDependenciesMeta": {
56
+ "@adriansteffan/immersive-mode": {
57
+ "optional": true
58
+ },
59
+ "@capacitor/core": {
60
+ "optional": true
61
+ },
62
+ "@capacitor/filesystem": {
63
+ "optional": true
64
+ },
65
+ "@capacitor/status-bar": {
66
+ "optional": true
67
+ },
68
+ "motion": {
69
+ "optional": true
70
+ },
71
+ "survey-core": {
72
+ "optional": true
73
+ },
74
+ "survey-react-ui": {
75
+ "optional": true
76
+ }
77
+ },
66
78
  "devDependencies": {
67
- "@eslint/config-array": "^0.19.0",
68
- "@eslint/object-schema": "^2.1.4",
69
- "@tailwindcss/postcss": "^4.0.9",
70
- "@types/howler": "^2.2.11",
71
- "@types/node": "^22.9.2",
79
+ "@adriansteffan/immersive-mode": "^0.0.1",
80
+ "@biomejs/biome": "^2.5.15",
81
+ "@capacitor/core": "^7.0.1",
82
+ "@capacitor/filesystem": "^7.0.0",
83
+ "@capacitor/status-bar": "^7.0.0",
84
+ "@types/bun": "^1.4.3",
72
85
  "@types/react": "^18.2.66",
73
86
  "@types/react-dom": "^18.2.22",
74
- "@types/uuid": "^10.0.0",
75
- "@typescript-eslint/eslint-plugin": "^8.16.0",
76
- "@typescript-eslint/parser": "^8.16.0",
77
- "@vitejs/plugin-react": "^4.2.1",
78
- "autoprefixer": "^10.4.20",
79
- "concurrently": "^9.1.0",
80
- "eslint": "^9.0.0",
81
- "eslint-plugin-react-hooks": "^5.0.0",
82
- "eslint-plugin-react-refresh": "^0.4.14",
83
- "glob": "^10.3.10",
84
- "lru-cache": "^10.0.1",
85
- "postcss": "^8.4.38",
86
- "prettier": "3.2.5",
87
- "rimraf": "^5.0.5",
88
- "tailwindcss": "^4.0.9",
89
- "typescript": "^5.2.2",
90
- "vite": "^5.2.0",
91
- "vite-plugin-dts": "^4.3.0",
92
- "vite-plugin-static-copy": "^2.1.0",
93
- "vitest": "^2.1.5"
87
+ "motion": "^12.38.0",
88
+ "react": "^18.2.0",
89
+ "react-dom": "^18.2.0",
90
+ "survey-core": "^2.4.1",
91
+ "survey-react-ui": "^2.4.1"
94
92
  }
95
93
  }
@@ -0,0 +1 @@
1
+ declare module "*.css" {}
@@ -0,0 +1,22 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import type { BunPlugin } from 'bun';
4
+
5
+ const root = process.cwd();
6
+
7
+ // Leaves absolute URLs that point into public/ untouched, so they are served as-is instead of bundled
8
+ const publicDir: BunPlugin = {
9
+ name: 'reactive-public-dir',
10
+ setup(build) {
11
+ // Source files are excluded because Bun's dev server fails to load an entry script that a plugin was asked to resolve
12
+ build.onResolve({ filter: /^\/(?!.*\.(?:[cm]?[jt]sx?|css|html)$)/ }, (args) => {
13
+ // References from HTML arrive already resolved against the project root, those from CSS as written
14
+ const url = args.path.startsWith(root + '/') ? args.path.slice(root.length) : args.path;
15
+ if (fs.existsSync(path.join(root, 'public', url))) {
16
+ return { path: url, external: true };
17
+ }
18
+ });
19
+ },
20
+ };
21
+
22
+ export default publicDir;