clarity-js 0.8.11-beta → 0.8.12
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/.lintstagedrc.yml +3 -0
- package/biome.json +43 -0
- package/build/clarity.extended.js +1 -1
- package/build/clarity.insight.js +1 -1
- package/build/clarity.js +4591 -4362
- package/build/clarity.min.js +1 -1
- package/build/clarity.module.js +4591 -4362
- package/build/clarity.performance.js +1 -1
- package/package.json +76 -69
- package/rollup.config.ts +84 -88
- package/src/clarity.ts +34 -28
- package/src/core/api.ts +8 -1
- package/src/core/config.ts +2 -2
- package/src/core/event.ts +36 -32
- package/src/core/hash.ts +5 -6
- package/src/core/history.ts +10 -11
- package/src/core/index.ts +21 -11
- package/src/core/measure.ts +9 -5
- package/src/core/report.ts +9 -5
- package/src/core/scrub.ts +29 -20
- package/src/core/task.ts +73 -45
- package/src/core/time.ts +3 -3
- package/src/core/timeout.ts +2 -2
- package/src/core/version.ts +1 -1
- package/src/data/baseline.ts +60 -55
- package/src/data/consent.ts +2 -2
- package/src/data/custom.ts +8 -13
- package/src/data/dimension.ts +11 -7
- package/src/data/encode.ts +36 -30
- package/src/data/envelope.ts +38 -38
- package/src/data/extract.ts +86 -77
- package/src/data/index.ts +10 -6
- package/src/data/limit.ts +1 -1
- package/src/data/metadata.ts +305 -266
- package/src/data/metric.ts +18 -8
- package/src/data/ping.ts +8 -4
- package/src/data/signal.ts +18 -18
- package/src/data/summary.ts +6 -4
- package/src/data/token.ts +10 -8
- package/src/data/upgrade.ts +7 -3
- package/src/data/upload.ts +100 -49
- package/src/data/variable.ts +27 -20
- package/src/diagnostic/encode.ts +2 -2
- package/src/diagnostic/fraud.ts +3 -4
- package/src/diagnostic/internal.ts +11 -5
- package/src/diagnostic/script.ts +12 -8
- package/src/global.ts +1 -1
- package/src/insight/blank.ts +4 -4
- package/src/insight/encode.ts +23 -17
- package/src/insight/snapshot.ts +57 -37
- package/src/interaction/change.ts +9 -6
- package/src/interaction/click.ts +34 -28
- package/src/interaction/clipboard.ts +2 -2
- package/src/interaction/encode.ts +35 -31
- package/src/interaction/input.ts +11 -9
- package/src/interaction/pointer.ts +42 -31
- package/src/interaction/resize.ts +5 -5
- package/src/interaction/scroll.ts +21 -18
- package/src/interaction/selection.ts +12 -8
- package/src/interaction/submit.ts +2 -2
- package/src/interaction/timeline.ts +13 -9
- package/src/interaction/unload.ts +1 -1
- package/src/interaction/visibility.ts +2 -2
- package/src/layout/animation.ts +47 -41
- package/src/layout/discover.ts +5 -5
- package/src/layout/document.ts +31 -19
- package/src/layout/dom.ts +141 -91
- package/src/layout/encode.ts +52 -37
- package/src/layout/mutation.ts +321 -318
- package/src/layout/node.ts +104 -81
- package/src/layout/offset.ts +7 -6
- package/src/layout/region.ts +67 -44
- package/src/layout/schema.ts +15 -8
- package/src/layout/selector.ts +47 -25
- package/src/layout/style.ts +44 -36
- package/src/layout/target.ts +14 -10
- package/src/layout/traverse.ts +17 -11
- package/src/performance/blank.ts +1 -1
- package/src/performance/encode.ts +4 -4
- package/src/performance/interaction.ts +58 -70
- package/src/performance/navigation.ts +2 -2
- package/src/performance/observer.ts +59 -26
- package/src/queue.ts +16 -9
- package/tsconfig.json +1 -1
- package/tslint.json +25 -32
- package/types/core.d.ts +13 -13
- package/types/data.d.ts +33 -29
- package/types/diagnostic.d.ts +1 -1
- package/types/interaction.d.ts +7 -5
- package/types/layout.d.ts +36 -21
- package/types/performance.d.ts +6 -5
package/src/data/extract.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ExtractSource, Syntax, Type } from "@clarity-types/core";
|
|
2
|
-
import { Event,
|
|
3
|
-
import encode from "./encode";
|
|
4
|
-
import * as internal from "@src/diagnostic/internal";
|
|
1
|
+
import { ExtractSource, type Syntax, Type } from "@clarity-types/core";
|
|
2
|
+
import { Event, type ExtractData, Setting } from "@clarity-types/data";
|
|
5
3
|
import { Code, Constant, Severity } from "@clarity-types/data";
|
|
6
4
|
import { hashText } from "@src/clarity";
|
|
7
5
|
import hash from "@src/core/hash";
|
|
6
|
+
import * as internal from "@src/diagnostic/internal";
|
|
7
|
+
import encode from "./encode";
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export const data: ExtractData = {};
|
|
10
|
+
export const keys: Set<number> = new Set();
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const variables: { [key: number]: { [key: number]: Syntax[] } } = {};
|
|
13
|
+
const selectors: { [key: number]: { [key: number]: string } } = {};
|
|
14
|
+
const hashes: { [key: number]: { [key: number]: string } } = {};
|
|
15
|
+
const validation: { [key: number]: string } = {};
|
|
16
16
|
|
|
17
17
|
export function start(): void {
|
|
18
18
|
reset();
|
|
@@ -23,44 +23,45 @@ export function start(): void {
|
|
|
23
23
|
// if element is present on the page it will set up event 101 to grab the contents of the class1 selector into component 1,
|
|
24
24
|
// the javascript evaluated contents of window.a.b into component 2,
|
|
25
25
|
// and the contents of Clarity's hash abc into component 3
|
|
26
|
-
export function trigger(input: string): void {
|
|
26
|
+
export function trigger(input: string): void {
|
|
27
27
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const parts = input && input.length > 0 ? input.split(/ (.*)/) : [Constant.Empty];
|
|
29
|
+
const keyparts = parts[0].split(/\|(.*)/);
|
|
30
|
+
const key = Number.parseInt(keyparts[0]);
|
|
31
|
+
const element = keyparts.length > 1 ? keyparts[1] : Constant.Empty;
|
|
32
|
+
const values = parts.length > 1 ? JSON.parse(parts[1]) : {};
|
|
33
33
|
variables[key] = {};
|
|
34
34
|
selectors[key] = {};
|
|
35
35
|
hashes[key] = {};
|
|
36
36
|
validation[key] = element;
|
|
37
|
-
for (
|
|
38
|
-
// values is a set of strings for proper JSON parsing, but it's more efficient
|
|
37
|
+
for (const v in values) {
|
|
38
|
+
// values is a set of strings for proper JSON parsing, but it's more efficient
|
|
39
39
|
// to interact with them as numbers
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const id = Number.parseInt(v);
|
|
41
|
+
const value = values[v] as string;
|
|
42
42
|
let source = ExtractSource.Text;
|
|
43
43
|
if (value.startsWith(Constant.Tilde)) {
|
|
44
|
-
source = ExtractSource.Javascript
|
|
44
|
+
source = ExtractSource.Javascript;
|
|
45
45
|
} else if (value.startsWith(Constant.Bang)) {
|
|
46
|
-
source = ExtractSource.Hash
|
|
46
|
+
source = ExtractSource.Hash;
|
|
47
47
|
}
|
|
48
48
|
switch (source) {
|
|
49
|
-
case ExtractSource.Javascript:
|
|
50
|
-
|
|
49
|
+
case ExtractSource.Javascript: {
|
|
50
|
+
const variable = value.slice(1);
|
|
51
51
|
variables[key][id] = parse(variable);
|
|
52
52
|
break;
|
|
53
|
+
}
|
|
53
54
|
case ExtractSource.Text:
|
|
54
55
|
selectors[key][id] = value;
|
|
55
56
|
break;
|
|
56
|
-
case ExtractSource.Hash:
|
|
57
|
-
|
|
57
|
+
case ExtractSource.Hash: {
|
|
58
|
+
const hash = value.slice(1);
|
|
58
59
|
hashes[key][id] = hash;
|
|
59
60
|
break;
|
|
61
|
+
}
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
|
-
}
|
|
63
|
-
catch(e) {
|
|
64
|
+
} catch (e) {
|
|
64
65
|
internal.log(Code.Config, Severity.Warning, e ? e.name : null);
|
|
65
66
|
}
|
|
66
67
|
}
|
|
@@ -71,39 +72,40 @@ export function clone(v: Syntax[]): Syntax[] {
|
|
|
71
72
|
|
|
72
73
|
export function compute(): void {
|
|
73
74
|
try {
|
|
74
|
-
for (
|
|
75
|
-
|
|
76
|
-
if (validation[key]
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (value) {
|
|
75
|
+
for (const v in variables) {
|
|
76
|
+
const key = Number.parseInt(v);
|
|
77
|
+
if (validation[key] === Constant.Empty || document.querySelector(validation[key])) {
|
|
78
|
+
const variableData = variables[key];
|
|
79
|
+
for (const v in variableData) {
|
|
80
|
+
const variableKey = Number.parseInt(v);
|
|
81
|
+
const value = str(evaluate(clone(variableData[variableKey])));
|
|
82
|
+
if (value) {
|
|
83
83
|
update(key, variableKey, value);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
for (
|
|
87
|
+
const selectorData = selectors[key];
|
|
88
|
+
for (const s in selectorData) {
|
|
89
89
|
let shouldMask = false;
|
|
90
|
-
|
|
90
|
+
const selectorKey = Number.parseInt(s);
|
|
91
91
|
let selector = selectorData[selectorKey];
|
|
92
|
-
if (selector.startsWith(Constant.At)){
|
|
92
|
+
if (selector.startsWith(Constant.At)) {
|
|
93
93
|
shouldMask = true;
|
|
94
94
|
selector = selector.slice(1);
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
const nodes = document.querySelectorAll(selector) as NodeListOf<HTMLElement>;
|
|
97
97
|
if (nodes) {
|
|
98
|
-
|
|
98
|
+
const text = Array.from(nodes)
|
|
99
|
+
.map((e) => e.textContent)
|
|
100
|
+
.join(Constant.Seperator);
|
|
99
101
|
update(key, selectorKey, (shouldMask ? hash(text).trim() : text).slice(0, Setting.ExtractLimit));
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
|
|
104
|
-
for (
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
const hashData = hashes[key];
|
|
106
|
+
for (const h in hashData) {
|
|
107
|
+
const hashKey = Number.parseInt(h);
|
|
108
|
+
const content = hashText(hashData[hashKey]).trim().slice(0, Setting.ExtractLimit);
|
|
107
109
|
update(key, hashKey, content);
|
|
108
110
|
}
|
|
109
111
|
}
|
|
@@ -112,8 +114,9 @@ export function compute(): void {
|
|
|
112
114
|
if (keys.size > 0) {
|
|
113
115
|
encode(Event.Extract);
|
|
114
116
|
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
internal.log(Code.Selector, Severity.Warning, e ? e.name : null);
|
|
115
119
|
}
|
|
116
|
-
catch (e) { internal.log(Code.Selector, Severity.Warning, e ? e.name : null); }
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
export function reset(): void {
|
|
@@ -121,15 +124,13 @@ export function reset(): void {
|
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
export function update(key: number, subkey: number, value: string): void {
|
|
124
|
-
|
|
127
|
+
let update = false;
|
|
125
128
|
if (!(key in data)) {
|
|
126
129
|
data[key] = {};
|
|
127
130
|
update = true;
|
|
128
131
|
}
|
|
129
|
-
|
|
130
|
-
if (!isEmpty(hashes[key])
|
|
131
|
-
&& (!(subkey in data[key]) || data[key][subkey] != value))
|
|
132
|
-
{
|
|
132
|
+
|
|
133
|
+
if (!isEmpty(hashes[key]) && (!(subkey in data[key]) || data[key][subkey] !== value)) {
|
|
133
134
|
update = true;
|
|
134
135
|
}
|
|
135
136
|
|
|
@@ -142,21 +143,21 @@ export function update(key: number, subkey: number, value: string): void {
|
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
export function stop(): void {
|
|
145
|
-
|
|
146
|
+
reset();
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
function parse(variable: string): Syntax[] {
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
const syntax: Syntax[] = [];
|
|
151
|
+
const parts = variable.split(Constant.Dot);
|
|
151
152
|
while (parts.length > 0) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
const part = parts.shift();
|
|
154
|
+
const arrayStart = part.indexOf(Constant.ArrayStart);
|
|
155
|
+
const conditionStart = part.indexOf(Constant.ConditionStart);
|
|
156
|
+
const conditionEnd = part.indexOf(Constant.ConditionEnd);
|
|
156
157
|
syntax.push({
|
|
157
|
-
name
|
|
158
|
-
type
|
|
159
|
-
condition
|
|
158
|
+
name: arrayStart > 0 ? part.slice(0, arrayStart) : conditionStart > 0 ? part.slice(0, conditionStart) : part,
|
|
159
|
+
type: arrayStart > 0 ? Type.Array : conditionStart > 0 ? Type.Object : Type.Simple,
|
|
160
|
+
condition: conditionStart > 0 ? part.slice(conditionStart + 1, conditionEnd) : null,
|
|
160
161
|
});
|
|
161
162
|
}
|
|
162
163
|
|
|
@@ -166,26 +167,32 @@ function parse(variable: string): Syntax[] {
|
|
|
166
167
|
// The function below takes in a variable name in following format: "a.b.c" and safely evaluates its value in javascript context
|
|
167
168
|
// For instance, for a.b.c, it will first check window["a"]. If it exists, it will recursively look at: window["a"]["b"] and finally,
|
|
168
169
|
// return the value for window["a"]["b"]["c"].
|
|
170
|
+
// biome-ignore lint/complexity/noBannedTypes: type of base is intentionally generic
|
|
171
|
+
// biome-ignore lint/suspicious/noExplicitAny: type of return value isn't known
|
|
169
172
|
function evaluate(variable: Syntax[], base: Object = window): any {
|
|
170
|
-
if (variable.length
|
|
171
|
-
|
|
173
|
+
if (variable.length === 0) {
|
|
174
|
+
return base;
|
|
175
|
+
}
|
|
176
|
+
const part = variable.shift();
|
|
177
|
+
// biome-ignore lint/suspicious/noImplicitAnyLet: type of return value isn't known
|
|
172
178
|
let output;
|
|
173
|
-
if (base
|
|
174
|
-
|
|
179
|
+
if (base?.[part.name]) {
|
|
180
|
+
const obj = base[part.name];
|
|
175
181
|
if (part.type !== Type.Array && match(obj, part.condition)) {
|
|
176
182
|
output = evaluate(variable, obj);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
for (var value of obj) {
|
|
183
|
+
} else if (Array.isArray(obj)) {
|
|
184
|
+
const filtered = [];
|
|
185
|
+
for (const value of obj) {
|
|
181
186
|
if (match(value, part.condition)) {
|
|
182
|
-
|
|
183
|
-
if (op) {
|
|
187
|
+
const op = evaluate(variable, value);
|
|
188
|
+
if (op) {
|
|
189
|
+
filtered.push(op);
|
|
190
|
+
}
|
|
184
191
|
}
|
|
185
192
|
}
|
|
186
193
|
output = filtered;
|
|
187
194
|
}
|
|
188
|
-
|
|
195
|
+
|
|
189
196
|
return output;
|
|
190
197
|
}
|
|
191
198
|
|
|
@@ -197,15 +204,17 @@ function str(input: string): string {
|
|
|
197
204
|
return input ? JSON.stringify(input).slice(0, Setting.ExtractLimit) : input;
|
|
198
205
|
}
|
|
199
206
|
|
|
207
|
+
// biome-ignore lint/complexity/noBannedTypes: type of base is intentionally generic
|
|
200
208
|
function match(base: Object, condition: string): boolean {
|
|
201
209
|
if (condition) {
|
|
202
|
-
|
|
203
|
-
return prop.length > 1 ? base[prop[0]]
|
|
210
|
+
const prop = condition.split(":");
|
|
211
|
+
return prop.length > 1 ? base[prop[0]] === prop[1] : base[prop[0]];
|
|
204
212
|
}
|
|
205
213
|
|
|
206
214
|
return true;
|
|
207
215
|
}
|
|
208
216
|
|
|
217
|
+
// biome-ignore lint/complexity/noBannedTypes: type of obj is intentionally generic
|
|
209
218
|
function isEmpty(obj: Object): boolean {
|
|
210
|
-
return Object.keys(obj).length
|
|
219
|
+
return Object.keys(obj).length === 0;
|
|
211
220
|
}
|
package/src/data/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import type { Module } from "@clarity-types/core";
|
|
1
2
|
import measure from "@src/core/measure";
|
|
2
3
|
import * as baseline from "@src/data/baseline";
|
|
3
|
-
import * as envelope from "@src/data/envelope";
|
|
4
4
|
import * as dimension from "@src/data/dimension";
|
|
5
|
+
import * as envelope from "@src/data/envelope";
|
|
6
|
+
import * as extract from "@src/data/extract";
|
|
7
|
+
import * as limit from "@src/data/limit";
|
|
5
8
|
import * as metadata from "@src/data/metadata";
|
|
6
|
-
import { Module } from "@clarity-types/core";
|
|
7
9
|
import * as metric from "@src/data/metric";
|
|
8
10
|
import * as ping from "@src/data/ping";
|
|
9
|
-
import * as limit from "@src/data/limit";
|
|
10
11
|
import * as summary from "@src/data/summary";
|
|
11
12
|
import * as upgrade from "@src/data/upgrade";
|
|
12
13
|
import * as upload from "@src/data/upload";
|
|
13
14
|
import * as variable from "@src/data/variable";
|
|
14
|
-
import * as extract from "@src/data/extract";
|
|
15
15
|
export { event } from "@src/data/custom";
|
|
16
16
|
export { consent, metadata } from "@src/data/metadata";
|
|
17
17
|
export { upgrade } from "@src/data/upgrade";
|
|
@@ -23,7 +23,9 @@ const modules: Module[] = [baseline, dimension, variable, limit, summary, metada
|
|
|
23
23
|
export function start(): void {
|
|
24
24
|
// Metric needs to be initialized before we can start measuring. so metric is not wrapped in measure
|
|
25
25
|
metric.start();
|
|
26
|
-
|
|
26
|
+
for (const x of modules) {
|
|
27
|
+
measure(x.start)();
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export function stop(): void {
|
|
@@ -31,7 +33,9 @@ export function stop(): void {
|
|
|
31
33
|
// The ordering below should respect inter-module dependency.
|
|
32
34
|
// E.g. if upgrade depends on upload, then upgrade needs to end before upload.
|
|
33
35
|
// Similarly, if upload depends on metadata, upload needs to end before metadata.
|
|
34
|
-
modules.slice().reverse()
|
|
36
|
+
for (const x of modules.slice().reverse()) {
|
|
37
|
+
measure(x.stop)();
|
|
38
|
+
}
|
|
35
39
|
metric.stop();
|
|
36
40
|
}
|
|
37
41
|
|
package/src/data/limit.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Check, Event, LimitData, Setting } from "@clarity-types/data";
|
|
1
|
+
import { Check, Event, type LimitData, Setting } from "@clarity-types/data";
|
|
2
2
|
import * as clarity from "@src/clarity";
|
|
3
3
|
import { time } from "@src/core/time";
|
|
4
4
|
import * as envelope from "@src/data/envelope";
|