@iblai/web-utils 1.11.11 → 1.12.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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iblai/web-utils",
3
- "version": "1.11.10",
3
+ "version": "1.11.12",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -3,27 +3,78 @@ export interface TimeTrackerConfig {
3
3
  onTimeUpdate: (url: string, timeSpent: number) => void;
4
4
  getCurrentUrl: () => string;
5
5
  onRouteChange?: (callback: () => void) => () => void;
6
+ /**
7
+ * Seconds of no user interaction (mouse, keyboard, touch, scroll) after
8
+ * which the user is considered idle and time tracking pauses. Set to 0 to
9
+ * disable idle detection. Defaults to 120 (2 minutes).
10
+ */
11
+ idleTimeoutSeconds?: number;
12
+ /**
13
+ * Pause tracking while the page/tab is hidden (Page Visibility API).
14
+ * Defaults to true.
15
+ */
16
+ pauseOnHidden?: boolean;
17
+ /**
18
+ * Pause tracking while the window loses focus (e.g. user switched to another
19
+ * application or window). Defaults to true.
20
+ */
21
+ pauseOnBlur?: boolean;
6
22
  }
7
23
  export interface TimeTrackerState {
8
24
  currentUrl: string;
9
- startTime: number;
10
25
  intervalId: number | null;
11
26
  routeUnsubscribe: (() => void) | null;
27
+ /** Active time (ms) banked since the last reset. */
28
+ accumulatedMs: number;
29
+ /** Timestamp the current active window started, or null while inactive. */
30
+ activeSince: number | null;
31
+ isVisible: boolean;
32
+ isFocused: boolean;
33
+ isIdle: boolean;
34
+ idleTimerId: number | null;
12
35
  }
13
36
  export declare class TimeTracker {
14
37
  private state;
15
38
  private config;
39
+ private readonly idleTimeoutMs;
40
+ private readonly pauseOnHidden;
41
+ private readonly pauseOnBlur;
42
+ private readonly idleDetectionEnabled;
43
+ private lastActivityAt;
44
+ private readonly handleActivity;
45
+ private readonly handleVisibilityChange;
46
+ private readonly handleWindowFocus;
47
+ private readonly handleWindowBlur;
16
48
  constructor(config: TimeTrackerConfig);
17
49
  private initialize;
18
- private startTracking;
19
- private clearInterval;
20
- private resetTimer;
50
+ /** Whether time should currently be counted. */
51
+ private isActive;
52
+ /**
53
+ * Reconcile the active window with the current activity signals: open a new
54
+ * window when the user becomes active, or bank the elapsed time when they
55
+ * become inactive.
56
+ */
57
+ private syncActiveWindow;
21
58
  private getTimeSpent;
59
+ private resetTimer;
60
+ private startTracking;
61
+ private clearTrackingInterval;
22
62
  private sendTimeUpdate;
23
63
  private handleRouteChange;
64
+ private attachActivityListeners;
65
+ private detachActivityListeners;
66
+ private startIdleTimer;
67
+ private clearIdleTimer;
68
+ private markIdle;
69
+ private onActivity;
70
+ private onVisibilityChange;
71
+ private onWindowFocus;
72
+ private onWindowBlur;
24
73
  pause(): void;
25
74
  resume(): void;
26
75
  destroy(): void;
27
76
  getCurrentUrl(): string;
28
77
  getTimeSpentSinceLastReset(): number;
78
+ /** Whether the user is currently considered active (present & interacting). */
79
+ getIsActive(): boolean;
29
80
  }