@adriansteffan/reactive 0.1.34 → 0.2.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 (40) hide show
  1. package/.claude/settings.local.json +7 -1
  2. package/README.md +108 -5
  3. package/dist/{mod-BpIlYaYt.js → mod-C-XUCKhQ.js} +11574 -11216
  4. package/dist/mod.d.ts +110 -6
  5. package/dist/reactive.es.js +74 -63
  6. package/dist/reactive.umd.js +626 -654
  7. package/dist/style.css +1 -1
  8. package/dist/{web-CoJYNnww.js → web-Dpb5MAUc.js} +1 -1
  9. package/dist/{web-CFP76jkq.js → web-Dv2PC8fG.js} +1 -1
  10. package/package.json +4 -2
  11. package/raw-loader-hooks.mjs +25 -0
  12. package/raw-loader.mjs +5 -0
  13. package/src/components/experimentrunner.tsx +54 -1
  14. package/src/components/index.ts +1 -0
  15. package/src/components/microphonecheck.tsx +70 -84
  16. package/src/components/text.tsx +1 -1
  17. package/src/components/upload.tsx +4 -1
  18. package/src/components/voicerecorder.tsx +184 -162
  19. package/src/components/voicerecording.tsx +198 -0
  20. package/src/index.css +6 -0
  21. package/src/mod.tsx +8 -3
  22. package/src/utils/array.ts +61 -11
  23. package/src/utils/audiodevice.ts +4 -0
  24. package/src/utils/distributions.ts +28 -5
  25. package/src/utils/llm.ts +101 -0
  26. package/src/utils/nodecompat.ts +11 -0
  27. package/src/utils/simulation.ts +2 -2
  28. package/src/utils/theme.ts +1 -0
  29. package/src/utils/tts.ts +82 -0
  30. package/src/utils/upload.ts +65 -5
  31. package/template/README.md +26 -0
  32. package/template/backend/src/backend.ts +32 -1
  33. package/template/docker-compose.yaml +32 -0
  34. package/template/package.json +5 -2
  35. package/template/simulate.ts +13 -3
  36. package/template/src/Experiment.tsx +10 -12
  37. package/template/transcription/Dockerfile.cpu +8 -0
  38. package/template/transcription/Dockerfile.gpu +8 -0
  39. package/template/transcription/transcribe.py +161 -0
  40. package/vite.config.ts +1 -1
package/dist/mod.d.ts CHANGED
@@ -11,6 +11,8 @@ declare type ApertureShape = 'circle' | 'ellipse' | 'square' | 'rectangle';
11
11
 
12
12
  export declare function arrayFlattener(item: TrialData): any[];
13
13
 
