@gem-sdk/clarity-js 0.8.94
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/CHANGELOG.md +8 -0
- package/README.md +1 -0
- package/build/clarity.extended.js +1 -0
- package/build/clarity.insight.js +1 -0
- package/build/clarity.js +7148 -0
- package/build/clarity.livechat.js +1 -0
- package/build/clarity.min.js +1 -0
- package/build/clarity.module.js +7144 -0
- package/build/clarity.performance.js +1 -0
- package/build/dynamic/clarity.crisp.js +1 -0
- package/build/dynamic/clarity.tidio.js +1 -0
- package/package.json +49 -0
- package/rollup.config.ts +161 -0
- package/src/clarity.ts +72 -0
- package/src/core/api.ts +8 -0
- package/src/core/config.ts +35 -0
- package/src/core/copy.ts +3 -0
- package/src/core/dynamic.ts +68 -0
- package/src/core/event.ts +53 -0
- package/src/core/hash.ts +19 -0
- package/src/core/history.ts +82 -0
- package/src/core/index.ts +81 -0
- package/src/core/measure.ts +19 -0
- package/src/core/report.ts +28 -0
- package/src/core/scrub.ts +201 -0
- package/src/core/task.ts +181 -0
- package/src/core/throttle.ts +46 -0
- package/src/core/time.ts +26 -0
- package/src/core/timeout.ts +10 -0
- package/src/core/version.ts +2 -0
- package/src/custom/README.md +44 -0
- package/src/custom/dialog.ts +69 -0
- package/src/custom/index.ts +6 -0
- package/src/data/baseline.ts +162 -0
- package/src/data/compress.ts +31 -0
- package/src/data/consent.ts +84 -0
- package/src/data/cookie.ts +90 -0
- package/src/data/custom.ts +23 -0
- package/src/data/dimension.ts +53 -0
- package/src/data/encode.ts +155 -0
- package/src/data/envelope.ts +53 -0
- package/src/data/extract.ts +217 -0
- package/src/data/gemx-upload.ts +51 -0
- package/src/data/gemx.ts +35 -0
- package/src/data/index.ts +57 -0
- package/src/data/limit.ts +44 -0
- package/src/data/metadata.ts +340 -0
- package/src/data/metric.ts +51 -0
- package/src/data/ping.ts +36 -0
- package/src/data/signal.ts +30 -0
- package/src/data/summary.ts +34 -0
- package/src/data/token.ts +39 -0
- package/src/data/upgrade.ts +44 -0
- package/src/data/upload.ts +375 -0
- package/src/data/util.ts +18 -0
- package/src/data/variable.ts +84 -0
- package/src/diagnostic/encode.ts +40 -0
- package/src/diagnostic/fraud.ts +37 -0
- package/src/diagnostic/index.ts +13 -0
- package/src/diagnostic/internal.ts +28 -0
- package/src/diagnostic/script.ts +35 -0
- package/src/dynamic/agent/blank.ts +2 -0
- package/src/dynamic/agent/crisp.ts +40 -0
- package/src/dynamic/agent/encode.ts +25 -0
- package/src/dynamic/agent/index.ts +8 -0
- package/src/dynamic/agent/livechat.ts +58 -0
- package/src/dynamic/agent/tidio.ts +44 -0
- package/src/global.ts +6 -0
- package/src/index.ts +10 -0
- package/src/insight/blank.ts +14 -0
- package/src/insight/encode.ts +64 -0
- package/src/insight/snapshot.ts +115 -0
- package/src/interaction/change.ts +38 -0
- package/src/interaction/click.ts +256 -0
- package/src/interaction/clipboard.ts +32 -0
- package/src/interaction/encode.ts +217 -0
- package/src/interaction/focus.ts +25 -0
- package/src/interaction/index.ts +66 -0
- package/src/interaction/input.ts +66 -0
- package/src/interaction/pageshow.ts +35 -0
- package/src/interaction/pointer.ts +137 -0
- package/src/interaction/resize.ts +50 -0
- package/src/interaction/scroll.ts +134 -0
- package/src/interaction/selection.ts +66 -0
- package/src/interaction/submit.ts +30 -0
- package/src/interaction/timeline.ts +69 -0
- package/src/interaction/unload.ts +32 -0
- package/src/interaction/visibility.ts +28 -0
- package/src/layout/animation.ts +133 -0
- package/src/layout/constants.ts +13 -0
- package/src/layout/custom.ts +48 -0
- package/src/layout/discover.ts +31 -0
- package/src/layout/document.ts +46 -0
- package/src/layout/dom.ts +444 -0
- package/src/layout/encode.ts +157 -0
- package/src/layout/gemx-snapshot.ts +84 -0
- package/src/layout/index.ts +47 -0
- package/src/layout/mutation.ts +424 -0
- package/src/layout/node.ts +302 -0
- package/src/layout/offset.ts +19 -0
- package/src/layout/region.ts +151 -0
- package/src/layout/schema.ts +63 -0
- package/src/layout/selector.ts +113 -0
- package/src/layout/style.ts +160 -0
- package/src/layout/target.ts +34 -0
- package/src/layout/traverse.ts +28 -0
- package/src/performance/blank.ts +10 -0
- package/src/performance/encode.ts +31 -0
- package/src/performance/index.ts +12 -0
- package/src/performance/interaction.ts +125 -0
- package/src/performance/navigation.ts +31 -0
- package/src/performance/observer.ts +112 -0
- package/src/queue.ts +33 -0
- package/test/consentv2.test.ts +1309 -0
- package/test/hash.test.ts +68 -0
- package/test/time.test.ts +42 -0
- package/tsconfig.json +12 -0
- package/tslint.json +33 -0
- package/types/agent.d.ts +39 -0
- package/types/core.d.ts +156 -0
- package/types/data.d.ts +611 -0
- package/types/diagnostic.d.ts +24 -0
- package/types/global.d.ts +43 -0
- package/types/index.d.ts +46 -0
- package/types/interaction.d.ts +187 -0
- package/types/layout.d.ts +271 -0
- package/types/performance.d.ts +34 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { BooleanFlag, Constant, Dimension, Event } from "@clarity-types/data";
|
|
2
|
+
import { ScrollState, Setting } from "@clarity-types/interaction";
|
|
3
|
+
import { bind } from "@src/core/event";
|
|
4
|
+
import { schedule } from "@src/core/task";
|
|
5
|
+
import { time } from "@src/core/time";
|
|
6
|
+
import { clearTimeout, setTimeout } from "@src/core/timeout";
|
|
7
|
+
import throttle from "@src/core/throttle";
|
|
8
|
+
import { iframe } from "@src/layout/dom";
|
|
9
|
+
import { target, metadata } from "@src/layout/target";
|
|
10
|
+
import encode from "./encode";
|
|
11
|
+
import * as dimension from "@src/data/dimension";
|
|
12
|
+
|
|
13
|
+
export let state: ScrollState[] = [];
|
|
14
|
+
let trustedCallback: (() => void) | null = null;
|
|
15
|
+
|
|
16
|
+
export function onTrustedScroll(cb: () => void): void { trustedCallback = cb; }
|
|
17
|
+
let initialTop: Node = null;
|
|
18
|
+
let initialBottom: Node = null;
|
|
19
|
+
let timeout: number = null;
|
|
20
|
+
|
|
21
|
+
export function start(): void {
|
|
22
|
+
state = [];
|
|
23
|
+
recompute();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function observe(root: Node): void {
|
|
27
|
+
let frame = iframe(root);
|
|
28
|
+
let node = frame ? frame.contentWindow : (root === document ? window : root);
|
|
29
|
+
bind(node, "scroll", throttledRecompute, true);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function recompute(event: UIEvent = null): void {
|
|
33
|
+
let w = window as Window;
|
|
34
|
+
let de = document.documentElement;
|
|
35
|
+
let element = event ? target(event) : de;
|
|
36
|
+
|
|
37
|
+
// In some edge cases, it's possible for target to be null.
|
|
38
|
+
// In those cases, we cannot proceed with scroll event instrumentation.
|
|
39
|
+
if (!element) { return; }
|
|
40
|
+
|
|
41
|
+
// If the target is a Document node, then identify corresponding documentElement and window for this document
|
|
42
|
+
if (element && element.nodeType === Node.DOCUMENT_NODE) {
|
|
43
|
+
let frame = iframe(element);
|
|
44
|
+
w = frame ? frame.contentWindow : w;
|
|
45
|
+
element = de = (element as Document).documentElement;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Edge doesn't support scrollTop position on document.documentElement.
|
|
49
|
+
// For cross browser compatibility, looking up pageYOffset on window if the scroll is on document.
|
|
50
|
+
// And, if for some reason that is not available, fall back to looking up scrollTop on document.documentElement.
|
|
51
|
+
let x = element === de && "pageXOffset" in w ? Math.round(w.pageXOffset) : Math.round((element as HTMLElement).scrollLeft);
|
|
52
|
+
let y = element === de && "pageYOffset" in w ? Math.round(w.pageYOffset) : Math.round((element as HTMLElement).scrollTop);
|
|
53
|
+
const width = window.innerWidth;
|
|
54
|
+
const height = window.innerHeight;
|
|
55
|
+
const xPosition = width / 3;
|
|
56
|
+
const yOffset = width > height ? height * 0.15 : height * 0.2;
|
|
57
|
+
const startYPosition = yOffset;
|
|
58
|
+
const endYPosition = height - yOffset;
|
|
59
|
+
const top = getPositionNode(xPosition, startYPosition);
|
|
60
|
+
const bottom = getPositionNode(xPosition, endYPosition);
|
|
61
|
+
const trust = event && event.isTrusted ? BooleanFlag.True : BooleanFlag.False;
|
|
62
|
+
if (event && event.isTrusted && trustedCallback) { trustedCallback(); }
|
|
63
|
+
|
|
64
|
+
let current: ScrollState = { time: time(event), event: Event.Scroll, data: {target: element, x, y, top, bottom, trust} };
|
|
65
|
+
|
|
66
|
+
// We don't send any scroll events if this is the first event and the current position is top (0,0)
|
|
67
|
+
if ((event === null && x === 0 && y === 0) || (x === null || y === null)) {
|
|
68
|
+
initialTop = top;
|
|
69
|
+
initialBottom = bottom;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let length = state.length;
|
|
74
|
+
let last = length > 1 ? state[length - 2] : null;
|
|
75
|
+
if (last && similar(last, current)) { state.pop(); }
|
|
76
|
+
state.push(current);
|
|
77
|
+
|
|
78
|
+
clearTimeout(timeout);
|
|
79
|
+
timeout = setTimeout(process, Setting.LookAhead, Event.Scroll);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const throttledRecompute = throttle(recompute, Setting.Throttle);
|
|
83
|
+
|
|
84
|
+
function getPositionNode(x: number, y: number): Node {
|
|
85
|
+
let node: Node;
|
|
86
|
+
if ("caretPositionFromPoint" in document) {
|
|
87
|
+
node = (document as any).caretPositionFromPoint(x, y)?.offsetNode;
|
|
88
|
+
} else if ("caretRangeFromPoint" in document) {
|
|
89
|
+
node = (document as any).caretRangeFromPoint(x, y)?.startContainer;
|
|
90
|
+
}
|
|
91
|
+
if (!node) {
|
|
92
|
+
node = document.elementFromPoint(x, y) as Node;
|
|
93
|
+
}
|
|
94
|
+
if (node && node.nodeType === Node.TEXT_NODE) {
|
|
95
|
+
node = node.parentNode;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return node;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function reset(): void {
|
|
102
|
+
state = [];
|
|
103
|
+
initialTop = null;
|
|
104
|
+
initialBottom = null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function process(event: Event): void {
|
|
108
|
+
schedule(encode.bind(this, event));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function similar(last: ScrollState, current: ScrollState): boolean {
|
|
112
|
+
let dx = last.data.x - current.data.x;
|
|
113
|
+
let dy = last.data.y - current.data.y;
|
|
114
|
+
return (dx * dx + dy * dy < Setting.Distance * Setting.Distance) && (current.time - last.time < Setting.ScrollInterval);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function compute(): void {
|
|
118
|
+
if (initialTop) {
|
|
119
|
+
const top = metadata(initialTop, null);
|
|
120
|
+
dimension.log(Dimension.InitialScrollTop, top?.hash?.join(Constant.Dot));
|
|
121
|
+
}
|
|
122
|
+
if (initialBottom) {
|
|
123
|
+
const bottom = metadata(initialBottom, null);
|
|
124
|
+
dimension.log(Dimension.InitialScrollBottom, bottom?.hash?.join(Constant.Dot));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function stop(): void {
|
|
129
|
+
clearTimeout(timeout);
|
|
130
|
+
throttledRecompute.cleanup();
|
|
131
|
+
state = [];
|
|
132
|
+
initialTop = null;
|
|
133
|
+
initialBottom = null;
|
|
134
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Event } from "@clarity-types/data";
|
|
2
|
+
import { SelectionData, Setting } from "@clarity-types/interaction";
|
|
3
|
+
import { bind } from "@src/core/event";
|
|
4
|
+
import { schedule } from "@src/core/task";
|
|
5
|
+
import { clearTimeout, setTimeout } from "@src/core/timeout";
|
|
6
|
+
import encode from "./encode";
|
|
7
|
+
|
|
8
|
+
export let data: SelectionData = null;
|
|
9
|
+
let previous: Selection = null;
|
|
10
|
+
let timeout: number = null;
|
|
11
|
+
|
|
12
|
+
export function start(): void {
|
|
13
|
+
reset();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function observe(root: Node): void {
|
|
17
|
+
bind(root, "selectstart", recompute.bind(this, root), true);
|
|
18
|
+
bind(root, "selectionchange", recompute.bind(this, root), true);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function recompute(root: Node): void {
|
|
22
|
+
let doc = root.nodeType === Node.DOCUMENT_NODE ? root as Document : document;
|
|
23
|
+
let current = doc.getSelection();
|
|
24
|
+
|
|
25
|
+
// Bail out if we don't have a valid selection
|
|
26
|
+
if (current === null) { return; }
|
|
27
|
+
|
|
28
|
+
// Bail out if we got a valid selection but not valid nodes
|
|
29
|
+
// In Edge, selectionchange gets fired even on interactions like right clicks and
|
|
30
|
+
// can result in null anchorNode and focusNode if there was no previous selection on page
|
|
31
|
+
// Also, ignore any selections that start and end at the exact same point
|
|
32
|
+
if ((current.anchorNode === null && current.focusNode === null) ||
|
|
33
|
+
(current.anchorNode === current.focusNode && current.anchorOffset === current.focusOffset)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
let startNode = data.start ? data.start : null;
|
|
37
|
+
if (previous !== null && data.start !== null && startNode !== current.anchorNode) {
|
|
38
|
+
clearTimeout(timeout);
|
|
39
|
+
process(Event.Selection);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
data = {
|
|
43
|
+
start: current.anchorNode,
|
|
44
|
+
startOffset: current.anchorOffset,
|
|
45
|
+
end: current.focusNode,
|
|
46
|
+
endOffset: current.focusOffset
|
|
47
|
+
};
|
|
48
|
+
previous = current;
|
|
49
|
+
|
|
50
|
+
clearTimeout(timeout);
|
|
51
|
+
timeout = setTimeout(process, Setting.LookAhead, Event.Selection);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function process(event: Event): void {
|
|
55
|
+
schedule(encode.bind(this, event));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function reset(): void {
|
|
59
|
+
previous = null;
|
|
60
|
+
data = { start: 0, startOffset: 0, end: 0, endOffset: 0 };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function stop(): void {
|
|
64
|
+
reset();
|
|
65
|
+
clearTimeout(timeout);
|
|
66
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Event } from "@clarity-types/data";
|
|
2
|
+
import { SubmitState } from "@clarity-types/interaction";
|
|
3
|
+
import { bind } from "@src/core/event";
|
|
4
|
+
import { schedule } from "@src/core/task";
|
|
5
|
+
import { time } from "@src/core/time";
|
|
6
|
+
import encode from "./encode";
|
|
7
|
+
import { target } from "@src/layout/target";
|
|
8
|
+
|
|
9
|
+
export let state: SubmitState[] = [];
|
|
10
|
+
|
|
11
|
+
export function start(): void {
|
|
12
|
+
reset();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function observe(root: Node): void {
|
|
16
|
+
bind(root, "submit", recompute, true);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function recompute(evt: UIEvent): void {
|
|
20
|
+
state.push({ time: time(evt), event: Event.Submit, data: { target: target(evt) } });
|
|
21
|
+
schedule(encode.bind(this, Event.Submit));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function reset(): void {
|
|
25
|
+
state = [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function stop(): void {
|
|
29
|
+
reset();
|
|
30
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BooleanFlag, Event } from "@clarity-types/data";
|
|
2
|
+
import { BrowsingContext, Setting, TimelineState } from "@clarity-types/interaction";
|
|
3
|
+
import * as baseline from "@src/data/baseline";
|
|
4
|
+
import * as envelope from "@src/data/envelope";
|
|
5
|
+
import encode from "@src/interaction/encode";
|
|
6
|
+
|
|
7
|
+
let state: TimelineState[] = [];
|
|
8
|
+
export let updates: TimelineState[] = [];
|
|
9
|
+
|
|
10
|
+
export function start(): void {
|
|
11
|
+
state = [];
|
|
12
|
+
reset();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function reset(): void {
|
|
16
|
+
updates = [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function track(time: number,
|
|
20
|
+
event: Event,
|
|
21
|
+
hash: string,
|
|
22
|
+
x: number,
|
|
23
|
+
y: number,
|
|
24
|
+
reaction: number = BooleanFlag.True,
|
|
25
|
+
context: number = BrowsingContext.Self): void {
|
|
26
|
+
state.push({
|
|
27
|
+
time,
|
|
28
|
+
event: Event.Timeline,
|
|
29
|
+
data: {
|
|
30
|
+
type: event,
|
|
31
|
+
hash,
|
|
32
|
+
x,
|
|
33
|
+
y,
|
|
34
|
+
reaction,
|
|
35
|
+
context
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Since timeline only keeps the data for configured time, we still want to continue tracking these values
|
|
40
|
+
// as part of the baseline. For instance, in a scenario where last scroll happened 5s ago.
|
|
41
|
+
// We would still need to capture the last scroll position as part of the baseline event, even when timeline will be empty.
|
|
42
|
+
baseline.track(event, x, y, time);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function compute(): void {
|
|
46
|
+
if (!envelope.data) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const temp = [];
|
|
51
|
+
updates = [];
|
|
52
|
+
let max = (envelope.data.start || 0) + (envelope.data.duration || 0);
|
|
53
|
+
let min = Math.max(max - Setting.TimelineSpan, 0);
|
|
54
|
+
|
|
55
|
+
for (let s of state) {
|
|
56
|
+
if (s.time >= min) {
|
|
57
|
+
if (s.time <= max) { updates.push(s); }
|
|
58
|
+
temp.push(s);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
state = temp; // Drop events less than the min time
|
|
63
|
+
encode(Event.Timeline);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function stop(): void {
|
|
67
|
+
state = [];
|
|
68
|
+
reset();
|
|
69
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BooleanFlag, Event } from "@clarity-types/data";
|
|
2
|
+
import { UnloadData } from "@clarity-types/interaction";
|
|
3
|
+
import * as clarity from "@src/clarity";
|
|
4
|
+
import { bind } from "@src/core/event";
|
|
5
|
+
import { time } from "@src/core/time";
|
|
6
|
+
import encode from "./encode";
|
|
7
|
+
import * as upload from "@src/data/upload";
|
|
8
|
+
|
|
9
|
+
export let data: UnloadData;
|
|
10
|
+
|
|
11
|
+
export function start(): void {
|
|
12
|
+
bind(window, "pagehide", recompute);
|
|
13
|
+
bind(window, "beforeunload", beforeUnload);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function beforeUnload(): void {
|
|
17
|
+
upload.flush('gemx-unload');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function recompute(evt: PageTransitionEvent): void {
|
|
21
|
+
data = { name: evt.type, persisted: evt.persisted ? BooleanFlag.True : BooleanFlag.False };
|
|
22
|
+
encode(Event.Unload, time(evt));
|
|
23
|
+
clarity.stop();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function reset(): void {
|
|
27
|
+
data = null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function stop(): void {
|
|
31
|
+
reset();
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BooleanFlag, Event } from "@clarity-types/data";
|
|
2
|
+
import { VisibilityData } from "@clarity-types/interaction";
|
|
3
|
+
import { bind } from "@src/core/event";
|
|
4
|
+
import { time } from "@src/core/time";
|
|
5
|
+
import encode from "./encode";
|
|
6
|
+
|
|
7
|
+
export let data: VisibilityData;
|
|
8
|
+
|
|
9
|
+
export function start(): void {
|
|
10
|
+
bind(document, "visibilitychange", recompute);
|
|
11
|
+
recompute();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function recompute(evt: UIEvent = null): void {
|
|
15
|
+
if ("visibilityState" in document) {
|
|
16
|
+
const visible = document.visibilityState === "visible" ? BooleanFlag.True : BooleanFlag.False;
|
|
17
|
+
data = { visible };
|
|
18
|
+
encode(Event.Visibility, time(evt));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function reset(): void {
|
|
23
|
+
data = null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function stop(): void {
|
|
27
|
+
reset();
|
|
28
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Event } from "@clarity-types/data";
|
|
2
|
+
import { AnimationOperation, AnimationState } from "@clarity-types/layout";
|
|
3
|
+
import { time } from "@src/core/time";
|
|
4
|
+
import { shortid } from "@src/data/metadata";
|
|
5
|
+
import encode from "@src/layout/encode";
|
|
6
|
+
import { getId } from "@src/layout/dom";
|
|
7
|
+
import * as core from "@src/core";
|
|
8
|
+
|
|
9
|
+
export let state: AnimationState[] = [];
|
|
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';
|
|
18
|
+
const maxOperations = 20;
|
|
19
|
+
|
|
20
|
+
export function start(): void {
|
|
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
|
|
28
|
+
) {
|
|
29
|
+
reset();
|
|
30
|
+
overrideAnimationHelper(animationPlay, "play");
|
|
31
|
+
overrideAnimationHelper(animationPause, "pause");
|
|
32
|
+
overrideAnimationHelper(animationCommitStyles, "commitStyles");
|
|
33
|
+
overrideAnimationHelper(animationCancel, "cancel");
|
|
34
|
+
overrideAnimationHelper(animationFinish, "finish");
|
|
35
|
+
if (elementAnimate === null) {
|
|
36
|
+
elementAnimate = Element.prototype.animate;
|
|
37
|
+
Element.prototype.animate = function(): Animation {
|
|
38
|
+
var createdAnimation = elementAnimate.apply(this, arguments);
|
|
39
|
+
trackAnimationOperation(createdAnimation, "play");
|
|
40
|
+
return createdAnimation;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (document.getAnimations) {
|
|
44
|
+
for (var animation of document.getAnimations()) {
|
|
45
|
+
if (animation.playState === "finished") {
|
|
46
|
+
trackAnimationOperation(animation, "finish");
|
|
47
|
+
}
|
|
48
|
+
else if (animation.playState === "paused" || animation.playState === "idle") {
|
|
49
|
+
trackAnimationOperation(animation, "pause");
|
|
50
|
+
}
|
|
51
|
+
else if (animation.playState === "running") {
|
|
52
|
+
trackAnimationOperation(animation, "play");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function reset(): void {
|
|
60
|
+
state = [];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function track(time: number, id: string, operation: AnimationOperation, keyFrames?: string, timing?: string, targetId?: number, timeline?: string): void {
|
|
64
|
+
state.push({
|
|
65
|
+
time,
|
|
66
|
+
event: Event.Animation,
|
|
67
|
+
data: {
|
|
68
|
+
id,
|
|
69
|
+
operation,
|
|
70
|
+
keyFrames,
|
|
71
|
+
timing,
|
|
72
|
+
targetId,
|
|
73
|
+
timeline
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
encode(Event.Animation);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function stop(): void {
|
|
81
|
+
reset();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function overrideAnimationHelper(functionToOverride: () => void, name: string) {
|
|
85
|
+
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
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function trackAnimationOperation(animation: Animation, name: string) {
|
|
95
|
+
if (core.active()) {
|
|
96
|
+
let effect = <KeyframeEffect>animation.effect;
|
|
97
|
+
let target = effect?.target ? getId(effect.target) : null;
|
|
98
|
+
if (target !== null && effect.getKeyframes && effect.getTiming) {
|
|
99
|
+
if (!animation[animationId]) {
|
|
100
|
+
animation[animationId] = shortid();
|
|
101
|
+
animation[operationCount] = 0;
|
|
102
|
+
|
|
103
|
+
let keyframes = effect.getKeyframes();
|
|
104
|
+
let timing = effect.getTiming();
|
|
105
|
+
track(time(), animation[animationId], AnimationOperation.Create, JSON.stringify(keyframes), JSON.stringify(timing), target);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (animation[operationCount]++ < maxOperations) {
|
|
109
|
+
let operation: AnimationOperation = null;
|
|
110
|
+
switch (name) {
|
|
111
|
+
case "play":
|
|
112
|
+
operation = AnimationOperation.Play;
|
|
113
|
+
break;
|
|
114
|
+
case "pause":
|
|
115
|
+
operation = AnimationOperation.Pause;
|
|
116
|
+
break;
|
|
117
|
+
case "cancel":
|
|
118
|
+
operation = AnimationOperation.Cancel;
|
|
119
|
+
break;
|
|
120
|
+
case "finish":
|
|
121
|
+
operation = AnimationOperation.Finish;
|
|
122
|
+
break;
|
|
123
|
+
case "commitStyles":
|
|
124
|
+
operation = AnimationOperation.CommitStyles;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
if (operation) {
|
|
128
|
+
track(time(), animation[animationId], operation);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-computed arrays for better minification and performance
|
|
3
|
+
* These replace comma-separated strings that were previously split at runtime
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Pre-computed mask arrays (replaces Mask.Text.split(), etc.)
|
|
7
|
+
export const MaskTextList = ["address", "password", "contact"];
|
|
8
|
+
export const MaskDisableList = ["radio", "checkbox", "range", "button", "reset", "submit"];
|
|
9
|
+
export const MaskExcludeList = ["password", "secret", "pass", "social", "ssn", "code", "hidden"];
|
|
10
|
+
export const MaskTagsList = ["INPUT", "SELECT", "TEXTAREA"];
|
|
11
|
+
|
|
12
|
+
// Pre-computed exclude class names (replaces Constant.ExcludeClassNames.split())
|
|
13
|
+
export const ExcludeClassNamesList = ["load", "active", "fixed", "visible", "focus", "show", "collaps", "animat"];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Event } from "@clarity-types/data";
|
|
2
|
+
import { active } from "@src/core";
|
|
3
|
+
import { schedule } from "@src/core/task";
|
|
4
|
+
import encode from "@src/layout/encode";
|
|
5
|
+
|
|
6
|
+
export const elements: string[] = [];
|
|
7
|
+
|
|
8
|
+
const definedElements = new Set<string>();
|
|
9
|
+
function register(tag: string) {
|
|
10
|
+
if (!definedElements.has(tag)) {
|
|
11
|
+
definedElements.add(tag);
|
|
12
|
+
elements.push(tag);
|
|
13
|
+
schedule(encode.bind(this, Event.CustomElement));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function check(tag: string) {
|
|
18
|
+
if (window.customElements?.get && window.customElements.get(tag)) {
|
|
19
|
+
register(tag);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function start() {
|
|
24
|
+
// Wrap in try-catch to handle Safari iOS where window properties or customElements.define may be readonly
|
|
25
|
+
try {
|
|
26
|
+
window.clarityOverrides = window.clarityOverrides || {};
|
|
27
|
+
if (window.customElements?.define && !window.clarityOverrides.define) {
|
|
28
|
+
window.clarityOverrides.define = window.customElements.define;
|
|
29
|
+
window.customElements.define = function () {
|
|
30
|
+
if (active()) {
|
|
31
|
+
register(arguments[0]);
|
|
32
|
+
}
|
|
33
|
+
return window.clarityOverrides.define.apply(this, arguments);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
// customElements.define or window properties are readonly in this environment (e.g., Safari iOS WKWebView)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function reset() {
|
|
42
|
+
elements.length = 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function stop() {
|
|
46
|
+
reset();
|
|
47
|
+
definedElements.clear();
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Priority, Timer } from "@clarity-types/core";
|
|
2
|
+
import { Event, Metric } from "@clarity-types/data";
|
|
3
|
+
import { Source } from "@clarity-types/layout";
|
|
4
|
+
import measure from "@src/core/measure";
|
|
5
|
+
import * as task from "@src/core/task";
|
|
6
|
+
import { time } from "@src/core/time";
|
|
7
|
+
import { id } from "@src/data/metadata";
|
|
8
|
+
import * as doc from "@src/layout/document";
|
|
9
|
+
import encode from "@src/layout/encode";
|
|
10
|
+
import * as region from "@src/layout/region";
|
|
11
|
+
import traverse from "@src/layout/traverse";
|
|
12
|
+
import { checkDocumentStyles } from "@src/layout/style";
|
|
13
|
+
import * as scroll from "@src/interaction/scroll";
|
|
14
|
+
|
|
15
|
+
export function start(): void {
|
|
16
|
+
task.schedule(discover, Priority.High).then((): void => {
|
|
17
|
+
measure(doc.compute)();
|
|
18
|
+
measure(region.compute)();
|
|
19
|
+
measure(scroll.compute)();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function discover(): Promise<void> {
|
|
24
|
+
let ts = time();
|
|
25
|
+
let timer: Timer = { id: id(), cost: Metric.LayoutCost };
|
|
26
|
+
task.start(timer);
|
|
27
|
+
await traverse(document, timer, Source.Discover, ts);
|
|
28
|
+
checkDocumentStyles(document, ts);
|
|
29
|
+
await encode(Event.Discover, timer, ts);
|
|
30
|
+
task.stop(timer);
|
|
31
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Event } from "@clarity-types/data";
|
|
2
|
+
import { DocumentData } from "@clarity-types/layout";
|
|
3
|
+
import encode from "@src/layout/encode";
|
|
4
|
+
|
|
5
|
+
export let data: DocumentData;
|
|
6
|
+
|
|
7
|
+
export function reset(): void {
|
|
8
|
+
data = null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function start(): void {
|
|
12
|
+
reset();
|
|
13
|
+
compute();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function compute(): void {
|
|
17
|
+
let body = document.body;
|
|
18
|
+
let d = document.documentElement;
|
|
19
|
+
let bodyClientWidth = body ? body.clientWidth : null;
|
|
20
|
+
let bodyScrollWidth = body ? body.scrollWidth : null;
|
|
21
|
+
let bodyOffsetWidth = body ? body.offsetWidth : null;
|
|
22
|
+
let documentClientWidth = d ? d.clientWidth : null;
|
|
23
|
+
let documentScrollWidth = d ? d.scrollWidth : null;
|
|
24
|
+
let documentOffsetWidth = d ? d.offsetWidth : null;
|
|
25
|
+
let width = Math.max(bodyClientWidth, bodyScrollWidth, bodyOffsetWidth,
|
|
26
|
+
documentClientWidth, documentScrollWidth, documentOffsetWidth);
|
|
27
|
+
|
|
28
|
+
let bodyClientHeight = body ? body.clientHeight : null;
|
|
29
|
+
let bodyScrollHeight = body ? body.scrollHeight : null;
|
|
30
|
+
let bodyOffsetHeight = body ? body.offsetHeight : null;
|
|
31
|
+
let documentClientHeight = d ? d.clientHeight : null;
|
|
32
|
+
let documentScrollHeight = d ? d.scrollHeight : null;
|
|
33
|
+
let documentOffsetHeight = d ? d.offsetHeight : null;
|
|
34
|
+
let height = Math.max(bodyClientHeight, bodyScrollHeight, bodyOffsetHeight,
|
|
35
|
+
documentClientHeight, documentScrollHeight, documentOffsetHeight);
|
|
36
|
+
|
|
37
|
+
// Check that width or height has changed from before, and also that width & height are not null values
|
|
38
|
+
if ((data === null || width !== data.width || height !== data.height) && width !== null && height !== null) {
|
|
39
|
+
data = { width, height };
|
|
40
|
+
encode(Event.Document);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function stop(): void {
|
|
45
|
+
reset();
|
|
46
|
+
}
|