clarity-js 0.8.9 → 0.8.10

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.
Files changed (90) hide show
  1. package/.lintstagedrc.yml +3 -0
  2. package/biome.json +43 -0
  3. package/build/clarity.extended.js +1 -1
  4. package/build/clarity.insight.js +1 -1
  5. package/build/clarity.js +3095 -2876
  6. package/build/clarity.min.js +1 -1
  7. package/build/clarity.module.js +3095 -2876
  8. package/build/clarity.performance.js +1 -1
  9. package/package.json +17 -10
  10. package/rollup.config.ts +84 -88
  11. package/src/clarity.ts +34 -28
  12. package/src/core/config.ts +2 -2
  13. package/src/core/event.ts +36 -32
  14. package/src/core/hash.ts +5 -6
  15. package/src/core/history.ts +10 -11
  16. package/src/core/index.ts +21 -11
  17. package/src/core/measure.ts +9 -5
  18. package/src/core/report.ts +9 -5
  19. package/src/core/scrub.ts +29 -20
  20. package/src/core/task.ts +73 -45
  21. package/src/core/time.ts +3 -3
  22. package/src/core/timeout.ts +2 -2
  23. package/src/core/version.ts +1 -1
  24. package/src/data/baseline.ts +60 -55
  25. package/src/data/consent.ts +2 -2
  26. package/src/data/custom.ts +8 -13
  27. package/src/data/dimension.ts +11 -7
  28. package/src/data/encode.ts +36 -30
  29. package/src/data/envelope.ts +38 -38
  30. package/src/data/extract.ts +86 -77
  31. package/src/data/index.ts +10 -6
  32. package/src/data/limit.ts +1 -1
  33. package/src/data/metadata.ts +305 -266
  34. package/src/data/metric.ts +18 -8
  35. package/src/data/ping.ts +8 -4
  36. package/src/data/signal.ts +18 -18
  37. package/src/data/summary.ts +6 -4
  38. package/src/data/token.ts +10 -8
  39. package/src/data/upgrade.ts +7 -3
  40. package/src/data/upload.ts +100 -49
  41. package/src/data/variable.ts +27 -20
  42. package/src/diagnostic/encode.ts +2 -2
  43. package/src/diagnostic/fraud.ts +3 -4
  44. package/src/diagnostic/internal.ts +11 -5
  45. package/src/diagnostic/script.ts +12 -8
  46. package/src/global.ts +1 -1
  47. package/src/insight/blank.ts +4 -4
  48. package/src/insight/encode.ts +23 -17
  49. package/src/insight/snapshot.ts +57 -37
  50. package/src/interaction/change.ts +9 -6
  51. package/src/interaction/click.ts +34 -28
  52. package/src/interaction/clipboard.ts +2 -2
  53. package/src/interaction/encode.ts +35 -31
  54. package/src/interaction/input.ts +11 -9
  55. package/src/interaction/pointer.ts +41 -30
  56. package/src/interaction/resize.ts +5 -5
  57. package/src/interaction/scroll.ts +20 -17
  58. package/src/interaction/selection.ts +12 -8
  59. package/src/interaction/submit.ts +2 -2
  60. package/src/interaction/timeline.ts +13 -9
  61. package/src/interaction/unload.ts +1 -1
  62. package/src/interaction/visibility.ts +2 -2
  63. package/src/layout/animation.ts +47 -41
  64. package/src/layout/discover.ts +5 -5
  65. package/src/layout/document.ts +31 -19
  66. package/src/layout/dom.ts +141 -91
  67. package/src/layout/encode.ts +52 -37
  68. package/src/layout/mutation.ts +321 -318
  69. package/src/layout/node.ts +104 -81
  70. package/src/layout/offset.ts +7 -6
  71. package/src/layout/region.ts +66 -43
  72. package/src/layout/schema.ts +15 -8
  73. package/src/layout/selector.ts +47 -25
  74. package/src/layout/style.ts +45 -37
  75. package/src/layout/target.ts +14 -10
  76. package/src/layout/traverse.ts +17 -11
  77. package/src/performance/blank.ts +1 -1
  78. package/src/performance/encode.ts +4 -4
  79. package/src/performance/interaction.ts +58 -70
  80. package/src/performance/navigation.ts +2 -2
  81. package/src/performance/observer.ts +59 -26
  82. package/src/queue.ts +16 -9
  83. package/tsconfig.json +1 -1
  84. package/tslint.json +25 -32
  85. package/types/core.d.ts +13 -13
  86. package/types/data.d.ts +32 -29
  87. package/types/diagnostic.d.ts +1 -1
  88. package/types/interaction.d.ts +5 -4
  89. package/types/layout.d.ts +36 -21
  90. package/types/performance.d.ts +6 -5
