clarity-js 0.8.1 → 0.8.2

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 (102) hide show
  1. package/README.md +26 -26
  2. package/build/clarity.extended.js +1 -1
  3. package/build/clarity.insight.js +1 -1
  4. package/build/clarity.js +5537 -5537
  5. package/build/clarity.min.js +1 -1
  6. package/build/clarity.module.js +5537 -5537
  7. package/build/clarity.performance.js +1 -1
  8. package/package.json +70 -70
  9. package/rollup.config.ts +98 -98
  10. package/src/clarity.ts +60 -60
  11. package/src/core/api.ts +8 -8
  12. package/src/core/config.ts +32 -32
  13. package/src/core/copy.ts +3 -3
  14. package/src/core/event.ts +53 -53
  15. package/src/core/hash.ts +19 -19
  16. package/src/core/history.ts +73 -73
  17. package/src/core/index.ts +83 -83
  18. package/src/core/measure.ts +19 -19
  19. package/src/core/report.ts +28 -28
  20. package/src/core/scrub.ts +196 -196
  21. package/src/core/task.ts +180 -180
  22. package/src/core/time.ts +19 -19
  23. package/src/core/timeout.ts +10 -10
  24. package/src/core/version.ts +2 -2
  25. package/src/data/baseline.ts +155 -155
  26. package/src/data/compress.ts +31 -31
  27. package/src/data/consent.ts +20 -20
  28. package/src/data/custom.ts +23 -23
  29. package/src/data/dimension.ts +53 -53
  30. package/src/data/encode.ts +140 -140
  31. package/src/data/envelope.ts +53 -53
  32. package/src/data/extract.ts +211 -211
  33. package/src/data/index.ts +46 -46
  34. package/src/data/limit.ts +44 -44
  35. package/src/data/metadata.ts +356 -356
  36. package/src/data/metric.ts +51 -51
  37. package/src/data/ping.ts +36 -36
  38. package/src/data/signal.ts +30 -30
  39. package/src/data/summary.ts +34 -34
  40. package/src/data/token.ts +39 -39
  41. package/src/data/upgrade.ts +37 -37
  42. package/src/data/upload.ts +283 -283
  43. package/src/data/variable.ts +83 -83
  44. package/src/diagnostic/encode.ts +40 -40
  45. package/src/diagnostic/fraud.ts +36 -36
  46. package/src/diagnostic/index.ts +15 -15
  47. package/src/diagnostic/internal.ts +28 -28
  48. package/src/diagnostic/script.ts +37 -37
  49. package/src/global.ts +6 -6
  50. package/src/index.ts +9 -9
  51. package/src/insight/blank.ts +14 -14
  52. package/src/insight/encode.ts +60 -60
  53. package/src/insight/snapshot.ts +114 -114
  54. package/src/interaction/change.ts +40 -40
  55. package/src/interaction/click.ts +162 -162
  56. package/src/interaction/clipboard.ts +34 -34
  57. package/src/interaction/encode.ts +193 -193
  58. package/src/interaction/index.ts +59 -59
  59. package/src/interaction/input.ts +59 -59
  60. package/src/interaction/pointer.ts +139 -139
  61. package/src/interaction/resize.ts +47 -47
  62. package/src/interaction/scroll.ts +124 -124
  63. package/src/interaction/selection.ts +68 -68
  64. package/src/interaction/submit.ts +32 -32
  65. package/src/interaction/timeline.ts +65 -65
  66. package/src/interaction/unload.ts +28 -28
  67. package/src/interaction/visibility.ts +26 -26
  68. package/src/layout/animation.ts +133 -133
  69. package/src/layout/discover.ts +31 -31
  70. package/src/layout/document.ts +48 -48
  71. package/src/layout/dom.ts +437 -437
  72. package/src/layout/encode.ts +147 -147
  73. package/src/layout/index.ts +41 -41
  74. package/src/layout/mutation.ts +409 -409
  75. package/src/layout/node.ts +292 -292
  76. package/src/layout/offset.ts +19 -19
  77. package/src/layout/region.ts +153 -153
  78. package/src/layout/schema.ts +63 -63
  79. package/src/layout/selector.ts +82 -82
  80. package/src/layout/style.ts +150 -150
  81. package/src/layout/target.ts +32 -32
  82. package/src/layout/traverse.ts +27 -27
  83. package/src/performance/blank.ts +7 -7
  84. package/src/performance/encode.ts +31 -31
  85. package/src/performance/index.ts +14 -14
  86. package/src/performance/interaction.ts +125 -125
  87. package/src/performance/navigation.ts +31 -31
  88. package/src/performance/observer.ts +108 -108
  89. package/src/queue.ts +33 -33
  90. package/test/core.test.ts +139 -139
  91. package/test/helper.ts +162 -162
  92. package/test/html/core.html +27 -27
  93. package/test/tsconfig.test.json +5 -5
  94. package/tsconfig.json +21 -21
  95. package/tslint.json +32 -32
  96. package/types/core.d.ts +153 -153
  97. package/types/data.d.ts +510 -510
  98. package/types/diagnostic.d.ts +24 -24
  99. package/types/index.d.ts +39 -39
  100. package/types/interaction.d.ts +165 -165
  101. package/types/layout.d.ts +272 -272
  102. package/types/performance.d.ts +64 -64
