clarity-js 0.8.11-beta → 0.8.12
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/.lintstagedrc.yml +3 -0
- package/biome.json +43 -0
- package/build/clarity.extended.js +1 -1
- package/build/clarity.insight.js +1 -1
- package/build/clarity.js +4591 -4362
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +4591 -4362
- package/build/clarity.performance.js +1 -1
- package/package.json +76 -69
- package/rollup.config.ts +84 -88
- package/src/clarity.ts +34 -28
- package/src/core/api.ts +8 -1
- package/src/core/config.ts +2 -2
- package/src/core/event.ts +36 -32
- package/src/core/hash.ts +5 -6
- package/src/core/history.ts +10 -11
- package/src/core/index.ts +21 -11
- package/src/core/measure.ts +9 -5
- package/src/core/report.ts +9 -5
- package/src/core/scrub.ts +29 -20
- package/src/core/task.ts +73 -45
- package/src/core/time.ts +3 -3
- package/src/core/timeout.ts +2 -2
- package/src/core/version.ts +1 -1
- package/src/data/baseline.ts +60 -55
- package/src/data/consent.ts +2 -2
- package/src/data/custom.ts +8 -13
- package/src/data/dimension.ts +11 -7
- package/src/data/encode.ts +36 -30
- package/src/data/envelope.ts +38 -38
- package/src/data/extract.ts +86 -77
- package/src/data/index.ts +10 -6
- package/src/data/limit.ts +1 -1
- package/src/data/metadata.ts +305 -266
- package/src/data/metric.ts +18 -8
- package/src/data/ping.ts +8 -4
- package/src/data/signal.ts +18 -18
- package/src/data/summary.ts +6 -4
- package/src/data/token.ts +10 -8
- package/src/data/upgrade.ts +7 -3
- package/src/data/upload.ts +100 -49
- package/src/data/variable.ts +27 -20
- package/src/diagnostic/encode.ts +2 -2
- package/src/diagnostic/fraud.ts +3 -4
- package/src/diagnostic/internal.ts +11 -5
- package/src/diagnostic/script.ts +12 -8
- package/src/global.ts +1 -1
- package/src/insight/blank.ts +4 -4
- package/src/insight/encode.ts +23 -17
- package/src/insight/snapshot.ts +57 -37
- package/src/interaction/change.ts +9 -6
- package/src/interaction/click.ts +34 -28
- package/src/interaction/clipboard.ts +2 -2
- package/src/interaction/encode.ts +35 -31
- package/src/interaction/input.ts +11 -9
- package/src/interaction/pointer.ts +42 -31
- package/src/interaction/resize.ts +5 -5
- package/src/interaction/scroll.ts +21 -18
- package/src/interaction/selection.ts +12 -8
- package/src/interaction/submit.ts +2 -2
- package/src/interaction/timeline.ts +13 -9
- package/src/interaction/unload.ts +1 -1
- package/src/interaction/visibility.ts +2 -2
- package/src/layout/animation.ts +47 -41
- package/src/layout/discover.ts +5 -5
- package/src/layout/document.ts +31 -19
- package/src/layout/dom.ts +141 -91
- package/src/layout/encode.ts +52 -37
- package/src/layout/mutation.ts +321 -318
- package/src/layout/node.ts +104 -81
- package/src/layout/offset.ts +7 -6
- package/src/layout/region.ts +67 -44
- package/src/layout/schema.ts +15 -8
- package/src/layout/selector.ts +47 -25
- package/src/layout/style.ts +44 -36
- package/src/layout/target.ts +14 -10
- package/src/layout/traverse.ts +17 -11
- package/src/performance/blank.ts +1 -1
- package/src/performance/encode.ts +4 -4
- package/src/performance/interaction.ts +58 -70
- package/src/performance/navigation.ts +2 -2
- package/src/performance/observer.ts +59 -26
- package/src/queue.ts +16 -9
- package/tsconfig.json +1 -1
- package/tslint.json +25 -32
- package/types/core.d.ts +13 -13
- package/types/data.d.ts +33 -29
- package/types/diagnostic.d.ts +1 -1
- package/types/interaction.d.ts +7 -5
- package/types/layout.d.ts +36 -21
- package/types/performance.d.ts +6 -5
package/src/layout/animation.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const animationId =
|
|
17
|
-
const operationCount =
|
|
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
|
|
23
|
-
window
|
|
24
|
-
window
|
|
25
|
-
window
|
|
26
|
-
window
|
|
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
|
-
|
|
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 (
|
|
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(
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
97
|
-
|
|
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
|
-
|
|
104
|
-
|
|
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
|
}
|
package/src/layout/discover.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
25
|
-
|
|
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);
|
package/src/layout/document.ts
CHANGED
|
@@ -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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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) {
|