14
+ export declare const AudioDeviceContext: Context<string | undefined>;
15
+
14
16
  export declare interface BaseComponentProps {
15
17
  next: (data?: object, actualStartTime?: number, actualStopTime?: number) => void;
16
18
  data: TrialData[];
@@ -143,7 +145,19 @@ declare interface DeviceInfo {
143
145
  hasMicrophone: boolean;
144
146
  }
145
147
 
146
- export declare type DimensionSpec = UniformSpec | NormalSpec | PoissonSpec;
148
+ export declare type DimensionSpec = UniformSpec | NormalSpec | PoissonSpec | IntegerSpec | DiscreteSpec;
149
+
150
+ export declare type DiscreteSpec = {
151
+ distribution: 'discrete';
152
+ outcomes: Array<{
153
+ value: number;
154
+ weight: number;
155
+ }>;
156
+ };
157
+
158
+ export declare function draw(spec: DimensionSpec): number;
159
+
160
+ export declare const DUMMY_AUDIO_BASE64 = "GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQRChYECGFOAZwEAAAAAAARQEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHYTbuMU6uEElTDZ1OsggE/TbuMU6uEHFO7a1OsggQ67AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmsirXsYMPQkBNgI1MYXZmNTguNzYuMTAwV0GNTGF2ZjU4Ljc2LjEwMESJiEB/wAAAAAAAFlSua+KuAQAAAAAAAFnXgQFzxYhRMt5OPJYVP5yBACK1nIN1bmSGhkFfT1BVU1aqg2MuoFa7hATEtACDgQLhkZ+BAbWIQOdwAAAAAABiZIEQY6KTT3B1c0hlYWQBATgBgLsAAAAAABJUw2dAm3NzAQAAAAAAACdjwIBnyAEAAAAAAAAaRaOHRU5DT0RFUkSHjUxhdmY1OC43Ni4xMDBzcwEAAAAAAABgY8CLY8WIUTLeTjyWFT9nyAEAAAAAAAAjRaOHRU5DT0RFUkSHlkxhdmM1OC4xMzQuMTAwIGxpYm9wdXNnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjUwODAwMDAwMAAAH0O2dUJU54EAo5GBAACACINtgtAc/epJ/gE/wKOZgQAVgAinGl2KmC5fWspQj0PpJrkNsG40QKOVgQApgAihLxDkXfvcBBqwyPJFmpFgo5OBAD2ACKE40Hcyqlc9/1ttqV84o5SBAFGACKE40Hcyql5YIeRahOZfwKOXgQBlgAihTMA96uabsR453W080Xeb9h6jkYEAeYAIoTjQdzKqXDNU2kjGo5aBAI2ACKDZbPIJxX8xM7SEPNZetOMco5OBAKGACKE40Hcyqla9XawRHUWoo5OBALWACKE40Hcyqmb1XKO++uAQo5SBAMmACKEvEORd+8XekK1/rf/rrKOVgQDdgAihONB3MqpWRgIfsDV4YBUIo5OBAPGACKE40Hcyql5SyE1S2QFAo5SBAQWACKE40Hcyqla+8h2o+iaxgKOVgQEZgAihONB3MqpeqdUAtSaZmdKAo5OBAS2ACKFIA0bVUn3Jmsi7ollwo5OBAUGACKE40Hcyql6pt6b1uh3oo5WBAVWACKEvEORd+9/La7aeTKZnv/CjlYEBaYAIoTjO/AZGOE9OIX9kO96+gKOTgQF9gAihONB3MqpekAQ00UpCUKOTgQGRgAihSANG1VJz2oSiMZRZKqOQgQGlgAihONB3MqpeqbeK3KORgQG5gAihLxDkXfvfy2sJCQyjmoEBzYAIosXU/J/RyZHEovOUhd6Ypj7UPC8Bo5uBAeGACKRIuuxKsgM4Wle7xUaBZDTNWofASYGgAQAAAAAAABuhkoEB9QAIBkQ+QjevBKpbiF1qJHWihADN/mAcU7trkbuPs4EAt4r3gQHxggHg8IED";
147
161
 
148
162
  export declare function EnterFullscreen({ content, buttonText, className, containerClass, centered, animate, next, data, updateStore, delayMs, }: {
149
163
  prolificCode?: string;
@@ -171,12 +185,16 @@ export declare function ExperimentProvider({ children, disableSettings, disableH
171
185
  disableHybridSimulation?: boolean;
172
186
  }): JSX_2.Element;
173
187
 
174
- export declare function ExperimentRunner({ timeline, config, components, questions, hybridParticipant, }: {
188
+ export declare function ExperimentRunner({ timeline, config, components, questions, hybridParticipant, disableDev, simulationConfig: _simulationConfig, }: {
175
189
  timeline: TimelineItem[];
176
190
  config?: ExperimentConfig;
177
191
  components?: ComponentsMap_2;
178
192
  questions?: ComponentsMap_2;
179
193
  hybridParticipant?: ParticipantState;
194
+ /** Disable the ?dev=true inspector panel. Set to true for production. */
195
+ disableDev?: boolean;
196
+ /** Simulation config — not used at runtime, extracted by simulate.ts via createElement. */
197
+ simulationConfig?: any;
180
198
  }): JSX_2.Element;
181
199
 
182
200
  export declare interface FileUpload {
@@ -209,10 +227,31 @@ declare interface IfGotoItem {
209
227
  marker: string;
210
228
  }
211
229
 
230
+ export declare type IntegerSpec = {
231
+ distribution: 'integer';
232
+ min: number;
233
+ max: number;
234
+ };
235
+
236
+ export declare function invokeLLM(config: LLMConfig, prompt: string, schema?: LLMSchema): Promise<string>;
237
+
212
238
  export declare function isDesktop(): boolean;
213
239
 
214
240
  export declare function isFullscreen(): boolean;
215
241
 
242
+ export declare const LIGHT_DOT_BG_CLASS = "reactive-light-dot-bg";
243
+
244
+ export declare interface LLMConfig {
245
+ provider: 'openai' | 'huggingface';
246
+ model: string;
247
+ apiKey: string;
248
+ /** Override the API base URL. Defaults to the provider's standard endpoint. */
249
+ baseUrl?: string;
250
+ }
251
+
252
+ /** JSON Schema object for constraining LLM output. Passed as the third argument to invokeLLM. */
253
+ export declare type LLMSchema = Record<string, any>;
254
+
216
255
  export declare function mapDDMChoice(choice: 0 | 1 | null, validKeys: string[], correctResponse?: string | string[]): string | null;
217
256
 
218
257
  declare interface MarkerItem {
@@ -220,8 +259,13 @@ declare interface MarkerItem {
220
259
  id: string;
221
260
  }
222
261
 
223
- export declare const MicCheck: ({ next }: {
224
- next: (data: object) => void;
262
+ /**
263
+ * Returns the arithmetic mean of a number array
264
+ */
265
+ export declare function mean(array: number[]): number;
266
+
267
+ export declare const MicCheck: ({ next, updateStore, animate }: BaseComponentProps & {
268
+ animate?: boolean;
225
269
  }) => JSX_2.Element;
226
270
 
227
271
  export declare type NoiseMovement = 'randomTeleport' | 'randomWalk' | 'randomDirection';
@@ -290,6 +334,12 @@ export declare type PoissonSpec = {
290
334
 
291
335
  export declare type PostStimStrategyDef = ContinueStrategy | CollapseStrategy | SnapshotStrategy;
292
336
 
337
+ /**
338
+ * Returns the duration of a base64-encoded audio file in milliseconds using ffprobe.
339
+ * Returns null if ffprobe is unavailable or the audio can't be probed.
340
+ */
341
+ export declare function probeAudioDurationMs(base64Audio: string): Promise<number | null>;
342
+
293
343
  export declare function ProlificEnding({ prolificCode, className, containerClass, centered, animate, data, updateStore }: {
294
344
  prolificCode?: string;
295
345
  className?: string;
@@ -466,10 +516,16 @@ export declare interface RunSimulationConfig {
466
516
  /**
467
517
  * Returns random elements from an array
468
518
  */
469
- export declare function sample<T>(array: T[], n?: number): T[];
519
+ export declare function sample<T>(array: T[], n?: number, options?: SampleOptions): T[];
520
+
521
+ declare interface SampleOptions {
522
+ replace?: boolean;
523
+ }
470
524
 
471
525
  export declare function sampleParticipants<T extends Record<string, DimensionSpec>>(method: SamplingMethod, count: number, specs: T): Array<{
472
526
  [K in keyof T]: number;
527
+ } & {
528
+ index: number;
473
529
  }>;
474
530
 
475
531
  export declare type SamplingMethod = 'sobol' | 'halton' | 'random';
@@ -517,6 +573,11 @@ declare type StoreUpdateFunction = (data?: TrialResult[], store?: Store_2) => Re
517
573
 
518
574
  export declare function subsetExperimentByParam(experiment: any[]): any[];
519
575
 
576
+ /**
577
+ * Returns the sum of a number array
578
+ */
579
+ export declare function sum(array: number[]): number;
580
+
520
581
  export declare function t(theme: Theme): {
521
582
  readonly containerBg: "";
522
583
  readonly text: "text-black";
@@ -605,6 +666,18 @@ declare function Text_2({ content, buttonText, className, containerClass, center
605
666
  } & BaseComponentProps): JSX_2.Element;
606
667
  export { Text_2 as Text }
607
668
 
669
+ /**
670
+ * Generates a WebM audio file from text using the platform's native TTS.
671
+ * Requires `ffmpeg` to be installed for WAV->WebM conversion.
672
+ *
673
+ * - macOS: `say` (prefers Ava voice if available)
674
+ * - Linux: `espeak-ng` or `espeak`
675
+ * - Windows: PowerShell `System.Speech`
676
+ *
677
+ * Returns base64-encoded WebM audio, or null if TTS/ffmpeg is unavailable.
678
+ */
679
+ export declare function textToWebmBase64(text: string): Promise<string | null>;
680
+
608
681
  export declare const THEME: {
609
682
  readonly light: {
610
683
  readonly containerBg: "";
@@ -756,6 +829,8 @@ export declare function Upload({ data, next, store, sessionID, generateFiles, se
756
829
  errorContent?: default_2.ReactNode;
757
830
  }): JSX_2.Element;
758
831
 
832
+ export declare const useAudioDeviceId: () => string | undefined;
833
+
759
834
  export declare const useTheme: () => Theme;
760
835
 
761
836
  /**
@@ -773,6 +848,25 @@ export declare const useTutorialSlide: ({ locked }?: {
773
848
  }) => void;
774
849
  };
775
850
 
851
+ export declare function VoiceRecording({ content, buttonText, shortButtonText, className, containerClass, next, store, minDuration, shortRecordingWarning, showVisualizer, eagerUpload, animate, name, }: BaseComponentProps & {
852
+ content?: default_2.ReactNode;
853
+ buttonText?: string;
854
+ /** Button text when recording is shorter than minDuration. Defaults to buttonText. */
855
+ shortButtonText?: string;
856
+ className?: string;
857
+ containerClass?: string;
858
+ /** Minimum recording duration in ms. If shorter, a warning is shown when paused. */
859
+ minDuration?: number;
860
+ /** Custom warning text for short recordings. */
861
+ shortRecordingWarning?: default_2.ReactNode;
862
+ /** Show the volume level meter during recording. Default true. */
863
+ showVisualizer?: boolean;
864
+ /** Upload audio immediately after recording to reduce final upload size. Default true. */
865
+ eagerUpload?: boolean;
866
+ animate?: boolean;
867
+ name?: string;
868
+ }): JSX_2.Element;
869
+
776
870
  declare interface WhileBlockItem {
777
871
  type: 'WHILE_BLOCK';
778
872
  cond: ConditionalFunction;
@@ -784,13 +878,15 @@ export * from "react-toastify";
784
878
 
785
879
  export { }
786
880
 
881
+
787
882
  declare global {
788
883
  interface Array<T> {
789
884
  /**
790
885
  * Returns random elements from the array
791
886
  * @param n Number of random elements to return (defaults to 1)
887
+ * @param options Options object with `replace` (default: true)
792
888
  */
793
- sample(n?: number): Array<T>;
889
+ sample(n?: number, options?: SampleOptions): Array<T>;
794
890
  /**
795
891
  * Shuffles array elements using Fisher-Yates algorithm
796
892
  */
@@ -805,5 +901,13 @@ declare global {
805
901
  * @param n Number of chunks to create
806
902
  */
807
903
  chunk(n: number): Array<Array<T>>;
904
+ /**
905
+ * Returns the arithmetic mean of the array
906
+ */
907
+ mean(): number;
908
+ /**
909
+ * Returns the sum of the array
910
+ */
911
+ sum(): number;
808
912
  }
809
913
  }
@@ -1,73 +1,84 @@
1
- import { H as e, C as t, a as i, D as r, c as n, d as o, e as l, f as m, g as u, Y as c, z as p, M as P, P as g, h as T, i as C, Q as D, R as d, j as S, k as h, F as x, T as E, l as f, m as k, n as v, o as B, U as F, X as A, p as R, q as _, r as I, s as K, t as M, u as b, v as y, w as L, x as U, y as w, A as G, B as q, G as H, I as N, J as Q, K as Z, L as j, N as z, O as J, S as O, V, Z as X, _ as Y, $, a0 as W, a1 as aa, a2 as sa, a3 as ea, a4 as ta, a5 as ia, a6 as ra, a7 as na, a8 as oa, a9 as la, aa as ma, ab as ua, ac as ca, ad as pa, ae as Pa, af as ga, ag as Ta, ah as Ca, ai as Da } from "./mod-BpIlYaYt.js";
1
+ import { A as e, H as t, C as i, a as o, D as r, c as n, d as l, e as m, f as u, g as c, h as p, Y as D, z as d, L as T, M as P, P as g, i as C, j as S, Q as A, R as x, k as h, l as v, F as B, T as E, m as _, n as k, o as M, p as f, U as F, V as I, X as L, q as R, r as b, s as U, t as G, u as K, v as w, w as y, x as q, y as H, B as O, G as j, I as N, J as Q, K as V, N as Y, O as Z, S as z, Z as J, _ as W, $ as X, a0 as $, a1 as aa, a2 as sa, a3 as ea, a4 as ta, a5 as ia, a6 as oa, a7 as ra, a8 as na, a9 as la, aa as ma, ab as ua, ac as ca, ad as pa, ae as Da, af as da, ag as Ta, ah as Pa, ai as ga, aj as Ca, ak as Sa, al as Aa, am as xa, an as ha, ao as va, ap as Ba, aq as Ea, ar as _a, as as ka, at as Ma } from "./mod-C-XUCKhQ.js";
2
2
  export {
3
- e as Bounce,
4
- t as CanvasBlock,
5
- i as CheckDevice,
3
+ e as AudioDeviceContext,
4
+ t as Bounce,
5
+ i as CanvasBlock,
6
+ o as CheckDevice,
6
7
  r as DARK_BG_CLASS,
7
8
  n as DARK_BG_PLAIN_CLASS,
8
- o as EnterFullscreen,
9
- l as ExitFullscreen,
10
- m as ExperimentProvider,
11
- u as ExperimentRunner,
12
- c as Flip,
13
- p as Icons,
9
+ l as DUMMY_AUDIO_BASE64,
10
+ m as EnterFullscreen,
11
+ u as ExitFullscreen,
12
+ c as ExperimentProvider,
13
+ p as ExperimentRunner,
14
+ D as Flip,
15
+ d as Icons,
16
+ T as LIGHT_DOT_BG_CLASS,
14
17
  P as MicCheck,
15
18
  g as Param,
16
- T as PlainInput,
17
- C as ProlificEnding,
18
- D as Quest,
19
- d as RDKCanvas,
20
- S as RandomDotKinematogram,
21
- h as RequestFilePermission,
22
- x as Slide,
19
+ C as PlainInput,
20
+ S as ProlificEnding,
21
+ A as Quest,
22
+ x as RDKCanvas,
23
+ h as RandomDotKinematogram,
24
+ v as RequestFilePermission,
25
+ B as Slide,
23
26
  E as THEME,
24
- f as Text,
27
+ _ as Text,
25
28
  k as ThemeContext,
26
- v as ToastContainer,
27
- B as Tutorial,
29
+ M as ToastContainer,
30
+ f as Tutorial,
28
31
  F as Upload,
29
- A as Zoom,
32
+ I as VoiceRecording,
33
+ L as Zoom,
30
34
  R as arrayFlattener,
31
- _ as canvasCountdown,
32
- I as chunk,
33
- K as collapseToast,
34
- M as cssTransition,
35
- b as getBackendUrl,
36
- y as getInitialParticipant,
37
- L as getParam,
38
- U as getPlatform,
39
- w as getSimulation,
40
- G as halton,
41
- q as isDesktop,
42
- H as isFullscreen,
43
- N as mapDDMChoice,
44
- Q as noopSimulate,
45
- Z as normal,
46
- j as now,
47
- z as orchestrateSimulation,
48
- J as pipe,
49
- O as poisson,
50
- V as registerArrayExtensions,
51
- X as registerComponentParams,
52
- Y as registerExperimentParams,
53
- $ as registerFlattener,
54
- W as registerSimulation,
55
- aa as resolveSimulation,
56
- sa as sample,
57
- ea as sampleParticipants,
58
- ta as seedDistributions,
59
- ia as selectPrevTrialData,
60
- ra as setBackendUrl,
61
- na as shuffle,
62
- oa as simulateDDMTrial,
63
- la as simulateParticipant,
64
- ma as sobol,
65
- ua as subsetExperimentByParam,
66
- ca as t,
67
- pa as toast,
68
- Pa as uniform,
69
- ga as useTheme,
70
- Ta as useToast,
71
- Ca as useToastContainer,
72
- Da as useTutorialSlide
35
+ b as canvasCountdown,
36
+ U as chunk,
37
+ G as collapseToast,
38
+ K as cssTransition,
39
+ w as draw,
40
+ y as getBackendUrl,
41
+ q as getInitialParticipant,
42
+ H as getParam,
43
+ O as getPlatform,
44
+ j as getSimulation,
45
+ N as halton,
46
+ Q as invokeLLM,
47
+ V as isDesktop,
48
+ Y as isFullscreen,
49
+ Z as mapDDMChoice,
50
+ z as mean,
51
+ J as noopSimulate,
52
+ W as normal,
53
+ X as now,
54
+ $ as orchestrateSimulation,
55
+ aa as pipe,
56
+ sa as poisson,
57
+ ea as probeAudioDurationMs,
58
+ ta as registerArrayExtensions,
59
+ ia as registerComponentParams,
60
+ oa as registerExperimentParams,
61
+ ra as registerFlattener,
62
+ na as registerSimulation,
63
+ la as resolveSimulation,
64
+ ma as sample,
65
+ ua as sampleParticipants,
66
+ ca as seedDistributions,
67
+ pa as selectPrevTrialData,
68
+ Da as setBackendUrl,
69
+ da as shuffle,
70
+ Ta as simulateDDMTrial,
71
+ Pa as simulateParticipant,
72
+ ga as sobol,
73
+ Ca as subsetExperimentByParam,
74
+ Sa as sum,
75
+ Aa as t,
76
+ xa as textToWebmBase64,
77
+ ha as toast,
78
+ va as uniform,
79
+ Ba as useAudioDeviceId,
80
+ Ea as useTheme,
81
+ _a as useToast,
82
+ ka as useToastContainer,
83
+ Ma as useTutorialSlide
73
84
  };