@adriansteffan/reactive 0.1.28 → 0.1.30

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 P, b as x, E } from "./mod-qzwQpchZ.js";
1
+ import { W as P, b as x, E } from "./mod-CUZcjHfZ.js";
2
2
  function m(w) {
3
3
  const e = w.split("/").filter((t) => t !== "."), r = [];
4
4
  return e.forEach((t) => {
@@ -1,4 +1,4 @@
1
- import { W as e } from "./mod-qzwQpchZ.js";
1
+ import { W as e } from "./mod-CUZcjHfZ.js";
2
2
  class s extends e {
3
3
  async enable() {
4
4
  console.log("Immersive mode is only available on Android");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adriansteffan/reactive",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
package/planned.md ADDED
@@ -0,0 +1,103 @@
1
+ # Planned: Browser-based simulation mode
2
+
3
+ ## Motivation
4
+
5
+ The current simulation framework is headless — it bypasses rendering entirely and computes responseData directly in Node. This is fast (hundreds of participants in seconds) but doesn't test that the UI actually works. A browser-based mode would render components in a real browser and drive them with programmatic interactions, catching rendering bugs, event handler issues, and timing problems.
6
+
7
+ ## Key design insight
8
+
9
+ The existing **simulators stay unchanged**. They already encode *what* the participant decides (pick choice B, wait 2800ms, type "hello"). Only the execution layer changes — instead of directly building responseData from simulator output, a DOM driver translates decisions into browser interactions and lets components call `next()` naturally.
10
+
11
+ ```
12
+ Simulator (shared): "participant picks choice B after 2800ms"
13
+ Headless driver (current): constructs responseData directly → fast, no DOM
14
+ DOM driver (new): waits 2800ms, clicks the radio button → component calls next() with real data
15
+ ```
16
+
17
+ ## Architecture
18
+
19
+ ### Two simulation modes
20
+
21
+ - `headless` (existing) — Node subprocesses, no browser, fast bulk data generation
22
+ - `browser` (new) — Playwright browser contexts, real rendering, slow but thorough
23
+
24
+ The consumer chooses the mode in their simulate.ts config. Participant definitions, simulators, and timeline are identical between modes.
25
+
26
+ ### Component DOM drivers
27
+
28
+ Each component type gets a DOM driver function that maps simulator output to browser actions:
29
+
30
+ ```ts
31
+ type DOMDriver = (
32
+ page: Page, // Playwright page
33
+ simulatorOutput: { value: any; duration: number },
34
+ trialProps: Record<string, any>,
35
+ ) => Promise<void>;
36
+ ```
37
+
38
+ The generic driver loop per trial:
39
+ 1. Wait for the component to mount (detect a known selector or mutation)
40
+ 2. Call the simulator to get the participant's decision
41
+ 3. Wait `duration` ms
42
+ 4. Call the component-specific DOM driver
43
+ 5. Wait for the experiment runner to advance (next component mounts)
44
+
45
+ ### Per-component complexity
46
+
47
+ | Component | DOM driver complexity | Notes |
48
+ |---|---|---|
49
+ | Text | Trivial (~10 lines) | Wait, click button |
50
+ | PlainInput | Trivial (~10 lines) | Type into input, click button |
51
+ | Tutorial | Simple (~15 lines) | Click next arrow per slide |
52
+ | Upload | Trivial (~10 lines) | Click submit button |
53
+ | EnterFullscreen | Trivial (~5 lines) | Click button (fullscreen API may need mocking) |
54
+ | ExitFullscreen | Zero | Auto-advances |
55
+ | CheckDevice | Zero | Auto-advances |
56
+ | CanvasBlock | Medium (~30-50 lines) | Simulate mouse/keyboard events on canvas |
57
+ | RDK | Medium (~20-30 lines) | Keyboard response on canvas |
58
+ | **Quest (SurveyJS)** | **Hard (~80-100 lines)** | Per-question-type selectors against SurveyJS DOM |
59
+
60
+ **Quest is the riskiest part** — SurveyJS's internal DOM structure is an implementation detail that can change between versions. Each question type (rating, radiogroup, checkbox, text, boolean, matrix, dropdown) needs its own selector logic.
61
+
62
+ ### Orchestration
63
+
64
+ Replace `child_process.spawn` workers with Playwright browser contexts:
65
+
66
+ 1. Start Vite dev server (or serve the built app)
67
+ 2. For each participant: open a new browser context, navigate to the app URL with appropriate params
68
+ 3. Run the driver loop until the experiment completes
69
+ 4. Collect results from the backend (same upload path as headless)
70
+ 5. Tear down contexts and server
71
+
72
+ Concurrency is limited by browser resources rather than CPU cores. 4-8 parallel contexts is realistic.
73
+
74
+ ### Synchronization
75
+
76
+ The main technical challenge beyond SurveyJS DOM selectors. Need to reliably detect:
77
+ - Component has mounted and is interactive (not mid-animation)
78
+ - `next()` has been called and the next component is rendering
79
+ - The experiment has completed
80
+
81
+ Options: MutationObserver polling, custom data attributes on the experiment runner, or Playwright's `waitForSelector` / `waitForFunction`.
82
+
83
+ ## Estimated scope
84
+
85
+ ~400-500 lines of new code:
86
+ - Browser orchestrator: ~100-150 lines
87
+ - Generic driver loop: ~50 lines
88
+ - All component DOM drivers: ~200-250 lines
89
+
90
+ Existing code changes: minimal. Possibly add data attributes to ExperimentRunner for synchronization (e.g., `data-reactive-component-type` on the active component wrapper).
91
+
92
+ ## Constraints
93
+
94
+ - **Speed**: ~100x slower than headless. This is for smoke testing (1-5 participants), not bulk generation.
95
+ - **Dependency**: Playwright becomes a (dev) dependency for consumers using this mode.
96
+ - **Fragility**: SurveyJS DOM selectors will need maintenance when upgrading survey-core.
97
+ - **Fullscreen**: Browser automation and fullscreen API don't mix well. EnterFullscreen/ExitFullscreen may need to be mocked or skipped in browser mode.
98
+
99
+ ## Not in scope
100
+
101
+ - Replacing the headless simulation mode (it remains the default)
102
+ - Visual regression testing (screenshot comparison)
103
+ - Recording/replaying real participant sessions
@@ -16,6 +16,7 @@ export default function EnterFullscreen({
16
16
  buttonText,
17
17
  className,
18
18
  containerClass,
19
+ centered,
19
20
  animate,
20
21
  next,
21
22
  data,
@@ -27,6 +28,7 @@ export default function EnterFullscreen({
27
28
  buttonText?: string;
28
29
  className?: string;
29
30
  containerClass?: string;
31
+ centered?: boolean;
30
32
  animate?: boolean;
31
33
  delayMs?: number;
32
34
  } & BaseComponentProps) {
@@ -142,6 +144,7 @@ export default function EnterFullscreen({
142
144
  updateStore={updateStore}
143
145
  className={className}
144
146
  containerClass={containerClass}
147
+ centered={centered}
145
148
  animate={animate}
146
149
  content={contentWrap}
147
150
  buttonText={buttonText ?? 'Enter Fullscreen Mode'}
@@ -14,10 +14,11 @@ export default function ProlificEnding({
14
14
  prolificCode,
15
15
  className,
16
16
  containerClass,
17
+ centered,
17
18
  animate,
18
19
  data,
19
20
  updateStore
20
- }: { prolificCode?: string; className?: string; containerClass?: string; animate?: boolean } & BaseComponentProps) {
21
+ }: { prolificCode?: string; className?: string; containerClass?: string; centered?: boolean; animate?: boolean } & BaseComponentProps) {
21
22
  let prolificCodeUsed = prolificCode ?? getParam('cc', '', 'string') ?? null;
22
23
 
23
24
  const content = (
@@ -40,5 +41,5 @@ export default function ProlificEnding({
40
41
  </div>
41
42
  );
42
43
 
43
- return <Text data={data} updateStore={updateStore} className={className} containerClass={containerClass} animate={animate} content={content} buttonText='' next={() => {}} />;
44
+ return <Text data={data} updateStore={updateStore} className={className} containerClass={containerClass} centered={centered} animate={animate} content={content} buttonText='' next={() => {}} />;
44
45
  }
@@ -19,9 +19,10 @@ registerSimulation('Text', (trialProps, _experimentState, simulators, participan
19
19
 
20
20
  function Text({
21
21
  content,
22
- buttonText = 'Click me',
22
+ buttonText = 'Continue',
23
23
  className = '',
24
24
  containerClass,
25
+ centered = false,
25
26
  next,
26
27
  animate = false,
27
28
  allowedKeys = false,
@@ -31,6 +32,7 @@ function Text({
31
32
  onButtonClick?: () => void;
32
33
  className?: string;
33
34
  containerClass?: string;
35
+ centered?: boolean;
34
36
  animate?: boolean;
35
37
  allowedKeys?: string[] | boolean;
36
38
  } & BaseComponentProps) {
@@ -86,7 +88,7 @@ function Text({
86
88
  };
87
89
 
88
90
  return (
89
- <div className={`min-h-screen ${containerClass ?? th.containerBg}`}>
91
+ <div className={`min-h-screen ${centered ? 'flex items-center justify-center' : ''} ${containerClass ?? th.containerBg}`}>
90
92
  <div className={`max-w-prose mx-auto ${className} pt-20 pb-20 px-4 `}>
91
93
  <article
92
94
  className={`prose prose-2xl ${th.prose} text-xl ${th.proseLink} prose-a:underline prose-h1:text-4xl prose-h1:mb-10 prose-h1:font-bold prose-p:mb-4 prose-strong:font-bold ${th.text} leading-relaxed
@@ -166,7 +166,7 @@ export const Tutorial = ({
166
166
  return (
167
167
  <LayoutGroup>
168
168
  <div
169
- className={`${containerClass ?? th.containerBg} ${animate ? 'animate-slide-down opacity-0' : ''}`}
169
+ className={`${containerClass ?? th.containerBg} ${th.text} ${animate ? 'animate-slide-down opacity-0' : ''}`}
170
170
  style={{
171
171
  width: '100vw',
172
172
  height: '100vh',
@@ -231,6 +231,7 @@ export default function Upload({
231
231
  androidFolderName,
232
232
  className,
233
233
  containerClass,
234
+ centered,
234
235
  content,
235
236
  uploadingContent,
236
237
  errorContent,
@@ -243,6 +244,7 @@ export default function Upload({
243
244
  androidFolderName?: string;
244
245
  className?: string;
245
246
  containerClass?: string;
247
+ centered?: boolean;
246
248
  content?: React.ReactNode;
247
249
  uploadingContent?: React.ReactNode;
248
250
  errorContent?: React.ReactNode;
@@ -384,7 +386,7 @@ export default function Upload({
384
386
  const btnClass = `cursor-pointer ${th.buttonBg} px-8 py-3 border-2 ${th.buttonBorder} font-bold ${th.buttonText} text-lg rounded-xl ${th.buttonShadow} hover:translate-x-[2px] hover:translate-y-[2px] hover:shadow-none`;
385
387
 
386
388
  return (
387
- <div className={containerClass ?? th.containerBg} style={{ position: 'fixed', inset: 0 }}>
389
+ <div className={`${centered ? 'flex items-center justify-center' : ''} ${containerClass ?? th.containerBg}`} style={{ position: 'fixed', inset: 0 }}>
388
390
  <div className={`flex flex-col items-center justify-center gap-4 p-6 text-xl mt-16 px-10 h-full ${th.text} ${className ?? ''}`}>
389
391
  {uploadState == 'initial' && !autoUpload && (
390
392
  <>