clarity-js 0.7.57 → 0.7.59

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.
@@ -1,5 +1,6 @@
1
1
  import { Event } from "@clarity-types/data";
2
2
  import { PointerState, Setting } from "@clarity-types/interaction";
3
+ import { FunctionNames } from "@clarity-types/performance";
3
4
  import { bind } from "@src/core/event";
4
5
  import { schedule } from "@src/core/task";
5
6
  import { time } from "@src/core/time";
@@ -11,6 +12,9 @@ import encode from "./encode";
11
12
 
12
13
  export let state: PointerState[] = [];
13
14
  let timeout: number = null;
15
+ let hasPrimaryTouch = false;
16
+ let primaryTouchId = 0;
17
+ const activeTouchPointIds = new Set<number>();
14
18
 
15
19
  export function start(): void {
16
20
  reset();
@@ -43,6 +47,7 @@ function mouse(event: Event, root: Node, evt: MouseEvent): void {
43
47
  // Check for null values before processing this event
44
48
  if (x !== null && y !== null) { handler({ time: time(evt), event, data: { target: target(evt), x, y } }); }
45
49
  }
50
+ mouse.dn = FunctionNames.PointerMouse;
46
51
 
47
52
  function touch(event: Event, root: Node, evt: TouchEvent): void {
48
53
  let frame = iframe(root);
@@ -58,16 +63,37 @@ function touch(event: Event, root: Node, evt: TouchEvent): void {
58
63
  x = x && frame ? x + Math.round(frame.offsetLeft) : x;
59
64
  y = y && frame ? y + Math.round(frame.offsetTop) : y;
60
65
 
61
- // identifier is 0-based, unique for each touch point and resets when all fingers are lifted
62
- // that is not a part of the spec, but it is how it is implemented in browsers
63
- // tested in Chromium-based browsers as well as Firefox
66
+ // We cannot rely on identifier to determine primary touch as its value doesn't always start with 0.
67
+ // Safari/Webkit uses the address of the UITouch object as the identifier value for each touch point.
64
68
  const id = "identifier" in entry ? entry["identifier"] : undefined;
65
69
 
70
+ switch(event) {
71
+ case Event.TouchStart:
72
+ if (activeTouchPointIds.size === 0) {
73
+ // Track presence of primary touch separately to handle scenarios when same id is repeated
74
+ hasPrimaryTouch = true;
75
+ primaryTouchId = id;
76
+ }
77
+ activeTouchPointIds.add(id);
78
+ break;
79
+ case Event.TouchEnd:
80
+ case Event.TouchCancel:
81
+ activeTouchPointIds.delete(id);
82
+ break;
83
+ }
84
+ const isPrimary = hasPrimaryTouch && primaryTouchId === id;
85
+
66
86
  // Check for null values before processing this event
67
- if (x !== null && y !== null) { handler({ time: t, event, data: { target: target(evt), x, y, id } }); }
87
+ if (x !== null && y !== null) { handler({ time: t, event, data: { target: target(evt), x, y, id, isPrimary } }); }
88
+
89
+ // Reset primary touch point id once touch event ends
90
+ if (event === Event.TouchCancel || event === Event.TouchEnd) {
91
+ if (primaryTouchId === id) { hasPrimaryTouch = false; }
92
+ }
68
93
  }
69
94
  }
70
95
  }
96
+ touch.dn = FunctionNames.PointerTouch;
71
97
 
