@slopit/adapter-labjs 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 +166 -0
- package/dist/index.js +167 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -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,166 @@
|
|
|
1
|
+
import { AdapterConfig, AdapterData, BaseRecorder } from '@slopit/adapter-shared';
|
|
2
|
+
import { PlatformInfo } from '@slopit/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type definitions for lab.js adapter.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for slopit behavioral capture in lab.js components.
|
|
12
|
+
*
|
|
13
|
+
* Extends the base adapter configuration with lab.js-specific options.
|
|
14
|
+
*/
|
|
15
|
+
interface LabjsSlopitConfig extends AdapterConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Container selector to search within for the target element.
|
|
18
|
+
*
|
|
19
|
+
* If not specified, searches within the lab.js content container
|
|
20
|
+
* or falls back to document.body.
|
|
21
|
+
*
|
|
22
|
+
* @default ".lab-content"
|
|
23
|
+
*/
|
|
24
|
+
containerSelector?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Trial data structure with optional slopit capture data.
|
|
28
|
+
*
|
|
29
|
+
* Represents the data object attached to a lab.js component after capture.
|
|
30
|
+
*/
|
|
31
|
+
interface LabjsTrialData {
|
|
32
|
+
/**
|
|
33
|
+
* Slopit behavioral capture data, if capture was enabled and attached.
|
|
34
|
+
*/
|
|
35
|
+
slopit?: AdapterData | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Allow additional properties from lab.js components.
|
|
38
|
+
*/
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Minimal interface for lab.js component lifecycle hooks.
|
|
43
|
+
*
|
|
44
|
+
* Since lab.js does not provide TypeScript definitions, this interface
|
|
45
|
+
* describes the subset of component behavior used by the adapter.
|
|
46
|
+
*/
|
|
47
|
+
interface LabjsComponentLike {
|
|
48
|
+
/**
|
|
49
|
+
* Component options, including custom parameters.
|
|
50
|
+
*/
|
|
51
|
+
options: Record<string, unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* Component data store for trial results.
|
|
54
|
+
*/
|
|
55
|
+
data: Record<string, unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* Registers an event handler for a lifecycle event.
|
|
58
|
+
*
|
|
59
|
+
* @param event - Event name (e.g., "run", "end")
|
|
60
|
+
* @param handler - Handler function
|
|
61
|
+
*/
|
|
62
|
+
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Constructor type for lab.js components.
|
|
66
|
+
*/
|
|
67
|
+
type LabjsComponentConstructor<T extends LabjsComponentLike = LabjsComponentLike> = new (...args: unknown[]) => T;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Mixin and component wrapper for adding slopit behavioral capture to lab.js components.
|
|
71
|
+
*
|
|
72
|
+
* @module
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Mixin function to add slopit behavioral capture to any lab.js component.
|
|
77
|
+
*
|
|
78
|
+
* Returns an enhanced component class that automatically attaches behavioral
|
|
79
|
+
* capture during the component's run lifecycle and collects data when the
|
|
80
|
+
* component ends.
|
|
81
|
+
*
|
|
82
|
+
* @typeParam T - The lab.js component constructor type
|
|
83
|
+
* @param Component - The lab.js component class to enhance
|
|
84
|
+
* @returns Enhanced component class with slopit behavioral capture
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { withSlopit } from "@slopit/adapter-labjs";
|
|
89
|
+
*
|
|
90
|
+
* // Assuming lab.js is loaded as a global
|
|
91
|
+
* declare const lab: { html: { Screen: new (...args: unknown[]) => unknown } };
|
|
92
|
+
*
|
|
93
|
+
* // Create enhanced component class
|
|
94
|
+
* const SlopitScreen = withSlopit(lab.html.Screen as LabjsComponentConstructor);
|
|
95
|
+
*
|
|
96
|
+
* // Use the enhanced component
|
|
97
|
+
* const screen = new SlopitScreen({
|
|
98
|
+
* content: "<textarea id='response'></textarea>",
|
|
99
|
+
* slopit: {
|
|
100
|
+
* targetSelector: "#response",
|
|
101
|
+
* keystroke: { enabled: true },
|
|
102
|
+
* paste: { enabled: true },
|
|
103
|
+
* },
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare function withSlopit<T extends LabjsComponentConstructor>(Component: T): T;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Session recorder for lab.js experiments.
|
|
111
|
+
*
|
|
112
|
+
* @module
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Session recorder for lab.js experiments.
|
|
117
|
+
*
|
|
118
|
+
* Extends BaseRecorder to provide lab.js-specific platform information
|
|
119
|
+
* and session management.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* import { LabjsRecorder } from "@slopit/adapter-labjs";
|
|
124
|
+
*
|
|
125
|
+
* const recorder = new LabjsRecorder({
|
|
126
|
+
* participantId: "P001",
|
|
127
|
+
* studyId: "my-study",
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* // Start recording a trial
|
|
131
|
+
* recorder.startTrial({
|
|
132
|
+
* trialType: "text-entry",
|
|
133
|
+
* targetElement: document.querySelector("textarea"),
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* // ... participant completes the trial ...
|
|
137
|
+
*
|
|
138
|
+
* // End the trial with response data
|
|
139
|
+
* recorder.endTrial({
|
|
140
|
+
* type: "text",
|
|
141
|
+
* value: "participant response",
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* // Export the session
|
|
145
|
+
* const session = recorder.exportSession();
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
declare class LabjsRecorder extends BaseRecorder {
|
|
149
|
+
/**
|
|
150
|
+
* Gets platform-specific information for lab.js.
|
|
151
|
+
*
|
|
152
|
+
* Attempts to detect the lab.js version from the global scope.
|
|
153
|
+
* If not available, returns "unknown" for the version.
|
|
154
|
+
*
|
|
155
|
+
* @returns Platform information including lab.js version
|
|
156
|
+
*/
|
|
157
|
+
protected getPlatformInfo(): PlatformInfo;
|
|
158
|
+
/**
|
|
159
|
+
* Detects the lab.js library version from the global scope.
|
|
160
|
+
*
|
|
161
|
+
* @returns The lab.js version string or "unknown"
|
|
162
|
+
*/
|
|
163
|
+
private detectLabjsVersion;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { type LabjsComponentConstructor, type LabjsComponentLike, LabjsRecorder, type LabjsSlopitConfig, type LabjsTrialData, withSlopit };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { BaseRecorder, discoverElement } from '@slopit/adapter-shared';
|
|
2
|
+
import { createBehavioralCapture } from '@slopit/behavioral';
|
|
3
|
+
|
|
4
|
+
// src/extension.ts
|
|
5
|
+
var DEFAULT_TARGET_SELECTOR = "textarea, input[type='text']";
|
|
6
|
+
var DEFAULT_CONTAINER_SELECTOR = ".lab-content";
|
|
7
|
+
var DEFAULT_DISCOVERY_TIMEOUT = 5e3;
|
|
8
|
+
function withSlopit(Component) {
|
|
9
|
+
const EnhancedComponent = class SlopitEnhancedComponent extends Component {
|
|
10
|
+
/**
|
|
11
|
+
* Behavioral capture instance for the current component.
|
|
12
|
+
*/
|
|
13
|
+
_slopitCapture = null;
|
|
14
|
+
/**
|
|
15
|
+
* Start time for the component run (performance.now()).
|
|
16
|
+
*/
|
|
17
|
+
_slopitStartTime = 0;
|
|
18
|
+
/**
|
|
19
|
+
* Cleanup function for element discovery observer.
|
|
20
|
+
*/
|
|
21
|
+
_slopitCleanup = null;
|
|
22
|
+
/**
|
|
23
|
+
* Captured slopit data after component ends.
|
|
24
|
+
*/
|
|
25
|
+
_slopitData = null;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an enhanced component with slopit behavioral capture.
|
|
28
|
+
*
|
|
29
|
+
* @param args - Arguments passed to the base component constructor
|
|
30
|
+
*/
|
|
31
|
+
constructor(...args) {
|
|
32
|
+
super(...args);
|
|
33
|
+
this.on("run", () => this._slopitOnRun());
|
|
34
|
+
this.on("end", () => this._slopitOnEnd());
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Handles the component "run" lifecycle event.
|
|
38
|
+
*
|
|
39
|
+
* Initializes behavioral capture and attaches to the target element.
|
|
40
|
+
*/
|
|
41
|
+
_slopitOnRun() {
|
|
42
|
+
const config = this.options.slopit;
|
|
43
|
+
if (config === void 0 || config.enabled === false) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this._slopitStartTime = performance.now();
|
|
47
|
+
const selector = config.targetSelector ?? DEFAULT_TARGET_SELECTOR;
|
|
48
|
+
const containerSelector = config.containerSelector ?? DEFAULT_CONTAINER_SELECTOR;
|
|
49
|
+
const container = document.querySelector(containerSelector) ?? document.body;
|
|
50
|
+
const element = container.querySelector(selector);
|
|
51
|
+
if (element !== null) {
|
|
52
|
+
this._attachCapture(element, config);
|
|
53
|
+
} else {
|
|
54
|
+
this._slopitCleanup = discoverElement({
|
|
55
|
+
selector,
|
|
56
|
+
container,
|
|
57
|
+
timeout: DEFAULT_DISCOVERY_TIMEOUT,
|
|
58
|
+
onFound: (el) => this._attachCapture(el, config)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Attaches behavioral capture to the target element.
|
|
64
|
+
*
|
|
65
|
+
* @param element - The DOM element to attach to
|
|
66
|
+
* @param config - Slopit configuration
|
|
67
|
+
*/
|
|
68
|
+
_attachCapture(element, config) {
|
|
69
|
+
if (this._slopitCapture !== null) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const captureConfig = {};
|
|
73
|
+
if (config.keystroke !== void 0) {
|
|
74
|
+
captureConfig.keystroke = config.keystroke;
|
|
75
|
+
}
|
|
76
|
+
if (config.focus !== void 0) {
|
|
77
|
+
captureConfig.focus = config.focus;
|
|
78
|
+
}
|
|
79
|
+
if (config.paste !== void 0) {
|
|
80
|
+
captureConfig.paste = config.paste;
|
|
81
|
+
}
|
|
82
|
+
if (config.clipboard !== void 0) {
|
|
83
|
+
captureConfig.clipboard = config.clipboard;
|
|
84
|
+
}
|
|
85
|
+
if (config.mouse !== void 0) {
|
|
86
|
+
captureConfig.mouse = config.mouse;
|
|
87
|
+
}
|
|
88
|
+
if (config.scroll !== void 0) {
|
|
89
|
+
captureConfig.scroll = config.scroll;
|
|
90
|
+
}
|
|
91
|
+
if (config.inputDuration !== void 0) {
|
|
92
|
+
captureConfig.inputDuration = config.inputDuration;
|
|
93
|
+
}
|
|
94
|
+
this._slopitCapture = createBehavioralCapture(captureConfig);
|
|
95
|
+
this._slopitCapture.attach(element, this._slopitStartTime);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Handles the component "end" lifecycle event.
|
|
99
|
+
*
|
|
100
|
+
* Collects captured data and cleans up resources.
|
|
101
|
+
*/
|
|
102
|
+
_slopitOnEnd() {
|
|
103
|
+
if (this._slopitCleanup !== null) {
|
|
104
|
+
this._slopitCleanup();
|
|
105
|
+
this._slopitCleanup = null;
|
|
106
|
+
}
|
|
107
|
+
if (this._slopitCapture !== null) {
|
|
108
|
+
this._slopitData = {
|
|
109
|
+
behavioral: this._slopitCapture.getData(),
|
|
110
|
+
flags: this._slopitCapture.getFlags()
|
|
111
|
+
};
|
|
112
|
+
this._slopitCapture.detach();
|
|
113
|
+
this._slopitCapture = null;
|
|
114
|
+
}
|
|
115
|
+
if (this._slopitData !== null) {
|
|
116
|
+
this.data["slopit"] = this._slopitData;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Gets the captured slopit data for this component.
|
|
121
|
+
*
|
|
122
|
+
* Returns null if capture was not enabled or no data was collected.
|
|
123
|
+
*
|
|
124
|
+
* @returns The captured behavioral data and flags, or null
|
|
125
|
+
*/
|
|
126
|
+
getSlopitData() {
|
|
127
|
+
return this._slopitData;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return EnhancedComponent;
|
|
131
|
+
}
|
|
132
|
+
var ADAPTER_VERSION = "0.1.0";
|
|
133
|
+
var LabjsRecorder = class extends BaseRecorder {
|
|
134
|
+
/**
|
|
135
|
+
* Gets platform-specific information for lab.js.
|
|
136
|
+
*
|
|
137
|
+
* Attempts to detect the lab.js version from the global scope.
|
|
138
|
+
* If not available, returns "unknown" for the version.
|
|
139
|
+
*
|
|
140
|
+
* @returns Platform information including lab.js version
|
|
141
|
+
*/
|
|
142
|
+
getPlatformInfo() {
|
|
143
|
+
return {
|
|
144
|
+
name: "lab.js",
|
|
145
|
+
version: this.detectLabjsVersion(),
|
|
146
|
+
adapterVersion: ADAPTER_VERSION
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Detects the lab.js library version from the global scope.
|
|
151
|
+
*
|
|
152
|
+
* @returns The lab.js version string or "unknown"
|
|
153
|
+
*/
|
|
154
|
+
detectLabjsVersion() {
|
|
155
|
+
if (typeof window !== "undefined") {
|
|
156
|
+
const labGlobal = window.lab;
|
|
157
|
+
if (labGlobal?.version !== void 0) {
|
|
158
|
+
return labGlobal.version;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return "unknown";
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export { LabjsRecorder, withSlopit };
|
|
166
|
+
//# sourceMappingURL=index.js.map
|
|
167
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/extension.ts","../src/recorder.ts"],"names":[],"mappings":";;;;AAkBA,IAAM,uBAAA,GAA0B,8BAAA;AAKhC,IAAM,0BAAA,GAA6B,cAAA;AAKnC,IAAM,yBAAA,GAA4B,GAAA;AAkC3B,SAAS,WAAgD,SAAA,EAAiB;AAC/E,EAAA,MAAM,iBAAA,GAAoB,MAAM,uBAAA,SAAiC,SAAA,CAAwC;AAAA;AAAA;AAAA;AAAA,IAI/F,cAAA,GAA2C,IAAA;AAAA;AAAA;AAAA;AAAA,IAK3C,gBAAA,GAAmB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AO,SAAA,CAAU,OAAA;AAAA,MACnB;AAAA,IACF;AACA,IAAA,OAAO,SAAA;AAAA,EACT;AACF","file":"index.js","sourcesContent":["/**\n * Mixin and component wrapper for adding slopit behavioral capture to lab.js components.\n *\n * @module\n */\n\nimport { type AdapterData, discoverElement } from \"@slopit/adapter-shared\";\nimport {\n type BehavioralCapture,\n type BehavioralCaptureConfig,\n createBehavioralCapture,\n} from \"@slopit/behavioral\";\n\nimport type { LabjsComponentConstructor, LabjsSlopitConfig } from \"./types.js\";\n\n/**\n * Default CSS selector for finding text input elements.\n */\nconst DEFAULT_TARGET_SELECTOR = \"textarea, input[type='text']\";\n\n/**\n * Default CSS selector for the lab.js content container.\n */\nconst DEFAULT_CONTAINER_SELECTOR = \".lab-content\";\n\n/**\n * Default timeout for element discovery in milliseconds.\n */\nconst DEFAULT_DISCOVERY_TIMEOUT = 5000;\n\n/**\n * Mixin function to add slopit behavioral capture to any lab.js component.\n *\n * Returns an enhanced component class that automatically attaches behavioral\n * capture during the component's run lifecycle and collects data when the\n * component ends.\n *\n * @typeParam T - The lab.js component constructor type\n * @param Component - The lab.js component class to enhance\n * @returns Enhanced component class with slopit behavioral capture\n *\n * @example\n * ```typescript\n * import { withSlopit } from \"@slopit/adapter-labjs\";\n *\n * // Assuming lab.js is loaded as a global\n * declare const lab: { html: { Screen: new (...args: unknown[]) => unknown } };\n *\n * // Create enhanced component class\n * const SlopitScreen = withSlopit(lab.html.Screen as LabjsComponentConstructor);\n *\n * // Use the enhanced component\n * const screen = new SlopitScreen({\n * content: \"<textarea id='response'></textarea>\",\n * slopit: {\n * targetSelector: \"#response\",\n * keystroke: { enabled: true },\n * paste: { enabled: true },\n * },\n * });\n * ```\n */\nexport function withSlopit<T extends LabjsComponentConstructor>(Component: T): T {\n const EnhancedComponent = class SlopitEnhancedComponent extends (Component as LabjsComponentConstructor) {\n /**\n * Behavioral capture instance for the current component.\n */\n private _slopitCapture: BehavioralCapture | null = null;\n\n /**\n * Start time for the component run (performance.now()).\n */\n private _slopitStartTime = 0;\n\n /**\n * Cleanup function for element discovery observer.\n */\n private _slopitCleanup: (() => void) | null = null;\n\n /**\n * Captured slopit data after component ends.\n */\n private _slopitData: AdapterData | null = null;\n\n /**\n * Creates an enhanced component with slopit behavioral capture.\n *\n * @param args - Arguments passed to the base component constructor\n */\n constructor(...args: unknown[]) {\n super(...args);\n\n // Hook into lifecycle events\n this.on(\"run\", () => this._slopitOnRun());\n this.on(\"end\", () => this._slopitOnEnd());\n }\n\n /**\n * Handles the component \"run\" lifecycle event.\n *\n * Initializes behavioral capture and attaches to the target element.\n */\n private _slopitOnRun(): void {\n const config = (this.options as OptionsWithSlopit).slopit;\n\n // Skip if slopit is not configured or explicitly disabled\n if (config === undefined || config.enabled === false) {\n return;\n }\n\n this._slopitStartTime = performance.now();\n\n const selector = config.targetSelector ?? DEFAULT_TARGET_SELECTOR;\n const containerSelector = config.containerSelector ?? DEFAULT_CONTAINER_SELECTOR;\n const container =\n (document.querySelector(containerSelector) as HTMLElement | null) ?? document.body;\n\n // Try immediate element discovery\n const element = container.querySelector<HTMLElement>(selector);\n\n if (element !== null) {\n this._attachCapture(element, config);\n } else {\n // Use MutationObserver for dynamically created elements\n this._slopitCleanup = discoverElement({\n selector,\n container,\n timeout: DEFAULT_DISCOVERY_TIMEOUT,\n onFound: (el) => this._attachCapture(el, config),\n });\n }\n }\n\n /**\n * Attaches behavioral capture to the target element.\n *\n * @param element - The DOM element to attach to\n * @param config - Slopit configuration\n */\n private _attachCapture(element: HTMLElement, config: LabjsSlopitConfig): void {\n if (this._slopitCapture !== null) {\n return; // Already attached\n }\n\n // Build capture configuration, omitting undefined properties\n const captureConfig: BehavioralCaptureConfig = {};\n\n if (config.keystroke !== undefined) {\n captureConfig.keystroke = config.keystroke;\n }\n if (config.focus !== undefined) {\n captureConfig.focus = config.focus;\n }\n if (config.paste !== undefined) {\n captureConfig.paste = config.paste;\n }\n if (config.clipboard !== undefined) {\n captureConfig.clipboard = config.clipboard;\n }\n if (config.mouse !== undefined) {\n captureConfig.mouse = config.mouse;\n }\n if (config.scroll !== undefined) {\n captureConfig.scroll = config.scroll;\n }\n if (config.inputDuration !== undefined) {\n captureConfig.inputDuration = config.inputDuration;\n }\n\n this._slopitCapture = createBehavioralCapture(captureConfig);\n this._slopitCapture.attach(element, this._slopitStartTime);\n }\n\n /**\n * Handles the component \"end\" lifecycle event.\n *\n * Collects captured data and cleans up resources.\n */\n private _slopitOnEnd(): void {\n // Clean up element discovery observer\n if (this._slopitCleanup !== null) {\n this._slopitCleanup();\n this._slopitCleanup = null;\n }\n\n // Collect data and detach capture\n if (this._slopitCapture !== null) {\n this._slopitData = {\n behavioral: this._slopitCapture.getData(),\n flags: this._slopitCapture.getFlags(),\n };\n this._slopitCapture.detach();\n this._slopitCapture = null;\n }\n\n // Store data in component's data store\n if (this._slopitData !== null) {\n this.data[\"slopit\"] = this._slopitData;\n }\n }\n\n /**\n * Gets the captured slopit data for this component.\n *\n * Returns null if capture was not enabled or no data was collected.\n *\n * @returns The captured behavioral data and flags, or null\n */\n getSlopitData(): AdapterData | null {\n return this._slopitData;\n }\n };\n\n return EnhancedComponent as unknown as T;\n}\n\n/**\n * Component options interface with optional slopit configuration.\n */\ninterface OptionsWithSlopit {\n slopit?: LabjsSlopitConfig | undefined;\n}\n","/**\n * Session recorder for lab.js experiments.\n *\n * @module\n */\n\nimport { BaseRecorder } from \"@slopit/adapter-shared\";\nimport type { PlatformInfo } from \"@slopit/core\";\n\n/**\n * Adapter version for platform metadata.\n */\nconst ADAPTER_VERSION = \"0.1.0\";\n\n/**\n * Session recorder for lab.js experiments.\n *\n * Extends BaseRecorder to provide lab.js-specific platform information\n * and session management.\n *\n * @example\n * ```typescript\n * import { LabjsRecorder } from \"@slopit/adapter-labjs\";\n *\n * const recorder = new LabjsRecorder({\n * participantId: \"P001\",\n * studyId: \"my-study\",\n * });\n *\n * // Start recording a trial\n * recorder.startTrial({\n * trialType: \"text-entry\",\n * targetElement: document.querySelector(\"textarea\"),\n * });\n *\n * // ... participant completes the trial ...\n *\n * // End the trial with response data\n * recorder.endTrial({\n * type: \"text\",\n * value: \"participant response\",\n * });\n *\n * // Export the session\n * const session = recorder.exportSession();\n * ```\n */\nexport class LabjsRecorder extends BaseRecorder {\n /**\n * Gets platform-specific information for lab.js.\n *\n * Attempts to detect the lab.js version from the global scope.\n * If not available, returns \"unknown\" for the version.\n *\n * @returns Platform information including lab.js version\n */\n protected getPlatformInfo(): PlatformInfo {\n return {\n name: \"lab.js\",\n version: this.detectLabjsVersion(),\n adapterVersion: ADAPTER_VERSION,\n };\n }\n\n /**\n * Detects the lab.js library version from the global scope.\n *\n * @returns The lab.js version string or \"unknown\"\n */\n private detectLabjsVersion(): string {\n if (typeof window !== \"undefined\") {\n // lab.js exposes version on the lab global\n const labGlobal = (window as WindowWithLab).lab;\n if (labGlobal?.version !== undefined) {\n return labGlobal.version;\n }\n }\n return \"unknown\";\n }\n}\n\n/**\n * Window interface with optional lab.js global.\n */\ninterface WindowWithLab extends Window {\n lab?: {\n version?: string;\n };\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@slopit/adapter-labjs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "lab.js integration 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-labjs"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/slopit/slopit/issues"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"labjs",
|
|
26
|
+
"lab.js",
|
|
27
|
+
"behavioral-research",
|
|
28
|
+
"experiment",
|
|
29
|
+
"psychology",
|
|
30
|
+
"ai-detection",
|
|
31
|
+
"crowdsourcing"
|
|
32
|
+
],
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"lab.js": ">=21.0.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"lab.js": {
|
|
47
|
+
"optional": true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@slopit/behavioral": "0.1.0",
|
|
52
|
+
"@slopit/core": "0.1.0",
|
|
53
|
+
"@slopit/adapter-shared": "0.1.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"jsdom": "^25.0.1",
|
|
57
|
+
"lab.js": "^20.2.4",
|
|
58
|
+
"tsup": "^8.3.5",
|
|
59
|
+
"typescript": "^5.7.2",
|
|
60
|
+
"vitest": "^2.1.8"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsup",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"test": "vitest run",
|
|
66
|
+
"test:watch": "vitest",
|
|
67
|
+
"clean": "rm -rf dist"
|
|
68
|
+
}
|
|
69
|
+
}
|