@@ -1,51 +1,51 @@
1
- import { Event, Metric, MetricData } from "@clarity-types/data";
2
- import encode from "./encode";
3
-
4
- export let data: MetricData = null;
5
- export let updates: MetricData = null;
6
-
7
- export function start(): void {
8
- data = {};
9
- updates = {};
10
- count(Metric.InvokeCount);
11
- }
12
-
13
- export function stop(): void {
14
- data = {};
15
- updates = {};
16
- }
17
-
18
- export function count(metric: Metric): void {
19
- if (!(metric in data)) { data[metric] = 0; }
20
- if (!(metric in updates)) { updates[metric] = 0; }
21
- data[metric]++;
22
- updates[metric]++;
23
- }
24
-
25
- export function sum(metric: Metric, value: number): void {
26
- if (value !== null) {
27
- if (!(metric in data)) { data[metric] = 0; }
28
- if (!(metric in updates)) { updates[metric] = 0; }
29
- data[metric] += value;
30
- updates[metric] += value;
31
- }
32
- }
33
-
34
- export function max(metric: Metric, value: number): void {
35
- // Ensure that we do not process null or NaN values
36
- if (value !== null && isNaN(value) === false) {
37
- if (!(metric in data)) { data[metric] = 0; }
38
- if (value > data[metric] || data[metric] === 0) {
39
- updates[metric] = value;
40
- data[metric] = value;
41
- }
42
- }
43
- }
44
-
45
- export function compute(): void {
46
- encode(Event.Metric);
47
- }
48
-
49
- export function reset(): void {
50
- updates = {};
51
- }
1
+ import { Event, Metric, MetricData } from "@clarity-types/data";
2
+ import encode from "./encode";
3
+
4
+ export let data: MetricData = null;
5
+ export let updates: MetricData = null;
6
+
7
+ export function start(): void {
8
+ data = {};
9
+ updates = {};
10
+ count(Metric.InvokeCount);
11
+ }
12
+
13
+ export function stop(): void {
14
+ data = {};
15
+ updates = {};
16
+ }
17
+
18
+ export function count(metric: Metric): void {
19
+ if (!(metric in data)) { data[metric] = 0; }
20
+ if (!(metric in updates)) { updates[metric] = 0; }
21
+ data[metric]++;
22
+ updates[metric]++;
23
+ }
24
+
25
+ export function sum(metric: Metric, value: number): void {
26
+ if (value !== null) {
27
+ if (!(metric in data)) { data[metric] = 0; }
28
+ if (!(metric in updates)) { updates[metric] = 0; }
29
+ data[metric] += value;
30
+ updates[metric] += value;
31
+ }
32
+ }
33
+
34
+ export function max(metric: Metric, value: number): void {
35
+ // Ensure that we do not process null or NaN values
36
+ if (value !== null && isNaN(value) === false) {
37
+ if (!(metric in data)) { data[metric] = 0; }
38
+ if (value > data[metric] || data[metric] === 0) {
39
+ updates[metric] = value;
40
+ data[metric] = value;
41
+ }
42
+ }
43
+ }
44
+
45
+ export function compute(): void {
46
+ encode(Event.Metric);
47
+ }
48
+
49
+ export function reset(): void {
50
+ updates = {};
51
+ }
package/src/data/ping.ts CHANGED
@@ -1,36 +1,36 @@
1
- import { Event, PingData, Setting } from "@clarity-types/data";
2
- import { suspend } from "@src/core";
3
- import { time } from "@src/core/time";
4
- import { clearTimeout, setTimeout } from "@src/core/timeout";
5
- import encode from "./encode";
6
-
7
- export let data: PingData;
8
- let last = 0;
9
- let interval = 0;
10
- let timeout: number = null;
11
-
12
- export function start(): void {
13
- interval = Setting.PingInterval;
14
- last = 0;
15
- }
16
-
17
- export function reset(): void {
18
- if (timeout) { clearTimeout(timeout); }
19
- timeout = setTimeout(ping, interval);
20
- last = time();
21
- }
22
-
23
- function ping(): void {
24
- let now = time();
25
- data = { gap: now - last };
26
- encode(Event.Ping);
27
- if (data.gap < Setting.PingTimeout) {
28
- timeout = setTimeout(ping, interval);
29
- } else { suspend(); }
30
- }
31
-
32
- export function stop(): void {
33
- clearTimeout(timeout);
34
- last = 0;
35
- interval = 0;
36
- }
1
+ import { Event, PingData, Setting } from "@clarity-types/data";
2
+ import { suspend } from "@src/core";
3
+ import { time } from "@src/core/time";
4
+ import { clearTimeout, setTimeout } from "@src/core/timeout";
5
+ import encode from "./encode";
6
+
7
+ export let data: PingData;
8
+ let last = 0;
9
+ let interval = 0;
10
+ let timeout: number = null;
11
+
12
+ export function start(): void {
13
+ interval = Setting.PingInterval;
14
+ last = 0;
15
+ }
16
+
17
+ export function reset(): void {
18
+ if (timeout) { clearTimeout(timeout); }
19
+ timeout = setTimeout(ping, interval);
20
+ last = time();
21
+ }
22
+
23
+ function ping(): void {
24
+ let now = time();
25
+ data = { gap: now - last };
26
+ encode(Event.Ping);
27
+ if (data.gap < Setting.PingTimeout) {
28
+ timeout = setTimeout(ping, interval);
29
+ } else { suspend(); }
30
+ }
31
+
32
+ export function stop(): void {
33
+ clearTimeout(timeout);
34
+ last = 0;
35
+ interval = 0;
36
+ }
@@ -1,30 +1,30 @@
1
- import { ClaritySignal, SignalCallback } from '@clarity-types/data';
2
-
3
- export let signalCallback: SignalCallback = null;
4
-
5
- export function signal(cb: SignalCallback): void {
6
- signalCallback = cb;
7
- }
8
-
9
- function parseSignals(signalsPayload: string): ClaritySignal[] {
10
- try{
11
- const parsedSignals: ClaritySignal[] = JSON.parse(signalsPayload);
12
- return parsedSignals;
13
- }catch{
14
- return []
15
- }
16
- }
17
-
18
- export function signalsEvent(signalsPayload: string) {
19
- try {
20
- if (!signalCallback) {
21
- return;
22
- }
23
- const signals = parseSignals(signalsPayload);
24
- signals.forEach((signal) => {
25
- signalCallback(signal);
26
- });
27
- } catch {
28
- //do nothing
29
- }
30
- }
1
+ import { ClaritySignal, SignalCallback } from '@clarity-types/data';
2
+
3
+ export let signalCallback: SignalCallback = null;
4
+
5
+ export function signal(cb: SignalCallback): void {
6
+ signalCallback = cb;
7
+ }
8
+
9
+ function parseSignals(signalsPayload: string): ClaritySignal[] {
10
+ try{
11
+ const parsedSignals: ClaritySignal[] = JSON.parse(signalsPayload);
12
+ return parsedSignals;
13
+ }catch{
14
+ return []
15
+ }
16
+ }
17
+
18
+ export function signalsEvent(signalsPayload: string) {
19
+ try {
20
+ if (!signalCallback) {
21
+ return;
22
+ }
23
+ const signals = parseSignals(signalsPayload);
24
+ signals.forEach((signal) => {
25
+ signalCallback(signal);
26
+ });
27
+ } catch {
28
+ //do nothing
29
+ }
30
+ }
@@ -1,34 +1,34 @@
1
- import { Event, SummaryData, Setting } from "@clarity-types/data";
2
- import encode from "./encode";
3
-
4
- export let data: SummaryData = null;
5
-
6
- export function start(): void {
7
- data = {};
8
- }
9
-
10
- export function stop(): void {
11
- data = {};
12
- }
13
-
14
- export function track(event: Event, time: number): void {
15
- if (!(event in data)) {
16
- data[event] = [[time, 0]];
17
- } else {
18
- let e = data[event];
19
- let last = e[e.length - 1];
20
- // Add a new entry only if the new event occurs after configured interval
21
- // Otherwise, extend the duration of the previous entry
22
- if (time - last[0] > Setting.SummaryInterval) {
23
- data[event].push([time, 0]);
24
- } else { last[1] = time - last[0]; }
25
- }
26
- }
27
-
28
- export function compute(): void {
29
- encode(Event.Summary);
30
- }
31
-
32
- export function reset(): void {
33
- data = {};
34
- }
1
+ import { Event, SummaryData, Setting } from "@clarity-types/data";
2
+ import encode from "./encode";
3
+
4
+ export let data: SummaryData = null;
5
+
6
+ export function start(): void {
7
+ data = {};
8
+ }
9
+
10
+ export function stop(): void {
11
+ data = {};
12
+ }
13
+
14
+ export function track(event: Event, time: number): void {
15
+ if (!(event in data)) {
16
+ data[event] = [[time, 0]];
17
+ } else {
18
+ let e = data[event];
19
+ let last = e[e.length - 1];
20
+ // Add a new entry only if the new event occurs after configured interval
21
+ // Otherwise, extend the duration of the previous entry
22
+ if (time - last[0] > Setting.SummaryInterval) {
23
+ data[event].push([time, 0]);
24
+ } else { last[1] = time - last[0]; }
25
+ }
26
+ }
27
+
28
+ export function compute(): void {
29
+ encode(Event.Summary);
30
+ }
31
+
32
+ export function reset(): void {
33
+ data = {};
34
+ }
package/src/data/token.ts CHANGED
@@ -1,39 +1,39 @@
1
- import {Constant, Token} from "@clarity-types/data";
2
-
3
- // Following code takes an array of tokens and transforms it to optimize for repeating tokens and make it efficient to send over the wire
4
- // The way it works is that it iterate over all tokens and checks if the current token was already seen in the tokens array so far
5
- // If so, it replaces the token with its reference (index). This helps us save bytes by not repeating the same value twice.
6
- // E.g. If tokens array is: ["hello", "world", "coding", "language", "world", "language", "example"]
7
- // Then the resulting tokens array after following code execution would be: ["hello", "world", "coding", "language", [1, 3], "example"]
8
- // Where [1,3] points to tokens[1] => "world" and tokens[3] => "language"
9
- export default function(tokens: Token[]): Token[] {
10
- let output: Token[] = [];
11
- let lookup: {[key: string]: number} = {};
12
- let pointer = 0;
13
- let reference = null;
14
- for (let i = 0; i < tokens.length; i++) {
15
- // Only optimize for string values
16
- if (typeof tokens[i] === Constant.String) {
17
- let token = tokens[i] as string;
18
- let index = lookup[token] || -1;
19
- if (index >= 0) {
20
- if (reference) { reference.push(index); } else {
21
- reference = [index];
22
- output.push(reference);
23
- pointer++;
24
- }
25
- } else {
26
- reference = null;
27
- output.push(token);
28
- lookup[token] = pointer++;
29
- }
30
- } else {
31
- // If the value is anything other than string, append it as it is to the output array
32
- // And, also increment the pointer to stay in sync with output array
33
- reference = null;
34
- output.push(tokens[i]);
35
- pointer++;
36
- }
37
- }
38
- return output;
39
- }
1
+ import {Constant, Token} from "@clarity-types/data";
2
+
3
+ // Following code takes an array of tokens and transforms it to optimize for repeating tokens and make it efficient to send over the wire
4
+ // The way it works is that it iterate over all tokens and checks if the current token was already seen in the tokens array so far
5
+ // If so, it replaces the token with its reference (index). This helps us save bytes by not repeating the same value twice.
6
+ // E.g. If tokens array is: ["hello", "world", "coding", "language", "world", "language", "example"]
7
+ // Then the resulting tokens array after following code execution would be: ["hello", "world", "coding", "language", [1, 3], "example"]
8
+ // Where [1,3] points to tokens[1] => "world" and tokens[3] => "language"
9
+ export default function(tokens: Token[]): Token[] {
10
+ let output: Token[] = [];
11
+ let lookup: {[key: string]: number} = {};
12
+ let pointer = 0;
13
+ let reference = null;
14
+ for (let i = 0; i < tokens.length; i++) {
15
+ // Only optimize for string values
16
+ if (typeof tokens[i] === Constant.String) {
17
+ let token = tokens[i] as string;
18
+ let index = lookup[token] || -1;
19
+ if (index >= 0) {
20
+ if (reference) { reference.push(index); } else {
21
+ reference = [index];
22
+ output.push(reference);
23
+ pointer++;
24
+ }
25
+ } else {
26
+ reference = null;
27
+ output.push(token);
28
+ lookup[token] = pointer++;
29
+ }
30
+ } else {
31
+ // If the value is anything other than string, append it as it is to the output array
32
+ // And, also increment the pointer to stay in sync with output array
33
+ reference = null;
34
+ output.push(tokens[i]);
35
+ pointer++;
36
+ }
37
+ }
38
+ return output;
39
+ }
@@ -1,37 +1,37 @@
1
- import { Constant, Event, UpgradeData } from "@clarity-types/data";
2
- import * as core from "@src/core";
3
- import config from "@src/core/config";
4
- import encode from "@src/data/encode";
5
- import * as metadata from "@src/data/metadata";
6
-
7
- export let data: UpgradeData = null;
8
-
9
- export function start(): void {
10
- if (!config.lean && config.upgrade) { config.upgrade(Constant.Config); }
11
- data = null;
12
- }
13
-
14
- // Following call will upgrade the session from lean mode into the full mode retroactively from the start of the page.
15
- // As part of the lean mode, we do not send back any layout information - including discovery of DOM and mutations.
16
- // However, if there's a need for full fidelity playback, calling this function will disable lean mode
17
- // and send all backed up layout events to the server.
18
- export function upgrade(key: string): void {
19
- // Upgrade only if Clarity was successfully activated on the page
20
- if (core.active() && config.lean) {
21
- config.lean = false;
22
- data = { key };
23
-
24
- // Update metadata to track we have upgraded this session
25
- metadata.callback();
26
- metadata.save();
27
-
28
- // Callback upgrade handler, if configured
29
- if (config.upgrade) { config.upgrade(key); }
30
-
31
- encode(Event.Upgrade);
32
- }
33
- }
34
-
35
- export function stop(): void {
36
- data = null;
37
- }
1
+ import { Constant, Event, UpgradeData } from "@clarity-types/data";
2
+ import * as core from "@src/core";
3
+ import config from "@src/core/config";
4
+ import encode from "@src/data/encode";
5
+ import * as metadata from "@src/data/metadata";
6
+
7
+ export let data: UpgradeData = null;
8
+
9
+ export function start(): void {
10
+ if (!config.lean && config.upgrade) { config.upgrade(Constant.Config); }
11
+ data = null;
12
+ }
13
+
14
+ // Following call will upgrade the session from lean mode into the full mode retroactively from the start of the page.
15
+ // As part of the lean mode, we do not send back any layout information - including discovery of DOM and mutations.
16
+ // However, if there's a need for full fidelity playback, calling this function will disable lean mode
17
+ // and send all backed up layout events to the server.
18
+ export function upgrade(key: string): void {
19
+ // Upgrade only if Clarity was successfully activated on the page
20
+ if (core.active() && config.lean) {
21
+ config.lean = false;
22
+ data = { key };
23
+
24
+ // Update metadata to track we have upgraded this session
25
+ metadata.callback();
26
+ metadata.save();
27
+
28
+ // Callback upgrade handler, if configured
29
+ if (config.upgrade) { config.upgrade(key); }
30
+
31
+ encode(Event.Upgrade);
32
+ }
33
+ }
34
+
35
+ export function stop(): void {
36
+ data = null;
37
+ }