@@ -1,30 +1,29 @@
1
1
  import { Event } from "@clarity-types/data";
2
- import { AnimationOperation, AnimationState } from "@clarity-types/layout";
2
+ import { AnimationOperation, type AnimationState } from "@clarity-types/layout";
3
+ import * as core from "@src/core";
3
4
  import { time } from "@src/core/time";
4
5
  import { shortid } from "@src/data/metadata";
5
- import encode from "@src/layout/encode";
6
6
  import { getId } from "@src/layout/dom";
7
- import * as core from "@src/core";
7
+ import encode from "@src/layout/encode";
8
8
 
9
9
  export let state: AnimationState[] = [];
10
10
  let elementAnimate: (keyframes: Keyframe[] | PropertyIndexedKeyframes, options?: number | KeyframeAnimationOptions) => Animation = null;
11
- let animationPlay: () => void = null;
12
- let animationPause: () => void = null;
13
- let animationCommitStyles: () => void = null;
14
- let animationCancel: () => void = null;
15
- let animationFinish: () => void = null;
16
- const animationId = 'clarityAnimationId';
17
- const operationCount = 'clarityOperationCount';
11
+ const animationPlay: () => void = null;
12
+ const animationPause: () => void = null;
13
+ const animationCommitStyles: () => void = null;
14
+ const animationCancel: () => void = null;
15
+ const animationFinish: () => void = null;
16
+ const animationId = "clarityAnimationId";
17
+ const operationCount = "clarityOperationCount";
18
18
  const maxOperations = 20;
19
19
 