72
98
  function handler(current: PointerState): void {
73
99
  switch (current.event) {
@@ -1,5 +1,6 @@
1
1
  import { Event } from "@clarity-types/data";
2
2
  import { ResizeData, Setting } from "@clarity-types/interaction";
3
+ import { FunctionNames } from "@clarity-types/performance";
3
4
  import { clearTimeout, setTimeout } from "@src/core/timeout";
4
5
  import { bind } from "@src/core/event";
5
6
  import encode from "./encode";
@@ -7,8 +8,10 @@ import { schedule } from "@src/core/task";
7
8
 
8
9
  export let data: ResizeData;
9
10
  let timeout: number = null;
11
+ let initialStateLogged = false;
10
12
 
11
13
  export function start(): void {
14
+ initialStateLogged = false;
12
15
  bind(window, "resize", recompute);
13
16
  recompute();
14
17
  }
@@ -21,9 +24,15 @@ function recompute(): void {
21
24
  width: de && "clientWidth" in de ? Math.min(de.clientWidth, window.innerWidth) : window.innerWidth,
22
25
  height: de && "clientHeight" in de ? Math.min(de.clientHeight, window.innerHeight) : window.innerHeight,
23
26
  };
24
- clearTimeout(timeout);
25
- timeout = setTimeout(process, Setting.LookAhead, Event.Resize);
27
+ if (initialStateLogged) {
28
+ clearTimeout(timeout);
29
+ timeout = setTimeout(process, Setting.LookAhead, Event.Resize);
30
+ } else {
31
+ encode(Event.Resize);
32
+ initialStateLogged = true;
33
+ }
26
34
  }
35
+ recompute.dn = FunctionNames.ResizeRecompute;
27
36
 
28
37
  function process(event: Event): void {
29
38
  schedule(encode.bind(this, event));
@@ -1,5 +1,6 @@
1
1
  import { Constant, Dimension, Event } from "@clarity-types/data";
2
2
  import { ScrollState, Setting } from "@clarity-types/interaction";
3
+ import { FunctionNames } from "@clarity-types/performance";
3
4
  import { bind } from "@src/core/event";
4
5
  import { schedule } from "@src/core/task";
5
6
  import { time } from "@src/core/time";
@@ -68,6 +69,7 @@ function recompute(event: UIEvent = null): void {
68
69
  clearTimeout(timeout);
69
70
  timeout = setTimeout(process, Setting.LookAhead, Event.Scroll);
70
71
  }
72
+ recompute.dn = FunctionNames.ScrollRecompute;
71
73
 
72
74
  function getPositionNode(x: number, y: number): Node {
73
75
  let node: Node;
@@ -112,6 +114,7 @@ export function compute(): void {
112
114
  dimension.log(Dimension.InitialScrollBottom, bottom?.hash?.join(Constant.Dot));
113
115
  }
114
116
  }
117
+ compute.dn = FunctionNames.ScrollCompute;
115
118
 
116
119
  export function stop(): void {
117
120
  clearTimeout(timeout);
@@ -1,5 +1,6 @@
1
1
  import { Event } from "@clarity-types/data";
2
2
  import { SelectionData, Setting } from "@clarity-types/interaction";
3
+ import { FunctionNames } from "@clarity-types/performance";
3
4
  import { bind } from "@src/core/event";
4
5
  import { schedule } from "@src/core/task";
5
6
  import { clearTimeout, setTimeout } from "@src/core/timeout";
@@ -50,6 +51,7 @@ function recompute(root: Node): void {
50
51
  clearTimeout(timeout);
51
52
  timeout = setTimeout(process, Setting.LookAhead, Event.Selection);
52
53
  }
54
+ recompute.dn = FunctionNames.SelectionRecompute;
53
55
 
54
56
  function process(event: Event): void {
55
57
  schedule(encode.bind(this, event));
@@ -1,5 +1,6 @@
1
1
  import { Event } from "@clarity-types/data";
2
2
  import { SubmitState } from "@clarity-types/interaction";
3
+ import { FunctionNames } from "@clarity-types/performance";
3
4
  import { bind } from "@src/core/event";
4
5
  import { schedule } from "@src/core/task";
5
6
  import { time } from "@src/core/time";
@@ -20,6 +21,7 @@ function recompute(evt: UIEvent): void {
20
21
  state.push({ time: time(evt), event: Event.Submit, data: { target: target(evt) } });
21
22
  schedule(encode.bind(this, Event.Submit));
22
23
  }
24
+ recompute.dn = FunctionNames.SubmitRecompute;
23
25
 
24
26
  export function reset(): void {
25
27
  state = [];
@@ -1,5 +1,6 @@
1
1
  import { Event } from "@clarity-types/data";
2
2
  import { UnloadData } from "@clarity-types/interaction";
3
+ import { FunctionNames } from "@clarity-types/performance";
3
4
  import * as clarity from "@src/clarity";
4
5
  import { bind } from "@src/core/event";
5
6
  import { time } from "@src/core/time";
@@ -16,6 +17,7 @@ function recompute(evt: UIEvent): void {
16
17
  encode(Event.Unload, time(evt));
17
18
  clarity.stop();
18
19
  }
20
+ recompute.dn = FunctionNames.UnloadRecompute;
19
21
 
20
22
  export function reset(): void {
21
23
  data = null;
@@ -1,5 +1,6 @@
1
1
  import { Event } from "@clarity-types/data";
2
2
  import { VisibilityData } from "@clarity-types/interaction";
3
+ import { FunctionNames } from "@clarity-types/performance";
3
4
  import { bind } from "@src/core/event";
4
5
  import { time } from "@src/core/time";
5
6
  import encode from "./encode";
@@ -15,6 +16,7 @@ function recompute(evt: UIEvent = null): void {
15
16
  data = { visible: "visibilityState" in document ? document.visibilityState : "default" };
16
17
  encode(Event.Visibility, time(evt));
17
18
  }
19
+ recompute.dn = FunctionNames.VisibilityRecompute;
18
20
 
19
21
  export function reset(): void {
20
22
  data = null;
@@ -1,5 +1,6 @@
1
1
  import { Event } from "@clarity-types/data";
2
2
  import { DocumentData } from "@clarity-types/layout";
3
+ import { FunctionNames } from "@clarity-types/performance";
3
4
  import encode from "@src/layout/encode";
4
5
 
5
6
  export let data: DocumentData;
@@ -40,6 +41,7 @@ export function compute(): void {
40
41
  encode(Event.Document);
41
42
  }
42
43
  }
44
+ compute.dn = FunctionNames.DocumentCompute;
43
45
 
44
46
  export function stop(): void {
45
47
  reset();
@@ -1,3 +1,4 @@
1
+ import { FunctionNames } from "@clarity-types/performance";
1
2
  import * as discover from "@src/layout/discover";
2
3
  import * as doc from "@src/layout/document";
3
4
  import * as dom from "@src/layout/dom";
@@ -28,6 +29,7 @@ export function start(): void {
28
29
  style.start();
29
30
  animation.start();
30
31
  }
32
+ start.dn = FunctionNames.LayoutStart;
31
33
 
32
34
  export function stop(): void {
33
35
  region.stop();
@@ -1,6 +1,7 @@
1
1
  import { Priority, Task, Timer } from "@clarity-types/core";
2
2
  import { Code, Event, Metric, Severity } from "@clarity-types/data";
3
3
  import { Constant, MutationHistory, MutationRecordWithTime, MutationQueue, Setting, Source } from "@clarity-types/layout";
4
+ import { FunctionNames } from "@clarity-types/performance";
4
5
  import api from "@src/core/api";
5
6
  import * as core from "@src/core";
6
7
  import { bind } from "@src/core/event";
@@ -89,6 +90,7 @@ export function start(): void {
89
90
  } catch { attachShadow = null; }
90
91
  }
91
92
  }
93
+ start.dn = FunctionNames.MutationStart;
92
94
 
93
95
  export function observe(node: Node): void {
94
96
  // Create a new observer for every time a new DOM tree (e.g. root document or shadowdom root) is discovered on the page
@@ -139,6 +141,7 @@ function handle(m: MutationRecord[]): void {
139
141
  measure(region.compute)();
140
142
  });
141
143
  }
144
+ handle.dn = FunctionNames.MutationHandle;
142
145
 
143
146
  async function processMutation(timer: Timer, mutation: MutationRecord, instance: number, timestamp: number): Promise<void> {
144
147
  let state = task.state(timer);
@@ -299,3 +302,4 @@ function generate(target: Node, type: MutationRecordType): void {
299
302
  type
300
303
  }]);
301
304
  }
305
+ generate.dn = FunctionNames.MutationGenerate;
@@ -1,5 +1,6 @@
1
1
  import { Event, Setting } from "@clarity-types/data";
2
2
  import { InteractionState, RegionData, RegionState, RegionQueue, RegionVisibility } from "@clarity-types/layout";
3
+ import { FunctionNames } from "@clarity-types/performance";
3
4
  import { time } from "@src/core/time";
4
5
  import * as dom from "@src/layout/dom";
5
6
  import encode from "@src/layout/encode";
@@ -76,6 +77,7 @@ export function compute(): void {
76
77
  // Schedule encode only when we have at least one valid data entry
77
78
  if (state.length > 0) { encode(Event.Region); }
78
79
  }
80
+ compute.dn = FunctionNames.RegionCompute;
79
81
 
80
82
  function handler(entries: IntersectionObserverEntry[]): void {
81
83
  for (let entry of entries) {
@@ -1,3 +1,4 @@
1
+ import { FunctionNames } from "@clarity-types/performance";
1
2
  import * as navigation from "@src/performance/navigation";
2
3
  import * as observer from "@src/performance/observer";
3
4
 
@@ -5,6 +6,7 @@ export function start(): void {
5
6
  navigation.reset();
6
7
  observer.start();
7
8
  }
9
+ start.dn = FunctionNames.PerformanceStart;
8
10
 
9
11
  export function stop(): void {
10
12
  observer.stop();
@@ -1,4 +1,5 @@
1
1
  import { Code, Constant, Dimension, Metric, Severity, PerformanceEventTiming } from "@clarity-types/data";
2
+ import { FunctionNames } from "@clarity-types/performance";
2
3
  import config from "@src/core/config";
3
4
  import { bind } from "@src/core/event";
4
5
  import measure from "@src/core/measure";
@@ -49,10 +50,12 @@ function observe(): void {
49
50
  }
50
51
  } catch { internal.log(Code.PerformanceObserver, Severity.Warning); }
51
52
  }
53
+ observe.dn = FunctionNames.ObserverObserve;
52
54
 
53
55
  function handle(entries: PerformanceObserverEntryList): void {
54
56
  process(entries.getEntries());
55
57
  }
58
+ handle.dn = FunctionNames.ObserverHandle;
56
59
 
57
60
  function process(entries: PerformanceEntryList): void {
58
61
  let visible = "visibilityState" in document ? document.visibilityState === "visible" : true;
package/types/data.d.ts CHANGED
@@ -194,7 +194,8 @@ export const enum Code {
194
194
  * @deprecated No longer support ContentSecurityPolicy
195
195
  */
196
196
  ContentSecurityPolicy = 7,
197
- Config = 8
197
+ Config = 8,
198
+ FunctionExecutionTime = 9
198
199
  }
199
200
 
200
201
  export const enum Severity {
@@ -105,6 +105,7 @@ export interface PointerData {
105
105
  x: number;
106
106
  y: number;
107
107
  id?: number;
108
+ isPrimary?: boolean;
108
109
  }
109
110
 
110
111
  export interface ClickData {
@@ -31,3 +31,35 @@ export interface NavigationData {
31
31
  encodedSize: number;
32
32
  decodedSize: number;
33
33
  }
34
+
35
+ export const enum FunctionNames {
36
+ HistoryCompute = 1,
37
+ Restart = 2,
38
+ DiagnosticStart = 3,
39
+ ScriptHandler = 4,
40
+ ChangeRecompute = 5,
41
+ ClickHandler = 6,
42
+ ClipboardRecompute = 7,
43
+ InteractionStart = 8,
44
+ InputRecompute = 9,
45
+ PointerMouse = 10,
46
+ PointerTouch = 11,
47
+ ResizeRecompute = 12,
48
+ ScrollRecompute = 13,
49
+ ScrollCompute = 14,
50
+ SelectionRecompute = 15,
51
+ SubmitRecompute = 16,
52
+ UnloadRecompute = 17,
53
+ VisibilityRecompute = 18,
54
+ DocumentCompute = 19,
55
+ LayoutStart = 20,
56
+ MutationStart = 21,
57
+ MutationHandle = 22,
58
+ MutationGenerate = 23,
59
+ RegionCompute = 24,
60
+ PerformanceStart = 25,
61
+ ObserverObserve = 26,
62
+ ObserverHandle = 27
63
+ }
64
+
65
+ declare global { interface Function { dn?: FunctionNames; } }