clarity-js 0.8.12 → 0.8.13-beta

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