clarity-js 0.7.66 → 0.7.68

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 +5422 -5372
  5. package/build/clarity.min.js +1 -1
  6. package/build/clarity.module.js +5422 -5372
  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 +30 -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 +162 -156
  56. package/src/interaction/clipboard.ts +34 -34
  57. package/src/interaction/encode.ts +193 -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 +150 -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 +154 -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 +165 -157
  101. package/types/layout.d.ts +273 -273
  102. package/types/performance.d.ts +64 -64
@@ -1,61 +1,61 @@
1
- import { Privacy } from "@clarity-types/core";
2
- import { Event, Token } from "@clarity-types/data";
3
- import { Constant, NodeInfo } from "@clarity-types/layout";
4
- import * as scrub from "@src/core/scrub";
5
- import { time } from "@src/core/time";
6
- import * as baseline from "@src/data/baseline";
7
- import tokenize from "@src/data/token";
8
- import { queue } from "@src/data/upload";
9
- import * as snapshot from "@src/insight/snapshot";
10
- import * as doc from "@src/layout/document";
11
-
12
- export default async function (type: Event): Promise<void> {
13
- let eventTime = time()
14
- let tokens: Token[] = [eventTime, type];
15
- switch (type) {
16
- case Event.Document:
17
- let d = doc.data;
18
- tokens.push(d.width);
19
- tokens.push(d.height);
20
- baseline.track(type, d.width, d.height);
21
- queue(tokens);
22
- break;
23
- case Event.Snapshot:
24
- let values = snapshot.values;
25
- // Only encode and queue DOM updates if we have valid updates to report back
26
- if (values.length > 0) {
27
- for (let value of values) {
28
- let privacy = value.metadata.privacy;
29
- let data: NodeInfo = value.data;
30
- for (let key of ["tag", "attributes", "value"]) {
31
- if (data[key]) {
32
- switch (key) {
33
- case "tag":
34
- tokens.push(value.id);
35
- if (value.parent) { tokens.push(value.parent); }
36
- if (value.previous) { tokens.push(value.previous); }
37
- tokens.push(data[key]);
38
- break;
39
- case "attributes":
40
- for (let attr in data[key]) {
41
- if (data[key][attr] !== undefined) {
42
- tokens.push(attribute(attr, data[key][attr], privacy));
43
- }
44
- }
45
- break;
46
- case "value":
47
- tokens.push(scrub.text(data[key], data.tag, privacy));
48
- break;
49
- }
50
- }
51
- }
52
- }
53
- queue(tokenize(tokens), true);
54
- }
55
- break;
56
- }
57
- }
58
-
59
- function attribute(key: string, value: string, privacy: Privacy): string {
60
- return `${key}=${scrub.text(value, key.indexOf(Constant.DataAttribute) === 0 ? Constant.DataAttribute : key, privacy)}`;
1
+ import { Privacy } from "@clarity-types/core";
2
+ import { Event, Token } from "@clarity-types/data";
3
+ import { Constant, NodeInfo } from "@clarity-types/layout";
4
+ import * as scrub from "@src/core/scrub";
5
+ import { time } from "@src/core/time";
6
+ import * as baseline from "@src/data/baseline";
7
+ import tokenize from "@src/data/token";
8
+ import { queue } from "@src/data/upload";
9
+ import * as snapshot from "@src/insight/snapshot";
10
+ import * as doc from "@src/layout/document";
11
+
12
+ export default async function (type: Event): Promise<void> {
13
+ let eventTime = time()
14
+ let tokens: Token[] = [eventTime, type];
15
+ switch (type) {
16
+ case Event.Document:
17
+ let d = doc.data;
18
+ tokens.push(d.width);
19
+ tokens.push(d.height);
20
+ baseline.track(type, d.width, d.height);
21
+ queue(tokens);
22
+ break;
23
+ case Event.Snapshot:
24
+ let values = snapshot.values;
25
+ // Only encode and queue DOM updates if we have valid updates to report back
26
+ if (values.length > 0) {
27
+ for (let value of values) {
28
+ let privacy = value.metadata.privacy;
29
+ let data: NodeInfo = value.data;
30
+ for (let key of ["tag", "attributes", "value"]) {
31
+ if (data[key]) {
32
+ switch (key) {
33
+ case "tag":
34
+ tokens.push(value.id);
35
+ if (value.parent) { tokens.push(value.parent); }
36
+ if (value.previous) { tokens.push(value.previous); }
37
+ tokens.push(data[key]);
38
+ break;
39
+ case "attributes":
40
+ for (let attr in data[key]) {
41
+ if (data[key][attr] !== undefined) {
42
+ tokens.push(attribute(attr, data[key][attr], privacy));
43
+ }
44
+ }
45
+ break;
46
+ case "value":
47
+ tokens.push(scrub.text(data[key], data.tag, privacy));
48
+ break;
49
+ }
50
+ }
51
+ }
52
+ }
53
+ queue(tokenize(tokens), true);
54
+ }
55
+ break;
56
+ }
57
+ }
58
+
59
+ function attribute(key: string, value: string, privacy: Privacy): string {
60
+ return `${key}=${scrub.text(value, key.indexOf(Constant.DataAttribute) === 0 ? Constant.DataAttribute : key, privacy)}`;
61
61
  }
@@ -1,115 +1,115 @@
1
- import { OffsetDistance, Privacy } from "@clarity-types/core";
2
- import { Event } from "@clarity-types/data";
3
- import { Constant, NodeInfo, NodeValue, TargetMetadata } from "@clarity-types/layout";
4
- import * as doc from "@src/layout/document";
5
- import encode from "@src/insight/encode";
6
- import * as interaction from "@src/interaction";
7
- import config from "@src/core/config";
8
- export let values: NodeValue[] = [];
9
- let index: number = 1;
10
- let idMap: WeakMap<Node, number> = null; // Maps node => id.
11
-
12
- export function start(): void {
13
- reset();
14
- doc.start();
15
- getId(document.documentElement); // Pre-discover ID for page root
16
- interaction.observe(document);
17
- }
18
-
19
- export function stop(): void {
20
- reset();
21
- doc.stop();
22
- }
23
-
24
- export function compute(): void { /* Intentionally Blank */ }
25
- export function iframe(): boolean { return false; }
26
- export function offset(): OffsetDistance { return { x: 0, y: 0 }; }
27
- export function hashText(): void { /* Intentionally Blank */ }
28
-
29
- export function target(evt: UIEvent): Node {
30
- let path = evt.composed && evt.composedPath ? evt.composedPath() : null;
31
- let node = (path && path.length > 0 ? path[0] : evt.target) as Node;
32
- return node.nodeType === Node.DOCUMENT_NODE ? (node as Document).documentElement : node;
33
- }
34
-
35
- export function metadata(node: Node): TargetMetadata {
36
- let output: TargetMetadata = { id: 0, hash: null, privacy: config.conversions ? Privacy.Sensitive : Privacy.Snapshot, node };
37
- if (node) { output.id = idMap.has(node) ? idMap.get(node) : getId(node); }
38
- return output;
39
- }
40
-
41
- export function snapshot(): void {
42
- values = [];
43
- traverse(document);
44
- encode(Event.Snapshot);
45
- }
46
-
47
- function reset(): void {
48
- idMap = new WeakMap();
49
- }
50
-
51
- function traverse(root: Node): void {
52
- let queue = [root];
53
- while (queue.length > 0) {
54
- let attributes = null, tag = null, value = null;
55
- let node = queue.shift();
56
- let next = node.firstChild;
57
- let parent = node.parentElement ? node.parentElement : (node.parentNode ? node.parentNode : null);
58
-
59
- while (next) {
60
- queue.push(next);
61
- next = next.nextSibling;
62
- }
63
-
64
- // Process the node
65
- let type = node.nodeType;
66
- switch (type) {
67
- case Node.DOCUMENT_TYPE_NODE:
68
- let doctype = node as DocumentType;
69
- tag = Constant.DocumentTag;
70
- attributes = { name: doctype.name, publicId: doctype.publicId, systemId: doctype.systemId }
71
- break;
72
- case Node.TEXT_NODE:
73
- value = node.nodeValue;
74
- tag = idMap.get(parent) ? Constant.TextTag : tag;
75
- break;
76
- case Node.ELEMENT_NODE:
77
- let element = node as HTMLElement;
78
- attributes = getAttributes(element);
79
- tag = ["NOSCRIPT", "SCRIPT", "STYLE"].indexOf(element.tagName) < 0 ? element.tagName : tag;
80
- break;
81
- }
82
- add(node, parent, { tag, attributes, value });
83
- }
84
- }
85
-
86
- /* Helper Functions - Snapshot Traversal */
87
- function getAttributes(element: HTMLElement): { [key: string]: string } {
88
- let output = {};
89
- let attributes = element.attributes;
90
- if (attributes && attributes.length > 0) {
91
- for (let i = 0; i < attributes.length; i++) {
92
- output[attributes[i].name] = attributes[i].value;
93
- }
94
- }
95
- return output;
96
- }
97
-
98
- function getId(node: Node): number {
99
- if (node === null) { return null; }
100
- if (idMap.has(node)) { return idMap.get(node); }
101
- idMap.set(node, index);
102
- return index++;
103
- }
104
-
105
- function add(node: Node, parent: Node, data: NodeInfo): void {
106
- if (node && data && data.tag) {
107
- let id = getId(node);
108
- let parentId = parent ? idMap.get(parent) : null;
109
- let previous = node.previousSibling ? idMap.get(node.previousSibling) : null;
110
- let metadata = { active: true, suspend: false, privacy: Privacy.Snapshot, position: null, fraud: null, size: null };
111
- values.push({ id, parent: parentId, previous, children: [], data, selector: null, hash: null, region: null, metadata });
112
- }
113
- }
114
-
1
+ import { OffsetDistance, Privacy } from "@clarity-types/core";
2
+ import { Event } from "@clarity-types/data";
3
+ import { Constant, NodeInfo, NodeValue, TargetMetadata } from "@clarity-types/layout";
4
+ import * as doc from "@src/layout/document";
5
+ import encode from "@src/insight/encode";
6
+ import * as interaction from "@src/interaction";
7
+ import config from "@src/core/config";
8
+ export let values: NodeValue[] = [];
9
+ let index: number = 1;
10
+ let idMap: WeakMap<Node, number> = null; // Maps node => id.
11
+
12
+ export function start(): void {
13
+ reset();
14
+ doc.start();
15
+ getId(document.documentElement); // Pre-discover ID for page root
16
+ interaction.observe(document);
17
+ }
18
+
19
+ export function stop(): void {
20
+ reset();
21
+ doc.stop();
22
+ }
23
+
24
+ export function compute(): void { /* Intentionally Blank */ }
25
+ export function iframe(): boolean { return false; }
26
+ export function offset(): OffsetDistance { return { x: 0, y: 0 }; }
27
+ export function hashText(): void { /* Intentionally Blank */ }
28
+
29
+ export function target(evt: UIEvent): Node {
30
+ let path = evt.composed && evt.composedPath ? evt.composedPath() : null;
31
+ let node = (path && path.length > 0 ? path[0] : evt.target) as Node;
32
+ return node.nodeType === Node.DOCUMENT_NODE ? (node as Document).documentElement : node;
33
+ }
34
+
35
+ export function metadata(node: Node): TargetMetadata {
36
+ let output: TargetMetadata = { id: 0, hash: null, privacy: config.conversions ? Privacy.Sensitive : Privacy.Snapshot, node };
37
+ if (node) { output.id = idMap.has(node) ? idMap.get(node) : getId(node); }
38
+ return output;
39
+ }
40
+
41
+ export function snapshot(): void {
42
+ values = [];
43
+ traverse(document);
44
+ encode(Event.Snapshot);
45
+ }
46
+
47
+ function reset(): void {
48
+ idMap = new WeakMap();
49
+ }
50
+
51
+ function traverse(root: Node): void {
52
+ let queue = [root];
53
+ while (queue.length > 0) {
54
+ let attributes = null, tag = null, value = null;
55
+ let node = queue.shift();
56
+ let next = node.firstChild;
57
+ let parent = node.parentElement ? node.parentElement : (node.parentNode ? node.parentNode : null);
58
+
59
+ while (next) {
60
+ queue.push(next);
61
+ next = next.nextSibling;
62
+ }
63
+
64
+ // Process the node
65
+ let type = node.nodeType;
66
+ switch (type) {
67
+ case Node.DOCUMENT_TYPE_NODE:
68
+ let doctype = node as DocumentType;
69
+ tag = Constant.DocumentTag;
70
+ attributes = { name: doctype.name, publicId: doctype.publicId, systemId: doctype.systemId }
71
+ break;
72
+ case Node.TEXT_NODE:
73
+ value = node.nodeValue;
74
+ tag = idMap.get(parent) ? Constant.TextTag : tag;
75
+ break;
76
+ case Node.ELEMENT_NODE:
77
+ let element = node as HTMLElement;
78
+ attributes = getAttributes(element);
79
+ tag = ["NOSCRIPT", "SCRIPT", "STYLE"].indexOf(element.tagName) < 0 ? element.tagName : tag;
80
+ break;
81
+ }
82
+ add(node, parent, { tag, attributes, value });
83
+ }
84
+ }
85
+
86
+ /* Helper Functions - Snapshot Traversal */
87
+ function getAttributes(element: HTMLElement): { [key: string]: string } {
88
+ let output = {};
89
+ let attributes = element.attributes;
90
+ if (attributes && attributes.length > 0) {
91
+ for (let i = 0; i < attributes.length; i++) {
92
+ output[attributes[i].name] = attributes[i].value;
93
+ }
94
+ }
95
+ return output;
96
+ }
97
+
98
+ function getId(node: Node): number {
99
+ if (node === null) { return null; }
100
+ if (idMap.has(node)) { return idMap.get(node); }
101
+ idMap.set(node, index);
102
+ return index++;
103
+ }
104
+
105
+ function add(node: Node, parent: Node, data: NodeInfo): void {
106
+ if (node && data && data.tag) {
107
+ let id = getId(node);
108
+ let parentId = parent ? idMap.get(parent) : null;
109
+ let previous = node.previousSibling ? idMap.get(node.previousSibling) : null;
110
+ let metadata = { active: true, suspend: false, privacy: Privacy.Snapshot, position: null, fraud: null, size: null };
111
+ values.push({ id, parent: parentId, previous, children: [], data, selector: null, hash: null, region: null, metadata });
112
+ }
113
+ }
114
+
115
115
  export function get(_node: Node): NodeValue {return null;}
@@ -1,40 +1,40 @@
1
- import { Constant, Event, Setting } from "@clarity-types/data";
2
- import { ChangeState } from "@clarity-types/interaction";
3
- import { FunctionNames } from "@clarity-types/performance";
4
- import config from "@src/core/config";
5
- import { bind } from "@src/core/event";
6
- import hash from "@src/core/hash";
7
- import { schedule } from "@src/core/task";
8
- import { time } from "@src/core/time";
9
- import { target } from "@src/layout/target";
10
- import encode from "./encode";
11
- import { Mask } from "@clarity-types/layout";
12
-
13
- export let state: ChangeState[] = [];
14
-
15
- export function start(): void {
16
- reset();
17
- }
18
-
19
- export function observe(root: Node): void {
20
- bind(root, "change", recompute, true);
21
- }
22
-
23
- function recompute(evt: UIEvent): void {
24
- let element = target(evt) as HTMLInputElement;
25
- if (element) {
26
- let value = element.value;
27
- let checksum = value && value.length >= Setting.WordLength && config.fraud && Mask.Exclude.indexOf(element.type) === -1 ? hash(value, Setting.ChecksumPrecision) : Constant.Empty;
28
- state.push({ time: time(evt), event: Event.Change, data: { target: target(evt), type: element.type, value, checksum } });
29
- schedule(encode.bind(this, Event.Change));
30
- }
31
- }
32
- recompute.dn = FunctionNames.ChangeRecompute;
33
-
34
- export function reset(): void {
35
- state = [];
36
- }
37
-
38
- export function stop(): void {
39
- reset();
40
- }
1
+ import { Constant, Event, Setting } from "@clarity-types/data";
2
+ import { ChangeState } from "@clarity-types/interaction";
3
+ import { FunctionNames } from "@clarity-types/performance";
4
+ import config from "@src/core/config";
5
+ import { bind } from "@src/core/event";
6
+ import hash from "@src/core/hash";
7
+ import { schedule } from "@src/core/task";
8
+ import { time } from "@src/core/time";
9
+ import { target } from "@src/layout/target";
10
+ import encode from "./encode";
11
+ import { Mask } from "@clarity-types/layout";
12
+
13
+ export let state: ChangeState[] = [];
14
+
15
+ export function start(): void {
16
+ reset();
17
+ }
18
+
19
+ export function observe(root: Node): void {
20
+ bind(root, "change", recompute, true);
21
+ }
22
+
23
+ function recompute(evt: UIEvent): void {
24
+ recompute.dn = FunctionNames.ChangeRecompute;
25
+ let element = target(evt) as HTMLInputElement;
26
+ if (element) {
27
+ let value = element.value;
28
+ let checksum = value && value.length >= Setting.WordLength && config.fraud && Mask.Exclude.indexOf(element.type) === -1 ? hash(value, Setting.ChecksumPrecision) : Constant.Empty;
29
+ state.push({ time: time(evt), event: Event.Change, data: { target: target(evt), type: element.type, value, checksum } });
30
+ schedule(encode.bind(this, Event.Change));
31
+ }
32
+ }
33
+
34
+ export function reset(): void {
35
+ state = [];
36
+ }
37
+
38
+ export function stop(): void {
39
+ reset();
40
+ }