@adriansteffan/reactive 0.1.30 → 0.1.32
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/.claude/settings.local.json +3 -1
- package/bin/setup.js +9 -9
- package/dist/{mod-CUZcjHfZ.js → mod-BstzgRJu.js} +4790 -4757
- package/dist/mod.d.ts +18 -0
- package/dist/reactive.es.js +1 -1
- package/dist/reactive.umd.js +212 -212
- package/dist/style.css +1 -1
- package/dist/{web-Dz1I9Wa3.js → web-BuhM8wPq.js} +1 -1
- package/dist/{web-BEDMfcxc.js → web-DAsCmbYK.js} +1 -1
- package/package.json +1 -1
- package/src/components/index.ts +1 -1
- package/src/components/randomdotkinetogram.tsx +168 -73
package/package.json
CHANGED
package/src/components/index.ts
CHANGED
|
@@ -14,4 +14,4 @@ export { default as CheckDevice } from './checkdevice';
|
|
|
14
14
|
export { Tutorial, useTutorialSlide } from './tutorial';
|
|
15
15
|
export type { TutorialProps } from './tutorial';
|
|
16
16
|
export { RandomDotKinematogram, RDKCanvas } from './randomdotkinetogram';
|
|
17
|
-
export type { RDKCanvasProps, RDKCanvasHandle, RDKProps, NoiseMovement } from './randomdotkinetogram';
|
|
17
|
+
export type { RDKCanvasProps, RDKCanvasHandle, RDKProps, RDKMessage, RDKFeedback, NoiseMovement } from './randomdotkinetogram';
|
|
@@ -52,6 +52,7 @@ registerSimulation('RandomDotKinematogram', (trialProps, _experimentState, simul
|
|
|
52
52
|
const result = simulators.respond(merged, participant);
|
|
53
53
|
const { rt, response } = result.value;
|
|
54
54
|
|
|
55
|
+
const preTrialDuration = merged.preTrialMessage?.duration ?? 0;
|
|
55
56
|
const fixation = merged.fixationTime ?? RDK_DEFAULTS.fixationTime;
|
|
56
57
|
const trialDuration = merged.duration ?? RDK_DEFAULTS.duration;
|
|
57
58
|
const responseEndsTrial = merged.responseEndsTrial ?? RDK_DEFAULTS.responseEndsTrial;
|
|
@@ -60,18 +61,39 @@ registerSimulation('RandomDotKinematogram', (trialProps, _experimentState, simul
|
|
|
60
61
|
const correctKeys = Array.isArray(merged.correctResponse)
|
|
61
62
|
? merged.correctResponse.map((c: string) => c.toLowerCase())
|
|
62
63
|
: merged.correctResponse ? [merged.correctResponse.toLowerCase()] : null;
|
|
64
|
+
const correct = response && correctKeys ? correctKeys.includes(response.toLowerCase()) : null;
|
|
65
|
+
|
|
66
|
+
let totalDuration = preTrialDuration + fixation + elapsed;
|
|
67
|
+
|
|
68
|
+
const responseData: Record<string, any> = {
|
|
69
|
+
...merged,
|
|
70
|
+
rt,
|
|
71
|
+
response,
|
|
72
|
+
correct,
|
|
73
|
+
framesDisplayed: 0,
|
|
74
|
+
measuredRefreshRate: null,
|
|
75
|
+
feedbackShown: null as string | null,
|
|
76
|
+
feedbackDuration: null as number | null,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const fb = merged.feedback as RDKFeedback | undefined;
|
|
80
|
+
if (fb) {
|
|
81
|
+
let shown: RDKMessage | null = null;
|
|
82
|
+
if (rt === null && fb.onTimeout) shown = fb.onTimeout;
|
|
83
|
+
else if (correct === false && fb.onIncorrect) shown = fb.onIncorrect;
|
|
84
|
+
else if (correct === true && fb.onCorrect) shown = fb.onCorrect;
|
|
85
|
+
|
|
86
|
+
if (shown) {
|
|
87
|
+
responseData.feedbackShown = shown.content;
|
|
88
|
+
responseData.feedbackDuration = shown.duration;
|
|
89
|
+
totalDuration += shown.duration;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
63
92
|
|
|
64
93
|
return {
|
|
65
|
-
responseData
|
|
66
|
-
...merged,
|
|
67
|
-
rt,
|
|
68
|
-
response,
|
|
69
|
-
correct: response && correctKeys ? correctKeys.includes(response.toLowerCase()) : null,
|
|
70
|
-
framesDisplayed: 0,
|
|
71
|
-
measuredRefreshRate: null,
|
|
72
|
-
},
|
|
94
|
+
responseData,
|
|
73
95
|
participantState: result.participantState,
|
|
74
|
-
duration:
|
|
96
|
+
duration: totalDuration,
|
|
75
97
|
};
|
|
76
98
|
}, {
|
|
77
99
|
respond: (trialProps: any, participant: any) => {
|
|
@@ -96,6 +118,20 @@ registerSimulation('RandomDotKinematogram', (trialProps, _experimentState, simul
|
|
|
96
118
|
},
|
|
97
119
|
});
|
|
98
120
|
|
|
121
|
+
export interface RDKMessage {
|
|
122
|
+
content: string;
|
|
123
|
+
duration: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface RDKFeedback {
|
|
127
|
+
/** Shown when rt === null (no response within duration) */
|
|
128
|
+
onTimeout?: RDKMessage;
|
|
129
|
+
/** Shown when the response was incorrect (correct === false) */
|
|
130
|
+
onIncorrect?: RDKMessage;
|
|
131
|
+
/** Shown when the response was correct (correct === true) */
|
|
132
|
+
onCorrect?: RDKMessage;
|
|
133
|
+
}
|
|
134
|
+
|
|
99
135
|
// this is assigned per dot
|
|
100
136
|
export type NoiseMovement = 'randomTeleport' | 'randomWalk' | 'randomDirection';
|
|
101
137
|
type FrameMovement = 'coherent' | 'opposite' | NoiseMovement;
|
|
@@ -864,6 +900,10 @@ export interface RDKProps extends BaseComponentProps {
|
|
|
864
900
|
borderWidth?: number;
|
|
865
901
|
borderColor?: string;
|
|
866
902
|
responseHint?: string;
|
|
903
|
+
/** Timed message shown before the fixation cross. Useful for per-trial condition cues. */
|
|
904
|
+
preTrialMessage?: RDKMessage;
|
|
905
|
+
/** Post-response feedback. Evaluated after response/timeout, displayed before calling next(). */
|
|
906
|
+
feedback?: RDKFeedback;
|
|
867
907
|
}
|
|
868
908
|
|
|
869
909
|
export const RandomDotKinematogram = (rawProps: RDKProps) => {
|
|
@@ -884,18 +924,29 @@ export const RandomDotKinematogram = (rawProps: RDKProps) => {
|
|
|
884
924
|
const propsRef = useRef(rawProps);
|
|
885
925
|
propsRef.current = rawProps;
|
|
886
926
|
|
|
927
|
+
const preTrialDuration = rawProps.preTrialMessage?.duration ?? 0;
|
|
928
|
+
|
|
887
929
|
const canvasHandle = useRef<RDKCanvasHandle>(null);
|
|
888
930
|
const startTimeRef = useRef<number>(performance.now());
|
|
889
931
|
const trialEndedRef = useRef(false);
|
|
890
932
|
const responseRef = useRef<string | null>(null);
|
|
891
933
|
const responseTimeRef = useRef<number | null>(null);
|
|
892
934
|
|
|
935
|
+
const [preTrialDone, setPreTrialDone] = useState(!rawProps.preTrialMessage);
|
|
893
936
|
const [response, setResponse] = useState<string | null>(null);
|
|
894
937
|
const [fixationComplete, setFixationComplete] = useState(fixationTime <= 0);
|
|
895
938
|
const [stimulusVisible, setStimulusVisible] = useState(true);
|
|
939
|
+
const [feedbackMsg, setFeedbackMsg] = useState<RDKMessage | null>(null);
|
|
896
940
|
|
|
897
941
|
const initialRefreshRate = store?._reactiveScreenRefreshRate;
|
|
898
942
|
|
|
943
|
+
// Pre-trial message timer
|
|
944
|
+
useEffect(() => {
|
|
945
|
+
if (!rawProps.preTrialMessage) return;
|
|
946
|
+
const timer = setTimeout(() => setPreTrialDone(true), rawProps.preTrialMessage.duration);
|
|
947
|
+
return () => clearTimeout(timer);
|
|
948
|
+
}, []);
|
|
949
|
+
|
|
899
950
|
const endTrial = useCallback((key: string | null, rt: number | null) => {
|
|
900
951
|
if (trialEndedRef.current) return;
|
|
901
952
|
trialEndedRef.current = true;
|
|
@@ -907,46 +958,66 @@ export const RandomDotKinematogram = (rawProps: RDKProps) => {
|
|
|
907
958
|
: rdkProps.correctResponse
|
|
908
959
|
? [rdkProps.correctResponse.toLowerCase()]
|
|
909
960
|
: null;
|
|
961
|
+
const correct = key && correctKeys ? correctKeys.includes(key) : null;
|
|
910
962
|
|
|
911
|
-
|
|
963
|
+
const responseData: Record<string, any> = {
|
|
912
964
|
...RDK_DEFAULTS,
|
|
913
965
|
...rdkProps,
|
|
914
966
|
rt,
|
|
915
967
|
response: key,
|
|
916
|
-
correct
|
|
968
|
+
correct,
|
|
917
969
|
framesDisplayed: stats?.framesDisplayed ?? 0,
|
|
918
970
|
measuredRefreshRate: stats?.measuredRefreshRate ?? null,
|
|
919
|
-
|
|
971
|
+
feedbackShown: null,
|
|
972
|
+
feedbackDuration: null,
|
|
973
|
+
};
|
|
974
|
+
|
|
975
|
+
const fb = rdkProps.feedback;
|
|
976
|
+
let shown: RDKMessage | null = null;
|
|
977
|
+
if (fb) {
|
|
978
|
+
if (rt === null && fb.onTimeout) shown = fb.onTimeout;
|
|
979
|
+
else if (correct === false && fb.onIncorrect) shown = fb.onIncorrect;
|
|
980
|
+
else if (correct === true && fb.onCorrect) shown = fb.onCorrect;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
if (shown) {
|
|
984
|
+
responseData.feedbackShown = shown.content;
|
|
985
|
+
responseData.feedbackDuration = shown.duration;
|
|
986
|
+
setFeedbackMsg(shown);
|
|
987
|
+
setTimeout(() => nextFn(responseData), shown.duration);
|
|
988
|
+
} else {
|
|
989
|
+
nextFn(responseData);
|
|
990
|
+
}
|
|
920
991
|
}, []);
|
|
921
992
|
|
|
922
|
-
// Fixation duration delay before showing dots
|
|
993
|
+
// Fixation duration delay before showing dots (offset by preTrialDuration)
|
|
923
994
|
useEffect(() => {
|
|
924
995
|
if (fixationTime <= 0) return;
|
|
925
|
-
const timer = setTimeout(() => setFixationComplete(true), fixationTime);
|
|
996
|
+
const timer = setTimeout(() => setFixationComplete(true), preTrialDuration + fixationTime);
|
|
926
997
|
return () => clearTimeout(timer);
|
|
927
|
-
}, [fixationTime]);
|
|
998
|
+
}, [fixationTime, preTrialDuration]);
|
|
928
999
|
|
|
929
|
-
// Stimulus duration timer
|
|
1000
|
+
// Stimulus duration timer (offset by preTrialDuration)
|
|
930
1001
|
useEffect(() => {
|
|
931
1002
|
const effectiveStimDur = stimulusDuration ?? duration;
|
|
932
1003
|
if (effectiveStimDur <= 0) return;
|
|
933
|
-
const timer = setTimeout(() => setStimulusVisible(false), fixationTime + effectiveStimDur);
|
|
1004
|
+
const timer = setTimeout(() => setStimulusVisible(false), preTrialDuration + fixationTime + effectiveStimDur);
|
|
934
1005
|
return () => clearTimeout(timer);
|
|
935
|
-
}, [fixationTime, stimulusDuration, duration]);
|
|
1006
|
+
}, [preTrialDuration, fixationTime, stimulusDuration, duration]);
|
|
936
1007
|
|
|
937
|
-
// Trial duration timer — ends trial with whatever response was collected
|
|
1008
|
+
// Trial duration timer — ends trial with whatever response was collected (offset by preTrialDuration)
|
|
938
1009
|
useEffect(() => {
|
|
939
1010
|
if (duration <= 0) return;
|
|
940
1011
|
const timer = setTimeout(() => {
|
|
941
1012
|
endTrial(responseRef.current, responseTimeRef.current);
|
|
942
|
-
}, fixationTime + duration);
|
|
1013
|
+
}, preTrialDuration + fixationTime + duration);
|
|
943
1014
|
return () => clearTimeout(timer);
|
|
944
|
-
}, [fixationTime, duration, endTrial]);
|
|
1015
|
+
}, [preTrialDuration, fixationTime, duration, endTrial]);
|
|
945
1016
|
|
|
946
|
-
// Handle keyboard response
|
|
1017
|
+
// Handle keyboard response (blocked during preTrialMessage)
|
|
947
1018
|
useEffect(() => {
|
|
948
1019
|
const handleKeyPress = (e: KeyboardEvent) => {
|
|
949
|
-
if (trialEndedRef.current || responseRef.current) return;
|
|
1020
|
+
if (trialEndedRef.current || responseRef.current || !preTrialDone) return;
|
|
950
1021
|
|
|
951
1022
|
const key = e.key.toLowerCase();
|
|
952
1023
|
const allowedKeys = validKeys.length > 0 ? validKeys.map((c) => c.toLowerCase()) : null;
|
|
@@ -965,59 +1036,83 @@ export const RandomDotKinematogram = (rawProps: RDKProps) => {
|
|
|
965
1036
|
|
|
966
1037
|
window.addEventListener('keydown', handleKeyPress);
|
|
967
1038
|
return () => window.removeEventListener('keydown', handleKeyPress);
|
|
968
|
-
}, [validKeys, responseEndsTrial, endTrial]);
|
|
1039
|
+
}, [validKeys, responseEndsTrial, endTrial, preTrialDone]);
|
|
1040
|
+
|
|
1041
|
+
const messageOverlay = (text: string) => (
|
|
1042
|
+
<div
|
|
1043
|
+
style={{
|
|
1044
|
+
position: 'absolute',
|
|
1045
|
+
inset: 0,
|
|
1046
|
+
display: 'flex',
|
|
1047
|
+
alignItems: 'center',
|
|
1048
|
+
justifyContent: 'center',
|
|
1049
|
+
}}
|
|
1050
|
+
>
|
|
1051
|
+
<span style={{ color: 'white', fontSize: '2rem', fontWeight: 'bold', textAlign: 'center', padding: '0 2rem' }}>
|
|
1052
|
+
{text}
|
|
1053
|
+
</span>
|
|
1054
|
+
</div>
|
|
1055
|
+
);
|
|
969
1056
|
|
|
970
1057
|
return (
|
|
971
1058
|
<div style={{ width: '100vw', height: '100vh', overflow: 'hidden', margin: 0, padding: 0, backgroundColor }}>
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1059
|
+
{!preTrialDone ? (
|
|
1060
|
+
messageOverlay(rawProps.preTrialMessage!.content)
|
|
1061
|
+
) : feedbackMsg ? (
|
|
1062
|
+
messageOverlay(feedbackMsg.content)
|
|
1063
|
+
) : (
|
|
1064
|
+
<>
|
|
1065
|
+
<RDKCanvas
|
|
1066
|
+
ref={canvasHandle}
|
|
1067
|
+
width={window.innerWidth}
|
|
1068
|
+
height={window.innerHeight}
|
|
1069
|
+
active={fixationComplete && stimulusVisible}
|
|
1070
|
+
initialRefreshRate={initialRefreshRate}
|
|
1071
|
+
dotCount={dotCount}
|
|
1072
|
+
dotSetCount={dotSetCount}
|
|
1073
|
+
direction={direction}
|
|
1074
|
+
coherence={coherence}
|
|
1075
|
+
opposite={opposite}
|
|
1076
|
+
speed={speed}
|
|
1077
|
+
dotLifetime={dotLifetime}
|
|
1078
|
+
updateRate={updateRate}
|
|
1079
|
+
dotRadius={dotRadius}
|
|
1080
|
+
dotCharacter={dotCharacter}
|
|
1081
|
+
dotColor={dotColor}
|
|
1082
|
+
coherentDotColor={coherentDotColor}
|
|
1083
|
+
backgroundColor={backgroundColor}
|
|
1084
|
+
apertureShape={apertureShape}
|
|
1085
|
+
apertureWidth={apertureWidth}
|
|
1086
|
+
apertureHeight={apertureHeight}
|
|
1087
|
+
apertureCenterX={apertureCenterX}
|
|
1088
|
+
apertureCenterY={apertureCenterY}
|
|
1089
|
+
reinsertMode={reinsertMode}
|
|
1090
|
+
noiseMovement={noiseMovement}
|
|
1091
|
+
reassignEveryMs={reassignEveryMs}
|
|
1092
|
+
showFixation={showFixation}
|
|
1093
|
+
fixationWidth={fixationWidth}
|
|
1094
|
+
fixationHeight={fixationHeight}
|
|
1095
|
+
fixationColor={fixationColor}
|
|
1096
|
+
fixationThickness={fixationThickness}
|
|
1097
|
+
showBorder={showBorder}
|
|
1098
|
+
borderWidth={borderWidth}
|
|
1099
|
+
borderColor={borderColor}
|
|
1100
|
+
/>
|
|
1101
|
+
{responseHint && !stimulusVisible && !response && (
|
|
1102
|
+
<div
|
|
1103
|
+
style={{
|
|
1104
|
+
position: 'absolute',
|
|
1105
|
+
top: '60%',
|
|
1106
|
+
width: '100%',
|
|
1107
|
+
textAlign: 'center',
|
|
1108
|
+
color: 'white',
|
|
1109
|
+
fontSize: '1.25rem',
|
|
1110
|
+
}}
|
|
1111
|
+
>
|
|
1112
|
+
{responseHint}
|
|
1113
|
+
</div>
|
|
1114
|
+
)}
|
|
1115
|
+
</>
|
|
1021
1116
|
)}
|
|
1022
1117
|
</div>
|
|
1023
1118
|
);
|