20
20
  export function start(): void {
21
21
  if (
22
- window["Animation"] &&
23
- window["Animation"].prototype &&
24
- window["KeyframeEffect"] &&
25
- window["KeyframeEffect"].prototype &&
26
- window["KeyframeEffect"].prototype.getKeyframes &&
27
- window["KeyframeEffect"].prototype.getTiming
22
+ window.Animation?.prototype &&
23
+ window.KeyframeEffect &&
24
+ window.KeyframeEffect.prototype &&
25
+ window.KeyframeEffect.prototype.getKeyframes &&
26
+ window.KeyframeEffect.prototype.getTiming
28
27
  ) {
29
28
  reset();
30
29
  overrideAnimationHelper(animationPlay, "play");
@@ -34,33 +33,39 @@ export function start(): void {
34
33
  overrideAnimationHelper(animationFinish, "finish");
35
34
  if (elementAnimate === null) {
36
35
  elementAnimate = Element.prototype.animate;
37
- Element.prototype.animate = function(): Animation {
38
- var createdAnimation = elementAnimate.apply(this, arguments);
36
+ Element.prototype.animate = function (...args): Animation {
37
+ const createdAnimation = elementAnimate.apply(this, args);
39
38
  trackAnimationOperation(createdAnimation, "play");
40
39
  return createdAnimation;
41
- }
40
+ };
42
41
  }
43
42
  if (document.getAnimations) {
44
- for (var animation of document.getAnimations()) {
43
+ for (const animation of document.getAnimations()) {
45
44
  if (animation.playState === "finished") {
46
45
  trackAnimationOperation(animation, "finish");
47
- }
48
- else if (animation.playState === "paused" || animation.playState === "idle") {
46
+ } else if (animation.playState === "paused" || animation.playState === "idle") {
49
47
  trackAnimationOperation(animation, "pause");
50
- }
51
- else if (animation.playState === "running") {
48
+ } else if (animation.playState === "running") {
52
49
  trackAnimationOperation(animation, "play");
53
50
  }
54
51
  }
55
52
  }
56
- }
53
+ }
57
54
  }
58
55
 
59
56
  export function reset(): void {
60
57
  state = [];
61
58
  }
62
59
 
63
- function track(time: number, id: string, operation: AnimationOperation, keyFrames?: string, timing?: string, targetId?: number, timeline?: string): void {
60
+ function track(
61
+ time: number,
62
+ id: string,
63
+ operation: AnimationOperation,
64
+ keyFrames?: string,
65
+ timing?: string,
66
+ targetId?: number,
67
+ timeline?: string,
68
+ ): void {
64
69
  state.push({
65
70
  time,
66
71
  event: Event.Animation,
@@ -70,8 +75,8 @@ function track(time: number, id: string, operation: AnimationOperation, keyFrame
70
75
  keyFrames,
71
76
  timing,
72
77
  targetId,
73
- timeline
74
- }
78
+ timeline,
79
+ },
75
80
  });
76
81
 
77
82
  encode(Event.Animation);
@@ -83,29 +88,30 @@ export function stop(): void {
83
88
 
84
89
  function overrideAnimationHelper(functionToOverride: () => void, name: string) {
85
90
  if (functionToOverride === null) {
86
- functionToOverride = Animation.prototype[name];
87
- Animation.prototype[name] = function(): void {
88
- trackAnimationOperation(this, name);
89
- return functionToOverride.apply(this, arguments);
90
- }
91
+ // biome-ignore lint/style/noParameterAssign: function intentionally reassigns parameter for shimming
92
+ functionToOverride = Animation.prototype[name];
93
+ Animation.prototype[name] = function (...args): void {
94
+ trackAnimationOperation(this, name);
95
+ functionToOverride.apply(this, args);
96
+ };
91
97
  }
92
- }
98
+ }
93
99
 
94
100
  function trackAnimationOperation(animation: Animation, name: string) {
95
101
  if (core.active()) {
96
- let effect = <KeyframeEffect>animation.effect;
97
- let target = getId(effect.target);
102
+ const effect = <KeyframeEffect>animation.effect;
103
+ const target = effect?.target ? getId(effect.target) : null;
98
104
  if (target !== null && effect.getKeyframes && effect.getTiming) {
99
105
  if (!animation[animationId]) {
100
106
  animation[animationId] = shortid();
101
107
  animation[operationCount] = 0;
102
-
103
- let keyframes = effect.getKeyframes();
104
- let timing = effect.getTiming();
108
+
109
+ const keyframes = effect.getKeyframes();
110
+ const timing = effect.getTiming();
105
111
  track(time(), animation[animationId], AnimationOperation.Create, JSON.stringify(keyframes), JSON.stringify(timing), target);
106
112
  }
107
113
 
108
- if (animation[operationCount]++ < maxOperations) {
114
+ if (animation[operationCount]++ < maxOperations) {
109
115
  let operation: AnimationOperation = null;
110
116
  switch (name) {
111
117
  case "play":
@@ -128,6 +134,6 @@ function trackAnimationOperation(animation: Animation, name: string) {
128
134
  track(time(), animation[animationId], operation);
129
135
  }
130
136
  }
131
- }
137
+ }
132
138
  }
133
139
  }
@@ -1,16 +1,16 @@
1
- import { Priority, Timer } from "@clarity-types/core";
1
+ import { Priority, type Timer } from "@clarity-types/core";
2
2
  import { Event, Metric } from "@clarity-types/data";
3
3
  import { Source } from "@clarity-types/layout";
4
4
  import measure from "@src/core/measure";
5
5
  import * as task from "@src/core/task";
6
6
  import { time } from "@src/core/time";
7
7
  import { id } from "@src/data/metadata";
8
+ import * as scroll from "@src/interaction/scroll";
8
9
  import * as doc from "@src/layout/document";
9
10
  import encode from "@src/layout/encode";
10
11
  import * as region from "@src/layout/region";
11
- import traverse from "@src/layout/traverse";
12
12
  import { checkDocumentStyles } from "@src/layout/style";
13
- import * as scroll from "@src/interaction/scroll";
13
+ import traverse from "@src/layout/traverse";
14
14
 
15
15
  export function start(): void {
16
16
  task.schedule(discover, Priority.High).then((): void => {
@@ -21,8 +21,8 @@ export function start(): void {
21
21
  }
22
22
 
23
23
  async function discover(): Promise<void> {
24
- let ts = time();
25
- let timer: Timer = { id: id(), cost: Metric.LayoutCost };
24
+ const ts = time();
25
+ const timer: Timer = { id: id(), cost: Metric.LayoutCost };
26
26
  task.start(timer);
27
27
  await traverse(document, timer, Source.Discover, ts);
28
28
  checkDocumentStyles(document, ts);
@@ -1,5 +1,5 @@
1
1
  import { Event } from "@clarity-types/data";
2
- import { DocumentData } from "@clarity-types/layout";
2
+ import type { DocumentData } from "@clarity-types/layout";
3
3
  import { FunctionNames } from "@clarity-types/performance";
4
4
  import encode from "@src/layout/encode";
5
5
 
@@ -16,25 +16,37 @@ export function start(): void {
16
16
 
17
17
  export function compute(): void {
18
18
  compute.dn = FunctionNames.DocumentCompute;
19
- let body = document.body;
20
- let d = document.documentElement;
21
- let bodyClientWidth = body ? body.clientWidth : null;
22
- let bodyScrollWidth = body ? body.scrollWidth : null;
23
- let bodyOffsetWidth = body ? body.offsetWidth : null;
24
- let documentClientWidth = d ? d.clientWidth : null;
25
- let documentScrollWidth = d ? d.scrollWidth : null;
26
- let documentOffsetWidth = d ? d.offsetWidth : null;
27
- let width = Math.max(bodyClientWidth, bodyScrollWidth, bodyOffsetWidth,
28
- documentClientWidth, documentScrollWidth, documentOffsetWidth);
19
+ const body = document.body;
20
+ const d = document.documentElement;
21
+ const bodyClientWidth = body ? body.clientWidth : null;
22
+ const bodyScrollWidth = body ? body.scrollWidth : null;
23
+ const bodyOffsetWidth = body ? body.offsetWidth : null;
24
+ const documentClientWidth = d ? d.clientWidth : null;
25
+ const documentScrollWidth = d ? d.scrollWidth : null;
26
+ const documentOffsetWidth = d ? d.offsetWidth : null;
27
+ const width = Math.max(
28
+ bodyClientWidth,
29
+ bodyScrollWidth,
30
+ bodyOffsetWidth,
31
+ documentClientWidth,
32
+ documentScrollWidth,
33
+ documentOffsetWidth,
34
+ );
29
35
 
30
- let bodyClientHeight = body ? body.clientHeight : null;
31
- let bodyScrollHeight = body ? body.scrollHeight : null;
32
- let bodyOffsetHeight = body ? body.offsetHeight : null;
33
- let documentClientHeight = d ? d.clientHeight : null;
34
- let documentScrollHeight = d ? d.scrollHeight : null;
35
- let documentOffsetHeight = d ? d.offsetHeight : null;
36
- let height = Math.max(bodyClientHeight, bodyScrollHeight, bodyOffsetHeight,
37
- documentClientHeight, documentScrollHeight, documentOffsetHeight);
36
+ const bodyClientHeight = body ? body.clientHeight : null;
37
+ const bodyScrollHeight = body ? body.scrollHeight : null;
38
+ const bodyOffsetHeight = body ? body.offsetHeight : null;
39
+ const documentClientHeight = d ? d.clientHeight : null;
40
+ const documentScrollHeight = d ? d.scrollHeight : null;
41
+ const documentOffsetHeight = d ? d.offsetHeight : null;
42
+ const height = Math.max(
43
+ bodyClientHeight,
44
+ bodyScrollHeight,
45
+ bodyOffsetHeight,
46
+ documentClientHeight,
47
+ documentScrollHeight,
48
+ documentOffsetHeight,
49
+ );
38
50
 
39
51
  // Check that width or height has changed from before, and also that width & height are not null values
40
52
  if ((data === null || width !== data.width || height !== data.height) && width !== null && height !== null) {