@slopit/adapter-gorilla 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +228 -0
- package/dist/index.js +187 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aaron Steven White
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { RecorderConfig, BaseRecorder, TrialConfig, CompletedTrial } from '@slopit/adapter-shared';
|
|
2
|
+
import { PlatformInfo, ResponseInfo } from '@slopit/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type definitions for Gorilla adapter.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for the Gorilla recorder.
|
|
12
|
+
*/
|
|
13
|
+
interface GorillaRecorderConfig extends RecorderConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Automatically call gorilla.store() on each endTrial().
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
autoStore?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Key prefix for gorilla.store() calls.
|
|
22
|
+
*
|
|
23
|
+
* @default "slopit"
|
|
24
|
+
*/
|
|
25
|
+
storeKey?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Interface for the global Gorilla module.
|
|
29
|
+
*
|
|
30
|
+
* Gorilla provides this module on the window object when running experiments.
|
|
31
|
+
*/
|
|
32
|
+
interface GorillaModule {
|
|
33
|
+
/**
|
|
34
|
+
* Registers a callback to run when the experiment is ready.
|
|
35
|
+
*
|
|
36
|
+
* @param callback - Function to execute when ready
|
|
37
|
+
*/
|
|
38
|
+
ready(callback: () => void): void;
|
|
39
|
+
/**
|
|
40
|
+
* Stores a metric value that appears in the exported data.
|
|
41
|
+
*
|
|
42
|
+
* @param key - Metric identifier
|
|
43
|
+
* @param value - Value to store (strings or numbers)
|
|
44
|
+
*/
|
|
45
|
+
metric(key: string, value: string | number): void;
|
|
46
|
+
/**
|
|
47
|
+
* Stores arbitrary data for later retrieval within the experiment.
|
|
48
|
+
*
|
|
49
|
+
* @param key - Storage key
|
|
50
|
+
* @param value - Value to store
|
|
51
|
+
*/
|
|
52
|
+
store(key: string, value: unknown): void;
|
|
53
|
+
/**
|
|
54
|
+
* Signals that the experiment has finished.
|
|
55
|
+
*/
|
|
56
|
+
finish(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the URL for a stimuli file uploaded to Gorilla.
|
|
59
|
+
*
|
|
60
|
+
* @param filename - Name of the stimuli file
|
|
61
|
+
* @returns Full URL to the stimuli resource
|
|
62
|
+
*/
|
|
63
|
+
stimuliURL(filename: string): string;
|
|
64
|
+
}
|
|
65
|
+
declare global {
|
|
66
|
+
interface Window {
|
|
67
|
+
gorilla?: GorillaModule;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Gorilla experiment recorder implementation.
|
|
73
|
+
*
|
|
74
|
+
* @module
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* SlopitRecorder for Gorilla experiments.
|
|
79
|
+
*
|
|
80
|
+
* Extends BaseRecorder with Gorilla-specific functionality for storing
|
|
81
|
+
* behavioral data via the Gorilla API.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* gorilla.ready(function() {
|
|
86
|
+
* const recorder = new SlopitRecorder();
|
|
87
|
+
* recorder.startTrial("trial_1", document.querySelector("textarea"));
|
|
88
|
+
*
|
|
89
|
+
* // On submit:
|
|
90
|
+
* recorder.endTrial(response);
|
|
91
|
+
* recorder.storeSession();
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example Auto-store mode
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const recorder = new SlopitRecorder({ autoStore: true });
|
|
98
|
+
* recorder.startTrial("trial_1", textarea);
|
|
99
|
+
* recorder.endTrial(response); // Automatically stores trial data
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare class SlopitRecorder extends BaseRecorder {
|
|
103
|
+
private autoStore;
|
|
104
|
+
private storeKey;
|
|
105
|
+
private discoveryCleanup;
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new SlopitRecorder for Gorilla experiments.
|
|
108
|
+
*
|
|
109
|
+
* @param config - Recorder configuration options
|
|
110
|
+
*/
|
|
111
|
+
constructor(config?: GorillaRecorderConfig);
|
|
112
|
+
/**
|
|
113
|
+
* Returns platform information for Gorilla.
|
|
114
|
+
*
|
|
115
|
+
* @returns Platform metadata
|
|
116
|
+
*/
|
|
117
|
+
protected getPlatformInfo(): PlatformInfo;
|
|
118
|
+
/**
|
|
119
|
+
* Detects the Gorilla platform version.
|
|
120
|
+
*
|
|
121
|
+
* Gorilla does not expose version information publicly, so this returns
|
|
122
|
+
* "unknown" by default.
|
|
123
|
+
*
|
|
124
|
+
* @returns Version string or "unknown"
|
|
125
|
+
*/
|
|
126
|
+
private detectGorillaVersion;
|
|
127
|
+
/**
|
|
128
|
+
* Gets the global Gorilla module if available.
|
|
129
|
+
*
|
|
130
|
+
* @returns Gorilla module or undefined if not available
|
|
131
|
+
*/
|
|
132
|
+
private getGorilla;
|
|
133
|
+
/**
|
|
134
|
+
* Starts capturing behavioral data for a trial.
|
|
135
|
+
*
|
|
136
|
+
* This convenience method provides a simpler API compared to the base
|
|
137
|
+
* startTrial() that accepts a TrialConfig object.
|
|
138
|
+
*
|
|
139
|
+
* @param trialId - Unique identifier for the trial
|
|
140
|
+
* @param element - Target DOM element (optional, can attach later)
|
|
141
|
+
* @param trialConfig - Additional trial configuration
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* recorder.startTrial("trial_1", document.querySelector("textarea"));
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
startTrial(trialId: string, element?: HTMLElement, trialConfig?: Partial<TrialConfig>): void;
|
|
149
|
+
/**
|
|
150
|
+
* Starts capturing behavioral data for a trial with full configuration.
|
|
151
|
+
*
|
|
152
|
+
* @param config - Complete trial configuration
|
|
153
|
+
*/
|
|
154
|
+
startTrial(config: TrialConfig): void;
|
|
155
|
+
/**
|
|
156
|
+
* Starts a trial with automatic element discovery.
|
|
157
|
+
*
|
|
158
|
+
* If the target element does not exist yet, this method uses a
|
|
159
|
+
* MutationObserver to wait for it to appear in the DOM.
|
|
160
|
+
*
|
|
161
|
+
* @param trialId - Unique identifier for the trial
|
|
162
|
+
* @param selector - CSS selector for target element
|
|
163
|
+
* @param container - Container to search within (default: document)
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* // Start trial and wait for textarea to appear
|
|
168
|
+
* recorder.startTrialWithSelector("trial_1", "textarea.response");
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
startTrialWithSelector(trialId: string, selector: string, container?: HTMLElement | Document): void;
|
|
172
|
+
/**
|
|
173
|
+
* Ends the current trial and returns the completed trial data.
|
|
174
|
+
*
|
|
175
|
+
* If autoStore is enabled, automatically stores trial data via gorilla.store().
|
|
176
|
+
*
|
|
177
|
+
* @param response - The participant's response (string or ResponseInfo)
|
|
178
|
+
* @returns The completed trial data
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const trial = recorder.endTrial("The participant's response text");
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @example With ResponseInfo
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const trial = recorder.endTrial({
|
|
188
|
+
* type: "text",
|
|
189
|
+
* value: "Response text",
|
|
190
|
+
* characterCount: 13,
|
|
191
|
+
* wordCount: 2,
|
|
192
|
+
* });
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
endTrial(response?: string | ResponseInfo): CompletedTrial;
|
|
196
|
+
/**
|
|
197
|
+
* Stores the complete session via gorilla.metric().
|
|
198
|
+
*
|
|
199
|
+
* Call this at experiment end to store the full session data as a metric,
|
|
200
|
+
* which will appear in the exported data.
|
|
201
|
+
*
|
|
202
|
+
* @param key - Metric key (default: "slopit_session")
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* // At end of experiment
|
|
207
|
+
* recorder.storeSession();
|
|
208
|
+
* gorilla.finish();
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
storeSession(key?: string): void;
|
|
212
|
+
/**
|
|
213
|
+
* Stores session data via gorilla.store() for later retrieval.
|
|
214
|
+
*
|
|
215
|
+
* Unlike storeSession(), this stores the data for access within the
|
|
216
|
+
* experiment rather than in the exported metrics.
|
|
217
|
+
*
|
|
218
|
+
* @param key - Store key (default: this.storeKey)
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* recorder.saveToStore("my_session_data");
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
saveToStore(key?: string): void;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { type GorillaModule, SlopitRecorder as GorillaRecorder, type GorillaRecorderConfig, SlopitRecorder };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { BaseRecorder, discoverElement } from '@slopit/adapter-shared';
|
|
2
|
+
|
|
3
|
+
// src/recorder.ts
|
|
4
|
+
var SlopitRecorder = class extends BaseRecorder {
|
|
5
|
+
autoStore;
|
|
6
|
+
storeKey;
|
|
7
|
+
discoveryCleanup = null;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new SlopitRecorder for Gorilla experiments.
|
|
10
|
+
*
|
|
11
|
+
* @param config - Recorder configuration options
|
|
12
|
+
*/
|
|
13
|
+
constructor(config) {
|
|
14
|
+
super(config);
|
|
15
|
+
this.autoStore = config?.autoStore ?? false;
|
|
16
|
+
this.storeKey = config?.storeKey ?? "slopit";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns platform information for Gorilla.
|
|
20
|
+
*
|
|
21
|
+
* @returns Platform metadata
|
|
22
|
+
*/
|
|
23
|
+
getPlatformInfo() {
|
|
24
|
+
return {
|
|
25
|
+
name: "Gorilla",
|
|
26
|
+
version: this.detectGorillaVersion(),
|
|
27
|
+
adapterVersion: "0.1.0"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Detects the Gorilla platform version.
|
|
32
|
+
*
|
|
33
|
+
* Gorilla does not expose version information publicly, so this returns
|
|
34
|
+
* "unknown" by default.
|
|
35
|
+
*
|
|
36
|
+
* @returns Version string or "unknown"
|
|
37
|
+
*/
|
|
38
|
+
detectGorillaVersion() {
|
|
39
|
+
return "unknown";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Gets the global Gorilla module if available.
|
|
43
|
+
*
|
|
44
|
+
* @returns Gorilla module or undefined if not available
|
|
45
|
+
*/
|
|
46
|
+
getGorilla() {
|
|
47
|
+
return typeof window !== "undefined" ? window.gorilla : void 0;
|
|
48
|
+
}
|
|
49
|
+
startTrial(trialIdOrConfig, element, trialConfig) {
|
|
50
|
+
if (typeof trialIdOrConfig === "string") {
|
|
51
|
+
const config = {
|
|
52
|
+
trialId: trialIdOrConfig,
|
|
53
|
+
...trialConfig
|
|
54
|
+
};
|
|
55
|
+
if (element !== void 0) {
|
|
56
|
+
config.targetElement = element;
|
|
57
|
+
}
|
|
58
|
+
super.startTrial(config);
|
|
59
|
+
} else {
|
|
60
|
+
super.startTrial(trialIdOrConfig);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Starts a trial with automatic element discovery.
|
|
65
|
+
*
|
|
66
|
+
* If the target element does not exist yet, this method uses a
|
|
67
|
+
* MutationObserver to wait for it to appear in the DOM.
|
|
68
|
+
*
|
|
69
|
+
* @param trialId - Unique identifier for the trial
|
|
70
|
+
* @param selector - CSS selector for target element
|
|
71
|
+
* @param container - Container to search within (default: document)
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Start trial and wait for textarea to appear
|
|
76
|
+
* recorder.startTrialWithSelector("trial_1", "textarea.response");
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
startTrialWithSelector(trialId, selector, container = document) {
|
|
80
|
+
const element = container.querySelector(selector);
|
|
81
|
+
if (element !== null) {
|
|
82
|
+
this.startTrial(trialId, element);
|
|
83
|
+
} else {
|
|
84
|
+
super.startTrial({ trialId });
|
|
85
|
+
this.discoveryCleanup = discoverElement({
|
|
86
|
+
selector,
|
|
87
|
+
container,
|
|
88
|
+
timeout: 1e4,
|
|
89
|
+
onFound: (el) => {
|
|
90
|
+
if (this.currentTrial !== null) {
|
|
91
|
+
this.attachCapture(el, this.currentTrial.startTime);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Ends the current trial and returns the completed trial data.
|
|
99
|
+
*
|
|
100
|
+
* If autoStore is enabled, automatically stores trial data via gorilla.store().
|
|
101
|
+
*
|
|
102
|
+
* @param response - The participant's response (string or ResponseInfo)
|
|
103
|
+
* @returns The completed trial data
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const trial = recorder.endTrial("The participant's response text");
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @example With ResponseInfo
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const trial = recorder.endTrial({
|
|
113
|
+
* type: "text",
|
|
114
|
+
* value: "Response text",
|
|
115
|
+
* characterCount: 13,
|
|
116
|
+
* wordCount: 2,
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
endTrial(response) {
|
|
121
|
+
if (this.discoveryCleanup !== null) {
|
|
122
|
+
this.discoveryCleanup();
|
|
123
|
+
this.discoveryCleanup = null;
|
|
124
|
+
}
|
|
125
|
+
const responseInfo = typeof response === "string" ? {
|
|
126
|
+
type: "text",
|
|
127
|
+
value: response,
|
|
128
|
+
characterCount: response.length,
|
|
129
|
+
wordCount: response.trim().split(/\s+/).filter(Boolean).length
|
|
130
|
+
} : response;
|
|
131
|
+
const trial = super.endTrial(responseInfo);
|
|
132
|
+
if (this.autoStore) {
|
|
133
|
+
const gorilla = this.getGorilla();
|
|
134
|
+
if (gorilla !== void 0) {
|
|
135
|
+
gorilla.store(`${this.storeKey}_trial_${trial.trialIndex}`, {
|
|
136
|
+
behavioral: trial.behavioral,
|
|
137
|
+
captureFlags: trial.captureFlags
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return trial;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Stores the complete session via gorilla.metric().
|
|
145
|
+
*
|
|
146
|
+
* Call this at experiment end to store the full session data as a metric,
|
|
147
|
+
* which will appear in the exported data.
|
|
148
|
+
*
|
|
149
|
+
* @param key - Metric key (default: "slopit_session")
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* // At end of experiment
|
|
154
|
+
* recorder.storeSession();
|
|
155
|
+
* gorilla.finish();
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
storeSession(key = "slopit_session") {
|
|
159
|
+
const gorilla = this.getGorilla();
|
|
160
|
+
if (gorilla !== void 0) {
|
|
161
|
+
gorilla.metric(key, JSON.stringify(this.exportSession()));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Stores session data via gorilla.store() for later retrieval.
|
|
166
|
+
*
|
|
167
|
+
* Unlike storeSession(), this stores the data for access within the
|
|
168
|
+
* experiment rather than in the exported metrics.
|
|
169
|
+
*
|
|
170
|
+
* @param key - Store key (default: this.storeKey)
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* recorder.saveToStore("my_session_data");
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
saveToStore(key) {
|
|
178
|
+
const gorilla = this.getGorilla();
|
|
179
|
+
if (gorilla !== void 0) {
|
|
180
|
+
gorilla.store(key ?? this.storeKey, this.exportSession());
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export { SlopitRecorder as GorillaRecorder, SlopitRecorder };
|
|
186
|
+
//# sourceMappingURL=index.js.map
|
|
187
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/recorder.ts"],"names":[],"mappings":";;;AAyCO,IAAM,cAAA,GAAN,cAA6B,YAAA,CAAa;AAAA,EACvC,SAAA;AAAA,EACA,QAAA;AAAA,EACA,gBAAA,GAAwC,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOhD,YAAY,MAAA,EAAgC;AAC1C,IAAA,KAAA,CAAM,MAAM,CAAA;AACZ,IAAA,IAAA,CAAK,SAAA,GAAY,QAAQ,SAAA,IAAa,KAAA;AACtC,IAAA,IAAA,CAAK,QAAA,GAAW,QAAQ,QAAA,IAAY,QAAA;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,eAAA,GAAgC;AACxC,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,SAAA;AAAA,MACN,OAAA,EAAS,KAAK,oBAAA,EAAqB;AAAA,MACnC,cAAA,EAAgB;AAAA,KAClB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUQ,oBAAA,GAA+B;AAErC,IAAA,OAAO,SAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOQ,UAAA,GAAwC;AAC9C,IAAA,OAAO,OAAO,MAAA,KAAW,WAAA,GAAc,MAAA,CAAO,OAAA,GAAU,MAAA;AAAA,EAC1D;AAAA,EA8BS,UAAA,CACP,eAAA,EACA,OAAA,EACA,WAAA,EACM;AACN,IAAA,IAAI,OAAO,oBAAoB,QAAA,EAAU;AACvC,MAAA,MAAM,MAAA,GAAsB;AAAA,QAC1B,OAAA,EAAS,eAAA;AAAA,QACT,GAAG;AAAA,OACL;AACA,MAAA,IAAI,YAAY,MAAA,EAAW;AACzB,QAAA,MAAA,CAAO,aAAA,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AChC,IAAA,IAAI,YAAY,MAAA,EAAW;AACzB,MAAA,OAAA,CAAQ,MAAM,GAAA,IAAO,IAAA,CAAK,QAAA,EAAU,IAAA,CAAK,eAAe,CAAA;AAAA,IAC1D;AAAA,EACF;AACF","file":"index.js","sourcesContent":["/**\n * Gorilla experiment recorder implementation.\n *\n * @module\n */\n\nimport {\n BaseRecorder,\n type CompletedTrial,\n type TrialConfig,\n discoverElement,\n} from \"@slopit/adapter-shared\";\nimport type { PlatformInfo, ResponseInfo } from \"@slopit/core\";\n\nimport type { GorillaModule, GorillaRecorderConfig } from \"./types.js\";\n\n/**\n * SlopitRecorder for Gorilla experiments.\n *\n * Extends BaseRecorder with Gorilla-specific functionality for storing\n * behavioral data via the Gorilla API.\n *\n * @example\n * ```typescript\n * gorilla.ready(function() {\n * const recorder = new SlopitRecorder();\n * recorder.startTrial(\"trial_1\", document.querySelector(\"textarea\"));\n *\n * // On submit:\n * recorder.endTrial(response);\n * recorder.storeSession();\n * });\n * ```\n *\n * @example Auto-store mode\n * ```typescript\n * const recorder = new SlopitRecorder({ autoStore: true });\n * recorder.startTrial(\"trial_1\", textarea);\n * recorder.endTrial(response); // Automatically stores trial data\n * ```\n */\nexport class SlopitRecorder extends BaseRecorder {\n private autoStore: boolean;\n private storeKey: string;\n private discoveryCleanup: (() => void) | null = null;\n\n /**\n * Creates a new SlopitRecorder for Gorilla experiments.\n *\n * @param config - Recorder configuration options\n */\n constructor(config?: GorillaRecorderConfig) {\n super(config);\n this.autoStore = config?.autoStore ?? false;\n this.storeKey = config?.storeKey ?? \"slopit\";\n }\n\n /**\n * Returns platform information for Gorilla.\n *\n * @returns Platform metadata\n */\n protected getPlatformInfo(): PlatformInfo {\n return {\n name: \"Gorilla\",\n version: this.detectGorillaVersion(),\n adapterVersion: \"0.1.0\",\n };\n }\n\n /**\n * Detects the Gorilla platform version.\n *\n * Gorilla does not expose version information publicly, so this returns\n * \"unknown\" by default.\n *\n * @returns Version string or \"unknown\"\n */\n private detectGorillaVersion(): string {\n // Gorilla does not expose version publicly\n return \"unknown\";\n }\n\n /**\n * Gets the global Gorilla module if available.\n *\n * @returns Gorilla module or undefined if not available\n */\n private getGorilla(): GorillaModule | undefined {\n return typeof window !== \"undefined\" ? window.gorilla : undefined;\n }\n\n /**\n * Starts capturing behavioral data for a trial.\n *\n * This convenience method provides a simpler API compared to the base\n * startTrial() that accepts a TrialConfig object.\n *\n * @param trialId - Unique identifier for the trial\n * @param element - Target DOM element (optional, can attach later)\n * @param trialConfig - Additional trial configuration\n *\n * @example\n * ```typescript\n * recorder.startTrial(\"trial_1\", document.querySelector(\"textarea\"));\n * ```\n */\n override startTrial(\n trialId: string,\n element?: HTMLElement,\n trialConfig?: Partial<TrialConfig>,\n ): void;\n\n /**\n * Starts capturing behavioral data for a trial with full configuration.\n *\n * @param config - Complete trial configuration\n */\n override startTrial(config: TrialConfig): void;\n\n override startTrial(\n trialIdOrConfig: string | TrialConfig,\n element?: HTMLElement,\n trialConfig?: Partial<TrialConfig>,\n ): void {\n if (typeof trialIdOrConfig === \"string\") {\n const config: TrialConfig = {\n trialId: trialIdOrConfig,\n ...trialConfig,\n };\n if (element !== undefined) {\n config.targetElement = element;\n }\n super.startTrial(config);\n } else {\n super.startTrial(trialIdOrConfig);\n }\n }\n\n /**\n * Starts a trial with automatic element discovery.\n *\n * If the target element does not exist yet, this method uses a\n * MutationObserver to wait for it to appear in the DOM.\n *\n * @param trialId - Unique identifier for the trial\n * @param selector - CSS selector for target element\n * @param container - Container to search within (default: document)\n *\n * @example\n * ```typescript\n * // Start trial and wait for textarea to appear\n * recorder.startTrialWithSelector(\"trial_1\", \"textarea.response\");\n * ```\n */\n startTrialWithSelector(\n trialId: string,\n selector: string,\n container: HTMLElement | Document = document,\n ): void {\n // Try immediate discovery\n const element = container.querySelector(selector) as HTMLElement | null;\n\n if (element !== null) {\n this.startTrial(trialId, element);\n } else {\n // Start trial first, then attach when element appears\n super.startTrial({ trialId });\n\n this.discoveryCleanup = discoverElement({\n selector,\n container: container as HTMLElement,\n timeout: 10000,\n onFound: (el) => {\n // Attach capture to discovered element\n if (this.currentTrial !== null) {\n this.attachCapture(el, this.currentTrial.startTime);\n }\n },\n });\n }\n }\n\n /**\n * Ends the current trial and returns the completed trial data.\n *\n * If autoStore is enabled, automatically stores trial data via gorilla.store().\n *\n * @param response - The participant's response (string or ResponseInfo)\n * @returns The completed trial data\n *\n * @example\n * ```typescript\n * const trial = recorder.endTrial(\"The participant's response text\");\n * ```\n *\n * @example With ResponseInfo\n * ```typescript\n * const trial = recorder.endTrial({\n * type: \"text\",\n * value: \"Response text\",\n * characterCount: 13,\n * wordCount: 2,\n * });\n * ```\n */\n override endTrial(response?: string | ResponseInfo): CompletedTrial {\n // Clean up discovery observer\n if (this.discoveryCleanup !== null) {\n this.discoveryCleanup();\n this.discoveryCleanup = null;\n }\n\n const responseInfo: ResponseInfo | undefined =\n typeof response === \"string\"\n ? {\n type: \"text\",\n value: response,\n characterCount: response.length,\n wordCount: response.trim().split(/\\s+/).filter(Boolean).length,\n }\n : response;\n\n const trial = super.endTrial(responseInfo);\n\n // Auto-store if enabled\n if (this.autoStore) {\n const gorilla = this.getGorilla();\n if (gorilla !== undefined) {\n gorilla.store(`${this.storeKey}_trial_${trial.trialIndex}`, {\n behavioral: trial.behavioral,\n captureFlags: trial.captureFlags,\n });\n }\n }\n\n return trial;\n }\n\n /**\n * Stores the complete session via gorilla.metric().\n *\n * Call this at experiment end to store the full session data as a metric,\n * which will appear in the exported data.\n *\n * @param key - Metric key (default: \"slopit_session\")\n *\n * @example\n * ```typescript\n * // At end of experiment\n * recorder.storeSession();\n * gorilla.finish();\n * ```\n */\n storeSession(key = \"slopit_session\"): void {\n const gorilla = this.getGorilla();\n if (gorilla !== undefined) {\n gorilla.metric(key, JSON.stringify(this.exportSession()));\n }\n }\n\n /**\n * Stores session data via gorilla.store() for later retrieval.\n *\n * Unlike storeSession(), this stores the data for access within the\n * experiment rather than in the exported metrics.\n *\n * @param key - Store key (default: this.storeKey)\n *\n * @example\n * ```typescript\n * recorder.saveToStore(\"my_session_data\");\n * ```\n */\n saveToStore(key?: string): void {\n const gorilla = this.getGorilla();\n if (gorilla !== undefined) {\n gorilla.store(key ?? this.storeKey, this.exportSession());\n }\n }\n}\n\n/**\n * Alias for SlopitRecorder for naming clarity.\n */\nexport { SlopitRecorder as GorillaRecorder };\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@slopit/adapter-gorilla",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Gorilla adapter for slopit behavioral capture",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Aaron Steven White",
|
|
9
|
+
"email": "aaron.white@rochester.edu",
|
|
10
|
+
"url": "https://aaronstevenwhite.io"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://slopit.github.io",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/slopit/slopit.git",
|
|
16
|
+
"directory": "packages/adapter-gorilla"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/slopit/slopit/issues"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"gorilla",
|
|
26
|
+
"behavioral-research",
|
|
27
|
+
"experiment",
|
|
28
|
+
"psychology",
|
|
29
|
+
"ai-detection",
|
|
30
|
+
"crowdsourcing"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@slopit/adapter-shared": "0.1.0",
|
|
43
|
+
"@slopit/behavioral": "0.1.0",
|
|
44
|
+
"@slopit/core": "0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"jsdom": "^25.0.1",
|
|
48
|
+
"tsup": "^8.3.5",
|
|
49
|
+
"typescript": "^5.7.2",
|
|
50
|
+
"vitest": "^2.1.8"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"test:watch": "vitest",
|
|
57
|
+
"clean": "rm -rf dist"
|
|
58
|
+
}
|
|
59
|
+
}
|