@gemx-dev/clarity-js 0.8.59 → 0.8.61

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.
@@ -147,6 +147,7 @@ export default async function (type: Event, ts: number = null): Promise<void> {
147
147
  tokens.push(entry.data.y);
148
148
  tokens.push(sTopHash);
149
149
  tokens.push(sBottomHash);
150
+ tokens.push(entry.data.trust);
150
151
  queue(tokens);
151
152
  baseline.track(entry.event, entry.data.x, entry.data.y, entry.time);
152
153
  }
@@ -11,6 +11,7 @@ import * as timeline from "@src/interaction/timeline";
11
11
  import * as unload from "@src/interaction/unload";
12
12
  import * as visibility from "@src/interaction/visibility";
13
13
  import * as focus from "@src/interaction/focus";
14
+ import * as pageshow from "@src/interaction/pageshow";
14
15
 
15
16
  export function start(): void {
16
17
  timeline.start();
@@ -21,6 +22,7 @@ export function start(): void {
21
22
  resize.start();
22
23
  visibility.start();
23
24
  focus.start();
25
+ pageshow.start();
24
26
  scroll.start();
25
27
  selection.start();
26
28
  change.start();
@@ -37,6 +39,7 @@ export function stop(): void {
37
39
  resize.stop();
38
40
  visibility.stop();
39
41
  focus.stop();
42
+ pageshow.stop();
40
43
  scroll.stop();
41
44
  selection.stop();
42
45
  change.stop();
@@ -0,0 +1,35 @@
1
+ import { Constant } from "@clarity-types/core";
2
+ import { Code, Severity } from "@clarity-types/data";
3
+ import * as clarity from "@src/clarity";
4
+ import api from "@src/core/api";
5
+ import measure from "@src/core/measure";
6
+ import * as internal from "@src/diagnostic/internal";
7
+
8
+ let bound = false;
9
+
10
+ export function start(): void {
11
+ // Only bind once - this listener must persist even when Clarity stops
12
+ // to detect when the page is restored from bfcache
13
+ if (!bound) {
14
+ try {
15
+ window[api(Constant.AddEventListener)]("pageshow", measure(handler) as EventListener, { capture: false, passive: true });
16
+ bound = true;
17
+ } catch {
18
+ /* do nothing */
19
+ }
20
+ }
21
+ }
22
+
23
+ function handler(evt: PageTransitionEvent): void {
24
+ // The persisted property indicates if the page was loaded from bfcache
25
+ if (evt && evt.persisted) {
26
+ // Restart Clarity since it was stopped when the page entered bfcache
27
+ clarity.start();
28
+ internal.log(Code.BFCache, Severity.Info);
29
+ }
30
+ }
31
+
32
+ export function stop(): void {
33
+ // Intentionally don't remove the listener or reset 'bound' flag
34
+ // We need the listener to persist to detect bfcache restoration
35
+ }
@@ -1,4 +1,4 @@
1
- import { Constant, Dimension, Event } from "@clarity-types/data";
1
+ import { BooleanFlag, Constant, Dimension, Event } from "@clarity-types/data";
2
2
  import { ScrollState, Setting } from "@clarity-types/interaction";
3
3
  import { bind } from "@src/core/event";
4
4
  import { schedule } from "@src/core/task";
@@ -55,8 +55,9 @@ function recompute(event: UIEvent = null): void {
55
55
  const endYPosition = height - yOffset;
56
56
  const top = getPositionNode(xPosition, startYPosition);
57
57
  const bottom = getPositionNode(xPosition, endYPosition);
58
+ const trust = event && event.isTrusted ? BooleanFlag.True : BooleanFlag.False;
58
59
 
59
- let current: ScrollState = { time: time(event), event: Event.Scroll, data: {target: element, x, y, top, bottom} };
60
+ let current: ScrollState = { time: time(event), event: Event.Scroll, data: {target: element, x, y, top, bottom, trust} };
60
61
 
61
62
  // We don't send any scroll events if this is the first event and the current position is top (0,0)
62
63
  if ((event === null && x === 0 && y === 0) || (x === null || y === null)) {