@adriansteffan/reactive 0.1.32 → 0.1.33

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.
@@ -1,4 +1,4 @@
1
- import { W as e } from "./mod-BstzgRJu.js";
1
+ import { W as e } from "./mod-BI0gtRcG.js";
2
2
  class s extends e {
3
3
  async enable() {
4
4
  console.log("Immersive mode is only available on Android");
@@ -1,4 +1,4 @@
1
- import { W as P, b as x, E } from "./mod-BstzgRJu.js";
1
+ import { W as P, b as x, E } from "./mod-BI0gtRcG.js";
2
2
  function m(w) {
3
3
  const e = w.split("/").filter((t) => t !== "."), r = [];
4
4
  return e.forEach((t) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adriansteffan/reactive",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -138,7 +138,7 @@ function Quest({
138
138
  ...surveyJson,
139
139
  css: { ...defaultCss, root: 'sd-root-modern custom-root' },
140
140
  });
141
- survey.applyTheme(theme ?? (contextTheme === 'dark' ? ContrastDark : ContrastLight));
141
+ survey.applyTheme(theme ?? (contextTheme.startsWith('dark') ? ContrastDark : ContrastLight));
142
142
 
143
143
  const saveResults = useCallback(
144
144
  (sender: any) => {
@@ -149,7 +149,7 @@ function Quest({
149
149
 
150
150
  survey.onComplete.add(saveResults);
151
151
 
152
- const useCustomBg = !!containerClass || contextTheme === 'dark';
152
+ const useCustomBg = !!containerClass || contextTheme.startsWith('dark');
153
153
 
154
154
  return (
155
155
  <div className={`min-h-screen ${containerClass ?? th.containerBg}`}>
@@ -8,6 +8,9 @@ import { useTheme, t } from '../utils/theme';
8
8
  registerFlattener('Text', 'text');
9
9
 
10
10
  registerSimulation('Text', (trialProps, _experimentState, simulators, participant) => {
11
+ if (trialProps.duration != null) {
12
+ return { responseData: {}, participantState: participant, duration: trialProps.duration };
13
+ }
11
14
  const result = simulators.respond(trialProps, participant);
12
15
  return { responseData: result.value, participantState: result.participantState, duration: result.value.reactionTime };
13
16
  }, {
@@ -26,6 +29,7 @@ function Text({
26
29
  next,
27
30
  animate = false,
28
31
  allowedKeys = false,
32
+ duration,
29
33
  }: {
30
34
  content: React.ReactNode;
31
35
  buttonText?: string;
@@ -35,15 +39,25 @@ function Text({
35
39
  centered?: boolean;
36
40
  animate?: boolean;
37
41
  allowedKeys?: string[] | boolean;
42
+ /** Auto-advance after N ms. When set, no button is shown and key presses are ignored. */
43
+ duration?: number;
38
44
  } & BaseComponentProps) {
39
45
  const th = t(useTheme());
40
46
  const startTimeRef = useRef<number>(0);
47
+ const timed = duration != null;
41
48
 
42
49
  useEffect(() => {
43
50
  window.scrollTo(0, 0);
44
51
  }, []);
45
52
 
46
53
  useEffect(() => {
54
+ if (!timed) return;
55
+ const timer = setTimeout(() => next({}), duration);
56
+ return () => clearTimeout(timer);
57
+ }, [timed, duration, next]);
58
+
59
+ useEffect(() => {
60
+ if (timed) return;
47
61
  startTimeRef.current = now();
48
62
 
49
63
  const handleKeyPress = (event: KeyboardEvent) => {
@@ -73,7 +87,7 @@ function Text({
73
87
  window.removeEventListener('keydown', handleKeyPress);
74
88
  }
75
89
  };
76
- }, [next, allowedKeys]);
90
+ }, [next, allowedKeys, timed]);
77
91
 
78
92
  const handleClick = () => {
79
93
  const clickTime = now();
@@ -97,7 +111,7 @@ function Text({
97
111
  {content}
98
112
  </article>
99
113
 
100
- {buttonText && (
114
+ {!timed && buttonText && (
101
115
  <div
102
116
  className={`mt-16 flex justify-center ${animate ? 'animate-fade-in opacity-0' : ''}`}
103
117
  style={animate ? { animationDelay: '1s' } : {}}
package/src/index.css CHANGED
@@ -85,6 +85,10 @@
85
85
  font-style: italic;
86
86
  }
87
87
 
88
+ .reactive-dark-bg-plain {
89
+ background-color: #21294b;
90
+ }
91
+
88
92
  .reactive-dark-bg {
89
93
  background-color: #21294b;
90
94
  background-image:
package/src/mod.tsx CHANGED
@@ -7,7 +7,7 @@ export * from './utils/common';
7
7
  export * from './utils/simulation';
8
8
  export { registerFlattener, arrayFlattener } from './utils/upload';
9
9
  export { normal, poisson, uniform, seedDistributions, sobol, halton, sampleParticipants } from './utils/distributions';
10
- export { useTheme, ThemeContext, THEME, t, DARK_BG_CLASS } from './utils/theme';
10
+ export { useTheme, ThemeContext, THEME, t, DARK_BG_CLASS, DARK_BG_PLAIN_CLASS } from './utils/theme';
11
11
  export type { Theme } from './utils/theme';
12
12
  export type { DimensionSpec, UniformSpec, NormalSpec, PoissonSpec, SamplingMethod } from './utils/distributions';
13
13
  export { simulateDDMTrial, mapDDMChoice } from './utils/ddm';
@@ -1,10 +1,35 @@
1
1
  import { createContext, useContext } from 'react';
2
2
 
3
- export type Theme = 'light' | 'dark';
3
+ export type Theme = 'light' | 'dark' | 'dark-plain';
4
4
 
5
5
  export const ThemeContext = createContext<Theme>('light');
6
6
  export const useTheme = () => useContext(ThemeContext);
7
7
 
8
+ const DARK_TOKENS = {
9
+ text: 'text-[#f5f5f5]',
10
+ prose: 'prose-invert',
11
+ proseLink: 'prose-a:text-blue-400',
12
+ buttonBg: 'bg-white',
13
+ buttonText: 'text-black',
14
+ buttonBorder: 'border-black',
15
+ buttonShadow: 'shadow-[2px_2px_0px_rgba(0,0,0,1)]',
16
+ buttonDisabledBg: 'bg-gray-700',
17
+ buttonDisabledText: 'text-gray-500',
18
+ buttonDisabledBorder: 'border-gray-600',
19
+ buttonDisabledShadow: 'shadow-[2px_2px_0px_rgba(75,85,99,1)]',
20
+ error: 'text-red-400',
21
+ focusRing: 'focus:ring-blue-400',
22
+ inputBg: 'bg-gray-700',
23
+ inputBorder: 'border-gray-500',
24
+ inputText: 'text-[#f5f5f5]',
25
+ progressBg: 'bg-gray-700',
26
+ progressStripe1: '#374151',
27
+ progressStripe2: '#4B5563',
28
+ dotActive: '#fff',
29
+ dotInactive: 'rgba(255,255,255,0.3)',
30
+ toastTheme: 'dark' as const,
31
+ } as const;
32
+
8
33
  export const THEME = {
9
34
  light: {
10
35
  containerBg: '',
@@ -33,32 +58,16 @@ export const THEME = {
33
58
  },
34
59
  dark: {
35
60
  containerBg: 'reactive-dark-bg',
36
- text: 'text-[#f5f5f5]',
37
- prose: 'prose-invert',
38
- proseLink: 'prose-a:text-blue-400',
39
- buttonBg: 'bg-white',
40
- buttonText: 'text-black',
41
- buttonBorder: 'border-black',
42
- buttonShadow: 'shadow-[2px_2px_0px_rgba(0,0,0,1)]',
43
- buttonDisabledBg: 'bg-gray-700',
44
- buttonDisabledText: 'text-gray-500',
45
- buttonDisabledBorder: 'border-gray-600',
46
- buttonDisabledShadow: 'shadow-[2px_2px_0px_rgba(75,85,99,1)]',
47
- error: 'text-red-400',
48
- focusRing: 'focus:ring-blue-400',
49
- inputBg: 'bg-gray-700',
50
- inputBorder: 'border-gray-500',
51
- inputText: 'text-[#f5f5f5]',
52
- progressBg: 'bg-gray-700',
53
- progressStripe1: '#374151',
54
- progressStripe2: '#4B5563',
55
- dotActive: '#fff',
56
- dotInactive: 'rgba(255,255,255,0.3)',
57
- toastTheme: 'dark' as const,
61
+ ...DARK_TOKENS,
62
+ },
63
+ 'dark-plain': {
64
+ containerBg: 'reactive-dark-bg-plain',
65
+ ...DARK_TOKENS,
58
66
  },
59
67
  } as const;
60
68
 
61
69
  export const DARK_BG_CLASS = 'reactive-dark-bg';
70
+ export const DARK_BG_PLAIN_CLASS = 'reactive-dark-bg-plain';
62
71
 
63
72
  export function t(theme: Theme) {
64
73
  return THEME[theme];