clarity-js 0.7.66 → 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.
- package/README.md +26 -26
- package/build/clarity.extended.js +1 -1
- package/build/clarity.insight.js +1 -1
- package/build/clarity.js +5410 -5372
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +5410 -5372
- package/build/clarity.performance.js +1 -1
- package/package.json +70 -70
- package/rollup.config.ts +98 -98
- package/src/clarity.ts +60 -60
- package/src/core/api.ts +8 -8
- package/src/core/config.ts +32 -32
- package/src/core/copy.ts +3 -3
- package/src/core/event.ts +26 -26
- package/src/core/hash.ts +19 -19
- package/src/core/history.ts +73 -73
- package/src/core/index.ts +83 -83
- package/src/core/measure.ts +19 -19
- package/src/core/report.ts +28 -28
- package/src/core/scrub.ts +196 -196
- package/src/core/task.ts +180 -180
- package/src/core/time.ts +19 -19
- package/src/core/timeout.ts +10 -10
- package/src/core/version.ts +2 -2
- package/src/data/baseline.ts +123 -92
- package/src/data/compress.ts +31 -31
- package/src/data/consent.ts +20 -20
- package/src/data/custom.ts +23 -23
- package/src/data/dimension.ts +53 -53
- package/src/data/encode.ts +134 -127
- package/src/data/envelope.ts +53 -53
- package/src/data/extract.ts +204 -204
- package/src/data/index.ts +46 -46
- package/src/data/limit.ts +44 -44
- package/src/data/metadata.ts +356 -356
- package/src/data/metric.ts +51 -51
- package/src/data/ping.ts +36 -36
- package/src/data/signal.ts +30 -30
- package/src/data/summary.ts +34 -34
- package/src/data/token.ts +39 -39
- package/src/data/upgrade.ts +37 -37
- package/src/data/upload.ts +283 -283
- package/src/data/variable.ts +83 -83
- package/src/diagnostic/encode.ts +40 -40
- package/src/diagnostic/fraud.ts +36 -36
- package/src/diagnostic/index.ts +15 -15
- package/src/diagnostic/internal.ts +28 -28
- package/src/diagnostic/script.ts +37 -37
- package/src/global.ts +6 -6
- package/src/index.ts +9 -9
- package/src/insight/blank.ts +14 -14
- package/src/insight/encode.ts +60 -60
- package/src/insight/snapshot.ts +114 -114
- package/src/interaction/change.ts +40 -40
- package/src/interaction/click.ts +156 -156
- package/src/interaction/clipboard.ts +34 -34
- package/src/interaction/encode.ts +191 -191
- package/src/interaction/index.ts +59 -59
- package/src/interaction/input.ts +59 -59
- package/src/interaction/pointer.ts +139 -139
- package/src/interaction/resize.ts +47 -47
- package/src/interaction/scroll.ts +124 -124
- package/src/interaction/selection.ts +68 -68
- package/src/interaction/submit.ts +32 -32
- package/src/interaction/timeline.ts +65 -65
- package/src/interaction/unload.ts +28 -28
- package/src/interaction/visibility.ts +26 -26
- package/src/layout/animation.ts +133 -133
- package/src/layout/discover.ts +31 -31
- package/src/layout/document.ts +48 -48
- package/src/layout/dom.ts +414 -414
- package/src/layout/encode.ts +145 -145
- package/src/layout/index.ts +41 -41
- package/src/layout/mutation.ts +340 -340
- package/src/layout/node.ts +264 -264
- package/src/layout/offset.ts +19 -19
- package/src/layout/region.ts +153 -153
- package/src/layout/schema.ts +63 -63
- package/src/layout/selector.ts +82 -82
- package/src/layout/style.ts +149 -149
- package/src/layout/target.ts +32 -32
- package/src/layout/traverse.ts +27 -27
- package/src/performance/blank.ts +7 -7
- package/src/performance/encode.ts +31 -31
- package/src/performance/index.ts +14 -14
- package/src/performance/interaction.ts +125 -125
- package/src/performance/navigation.ts +31 -31
- package/src/performance/observer.ts +108 -108
- package/src/queue.ts +33 -33
- package/test/core.test.ts +139 -139
- package/test/helper.ts +162 -162
- package/test/html/core.html +27 -27
- package/test/tsconfig.test.json +5 -5
- package/tsconfig.json +21 -21
- package/tslint.json +32 -32
- package/types/core.d.ts +151 -151
- package/types/data.d.ts +504 -497
- package/types/diagnostic.d.ts +24 -24
- package/types/index.d.ts +39 -39
- package/types/interaction.d.ts +157 -157
- package/types/layout.d.ts +273 -273
- package/types/performance.d.ts +64 -64
package/src/insight/encode.ts
CHANGED
|
@@ -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
|
}
|
package/src/insight/snapshot.ts
CHANGED
|
@@ -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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
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
|
+
}
|