clarity-js 0.7.65 → 0.7.67

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 +5410 -5355
  5. package/build/clarity.min.js +1 -1
  6. package/build/clarity.module.js +5410 -5355
  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 +26 -26
  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 +123 -92
  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 +134 -127
  31. package/src/data/envelope.ts +53 -53
  32. package/src/data/extract.ts +204 -204
  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 +156 -156
  56. package/src/interaction/clipboard.ts +34 -34
  57. package/src/interaction/encode.ts +191 -191
  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 +414 -414
  72. package/src/layout/encode.ts +145 -145
  73. package/src/layout/index.ts +41 -41
  74. package/src/layout/mutation.ts +340 -340
  75. package/src/layout/node.ts +264 -264
  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 +149 -149
  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 +151 -151
  97. package/types/data.d.ts +504 -497
  98. package/types/diagnostic.d.ts +24 -24
  99. package/types/index.d.ts +39 -39
  100. package/types/interaction.d.ts +157 -157
  101. package/types/layout.d.ts +273 -273
  102. package/types/performance.d.ts +64 -64
@@ -1,145 +1,145 @@
1
- import { Privacy, Task, Timer } from "@clarity-types/core";
2
- import { Event, Setting, Token } from "@clarity-types/data";
3
- import { Constant, NodeInfo, NodeValue } from "@clarity-types/layout";
4
- import config from "@src/core/config";
5
- import * as scrub from "@src/core/scrub";
6
- import * as task from "@src/core/task";
7
- import { time } from "@src/core/time";
8
- import tokenize from "@src/data/token";
9
- import * as baseline from "@src/data/baseline";
10
- import { queue } from "@src/data/upload";
11
- import * as fraud from "@src/diagnostic/fraud";
12
- import * as doc from "@src/layout/document";
13
- import * as dom from "@src/layout/dom";
14
- import * as region from "@src/layout/region";
15
- import * as style from "@src/layout/style";
16
- import * as animation from "@src/layout/animation";
17
-
18
- export default async function (type: Event, timer: Timer = null, ts: number = null): Promise<void> {
19
- let eventTime = ts || time()
20
- let tokens: Token[] = [eventTime, type];
21
- switch (type) {
22
- case Event.Document:
23
- let d = doc.data;
24
- tokens.push(d.width);
25
- tokens.push(d.height);
26
- baseline.track(type, d.width, d.height);
27
- queue(tokens);
28
- break;
29
- case Event.Region:
30
- for (let r of region.state) {
31
- tokens = [r.time, Event.Region];
32
- tokens.push(r.data.id);
33
- tokens.push(r.data.interaction);
34
- tokens.push(r.data.visibility);
35
- tokens.push(r.data.name);
36
- queue(tokens);
37
- }
38
- region.reset();
39
- break;
40
- case Event.StyleSheetAdoption:
41
- case Event.StyleSheetUpdate:
42
- for (let entry of style.sheetAdoptionState) {
43
- tokens = [entry.time, entry.event];
44
- tokens.push(entry.data.id);
45
- tokens.push(entry.data.operation);
46
- tokens.push(entry.data.newIds);
47
- queue(tokens);
48
- }
49
- for (let entry of style.sheetUpdateState) {
50
- tokens = [entry.time, entry.event];
51
- tokens.push(entry.data.id);
52
- tokens.push(entry.data.operation);
53
- tokens.push(entry.data.cssRules);
54
- queue(tokens);
55
- }
56
- style.reset();
57
- break;
58
- case Event.Animation:
59
- for (let entry of animation.state) {
60
- tokens = [entry.time, entry.event];
61
- tokens.push(entry.data.id);
62
- tokens.push(entry.data.operation);
63
- tokens.push(entry.data.keyFrames);
64
- tokens.push(entry.data.timing);
65
- tokens.push(entry.data.timeline);
66
- tokens.push(entry.data.targetId);
67
- queue(tokens);
68
- }
69
- animation.reset();
70
- break;
71
- case Event.Discover:
72
- case Event.Mutation:
73
- // Check if we are operating within the context of the current page
74
- if (task.state(timer) === Task.Stop) { break; }
75
- let values = dom.updates();
76
- // Only encode and queue DOM updates if we have valid updates to report back
77
- if (values.length > 0) {
78
- for (let value of values) {
79
- let state = task.state(timer);
80
- if (state === Task.Wait) { state = await task.suspend(timer); }
81
- if (state === Task.Stop) { break; }
82
- let data: NodeInfo = value.data;
83
- let active = value.metadata.active;
84
- let suspend = value.metadata.suspend;
85
- let privacy = value.metadata.privacy;
86
- let mangle = shouldMangle(value);
87
- let keys = active ? ["tag", "attributes", "value"] : ["tag"];
88
- for (let key of keys) {
89
- if (data[key]) {
90
- switch (key) {
91
- case "tag":
92
- let box = size(value);
93
- let factor = mangle ? -1 : 1;
94
- tokens.push(value.id * factor);
95
- if (value.parent && active) {
96
- tokens.push(value.parent);
97
- if (value.previous) { tokens.push(value.previous); }
98
- }
99
- tokens.push(suspend ? Constant.SuspendMutationTag : data[key]);
100
- if (box && box.length === 2) { tokens.push(`${Constant.Hash}${str(box[0])}.${str(box[1])}`); }
101
- break;
102
- case "attributes":
103
- for (let attr in data[key]) {
104
- if (data[key][attr] !== undefined) {
105
- tokens.push(attribute(attr, data[key][attr], privacy));
106
- }
107
- }
108
- break;
109
- case "value":
110
- fraud.check(value.metadata.fraud, value.id, data[key]);
111
- tokens.push(scrub.text(data[key], data.tag, privacy, mangle));
112
- break;
113
- }
114
- }
115
- }
116
- }
117
- if (type === Event.Mutation) { baseline.activity(eventTime); }
118
- queue(tokenize(tokens), !config.lean);
119
- }
120
- break;
121
- }
122
- }
123
-
124
- function shouldMangle(value: NodeValue): boolean {
125
- let privacy = value.metadata.privacy;
126
- return value.data.tag === Constant.TextTag && !(privacy === Privacy.None || privacy === Privacy.Sensitive);
127
- }
128
-
129
- function size(value: NodeValue): number[] {
130
- if (value.metadata.size !== null && value.metadata.size.length === 0) {
131
- let img = dom.getNode(value.id) as HTMLImageElement;
132
- if (img) {
133
- return [Math.floor(img.offsetWidth * Setting.BoxPrecision), Math.floor(img.offsetHeight * Setting.BoxPrecision)];
134
- }
135
- }
136
- return value.metadata.size;
137
- }
138
-
139
- function str(input: number): string {
140
- return input.toString(36);
141
- }
142
-
143
- function attribute(key: string, value: string, privacy: Privacy): string {
144
- return `${key}=${scrub.text(value, key.indexOf(Constant.DataAttribute) === 0 ? Constant.DataAttribute : key, privacy)}`;
145
- }
1
+ import { Privacy, Task, Timer } from "@clarity-types/core";
2
+ import { Event, Setting, Token } from "@clarity-types/data";
3
+ import { Constant, NodeInfo, NodeValue } from "@clarity-types/layout";
4
+ import config from "@src/core/config";
5
+ import * as scrub from "@src/core/scrub";
6
+ import * as task from "@src/core/task";
7
+ import { time } from "@src/core/time";
8
+ import tokenize from "@src/data/token";
9
+ import * as baseline from "@src/data/baseline";
10
+ import { queue } from "@src/data/upload";
11
+ import * as fraud from "@src/diagnostic/fraud";
12
+ import * as doc from "@src/layout/document";
13
+ import * as dom from "@src/layout/dom";
14
+ import * as region from "@src/layout/region";
15
+ import * as style from "@src/layout/style";
16
+ import * as animation from "@src/layout/animation";
17
+
18
+ export default async function (type: Event, timer: Timer = null, ts: number = null): Promise<void> {
19
+ let eventTime = ts || time()
20
+ let tokens: Token[] = [eventTime, type];
21
+ switch (type) {
22
+ case Event.Document:
23
+ let d = doc.data;
24
+ tokens.push(d.width);
25
+ tokens.push(d.height);
26
+ baseline.track(type, d.width, d.height);
27
+ queue(tokens);
28
+ break;
29
+ case Event.Region:
30
+ for (let r of region.state) {
31
+ tokens = [r.time, Event.Region];
32
+ tokens.push(r.data.id);
33
+ tokens.push(r.data.interaction);
34
+ tokens.push(r.data.visibility);
35
+ tokens.push(r.data.name);
36
+ queue(tokens);
37
+ }
38
+ region.reset();
39
+ break;
40
+ case Event.StyleSheetAdoption:
41
+ case Event.StyleSheetUpdate:
42
+ for (let entry of style.sheetAdoptionState) {
43
+ tokens = [entry.time, entry.event];
44
+ tokens.push(entry.data.id);
45
+ tokens.push(entry.data.operation);
46
+ tokens.push(entry.data.newIds);
47
+ queue(tokens);
48
+ }
49
+ for (let entry of style.sheetUpdateState) {
50
+ tokens = [entry.time, entry.event];
51
+ tokens.push(entry.data.id);
52
+ tokens.push(entry.data.operation);
53
+ tokens.push(entry.data.cssRules);
54
+ queue(tokens);
55
+ }
56
+ style.reset();
57
+ break;
58
+ case Event.Animation:
59
+ for (let entry of animation.state) {
60
+ tokens = [entry.time, entry.event];
61
+ tokens.push(entry.data.id);
62
+ tokens.push(entry.data.operation);
63
+ tokens.push(entry.data.keyFrames);
64
+ tokens.push(entry.data.timing);
65
+ tokens.push(entry.data.timeline);
66
+ tokens.push(entry.data.targetId);
67
+ queue(tokens);
68
+ }
69
+ animation.reset();
70
+ break;
71
+ case Event.Discover:
72
+ case Event.Mutation:
73
+ // Check if we are operating within the context of the current page
74
+ if (task.state(timer) === Task.Stop) { break; }
75
+ let values = dom.updates();
76
+ // Only encode and queue DOM updates if we have valid updates to report back
77
+ if (values.length > 0) {
78
+ for (let value of values) {
79
+ let state = task.state(timer);
80
+ if (state === Task.Wait) { state = await task.suspend(timer); }
81
+ if (state === Task.Stop) { break; }
82
+ let data: NodeInfo = value.data;
83
+ let active = value.metadata.active;
84
+ let suspend = value.metadata.suspend;
85
+ let privacy = value.metadata.privacy;
86
+ let mangle = shouldMangle(value);
87
+ let keys = active ? ["tag", "attributes", "value"] : ["tag"];
88
+ for (let key of keys) {
89
+ if (data[key]) {
90
+ switch (key) {
91
+ case "tag":
92
+ let box = size(value);
93
+ let factor = mangle ? -1 : 1;
94
+ tokens.push(value.id * factor);
95
+ if (value.parent && active) {
96
+ tokens.push(value.parent);
97
+ if (value.previous) { tokens.push(value.previous); }
98
+ }
99
+ tokens.push(suspend ? Constant.SuspendMutationTag : data[key]);
100
+ if (box && box.length === 2) { tokens.push(`${Constant.Hash}${str(box[0])}.${str(box[1])}`); }
101
+ break;
102
+ case "attributes":
103
+ for (let attr in data[key]) {
104
+ if (data[key][attr] !== undefined) {
105
+ tokens.push(attribute(attr, data[key][attr], privacy));
106
+ }
107
+ }
108
+ break;
109
+ case "value":
110
+ fraud.check(value.metadata.fraud, value.id, data[key]);
111
+ tokens.push(scrub.text(data[key], data.tag, privacy, mangle));
112
+ break;
113
+ }
114
+ }
115
+ }
116
+ }
117
+ if (type === Event.Mutation) { baseline.activity(eventTime); }
118
+ queue(tokenize(tokens), !config.lean);
119
+ }
120
+ break;
121
+ }
122
+ }
123
+
124
+ function shouldMangle(value: NodeValue): boolean {
125
+ let privacy = value.metadata.privacy;
126
+ return value.data.tag === Constant.TextTag && !(privacy === Privacy.None || privacy === Privacy.Sensitive);
127
+ }
128
+
129
+ function size(value: NodeValue): number[] {
130
+ if (value.metadata.size !== null && value.metadata.size.length === 0) {
131
+ let img = dom.getNode(value.id) as HTMLImageElement;
132
+ if (img) {
133
+ return [Math.floor(img.offsetWidth * Setting.BoxPrecision), Math.floor(img.offsetHeight * Setting.BoxPrecision)];
134
+ }
135
+ }
136
+ return value.metadata.size;
137
+ }
138
+
139
+ function str(input: number): string {
140
+ return input.toString(36);
141
+ }
142
+
143
+ function attribute(key: string, value: string, privacy: Privacy): string {
144
+ return `${key}=${scrub.text(value, key.indexOf(Constant.DataAttribute) === 0 ? Constant.DataAttribute : key, privacy)}`;
145
+ }
@@ -1,41 +1,41 @@
1
- import { FunctionNames } from "@clarity-types/performance";
2
- import * as discover from "@src/layout/discover";
3
- import * as doc from "@src/layout/document";
4
- import * as dom from "@src/layout/dom";
5
- import * as mutation from "@src/layout/mutation";
6
- import * as region from "@src/layout/region";
7
- import * as style from "@src/layout/style";
8
- import * as animation from "@src/layout/animation";
9
- import { bind } from "@src/core/event";
10
- import config from "@src/core/config";
11
-
12
- export { hashText } from "@src/layout/dom";
13
-
14
- export function start(): void {
15
- // The order below is important
16
- // and is determined by interdependencies of modules
17
- doc.start();
18
- region.start();
19
- dom.start();
20
- if (config.delayDom) {
21
- // Lazy load layout module as part of page load time performance improvements experiment
22
- bind(window, 'load', () => {
23
- mutation.start();
24
- });
25
- } else {
26
- mutation.start();
27
- }
28
- discover.start();
29
- style.start();
30
- animation.start();
31
- }
32
- start.dn = FunctionNames.LayoutStart;
33
-
34
- export function stop(): void {
35
- region.stop();
36
- dom.stop();
37
- mutation.stop();
38
- doc.stop();
39
- style.stop();
40
- animation.stop();
41
- }
1
+ import { FunctionNames } from "@clarity-types/performance";
2
+ import * as discover from "@src/layout/discover";
3
+ import * as doc from "@src/layout/document";
4
+ import * as dom from "@src/layout/dom";
5
+ import * as mutation from "@src/layout/mutation";
6
+ import * as region from "@src/layout/region";
7
+ import * as style from "@src/layout/style";
8
+ import * as animation from "@src/layout/animation";
9
+ import { bind } from "@src/core/event";
10
+ import config from "@src/core/config";
11
+
12
+ export { hashText } from "@src/layout/dom";
13
+
14
+ export function start(): void {
15
+ start.dn = FunctionNames.LayoutStart;
16
+ // The order below is important
17
+ // and is determined by interdependencies of modules
18
+ doc.start();
19
+ region.start();
20
+ dom.start();
21
+ if (config.delayDom) {
22
+ // Lazy load layout module as part of page load time performance improvements experiment
23
+ bind(window, 'load', () => {
24
+ mutation.start();
25
+ });
26
+ } else {
27
+ mutation.start();
28
+ }
29
+ discover.start();
30
+ style.start();
31
+ animation.start();
32
+ }
33
+
34
+ export function stop(): void {
35
+ region.stop();
36
+ dom.stop();
37
+ mutation.stop();
38
+ doc.stop();
39
+ style.stop();
40
+ animation.stop();
41
+ }