@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.
- 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 +48 -41
- 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/.prettierrc +0 -5
- package/Dockerfile +0 -20
- package/dist/mod-HDegGPrf.js +0 -87434
- package/dist/mod.d.ts +0 -946
- package/dist/reactive.es.js +0 -87
- package/dist/reactive.umd.js +0 -10255
- package/dist/style.css +0 -5
- package/dist/web-7BbR1Ad7.js +0 -435
- package/dist/web-CATfZO1Q.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
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import { BaseComponentProps } from '../
|
|
1
|
+
import { BaseComponentProps } from '../core/component';
|
|
2
2
|
import { useEffect, useRef, useState } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
registerFlattener('CheckDevice', 'session');
|
|
8
|
-
|
|
9
|
-
registerSimulation('CheckDevice', (_trialProps, _experimentState, _simulators, participant) => {
|
|
10
|
-
const deviceInfo = {
|
|
11
|
-
windowWidth: 1920, windowHeight: 1080, screenWidth: 1920, screenHeight: 1080,
|
|
12
|
-
browser: 'Simulated', browserVersion: '1.0', isMobile: false,
|
|
13
|
-
operatingSystem: 'Simulated', hasWebAudio: true, hasFullscreen: true,
|
|
14
|
-
hasWebcam: true, hasMicrophone: true,
|
|
15
|
-
};
|
|
16
|
-
return {
|
|
17
|
-
responseData: deviceInfo,
|
|
18
|
-
participantState: participant,
|
|
19
|
-
storeUpdates: { _reactiveDeviceInfo: deviceInfo },
|
|
20
|
-
};
|
|
21
|
-
}, {});
|
|
22
|
-
|
|
23
|
-
interface DeviceInfo {
|
|
3
|
+
import { defineComponent } from '../core/component';
|
|
4
|
+
import { useTheme, t } from '../runner/theme';
|
|
5
|
+
|
|
6
|
+
export interface DeviceInfo {
|
|
24
7
|
windowWidth: number;
|
|
25
8
|
windowHeight: number;
|
|
26
9
|
screenWidth: number;
|
|
@@ -35,17 +18,48 @@ interface DeviceInfo {
|
|
|
35
18
|
hasMicrophone: boolean;
|
|
36
19
|
}
|
|
37
20
|
|
|
21
|
+
// Edge's user agent names Chrome too, and Android's and iOS's name Linux and Mac OS X, so they come first
|
|
22
|
+
const browsers: [string, RegExp][] = [
|
|
23
|
+
['Edge', /Edg(?:e|A|iOS)?\/(\d+\.\d+)/],
|
|
24
|
+
['Chrome', /(?:Chrome|CriOS)\/(\d+\.\d+)/],
|
|
25
|
+
['Firefox', /(?:Firefox|FxiOS)\/(\d+\.\d+)/],
|
|
26
|
+
['Safari', /Version\/(\d+\.\d+).*Safari/],
|
|
27
|
+
];
|
|
28
|
+
const systems: [string, RegExp][] = [
|
|
29
|
+
['Android', /Android/],
|
|
30
|
+
['iOS', /iPhone|iPad|iPod/],
|
|
31
|
+
['Windows', /Windows/],
|
|
32
|
+
['MacOS', /Macintosh|Mac OS X/],
|
|
33
|
+
['Linux', /Linux/],
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
/** The browser, its version and the operating system that a user agent names. */
|
|
37
|
+
export function describeUserAgent(userAgent: string) {
|
|
38
|
+
let browser = 'Unknown';
|
|
39
|
+
let browserVersion = 'Unknown';
|
|
40
|
+
for (const [name, pattern] of browsers) {
|
|
41
|
+
const match = userAgent.match(pattern);
|
|
42
|
+
if (match) {
|
|
43
|
+
browser = name;
|
|
44
|
+
browserVersion = match[1];
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const operatingSystem = systems.find(([, pattern]) => pattern.test(userAgent))?.[0] ?? 'Unknown';
|
|
49
|
+
return { browser, browserVersion, operatingSystem };
|
|
50
|
+
}
|
|
51
|
+
|
|
38
52
|
function CheckDevice({
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
data,
|
|
42
|
-
store,
|
|
43
|
-
updateStore,
|
|
53
|
+
acceptDevice,
|
|
54
|
+
errorContent = <div>Your device doesn't meet the requirements for this experiment.</div>,
|
|
44
55
|
next,
|
|
45
56
|
}: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
/** Whether the device fits the study. Without it, every device does. */
|
|
58
|
+
/** Whether the participant's device fits the experiment; one that does not ends it on this screen. */
|
|
59
|
+
acceptDevice?: (deviceInfo: DeviceInfo) => boolean;
|
|
60
|
+
/** Shown when the device does not fit. */
|
|
61
|
+
errorContent?: React.ReactNode;
|
|
62
|
+
} & BaseComponentProps<DeviceInfo>) {
|
|
49
63
|
const [showContent, setShowContent] = useState<boolean>(false);
|
|
50
64
|
|
|
51
65
|
const hasNavigatedRef = useRef(false);
|
|
@@ -63,48 +77,12 @@ function CheckDevice({
|
|
|
63
77
|
const screenHeight = window.screen.height;
|
|
64
78
|
|
|
65
79
|
const userAgent = navigator.userAgent;
|
|
66
|
-
|
|
67
|
-
let browserVersion = 'Unknown';
|
|
68
|
-
|
|
69
|
-
if (userAgent.indexOf('Chrome') > -1) {
|
|
70
|
-
browser = 'Chrome';
|
|
71
|
-
const match = userAgent.match(/Chrome\/(\d+\.\d+)/);
|
|
72
|
-
browserVersion = match ? match[1] : 'Unknown';
|
|
73
|
-
} else if (userAgent.indexOf('Firefox') > -1) {
|
|
74
|
-
browser = 'Firefox';
|
|
75
|
-
const match = userAgent.match(/Firefox\/(\d+\.\d+)/);
|
|
76
|
-
browserVersion = match ? match[1] : 'Unknown';
|
|
77
|
-
} else if (userAgent.indexOf('Safari') > -1) {
|
|
78
|
-
browser = 'Safari';
|
|
79
|
-
const match = userAgent.match(/Version\/(\d+\.\d+)/);
|
|
80
|
-
browserVersion = match ? match[1] : 'Unknown';
|
|
81
|
-
} else if (userAgent.indexOf('Edge') > -1) {
|
|
82
|
-
browser = 'Edge';
|
|
83
|
-
const match = userAgent.match(/Edge\/(\d+\.\d+)/);
|
|
84
|
-
browserVersion = match ? match[1] : 'Unknown';
|
|
85
|
-
} else if (userAgent.indexOf('MSIE') > -1 || userAgent.indexOf('Trident/') > -1) {
|
|
86
|
-
browser = 'Internet Explorer';
|
|
87
|
-
const match = userAgent.match(/(?:MSIE |rv:)(\d+\.\d+)/);
|
|
88
|
-
browserVersion = match ? match[1] : 'Unknown';
|
|
89
|
-
}
|
|
80
|
+
const { browser, browserVersion, operatingSystem } = describeUserAgent(userAgent);
|
|
90
81
|
|
|
91
82
|
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
92
83
|
userAgent,
|
|
93
84
|
);
|
|
94
85
|
|
|
95
|
-
let operatingSystem = 'Unknown';
|
|
96
|
-
if (/Windows/.test(userAgent)) {
|
|
97
|
-
operatingSystem = 'Windows';
|
|
98
|
-
} else if (/Macintosh|Mac OS X/.test(userAgent)) {
|
|
99
|
-
operatingSystem = 'MacOS';
|
|
100
|
-
} else if (/Linux/.test(userAgent)) {
|
|
101
|
-
operatingSystem = 'Linux';
|
|
102
|
-
} else if (/Android/.test(userAgent)) {
|
|
103
|
-
operatingSystem = 'Android';
|
|
104
|
-
} else if (/iOS|iPhone|iPad|iPod/.test(userAgent)) {
|
|
105
|
-
operatingSystem = 'iOS';
|
|
106
|
-
}
|
|
107
|
-
|
|
108
86
|
const hasWebAudio = !!(
|
|
109
87
|
window.AudioContext ||
|
|
110
88
|
(window as any).webkitAudioContext ||
|
|
@@ -113,16 +91,7 @@ function CheckDevice({
|
|
|
113
91
|
(window as any).msAudioContext
|
|
114
92
|
);
|
|
115
93
|
|
|
116
|
-
const hasFullscreen = !!(
|
|
117
|
-
document.exitFullscreen ||
|
|
118
|
-
(document as any).webkitExitFullscreen ||
|
|
119
|
-
(document as any).mozCancelFullScreen ||
|
|
120
|
-
(document as any).msExitFullscreen ||
|
|
121
|
-
document.fullscreenEnabled ||
|
|
122
|
-
(document as any).webkitFullscreenEnabled ||
|
|
123
|
-
(document as any).mozFullScreenEnabled ||
|
|
124
|
-
(document as any).msFullscreenEnabled
|
|
125
|
-
);
|
|
94
|
+
const hasFullscreen = !!(document.exitFullscreen || (document as any).webkitExitFullscreen);
|
|
126
95
|
|
|
127
96
|
let hasWebcam = false;
|
|
128
97
|
let hasMicrophone = false;
|
|
@@ -150,9 +119,7 @@ function CheckDevice({
|
|
|
150
119
|
hasMicrophone,
|
|
151
120
|
};
|
|
152
121
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const checkResult = check ? check(deviceInfo, data, store) : true;
|
|
122
|
+
const checkResult = acceptDevice ? acceptDevice(deviceInfo) : true;
|
|
156
123
|
|
|
157
124
|
if (checkResult && !hasNavigatedRef.current) {
|
|
158
125
|
hasNavigatedRef.current = true;
|
|
@@ -163,19 +130,32 @@ function CheckDevice({
|
|
|
163
130
|
};
|
|
164
131
|
|
|
165
132
|
gatherDeviceInfo();
|
|
166
|
-
}, [
|
|
133
|
+
}, [acceptDevice, next]);
|
|
167
134
|
|
|
168
135
|
const th = t(useTheme());
|
|
169
136
|
|
|
170
137
|
return showContent ? (
|
|
171
138
|
<div className={`min-h-screen ${th.containerBg}`}>
|
|
172
139
|
<div className='max-w-prose mx-auto mt-20 mb-20 px-4'>
|
|
173
|
-
<article className={
|
|
174
|
-
{
|
|
140
|
+
<article className={th.article}>
|
|
141
|
+
{errorContent}
|
|
175
142
|
</article>
|
|
176
143
|
</div>
|
|
177
144
|
</div>
|
|
178
145
|
) : null;
|
|
179
146
|
}
|
|
180
147
|
|
|
181
|
-
export default
|
|
148
|
+
export default defineComponent({
|
|
149
|
+
name: 'CheckDevice',
|
|
150
|
+
component: CheckDevice,
|
|
151
|
+
session: true,
|
|
152
|
+
simulate: () => {
|
|
153
|
+
const deviceInfo = {
|
|
154
|
+
windowWidth: 1920, windowHeight: 1080, screenWidth: 1920, screenHeight: 1080,
|
|
155
|
+
browser: 'Simulated', browserVersion: '1.0', isMobile: false,
|
|
156
|
+
operatingSystem: 'Simulated', hasWebAudio: true, hasFullscreen: true,
|
|
157
|
+
hasWebcam: true, hasMicrophone: true,
|
|
158
|
+
};
|
|
159
|
+
return { recorded: deviceInfo };
|
|
160
|
+
},
|
|
161
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { type BaseComponentProps, defineComponent } from '../core/component';
|
|
3
|
+
import { getNative } from '../core/platform';
|
|
4
|
+
import { noopSimulate } from '../core/simulation';
|
|
5
|
+
import { type Block, fullscreenSpan, type Timeline } from '../core/timeline';
|
|
6
|
+
import { type FullscreenGuardConfig, useSetFullscreenGuard } from '../runner/fullscreenguard';
|
|
7
|
+
import { useTheme, t } from '../runner/theme';
|
|
8
|
+
import { enterFullscreen } from '../utils/fullscreen';
|
|
9
|
+
import Text from './text';
|
|
10
|
+
|
|
11
|
+
/** The screen that asks the participant into fullscreen, and whether the block keeps them there. */
|
|
12
|
+
export interface FullscreenOptions {
|
|
13
|
+
content?: React.ReactNode;
|
|
14
|
+
buttonText?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
containerClass?: string;
|
|
17
|
+
centered?: boolean;
|
|
18
|
+
animate?: boolean;
|
|
19
|
+
/** How long after entering fullscreen the block's first item starts. */
|
|
20
|
+
delayMs?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Shows a prompt to return to fullscreen on every trial of the block. `true` renders a small
|
|
23
|
+
* top-left button with default text; a config customizes the button text, or switches to a
|
|
24
|
+
* full-screen overlay with custom content.
|
|
25
|
+
*/
|
|
26
|
+
keepFullscreen?: boolean | FullscreenGuardConfig;
|
|
27
|
+
/** Ends the experiment on the screen when the browser cannot enter fullscreen, instead of asking again. Nothing is uploaded. */
|
|
28
|
+
stopOnFailure?: boolean;
|
|
29
|
+
/** Shown when the browser could not enter fullscreen: above the button when asking again, or on its own when stopping. */
|
|
30
|
+
errorContent?: React.ReactNode;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function EnterFullscreen({
|
|
34
|
+
content,
|
|
35
|
+
buttonText,
|
|
36
|
+
className,
|
|
37
|
+
containerClass,
|
|
38
|
+
centered,
|
|
39
|
+
animate,
|
|
40
|
+
next,
|
|
41
|
+
delayMs = 0,
|
|
42
|
+
keepFullscreen = false,
|
|
43
|
+
stopOnFailure = false,
|
|
44
|
+
errorContent,
|
|
45
|
+
}: FullscreenOptions & BaseComponentProps) {
|
|
46
|
+
const [isWaiting, setIsWaiting] = useState(false);
|
|
47
|
+
const [failed, setFailed] = useState(false);
|
|
48
|
+
const setGuard = useSetFullscreenGuard();
|
|
49
|
+
const timeoutId = useRef<ReturnType<typeof setTimeout>>(undefined);
|
|
50
|
+
useEffect(() => () => clearTimeout(timeoutId.current), []);
|
|
51
|
+
|
|
52
|
+
const handleEnterFullscreenClick = async () => {
|
|
53
|
+
setIsWaiting(true);
|
|
54
|
+
getNative()?.enterFullscreen();
|
|
55
|
+
try {
|
|
56
|
+
await enterFullscreen();
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error('Fullscreen request failed:', error);
|
|
59
|
+
// In the apps, the native call is what makes the app fullscreen, so a browser that refuses does not hold the participant back
|
|
60
|
+
if (!getNative()) {
|
|
61
|
+
setIsWaiting(false);
|
|
62
|
+
setFailed(true);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (keepFullscreen) setGuard(keepFullscreen === true ? {} : keepFullscreen);
|
|
67
|
+
timeoutId.current = setTimeout(() => next({}), delayMs);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const th = t(useTheme());
|
|
71
|
+
|
|
72
|
+
if (isWaiting) {
|
|
73
|
+
return <div className={`min-h-screen ${containerClass ?? th.containerBg}`} />;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const error =
|
|
77
|
+
errorContent ??
|
|
78
|
+
(stopOnFailure ? (
|
|
79
|
+
<p>This study needs fullscreen mode, which could not be started on this device. Unfortunately, you cannot continue.</p>
|
|
80
|
+
) : (
|
|
81
|
+
<p>Fullscreen mode could not be started. Please try again.</p>
|
|
82
|
+
));
|
|
83
|
+
|
|
84
|
+
if (failed && stopOnFailure) {
|
|
85
|
+
return (
|
|
86
|
+
<Text
|
|
87
|
+
className={className}
|
|
88
|
+
containerClass={containerClass}
|
|
89
|
+
centered={centered}
|
|
90
|
+
content={error}
|
|
91
|
+
buttonText=''
|
|
92
|
+
next={() => {}}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Text
|
|
99
|
+
className={className}
|
|
100
|
+
containerClass={containerClass}
|
|
101
|
+
centered={centered}
|
|
102
|
+
animate={animate}
|
|
103
|
+
content={
|
|
104
|
+
<div className='flex flex-col items-center'>
|
|
105
|
+
{failed && error}
|
|
106
|
+
{!!content && content}
|
|
107
|
+
{!content && <p className=''>Please click the Button below to enter Fullscreen mode.</p>}
|
|
108
|
+
</div>
|
|
109
|
+
}
|
|
110
|
+
buttonText={buttonText ?? 'Enter Fullscreen Mode'}
|
|
111
|
+
next={handleEnterFullscreenClick}
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const EnterFullscreenScreen = defineComponent({
|
|
117
|
+
name: 'EnterFullscreen',
|
|
118
|
+
component: EnterFullscreen,
|
|
119
|
+
csv: null,
|
|
120
|
+
simulate: noopSimulate,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Runs the items in fullscreen. A screen first asks the participant into it, and the experiment
|
|
125
|
+
* leaves it once the run is outside the block, at its end or through a jump. On the settings
|
|
126
|
+
* screen, the block's screen is an item of its own, so the items can run without it.
|
|
127
|
+
*/
|
|
128
|
+
export function fullscreenBlock(options: FullscreenOptions, items: Timeline): Block<'trials'> {
|
|
129
|
+
return fullscreenSpan([EnterFullscreenScreen.trial(options), ...items]);
|
|
130
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Heroicons, solid 24px (MIT License, https://heroicons.com)
|
|
2
|
+
|
|
3
|
+
type IconProps = { className?: string };
|
|
4
|
+
|
|
5
|
+
export const MicrophoneIcon = ({ className }: IconProps) => (
|
|
6
|
+
<svg viewBox='0 0 24 24' fill='currentColor' aria-hidden='true' className={className}>
|
|
7
|
+
<path d='M8.25 4.5a3.75 3.75 0 1 1 7.5 0v8.25a3.75 3.75 0 1 1-7.5 0V4.5Z' />
|
|
8
|
+
<path d='M6 10.5a.75.75 0 0 1 .75.75v1.5a5.25 5.25 0 1 0 10.5 0v-1.5a.75.75 0 0 1 1.5 0v1.5a6.751 6.751 0 0 1-6 6.709v2.291h3a.75.75 0 0 1 0 1.5h-7.5a.75.75 0 0 1 0-1.5h3v-2.291a6.751 6.751 0 0 1-6-6.709v-1.5A.75.75 0 0 1 6 10.5Z' />
|
|
9
|
+
</svg>
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export const StopIcon = ({ className }: IconProps) => (
|
|
13
|
+
<svg viewBox='0 0 24 24' fill='currentColor' aria-hidden='true' className={className}>
|
|
14
|
+
<path
|
|
15
|
+
fillRule='evenodd'
|
|
16
|
+
clipRule='evenodd'
|
|
17
|
+
d='M4.5 7.5a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3h-9a3 3 0 0 1-3-3v-9Z'
|
|
18
|
+
/>
|
|
19
|
+
</svg>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const PauseIcon = ({ className }: IconProps) => (
|
|
23
|
+
<svg viewBox='0 0 24 24' fill='currentColor' aria-hidden='true' className={className}>
|
|
24
|
+
<path
|
|
25
|
+
fillRule='evenodd'
|
|
26
|
+
clipRule='evenodd'
|
|
27
|
+
d='M6.75 5.25a.75.75 0 0 1 .75-.75H9a.75.75 0 0 1 .75.75v13.5a.75.75 0 0 1-.75.75H7.5a.75.75 0 0 1-.75-.75V5.25Zm7.5 0A.75.75 0 0 1 15 4.5h1.5a.75.75 0 0 1 .75.75v13.5a.75.75 0 0 1-.75.75H15a.75.75 0 0 1-.75-.75V5.25Z'
|
|
28
|
+
/>
|
|
29
|
+
</svg>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const TrashIcon = ({ className }: IconProps) => (
|
|
33
|
+
<svg viewBox='0 0 24 24' fill='currentColor' aria-hidden='true' className={className}>
|
|
34
|
+
<path
|
|
35
|
+
fillRule='evenodd'
|
|
36
|
+
clipRule='evenodd'
|
|
37
|
+
d='M16.5 4.478v.227a48.816 48.816 0 0 1 3.878.512.75.75 0 1 1-.256 1.478l-.209-.035-1.005 13.07a3 3 0 0 1-2.991 2.77H8.084a3 3 0 0 1-2.991-2.77L4.087 6.66l-.209.035a.75.75 0 0 1-.256-1.478A48.567 48.567 0 0 1 7.5 4.705v-.227c0-1.564 1.213-2.9 2.816-2.951a52.662 52.662 0 0 1 3.369 0c1.603.051 2.815 1.387 2.815 2.951Zm-6.136-1.452a51.196 51.196 0 0 1 3.273 0C14.39 3.05 15 3.684 15 4.478v.113a49.488 49.488 0 0 0-6 0v-.113c0-.794.609-1.428 1.364-1.452Zm-.355 5.945a.75.75 0 1 0-1.5.058l.347 9a.75.75 0 1 0 1.499-.058l-.346-9Zm5.48.058a.75.75 0 1 0-1.498-.058l-.347 9a.75.75 0 0 0 1.5.058l.345-9Z'
|
|
38
|
+
/>
|
|
39
|
+
</svg>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export const ExclamationTriangleIcon = ({ className }: IconProps) => (
|
|
43
|
+
<svg viewBox='0 0 24 24' fill='currentColor' aria-hidden='true' className={className}>
|
|
44
|
+
<path
|
|
45
|
+
fillRule='evenodd'
|
|
46
|
+
clipRule='evenodd'
|
|
47
|
+
d='M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z'
|
|
48
|
+
/>
|
|
49
|
+
</svg>
|
|
50
|
+
);
|
package/src/components/index.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
export { default as Text } from './text';
|
|
2
|
+
export { default as Stimulus, Canvas, type StimulusAnswer, type StimulusChoice, type StimulusControls, type StimulusData, type StimulusResponse } from './stimulus';
|
|
2
3
|
export { default as PlainInput } from './plaininput';
|
|
3
4
|
export { default as ProlificEnding } from './prolificending';
|
|
4
|
-
export { default as
|
|
5
|
-
export { default as Quest } from './quest';
|
|
5
|
+
export { default as MicrophoneCheck } from './microphonecheck';
|
|
6
6
|
export { default as Upload } from './upload';
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export { default as
|
|
10
|
-
export { default as
|
|
11
|
-
export { default as RequestFilePermission } from './mobilefilepermission';
|
|
7
|
+
export { fullscreenBlock, type FullscreenOptions } from './fullscreenblock';
|
|
8
|
+
export type { FullscreenGuardConfig } from '../runner/fullscreenguard';
|
|
9
|
+
export { default as ExperimentRunner } from '../runner/experimentrunner';
|
|
10
|
+
export { default as RequestFilePermission } from './requestfilepermission';
|
|
12
11
|
export { default as CanvasBlock } from './canvasblock';
|
|
13
12
|
export { default as CheckDevice } from './checkdevice';
|
|
14
|
-
export {
|
|
15
|
-
export type { TutorialProps } from './tutorial';
|
|
13
|
+
export { default as StoreUI } from './storeui';
|
|
16
14
|
export { default as VoiceRecording } from './voicerecording';
|
|
17
|
-
export { RandomDotKinematogram
|
|
18
|
-
export type {
|
|
15
|
+
export { RandomDotKinematogram } from './randomdotkinematogram';
|
|
16
|
+
export type { RDKProps, RDKResponse, RDKSettings, RDKMessage, RDKFeedback, NoiseMovement } from './randomdotkinematogram';
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { BaseComponentProps } from '../
|
|
6
|
-
import { useTheme, t } from '../
|
|
7
|
-
|
|
8
|
-
registerFlattener('MicrophoneCheck', 'session');
|
|
9
|
-
registerSimulation('MicrophoneCheck', noopSimulate, {});
|
|
1
|
+
import { type ReactNode, useState, useEffect } from 'react';
|
|
2
|
+
import { Recorder } from './recorder';
|
|
3
|
+
import { noopSimulate } from '../core/simulation';
|
|
4
|
+
import { defineComponent } from '../core/component';
|
|
5
|
+
import { BaseComponentProps } from '../core/component';
|
|
6
|
+
import { useTheme, t } from '../runner/theme';
|
|
10
7
|
|
|
11
8
|
interface MicrophoneDevice {
|
|
12
9
|
deviceId: string;
|
|
@@ -16,20 +13,25 @@ interface MicrophoneDevice {
|
|
|
16
13
|
function MicrophoneSelect({
|
|
17
14
|
onMicrophoneSelect,
|
|
18
15
|
disabled = false,
|
|
16
|
+
placeholder,
|
|
19
17
|
}: {
|
|
20
18
|
onMicrophoneSelect: (deviceId: string) => void;
|
|
21
19
|
disabled?: boolean;
|
|
20
|
+
placeholder: string;
|
|
22
21
|
}) {
|
|
23
22
|
const th = t(useTheme());
|
|
24
23
|
const [microphones, setMicrophones] = useState<MicrophoneDevice[]>([]);
|
|
25
24
|
const [selectedMic, setSelectedMic] = useState<string>('');
|
|
26
25
|
const [isOpen, setIsOpen] = useState(false);
|
|
27
26
|
|
|
27
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: asks for microphone access and picks a default device only once
|
|
28
28
|
useEffect(() => {
|
|
29
29
|
navigator.mediaDevices
|
|
30
30
|
.getUserMedia({ audio: true })
|
|
31
31
|
.then((stream) => {
|
|
32
|
-
stream.getTracks().forEach((track) =>
|
|
32
|
+
stream.getTracks().forEach((track) => {
|
|
33
|
+
track.stop();
|
|
34
|
+
});
|
|
33
35
|
navigator.mediaDevices.enumerateDevices().then((devices) => {
|
|
34
36
|
const mics = devices
|
|
35
37
|
.filter((device) => device.kind === 'audioinput')
|
|
@@ -39,7 +41,7 @@ function MicrophoneSelect({
|
|
|
39
41
|
}));
|
|
40
42
|
setMicrophones(mics);
|
|
41
43
|
|
|
42
|
-
if (mics.length > 0
|
|
44
|
+
if (mics.length > 0) {
|
|
43
45
|
setSelectedMic(mics[0].deviceId);
|
|
44
46
|
onMicrophoneSelect(mics[0].deviceId);
|
|
45
47
|
}
|
|
@@ -57,7 +59,7 @@ function MicrophoneSelect({
|
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
const selectedLabel =
|
|
60
|
-
microphones.find((mic) => mic.deviceId === selectedMic)?.label ||
|
|
62
|
+
microphones.find((mic) => mic.deviceId === selectedMic)?.label || placeholder;
|
|
61
63
|
|
|
62
64
|
return (
|
|
63
65
|
<div className='relative w-64 mx-auto mt-8 mb-8'>
|
|
@@ -90,7 +92,50 @@ function MicrophoneSelect({
|
|
|
90
92
|
);
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
const MicrophoneCheck = ({
|
|
95
|
+
const MicrophoneCheck = ({
|
|
96
|
+
next,
|
|
97
|
+
updateStore,
|
|
98
|
+
animate = false,
|
|
99
|
+
discardButtonText,
|
|
100
|
+
content = (
|
|
101
|
+
<>
|
|
102
|
+
<h1 className='text-3xl mb-6 font-semibold'>Let's test your microphone!</h1>
|
|
103
|
+
<p>
|
|
104
|
+
In this experiment, you will need to answer some questions verbally. To make sure that we
|
|
105
|
+
don't lose your input, please select your preferred microphone using the menu below...
|
|
106
|
+
</p>
|
|
107
|
+
</>
|
|
108
|
+
),
|
|
109
|
+
recordingContent = (
|
|
110
|
+
<p>
|
|
111
|
+
... and use the recording button below to make a test recording of your voice. After
|
|
112
|
+
stopping the recording, you can use the play button to play back the audio.
|
|
113
|
+
</p>
|
|
114
|
+
),
|
|
115
|
+
playbackContent = (
|
|
116
|
+
<p>
|
|
117
|
+
Can you hear yourself? Great! You can continue on to the next step. <br /> If you can't hear
|
|
118
|
+
your voice, try one of the other options from the list or check any physical mute switches on
|
|
119
|
+
your microphone. Be sure to also check that your computer audio is turned on so you can
|
|
120
|
+
actually listen back to your test recording!
|
|
121
|
+
</p>
|
|
122
|
+
),
|
|
123
|
+
buttonText = 'Next',
|
|
124
|
+
placeholder = 'Select Microphone',
|
|
125
|
+
}: BaseComponentProps & {
|
|
126
|
+
animate?: boolean;
|
|
127
|
+
/** The button that throws a test recording away. */
|
|
128
|
+
discardButtonText?: string;
|
|
129
|
+
/** Shown above the microphone menu. */
|
|
130
|
+
content?: ReactNode;
|
|
131
|
+
/** Shown above the recording button. */
|
|
132
|
+
recordingContent?: ReactNode;
|
|
133
|
+
/** Shown once a test recording exists, above the button. */
|
|
134
|
+
playbackContent?: ReactNode;
|
|
135
|
+
buttonText?: string;
|
|
136
|
+
/** Shown in the microphone menu until a microphone is selected. */
|
|
137
|
+
placeholder?: string;
|
|
138
|
+
}) => {
|
|
94
139
|
const th = t(useTheme());
|
|
95
140
|
const [recordingExists, setRecordingExists] = useState(false);
|
|
96
141
|
const [isRecording, setIsRecording] = useState(false);
|
|
@@ -98,57 +143,45 @@ const MicrophoneCheck = ({ next, updateStore, animate = false, discardLabel }: B
|
|
|
98
143
|
|
|
99
144
|
const handleMicSelect = (id: string) => {
|
|
100
145
|
setSelectedDeviceId(id);
|
|
101
|
-
updateStore({
|
|
146
|
+
updateStore({ __audioInputId: id });
|
|
102
147
|
};
|
|
103
148
|
|
|
104
149
|
return (
|
|
105
150
|
<div className={`min-h-screen ${th.containerBg}`}>
|
|
106
151
|
<div className={`max-w-prose mx-auto mt-20 mb-20 px-4 ${animate ? 'animate-fade-in opacity-0' : ''}`}>
|
|
107
|
-
<article className={
|
|
108
|
-
|
|
109
|
-
<p>
|
|
110
|
-
In this experiment, you will need to answer some questions verbally. To make sure that we
|
|
111
|
-
don't lose your input, please select your preferred microphone using the menu below...
|
|
112
|
-
</p>
|
|
152
|
+
<article className={th.article}>
|
|
153
|
+
{content}
|
|
113
154
|
</article>
|
|
114
|
-
<MicrophoneSelect onMicrophoneSelect={handleMicSelect} disabled={isRecording} />
|
|
155
|
+
<MicrophoneSelect onMicrophoneSelect={handleMicSelect} disabled={isRecording} placeholder={placeholder} />
|
|
115
156
|
|
|
116
|
-
<article className={
|
|
117
|
-
|
|
118
|
-
... and use the recording button below to make a test recording of your voice. After
|
|
119
|
-
stopping the recording, you can use the play button to play back the audio.
|
|
120
|
-
</p>
|
|
157
|
+
<article className={th.article}>
|
|
158
|
+
{recordingContent}
|
|
121
159
|
</article>
|
|
122
160
|
|
|
123
161
|
<div className='mt-4 mb-12'>
|
|
124
|
-
<
|
|
162
|
+
<Recorder
|
|
125
163
|
onRecordingStart={() => setIsRecording(true)}
|
|
126
164
|
handleSaveVoiceData={() => { setRecordingExists(true); setIsRecording(false); }}
|
|
127
165
|
handleDiscardVoiceData={() => { setRecordingExists(false); setIsRecording(false); }}
|
|
128
166
|
deviceId={selectedDeviceId}
|
|
129
167
|
showPause={false}
|
|
130
168
|
showDiscard={false}
|
|
131
|
-
|
|
169
|
+
discardButtonText={discardButtonText}
|
|
132
170
|
/>
|
|
133
171
|
</div>
|
|
134
172
|
|
|
135
173
|
{recordingExists && (
|
|
136
174
|
<div className='animate-fade-in opacity-0'>
|
|
137
|
-
<article className={
|
|
138
|
-
|
|
139
|
-
Can you hear yourself? Great! You can continue on to the next step. <br /> If you
|
|
140
|
-
can't hear your voice, try one of the other options from the list or check any
|
|
141
|
-
physical mute switches on your microphone. Be sure to also check that your computer
|
|
142
|
-
audio is turned on so you can actually listen back to your test recording!
|
|
143
|
-
</p>
|
|
175
|
+
<article className={th.article}>
|
|
176
|
+
{playbackContent}
|
|
144
177
|
</article>
|
|
145
178
|
|
|
146
179
|
<div className='mt-16 flex justify-center'>
|
|
147
180
|
<button
|
|
148
181
|
onClick={() => next({})}
|
|
149
|
-
className={
|
|
182
|
+
className={th.button}
|
|
150
183
|
>
|
|
151
|
-
|
|
184
|
+
{buttonText}
|
|
152
185
|
</button>
|
|
153
186
|
</div>
|
|
154
187
|
</div>
|
|
@@ -158,4 +191,9 @@ const MicrophoneCheck = ({ next, updateStore, animate = false, discardLabel }: B
|
|
|
158
191
|
);
|
|
159
192
|
};
|
|
160
193
|
|
|
161
|
-
export default
|
|
194
|
+
export default defineComponent({
|
|
195
|
+
name: 'MicrophoneCheck',
|
|
196
|
+
component: MicrophoneCheck,
|
|
197
|
+
csv: null,
|
|
198
|
+
simulate: noopSimulate,
|
|
199
|
+
});
|