clarity-js 0.8.5-beta → 0.8.6-beta

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/build/clarity.js CHANGED
@@ -12,39 +12,34 @@ var dom = /*#__PURE__*/Object.freeze({
12
12
  get iframe () { return iframe; },
13
13
  get iframeContent () { return iframeContent; },
14
14
  get lookup () { return lookup; },
15
- get parse () { return parse$1; },
15
+ get parse () { return parse; },
16
16
  get removeIFrame () { return removeIFrame; },
17
17
  get sameorigin () { return sameorigin; },
18
- get start () { return start$i; },
19
- get stop () { return stop$g; },
20
- get update () { return update$1; },
18
+ get start () { return start$j; },
19
+ get stop () { return stop$h; },
20
+ get update () { return update; },
21
21
  get updates () { return updates$2; }
22
22
  });
23
23
  var upload$1 = /*#__PURE__*/Object.freeze({
24
24
  __proto__: null,
25
25
  get queue () { return queue; },
26
- get start () { return start$f; },
27
- get stop () { return stop$d; },
26
+ get start () { return start$g; },
27
+ get stop () { return stop$e; },
28
28
  get track () { return track$1; }
29
29
  });
30
- var extract = /*#__PURE__*/Object.freeze({
30
+ var upgrade$1 = /*#__PURE__*/Object.freeze({
31
31
  __proto__: null,
32
- get clone () { return clone; },
33
- get compute () { return compute$4; },
34
32
  get data () { return data$5; },
35
- get keys () { return keys; },
36
- get reset () { return reset$4; },
37
- get start () { return start$c; },
33
+ get start () { return start$b; },
38
34
  get stop () { return stop$b; },
39
- get trigger () { return trigger$1; },
40
- get update () { return update; }
35
+ get upgrade () { return upgrade; }
41
36
  });
42
37
  var limit = /*#__PURE__*/Object.freeze({
43
38
  __proto__: null,
44
39
  get check () { return check$2; },
45
40
  get compute () { return compute$3; },
46
41
  get data () { return data$4; },
47
- get start () { return start$b; },
42
+ get start () { return start$a; },
48
43
  get stop () { return stop$a; },
49
44
  get trigger () { return trigger; }
50
45
  });
@@ -54,7 +49,7 @@ var dimension = /*#__PURE__*/Object.freeze({
54
49
  get data () { return data$3; },
55
50
  get log () { return log; },
56
51
  get reset () { return reset$3; },
57
- get start () { return start$a; },
52
+ get start () { return start$9; },
58
53
  get stop () { return stop$9; },
59
54
  get updates () { return updates; }
60
55
  });
@@ -70,14 +65,14 @@ var metadata$1 = /*#__PURE__*/Object.freeze({
70
65
  get metadata () { return metadata; },
71
66
  get save () { return save; },
72
67
  get shortid () { return shortid; },
73
- get start () { return start$9; },
68
+ get start () { return start$8; },
74
69
  get stop () { return stop$8; }
75
70
  });
76
71
  var envelope$1 = /*#__PURE__*/Object.freeze({
77
72
  __proto__: null,
78
73
  get data () { return data$1; },
79
74
  get envelope () { return envelope; },
80
- get start () { return start$8; },
75
+ get start () { return start$7; },
81
76
  get stop () { return stop$7; }
82
77
  });
83
78
  var clarity = /*#__PURE__*/Object.freeze({
@@ -139,6 +134,7 @@ var config$2 = {
139
134
  projectId: null,
140
135
  delay: 1 * 1000 /* Time.Second */,
141
136
  lean: false,
137
+ lite: false,
142
138
  track: true,
143
139
  content: true,
144
140
  drop: [],
@@ -189,7 +185,7 @@ function stop$F() {
189
185
  startTime = 0;
190
186
  }
191
187
 
192
- var version$1 = "0.8.5-beta";
188
+ var version$1 = "0.8.6-beta";
193
189
 
194
190
  // tslint:disable: no-bitwise
195
191
  function hash (input, precision) {
@@ -715,44 +711,6 @@ var summary = /*#__PURE__*/Object.freeze({
715
711
  track: track$7
716
712
  });
717
713
 
718
- var data$f = null;
719
- function start$D() {
720
- if (!config$2.lean && config$2.upgrade) {
721
- config$2.upgrade("Config" /* Constant.Config */);
722
- }
723
- data$f = null;
724
- }
725
- // Following call will upgrade the session from lean mode into the full mode retroactively from the start of the page.
726
- // As part of the lean mode, we do not send back any layout information - including discovery of DOM and mutations.
727
- // However, if there's a need for full fidelity playback, calling this function will disable lean mode
728
- // and send all backed up layout events to the server.
729
- function upgrade(key) {
730
- // Upgrade only if Clarity was successfully activated on the page
731
- if (active() && config$2.lean) {
732
- config$2.lean = false;
733
- data$f = { key: key };
734
- // Update metadata to track we have upgraded this session
735
- callback();
736
- save();
737
- // Callback upgrade handler, if configured
738
- if (config$2.upgrade) {
739
- config$2.upgrade(key);
740
- }
741
- encode$1(3 /* Event.Upgrade */);
742
- }
743
- }
744
- function stop$A() {
745
- data$f = null;
746
- }
747
-
748
- var upgrade$1 = /*#__PURE__*/Object.freeze({
749
- __proto__: null,
750
- get data () { return data$f; },
751
- start: start$D,
752
- stop: stop$A,
753
- upgrade: upgrade
754
- });
755
-
756
714
  /******************************************************************************
757
715
  Copyright (c) Microsoft Corporation.
758
716
 
@@ -808,8 +766,66 @@ function __generator(thisArg, body) {
808
766
  }
809
767
  }
810
768
 
811
- var data$e = null;
812
- function start$C() {
769
+ var supported$1 = "CompressionStream" /* Constant.CompressionStream */ in window;
770
+ function compress (input) {
771
+ return __awaiter(this, void 0, void 0, function () {
772
+ var stream, _a;
773
+ return __generator(this, function (_c) {
774
+ switch (_c.label) {
775
+ case 0:
776
+ _c.trys.push([0, 3, , 4]);
777
+ if (!supported$1) return [3 /*break*/, 2];
778
+ stream = new ReadableStream({ start: function (controller) {
779
+ return __awaiter(this, void 0, void 0, function () {
780
+ return __generator(this, function (_a) {
781
+ controller.enqueue(input);
782
+ controller.close();
783
+ return [2 /*return*/];
784
+ });
785
+ });
786
+ } }).pipeThrough(new TextEncoderStream()).pipeThrough(new window["CompressionStream" /* Constant.CompressionStream */]("gzip"));
787
+ _a = Uint8Array.bind;
788
+ return [4 /*yield*/, read(stream)];
789
+ case 1: return [2 /*return*/, new (_a.apply(Uint8Array, [void 0, _c.sent()]))()];
790
+ case 2: return [3 /*break*/, 4];
791
+ case 3:
792
+ _c.sent();
793
+ return [3 /*break*/, 4];
794
+ case 4: return [2 /*return*/, null];
795
+ }
796
+ });
797
+ });
798
+ }
799
+ function read(stream) {
800
+ return __awaiter(this, void 0, void 0, function () {
801
+ var reader, chunks, done, value;
802
+ var _a;
803
+ return __generator(this, function (_b) {
804
+ switch (_b.label) {
805
+ case 0:
806
+ reader = stream.getReader();
807
+ chunks = [];
808
+ done = false;
809
+ value = [];
810
+ _b.label = 1;
811
+ case 1:
812
+ if (!!done) return [3 /*break*/, 3];
813
+ return [4 /*yield*/, reader.read()];
814
+ case 2:
815
+ (_a = _b.sent(), done = _a.done, value = _a.value);
816
+ if (done) {
817
+ return [2 /*return*/, chunks];
818
+ }
819
+ chunks.push.apply(chunks, value);
820
+ return [3 /*break*/, 1];
821
+ case 3: return [2 /*return*/, chunks];
822
+ }
823
+ });
824
+ });
825
+ }
826
+
827
+ var data$f = null;
828
+ function start$D() {
813
829
  reset$o();
814
830
  }
815
831
  function set(variable, value) {
@@ -856,22 +872,22 @@ function log$2(variable, value) {
856
872
  value &&
857
873
  typeof variable === "string" /* Constant.String */ &&
858
874
  variable.length < 255) {
859
- var validValues = variable in data$e ? data$e[variable] : [];
875
+ var validValues = variable in data$f ? data$f[variable] : [];
860
876
  for (var i = 0; i < value.length; i++) {
861
877
  if (typeof value[i] === "string" /* Constant.String */ && value[i].length < 255) {
862
878
  validValues.push(value[i]);
863
879
  }
864
880
  }
865
- data$e[variable] = validValues;
881
+ data$f[variable] = validValues;
866
882
  }
867
883
  }
868
884
  function compute$b() {
869
885
  encode$1(34 /* Event.Variable */);
870
886
  }
871
887
  function reset$o() {
872
- data$e = {};
888
+ data$f = {};
873
889
  }
874
- function stop$z() {
890
+ function stop$A() {
875
891
  reset$o();
876
892
  }
877
893
  function redact(input) {
@@ -907,349 +923,294 @@ function detect(input) {
907
923
  var variable = /*#__PURE__*/Object.freeze({
908
924
  __proto__: null,
909
925
  compute: compute$b,
910
- get data () { return data$e; },
926
+ get data () { return data$f; },
911
927
  identify: identify,
912
928
  reset: reset$o,
913
929
  set: set,
914
- start: start$C,
915
- stop: stop$z
930
+ start: start$D,
931
+ stop: stop$A
916
932
  });
917
933
 
918
- var supported$1 = "CompressionStream" /* Constant.CompressionStream */ in window;
919
- function compress (input) {
920
- return __awaiter(this, void 0, void 0, function () {
921
- var stream, _a;
922
- return __generator(this, function (_c) {
923
- switch (_c.label) {
924
- case 0:
925
- _c.trys.push([0, 3, , 4]);
926
- if (!supported$1) return [3 /*break*/, 2];
927
- stream = new ReadableStream({ start: function (controller) {
928
- return __awaiter(this, void 0, void 0, function () {
929
- return __generator(this, function (_a) {
930
- controller.enqueue(input);
931
- controller.close();
932
- return [2 /*return*/];
933
- });
934
- });
935
- } }).pipeThrough(new TextEncoderStream()).pipeThrough(new window["CompressionStream" /* Constant.CompressionStream */]("gzip"));
936
- _a = Uint8Array.bind;
937
- return [4 /*yield*/, read(stream)];
938
- case 1: return [2 /*return*/, new (_a.apply(Uint8Array, [void 0, _c.sent()]))()];
939
- case 2: return [3 /*break*/, 4];
940
- case 3:
941
- _c.sent();
942
- return [3 /*break*/, 4];
943
- case 4: return [2 /*return*/, null];
944
- }
945
- });
946
- });
947
- }
948
- function read(stream) {
949
- return __awaiter(this, void 0, void 0, function () {
950
- var reader, chunks, done, value;
951
- var _a;
952
- return __generator(this, function (_b) {
953
- switch (_b.label) {
954
- case 0:
955
- reader = stream.getReader();
956
- chunks = [];
957
- done = false;
958
- value = [];
959
- _b.label = 1;
960
- case 1:
961
- if (!!done) return [3 /*break*/, 3];
962
- return [4 /*yield*/, reader.read()];
963
- case 2:
964
- (_a = _b.sent(), done = _a.done, value = _a.value);
965
- if (done) {
966
- return [2 /*return*/, chunks];
967
- }
968
- chunks.push.apply(chunks, value);
969
- return [3 /*break*/, 1];
970
- case 3: return [2 /*return*/, chunks];
971
- }
972
- });
973
- });
974
- }
975
-
976
- var signalCallback = null;
977
- function signal(cb) {
978
- signalCallback = cb;
979
- }
980
- function parseSignals(signalsPayload) {
981
- try {
982
- var parsedSignals = JSON.parse(signalsPayload);
983
- return parsedSignals;
984
- }
985
- catch (_a) {
986
- return [];
987
- }
934
+ var data$e = {};
935
+ var keys = new Set();
936
+ var variables = {};
937
+ var selectors = {};
938
+ var hashes = {};
939
+ var validation = {};
940
+ function start$C() {
941
+ reset$n();
988
942
  }
989
- function signalsEvent(signalsPayload) {
943
+ // Input string is of the following form:
944
+ // EXTRACT 101|element { "1": ".class1", "2": "~window.a.b", "3": "!abc"}
945
+ // if element is present on the page it will set up event 101 to grab the contents of the class1 selector into component 1,
946
+ // the javascript evaluated contents of window.a.b into component 2,
947
+ // and the contents of Clarity's hash abc into component 3
948
+ function trigger$2(input) {
990
949
  try {
991
- if (!signalCallback) {
992
- return;
950
+ var parts = input && input.length > 0 ? input.split(/ (.*)/) : ["" /* Constant.Empty */];
951
+ var keyparts = parts[0].split(/\|(.*)/);
952
+ var key = parseInt(keyparts[0]);
953
+ var element = keyparts.length > 1 ? keyparts[1] : "" /* Constant.Empty */;
954
+ var values = parts.length > 1 ? JSON.parse(parts[1]) : {};
955
+ variables[key] = {};
956
+ selectors[key] = {};
957
+ hashes[key] = {};
958
+ validation[key] = element;
959
+ for (var v in values) {
960
+ // values is a set of strings for proper JSON parsing, but it's more efficient
961
+ // to interact with them as numbers
962
+ var id = parseInt(v);
963
+ var value = values[v];
964
+ var source = 2 /* ExtractSource.Text */;
965
+ if (value.startsWith("~" /* Constant.Tilde */)) {
966
+ source = 0 /* ExtractSource.Javascript */;
967
+ }
968
+ else if (value.startsWith("!" /* Constant.Bang */)) {
969
+ source = 4 /* ExtractSource.Hash */;
970
+ }
971
+ switch (source) {
972
+ case 0 /* ExtractSource.Javascript */:
973
+ var variable = value.slice(1);
974
+ variables[key][id] = parse$1(variable);
975
+ break;
976
+ case 2 /* ExtractSource.Text */:
977
+ selectors[key][id] = value;
978
+ break;
979
+ case 4 /* ExtractSource.Hash */:
980
+ var hash_1 = value.slice(1);
981
+ hashes[key][id] = hash_1;
982
+ break;
983
+ }
993
984
  }
994
- var signals = parseSignals(signalsPayload);
995
- signals.forEach(function (signal) {
996
- signalCallback(signal);
997
- });
998
985
  }
999
- catch (_a) {
1000
- //do nothing
986
+ catch (e) {
987
+ log$1(8 /* Code.Config */, 1 /* Severity.Warning */, e ? e.name : null);
1001
988
  }
1002
989
  }
1003
-
1004
- var modules$1 = [baseline, dimension, variable, limit, summary, metadata$1, envelope$1, upload$1, ping$1, upgrade$1, extract];
1005
- function start$B() {
1006
- // Metric needs to be initialized before we can start measuring. so metric is not wrapped in measure
1007
- start$G();
1008
- modules$1.forEach(function (x) { return measure(x.start)(); });
1009
- }
1010
- function stop$y() {
1011
- // Stop modules in the reverse order of their initialization
1012
- // The ordering below should respect inter-module dependency.
1013
- // E.g. if upgrade depends on upload, then upgrade needs to end before upload.
1014
- // Similarly, if upload depends on metadata, upload needs to end before metadata.
1015
- modules$1.slice().reverse().forEach(function (x) { return measure(x.stop)(); });
1016
- stop$D();
990
+ function clone$1(v) {
991
+ return JSON.parse(JSON.stringify(v));
1017
992
  }
1018
993
  function compute$a() {
1019
- compute$b();
1020
- compute$e();
1021
- compute$2();
1022
- compute$d();
1023
- compute$c();
1024
- compute$3();
1025
- compute$4();
1026
- }
1027
-
1028
- var history$5 = [];
1029
- var data$d;
1030
- function start$A() {
1031
- history$5 = [];
1032
- max(26 /* Metric.Automation */, navigator.webdriver ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */);
1033
994
  try {
1034
- // some sites (unintentionally) overwrite the window.self property, so we also check for the main window object
1035
- max(31 /* Metric.Iframed */, window.top == window.self || window.top == window ? 1 /* IframeStatus.TopFrame */ : 2 /* IframeStatus.Iframe */);
995
+ for (var v in variables) {
996
+ var key = parseInt(v);
997
+ if (validation[key] == "" /* Constant.Empty */ || document.querySelector(validation[key])) {
998
+ var variableData = variables[key];
999
+ for (var v_1 in variableData) {
1000
+ var variableKey = parseInt(v_1);
1001
+ var value = str$1(evaluate(clone$1(variableData[variableKey])));
1002
+ if (value) {
1003
+ update$1(key, variableKey, value);
1004
+ }
1005
+ }
1006
+ var selectorData = selectors[key];
1007
+ for (var s in selectorData) {
1008
+ var shouldMask = false;
1009
+ var selectorKey = parseInt(s);
1010
+ var selector = selectorData[selectorKey];
1011
+ if (selector.startsWith("@" /* Constant.At */)) {
1012
+ shouldMask = true;
1013
+ selector = selector.slice(1);
1014
+ }
1015
+ var nodes = document.querySelectorAll(selector);
1016
+ if (nodes) {
1017
+ var text = Array.from(nodes).map(function (e) { return e.textContent; }).join("<SEP>" /* Constant.Seperator */);
1018
+ update$1(key, selectorKey, (shouldMask ? hash(text).trim() : text).slice(0, 10000 /* Setting.ExtractLimit */));
1019
+ }
1020
+ }
1021
+ var hashData = hashes[key];
1022
+ for (var h in hashData) {
1023
+ var hashKey = parseInt(h);
1024
+ var content = hashText(hashData[hashKey]).trim().slice(0, 10000 /* Setting.ExtractLimit */);
1025
+ update$1(key, hashKey, content);
1026
+ }
1027
+ }
1028
+ }
1029
+ if (keys.size > 0) {
1030
+ encode$1(40 /* Event.Extract */);
1031
+ }
1036
1032
  }
1037
- catch (ex) {
1038
- max(31 /* Metric.Iframed */, 0 /* IframeStatus.Unknown */);
1033
+ catch (e) {
1034
+ log$1(5 /* Code.Selector */, 1 /* Severity.Warning */, e ? e.name : null);
1039
1035
  }
1040
1036
  }
1041
- function check$4(id, target, input) {
1042
- // Compute hash for fraud detection, if enabled. Hash is computed only if input meets the minimum length criteria
1043
- if (config$2.fraud && id !== null && input && input.length >= 5 /* Setting.WordLength */) {
1044
- data$d = { id: id, target: target, checksum: hash(input, 28 /* Setting.ChecksumPrecision */) };
1045
- // Only encode this event if we haven't already reported this hash
1046
- if (history$5.indexOf(data$d.checksum) < 0) {
1047
- history$5.push(data$d.checksum);
1048
- encode$2(41 /* Event.Fraud */);
1049
- }
1050
- }
1037
+ function reset$n() {
1038
+ keys.clear();
1051
1039
  }
1052
-
1053
- // Track the start time to be able to compute duration at the end of the task
1054
- var idleTimeout = 5000;
1055
- var tracker = {};
1056
- var queuedTasks = [];
1057
- var activeTask = null;
1058
- var pauseTask = null;
1059
- var resumeResolve = null;
1060
- function pause$1() {
1061
- if (pauseTask === null) {
1062
- pauseTask = new Promise(function (resolve) {
1063
- resumeResolve = resolve;
1064
- });
1040
+ function update$1(key, subkey, value) {
1041
+ var update = false;
1042
+ if (!(key in data$e)) {
1043
+ data$e[key] = {};
1044
+ update = true;
1065
1045
  }
1066
- }
1067
- function resume$1() {
1068
- if (pauseTask) {
1069
- resumeResolve();
1070
- pauseTask = null;
1071
- if (activeTask === null) {
1072
- run();
1073
- }
1046
+ if (!isEmpty(hashes[key])
1047
+ && (!(subkey in data$e[key]) || data$e[key][subkey] != value)) {
1048
+ update = true;
1074
1049
  }
1050
+ data$e[key][subkey] = value;
1051
+ if (update) {
1052
+ keys.add(key);
1053
+ }
1054
+ return;
1075
1055
  }
1076
- function reset$n() {
1077
- tracker = {};
1078
- queuedTasks = [];
1079
- activeTask = null;
1080
- pauseTask = null;
1056
+ function stop$z() {
1057
+ reset$n();
1081
1058
  }
1082
- function schedule$1(task, priority) {
1083
- if (priority === void 0) { priority = 0 /* Priority.Normal */; }
1084
- return __awaiter(this, void 0, void 0, function () {
1085
- var _i, queuedTasks_1, q, promise;
1086
- return __generator(this, function (_a) {
1087
- // If this task is already scheduled, skip it
1088
- for (_i = 0, queuedTasks_1 = queuedTasks; _i < queuedTasks_1.length; _i++) {
1089
- q = queuedTasks_1[_i];
1090
- if (q.task === task) {
1091
- return [2 /*return*/];
1092
- }
1093
- }
1094
- promise = new Promise(function (resolve) {
1095
- var insert = priority === 1 /* Priority.High */ ? "unshift" : "push";
1096
- // Queue this task for asynchronous execution later
1097
- // We also store a unique page identifier (id) along with the task to ensure
1098
- // ensure that we do not accidentally execute this task in context of a different page
1099
- queuedTasks[insert]({ task: task, resolve: resolve, id: id() });
1100
- });
1101
- // If there is no active task running, and Clarity is not in pause state,
1102
- // invoke the first task in the queue synchronously. This ensures that we don't yield the thread during unload event
1103
- if (activeTask === null && pauseTask === null) {
1104
- run();
1105
- }
1106
- return [2 /*return*/, promise];
1059
+ function parse$1(variable) {
1060
+ var syntax = [];
1061
+ var parts = variable.split("." /* Constant.Dot */);
1062
+ while (parts.length > 0) {
1063
+ var part = parts.shift();
1064
+ var arrayStart = part.indexOf("[" /* Constant.ArrayStart */);
1065
+ var conditionStart = part.indexOf("{" /* Constant.ConditionStart */);
1066
+ var conditionEnd = part.indexOf("}" /* Constant.ConditionEnd */);
1067
+ syntax.push({
1068
+ name: arrayStart > 0 ? part.slice(0, arrayStart) : (conditionStart > 0 ? part.slice(0, conditionStart) : part),
1069
+ type: arrayStart > 0 ? 1 /* Type.Array */ : (conditionStart > 0 ? 2 /* Type.Object */ : 3 /* Type.Simple */),
1070
+ condition: conditionStart > 0 ? part.slice(conditionStart + 1, conditionEnd) : null
1107
1071
  });
1108
- });
1072
+ }
1073
+ return syntax;
1109
1074
  }
1110
- function run() {
1111
- var entry = queuedTasks.shift();
1112
- if (entry) {
1113
- activeTask = entry;
1114
- entry.task().then(function () {
1115
- // Bail out if the context in which this task was operating is different from the current page
1116
- // An example scenario where task could span across pages is Single Page Applications (SPA)
1117
- // A task that started on page #1, but completes on page #2
1118
- if (entry.id !== id()) {
1119
- return;
1120
- }
1121
- entry.resolve();
1122
- activeTask = null; // Reset active task back to null now that the promise is resolved
1123
- run();
1124
- }).catch(function (error) {
1125
- // If one of the scheduled tasks failed, log, recover and continue processing rest of the tasks
1126
- if (entry.id !== id()) {
1127
- return;
1128
- }
1129
- if (error) {
1130
- log$1(0 /* Code.RunTask */, 1 /* Severity.Warning */, error.name, error.message, error.stack);
1075
+ // The function below takes in a variable name in following format: "a.b.c" and safely evaluates its value in javascript context
1076
+ // 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,
1077
+ // return the value for window["a"]["b"]["c"].
1078
+ function evaluate(variable, base) {
1079
+ if (base === void 0) { base = window; }
1080
+ if (variable.length == 0) {
1081
+ return base;
1082
+ }
1083
+ var part = variable.shift();
1084
+ var output;
1085
+ if (base && base[part.name]) {
1086
+ var obj = base[part.name];
1087
+ if (part.type !== 1 /* Type.Array */ && match(obj, part.condition)) {
1088
+ output = evaluate(variable, obj);
1089
+ }
1090
+ else if (Array.isArray(obj)) {
1091
+ var filtered = [];
1092
+ for (var _i = 0, obj_1 = obj; _i < obj_1.length; _i++) {
1093
+ var value = obj_1[_i];
1094
+ if (match(value, part.condition)) {
1095
+ var op = evaluate(variable, value);
1096
+ if (op) {
1097
+ filtered.push(op);
1098
+ }
1099
+ }
1131
1100
  }
1132
- activeTask = null;
1133
- run();
1134
- });
1101
+ output = filtered;
1102
+ }
1103
+ return output;
1135
1104
  }
1105
+ return null;
1136
1106
  }
1137
- function state$a(timer) {
1138
- var id = key(timer);
1139
- if (id in tracker) {
1140
- var elapsed = performance.now() - tracker[id].start;
1141
- return (elapsed > tracker[id].yield) ? 0 /* Task.Wait */ : 1 /* Task.Run */;
1107
+ function str$1(input) {
1108
+ // Automatically trim string to max of Setting.ExtractLimit to avoid fetching long strings
1109
+ return input ? JSON.stringify(input).slice(0, 10000 /* Setting.ExtractLimit */) : input;
1110
+ }
1111
+ function match(base, condition) {
1112
+ if (condition) {
1113
+ var prop = condition.split(":");
1114
+ return prop.length > 1 ? base[prop[0]] == prop[1] : base[prop[0]];
1142
1115
  }
1143
- // If this task is no longer being tracked, send stop message to the caller
1144
- return 2 /* Task.Stop */;
1116
+ return true;
1145
1117
  }
1146
- function start$z(timer) {
1147
- tracker[key(timer)] = { start: performance.now(), calls: 0, yield: 30 /* Setting.LongTask */ };
1118
+ function isEmpty(obj) {
1119
+ return Object.keys(obj).length == 0;
1148
1120
  }
1149
- function restart$2(timer) {
1150
- var id = key(timer);
1151
- if (tracker && tracker[id]) {
1152
- var c = tracker[id].calls;
1153
- var y = tracker[id].yield;
1154
- start$z(timer);
1155
- tracker[id].calls = c + 1;
1156
- tracker[id].yield = y;
1157
- }
1121
+
1122
+ var extract = /*#__PURE__*/Object.freeze({
1123
+ __proto__: null,
1124
+ clone: clone$1,
1125
+ compute: compute$a,
1126
+ data: data$e,
1127
+ keys: keys,
1128
+ reset: reset$n,
1129
+ start: start$C,
1130
+ stop: stop$z,
1131
+ trigger: trigger$2,
1132
+ update: update$1
1133
+ });
1134
+
1135
+ var signalCallback = null;
1136
+ function signal(cb) {
1137
+ signalCallback = cb;
1158
1138
  }
1159
- function stop$x(timer) {
1160
- var end = performance.now();
1161
- var id = key(timer);
1162
- var duration = end - tracker[id].start;
1163
- sum(timer.cost, duration);
1164
- count$1(5 /* Metric.InvokeCount */);
1165
- // For the first execution, which is synchronous, time is automatically counted towards TotalDuration.
1166
- // However, for subsequent asynchronous runs, we need to manually update TotalDuration metric.
1167
- if (tracker[id].calls > 0) {
1168
- sum(4 /* Metric.TotalCost */, duration);
1139
+ function parseSignals(signalsPayload) {
1140
+ try {
1141
+ var parsedSignals = JSON.parse(signalsPayload);
1142
+ return parsedSignals;
1143
+ }
1144
+ catch (_a) {
1145
+ return [];
1169
1146
  }
1170
1147
  }
1171
- function suspend$1(timer) {
1172
- var _a;
1173
- return __awaiter(this, void 0, void 0, function () {
1174
- var id, _b;
1175
- return __generator(this, function (_c) {
1176
- switch (_c.label) {
1177
- case 0:
1178
- id = key(timer);
1179
- if (!(id in tracker)) return [3 /*break*/, 2];
1180
- stop$x(timer);
1181
- // some customer polyfills for requestIdleCallback return null
1182
- _b = tracker[id];
1183
- return [4 /*yield*/, wait()];
1184
- case 1:
1185
- // some customer polyfills for requestIdleCallback return null
1186
- _b.yield = ((_a = (_c.sent())) === null || _a === void 0 ? void 0 : _a.timeRemaining()) || 30 /* Setting.LongTask */;
1187
- restart$2(timer);
1188
- _c.label = 2;
1189
- case 2:
1190
- // After we are done with suspending task, ensure that we are still operating in the right context
1191
- // If the task is still being tracked, continue running the task, otherwise ask caller to stop execution
1192
- return [2 /*return*/, id in tracker ? 1 /* Task.Run */ : 2 /* Task.Stop */];
1193
- }
1148
+ function signalsEvent(signalsPayload) {
1149
+ try {
1150
+ if (!signalCallback) {
1151
+ return;
1152
+ }
1153
+ var signals = parseSignals(signalsPayload);
1154
+ signals.forEach(function (signal) {
1155
+ signalCallback(signal);
1194
1156
  });
1195
- });
1157
+ }
1158
+ catch (_a) {
1159
+ //do nothing
1160
+ }
1196
1161
  }
1197
- function key(timer) {
1198
- return "".concat(timer.id, ".").concat(timer.cost);
1162
+
1163
+ var modules$1 = [baseline, dimension, variable, limit, summary, metadata$1, envelope$1, upload$1, ping$1, upgrade$1, extract];
1164
+ function start$B() {
1165
+ // Metric needs to be initialized before we can start measuring. so metric is not wrapped in measure
1166
+ start$G();
1167
+ modules$1.forEach(function (x) { return measure(x.start)(); });
1199
1168
  }
1200
- function wait() {
1201
- return __awaiter(this, void 0, void 0, function () {
1202
- return __generator(this, function (_a) {
1203
- switch (_a.label) {
1204
- case 0:
1205
- if (!pauseTask) return [3 /*break*/, 2];
1206
- return [4 /*yield*/, pauseTask];
1207
- case 1:
1208
- _a.sent();
1209
- _a.label = 2;
1210
- case 2: return [2 /*return*/, new Promise(function (resolve) {
1211
- requestIdleCallback(resolve, { timeout: idleTimeout });
1212
- })];
1213
- }
1214
- });
1215
- });
1169
+ function stop$y() {
1170
+ // Stop modules in the reverse order of their initialization
1171
+ // The ordering below should respect inter-module dependency.
1172
+ // E.g. if upgrade depends on upload, then upgrade needs to end before upload.
1173
+ // Similarly, if upload depends on metadata, upload needs to end before metadata.
1174
+ modules$1.slice().reverse().forEach(function (x) { return measure(x.stop)(); });
1175
+ stop$D();
1216
1176
  }
1217
- // Use native implementation of requestIdleCallback if it exists.
1218
- // Otherwise, fall back to a custom implementation using requestAnimationFrame & MessageChannel.
1219
- // While it's not possible to build a perfect polyfill given the nature of this API, the following code attempts to get close.
1220
- // Background context: requestAnimationFrame invokes the js code right before: style, layout and paint computation within the frame.
1221
- // This means, that any code that runs as part of requestAnimationFrame will by default be blocking in nature. Not what we want.
1222
- // For non-blocking behavior, We need to know when browser has finished painting. This can be accomplished in two different ways (hacks):
1223
- // (1) Use MessageChannel to pass the message, and browser will receive the message right after paint event has occured.
1224
- // (2) Use setTimeout call within requestAnimationFrame. This also works, but there's a risk that browser may throttle setTimeout calls.
1225
- // Given this information, we are currently using (1) from above. More information on (2) as well as some additional context is below:
1226
- // https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Performance_best_practices_for_Firefox_fe_engineers
1227
- function requestIdleCallbackPolyfill(callback, options) {
1228
- var startTime = performance.now();
1229
- var channel = new MessageChannel();
1230
- var incoming = channel.port1;
1231
- var outgoing = channel.port2;
1232
- incoming.onmessage = function (event) {
1233
- var currentTime = performance.now();
1234
- var elapsed = currentTime - startTime;
1235
- var duration = currentTime - event.data;
1236
- if (duration > 30 /* Setting.LongTask */ && elapsed < options.timeout) {
1237
- requestAnimationFrame(function () { outgoing.postMessage(currentTime); });
1238
- }
1239
- else {
1240
- var didTimeout_1 = elapsed > options.timeout;
1241
- callback({
1242
- didTimeout: didTimeout_1,
1243
- timeRemaining: function () { return didTimeout_1 ? 30 /* Setting.LongTask */ : Math.max(0, 30 /* Setting.LongTask */ - duration); }
1244
- });
1177
+ function compute$9() {
1178
+ compute$b();
1179
+ compute$e();
1180
+ compute$2();
1181
+ compute$d();
1182
+ compute$c();
1183
+ compute$3();
1184
+ compute$a();
1185
+ }
1186
+
1187
+ var history$5 = [];
1188
+ var data$d;
1189
+ function start$A() {
1190
+ history$5 = [];
1191
+ max(26 /* Metric.Automation */, navigator.webdriver ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */);
1192
+ try {
1193
+ // some sites (unintentionally) overwrite the window.self property, so we also check for the main window object
1194
+ max(31 /* Metric.Iframed */, window.top == window.self || window.top == window ? 1 /* IframeStatus.TopFrame */ : 2 /* IframeStatus.Iframe */);
1195
+ }
1196
+ catch (ex) {
1197
+ max(31 /* Metric.Iframed */, 0 /* IframeStatus.Unknown */);
1198
+ }
1199
+ }
1200
+ function check$4(id, target, input) {
1201
+ // Compute hash for fraud detection, if enabled. Hash is computed only if input meets the minimum length criteria
1202
+ if (config$2.fraud && id !== null && input && input.length >= 5 /* Setting.WordLength */) {
1203
+ data$d = { id: id, target: target, checksum: hash(input, 28 /* Setting.ChecksumPrecision */) };
1204
+ // Only encode this event if we haven't already reported this hash
1205
+ if (history$5.indexOf(data$d.checksum) < 0) {
1206
+ history$5.push(data$d.checksum);
1207
+ encode$2(41 /* Event.Fraud */);
1245
1208
  }
1246
- };
1247
- requestAnimationFrame(function () { outgoing.postMessage(performance.now()); });
1209
+ }
1248
1210
  }
1249
- var requestIdleCallback = window["requestIdleCallback"] || requestIdleCallbackPolyfill;
1250
1211
 
1251
- var state$9 = [];
1252
- function start$y() {
1212
+ var state$a = [];
1213
+ function start$z() {
1253
1214
  reset$m();
1254
1215
  }
1255
1216
  function observe$c(root) {
@@ -1261,14 +1222,14 @@ function recompute$8(evt) {
1261
1222
  if (element) {
1262
1223
  var value = element.value;
1263
1224
  var checksum = value && value.length >= 5 /* Setting.WordLength */ && config$2.fraud && "password,secret,pass,social,ssn,code,hidden" /* Mask.Exclude */.indexOf(element.type) === -1 ? hash(value, 28 /* Setting.ChecksumPrecision */) : "" /* Constant.Empty */;
1264
- state$9.push({ time: time(evt), event: 42 /* Event.Change */, data: { target: target(evt), type: element.type, value: value, checksum: checksum } });
1265
- schedule$1(encode$3.bind(this, 42 /* Event.Change */));
1225
+ state$a.push({ time: time(evt), event: 42 /* Event.Change */, data: { target: target(evt), type: element.type, value: value, checksum: checksum } });
1226
+ schedule(encode$3.bind(this, 42 /* Event.Change */));
1266
1227
  }
1267
1228
  }
1268
1229
  function reset$m() {
1269
- state$9 = [];
1230
+ state$a = [];
1270
1231
  }
1271
- function stop$w() {
1232
+ function stop$x() {
1272
1233
  reset$m();
1273
1234
  }
1274
1235
 
@@ -1289,8 +1250,8 @@ function offset(element) {
1289
1250
  }
1290
1251
 
1291
1252
  var UserInputTags = ["input", "textarea", "radio", "button", "canvas", "select"];
1292
- var state$8 = [];
1293
- function start$x() {
1253
+ var state$9 = [];
1254
+ function start$y() {
1294
1255
  reset$l();
1295
1256
  }
1296
1257
  function observe$b(root) {
@@ -1326,7 +1287,7 @@ function handler$3(event, root, evt) {
1326
1287
  // Check for null values before processing this event
1327
1288
  if (x !== null && y !== null) {
1328
1289
  var textInfo = text(t);
1329
- state$8.push({
1290
+ state$9.push({
1330
1291
  time: time(evt),
1331
1292
  event: event,
1332
1293
  data: {
@@ -1348,7 +1309,7 @@ function handler$3(event, root, evt) {
1348
1309
  id: getElementAttribute(t, "id").substring(0, 25 /* Setting.ClickId */),
1349
1310
  }
1350
1311
  });
1351
- schedule$1(encode$3.bind(this, event));
1312
+ schedule(encode$3.bind(this, event));
1352
1313
  }
1353
1314
  }
1354
1315
  function link(node) {
@@ -1388,10 +1349,10 @@ function reaction(element) {
1388
1349
  return 1 /* BooleanFlag.True */;
1389
1350
  }
1390
1351
  function getElementAttribute(element, attribute) {
1391
- var _a;
1392
1352
  if (element.nodeType === Node.ELEMENT_NODE) {
1393
- var value = (_a = element === null || element === void 0 ? void 0 : element[attribute]) === null || _a === void 0 ? void 0 : _a.toLowerCase();
1394
- return value || "";
1353
+ var attr = element === null || element === void 0 ? void 0 : element[attribute];
1354
+ var value = typeof attr === "string" ? attr === null || attr === void 0 ? void 0 : attr.toLowerCase() : "";
1355
+ return value;
1395
1356
  }
1396
1357
  return "";
1397
1358
  }
@@ -1427,14 +1388,14 @@ function context(a) {
1427
1388
  return 0 /* BrowsingContext.Self */;
1428
1389
  }
1429
1390
  function reset$l() {
1430
- state$8 = [];
1391
+ state$9 = [];
1431
1392
  }
1432
- function stop$v() {
1393
+ function stop$w() {
1433
1394
  reset$l();
1434
1395
  }
1435
1396
 
1436
- var state$7 = [];
1437
- function start$w() {
1397
+ var state$8 = [];
1398
+ function start$x() {
1438
1399
  reset$k();
1439
1400
  }
1440
1401
  function observe$a(root) {
@@ -1444,19 +1405,19 @@ function observe$a(root) {
1444
1405
  }
1445
1406
  function recompute$7(action, evt) {
1446
1407
  recompute$7.dn = 7 /* FunctionNames.ClipboardRecompute */;
1447
- state$7.push({ time: time(evt), event: 38 /* Event.Clipboard */, data: { target: target(evt), action: action } });
1448
- schedule$1(encode$3.bind(this, 38 /* Event.Clipboard */));
1408
+ state$8.push({ time: time(evt), event: 38 /* Event.Clipboard */, data: { target: target(evt), action: action } });
1409
+ schedule(encode$3.bind(this, 38 /* Event.Clipboard */));
1449
1410
  }
1450
1411
  function reset$k() {
1451
- state$7 = [];
1412
+ state$8 = [];
1452
1413
  }
1453
- function stop$u() {
1414
+ function stop$v() {
1454
1415
  reset$k();
1455
1416
  }
1456
1417
 
1457
1418
  var timeout$6 = null;
1458
- var state$6 = [];
1459
- function start$v() {
1419
+ var state$7 = [];
1420
+ function start$w() {
1460
1421
  reset$j();
1461
1422
  }
1462
1423
  function observe$9(root) {
@@ -1477,31 +1438,31 @@ function recompute$6(evt) {
1477
1438
  }
1478
1439
  var data = { target: input, value: v, type: t };
1479
1440
  // If last entry in the queue is for the same target node as the current one, remove it so we can later swap it with current data.
1480
- if (state$6.length > 0 && (state$6[state$6.length - 1].data.target === data.target)) {
1481
- state$6.pop();
1441
+ if (state$7.length > 0 && (state$7[state$7.length - 1].data.target === data.target)) {
1442
+ state$7.pop();
1482
1443
  }
1483
- state$6.push({ time: time(evt), event: 27 /* Event.Input */, data: data });
1444
+ state$7.push({ time: time(evt), event: 27 /* Event.Input */, data: data });
1484
1445
  clearTimeout(timeout$6);
1485
1446
  timeout$6 = setTimeout(process$7, 1000 /* Setting.InputLookAhead */, 27 /* Event.Input */);
1486
1447
  }
1487
1448
  }
1488
1449
  function process$7(event) {
1489
- schedule$1(encode$3.bind(this, event));
1450
+ schedule(encode$3.bind(this, event));
1490
1451
  }
1491
1452
  function reset$j() {
1492
- state$6 = [];
1453
+ state$7 = [];
1493
1454
  }
1494
- function stop$t() {
1455
+ function stop$u() {
1495
1456
  clearTimeout(timeout$6);
1496
1457
  reset$j();
1497
1458
  }
1498
1459
 
1499
- var state$5 = [];
1460
+ var state$6 = [];
1500
1461
  var timeout$5 = null;
1501
1462
  var hasPrimaryTouch = false;
1502
1463
  var primaryTouchId = 0;
1503
1464
  var activeTouchPointIds = new Set();
1504
- function start$u() {
1465
+ function start$v() {
1505
1466
  reset$i();
1506
1467
  }
1507
1468
  function observe$8(root) {
@@ -1581,26 +1542,26 @@ function handler$2(current) {
1581
1542
  case 12 /* Event.MouseMove */:
1582
1543
  case 15 /* Event.MouseWheel */:
1583
1544
  case 19 /* Event.TouchMove */:
1584
- var length_1 = state$5.length;
1585
- var last = length_1 > 1 ? state$5[length_1 - 2] : null;
1545
+ var length_1 = state$6.length;
1546
+ var last = length_1 > 1 ? state$6[length_1 - 2] : null;
1586
1547
  if (last && similar$1(last, current)) {
1587
- state$5.pop();
1548
+ state$6.pop();
1588
1549
  }
1589
- state$5.push(current);
1550
+ state$6.push(current);
1590
1551
  clearTimeout(timeout$5);
1591
1552
  timeout$5 = setTimeout(process$6, 500 /* Setting.LookAhead */, current.event);
1592
1553
  break;
1593
1554
  default:
1594
- state$5.push(current);
1555
+ state$6.push(current);
1595
1556
  process$6(current.event);
1596
1557
  break;
1597
1558
  }
1598
1559
  }
1599
1560
  function process$6(event) {
1600
- schedule$1(encode$3.bind(this, event));
1561
+ schedule(encode$3.bind(this, event));
1601
1562
  }
1602
1563
  function reset$i() {
1603
- state$5 = [];
1564
+ state$6 = [];
1604
1565
  }
1605
1566
  function similar$1(last, current) {
1606
1567
  var dx = last.data.x - current.data.x;
@@ -1610,18 +1571,18 @@ function similar$1(last, current) {
1610
1571
  var match = current.data.target === last.data.target;
1611
1572
  return current.event === last.event && match && distance < 20 /* Setting.Distance */ && gap < 25 /* Setting.Interval */;
1612
1573
  }
1613
- function stop$s() {
1574
+ function stop$t() {
1614
1575
  clearTimeout(timeout$5);
1615
1576
  // Send out any pending pointer events in the pipeline
1616
- if (state$5.length > 0) {
1617
- process$6(state$5[state$5.length - 1].event);
1577
+ if (state$6.length > 0) {
1578
+ process$6(state$6[state$6.length - 1].event);
1618
1579
  }
1619
1580
  }
1620
1581
 
1621
1582
  var data$c;
1622
1583
  var timeout$4 = null;
1623
1584
  var initialStateLogged = false;
1624
- function start$t() {
1585
+ function start$u() {
1625
1586
  initialStateLogged = false;
1626
1587
  bind(window, "resize", recompute$5);
1627
1588
  recompute$5();
@@ -1645,22 +1606,22 @@ function recompute$5() {
1645
1606
  }
1646
1607
  }
1647
1608
  function process$5(event) {
1648
- schedule$1(encode$3.bind(this, event));
1609
+ schedule(encode$3.bind(this, event));
1649
1610
  }
1650
1611
  function reset$h() {
1651
1612
  data$c = null;
1652
1613
  clearTimeout(timeout$4);
1653
1614
  }
1654
- function stop$r() {
1615
+ function stop$s() {
1655
1616
  reset$h();
1656
1617
  }
1657
1618
 
1658
- var state$4 = [];
1619
+ var state$5 = [];
1659
1620
  var initialTop = null;
1660
1621
  var initialBottom = null;
1661
1622
  var timeout$3 = null;
1662
- function start$s() {
1663
- state$4 = [];
1623
+ function start$t() {
1624
+ state$5 = [];
1664
1625
  recompute$4();
1665
1626
  }
1666
1627
  function observe$7(root) {
@@ -1700,12 +1661,12 @@ function recompute$4(event) {
1700
1661
  initialBottom = bottom;
1701
1662
  return;
1702
1663
  }
1703
- var length = state$4.length;
1704
- var last = length > 1 ? state$4[length - 2] : null;
1664
+ var length = state$5.length;
1665
+ var last = length > 1 ? state$5[length - 2] : null;
1705
1666
  if (last && similar(last, current)) {
1706
- state$4.pop();
1667
+ state$5.pop();
1707
1668
  }
1708
- state$4.push(current);
1669
+ state$5.push(current);
1709
1670
  clearTimeout(timeout$3);
1710
1671
  timeout$3 = setTimeout(process$4, 500 /* Setting.LookAhead */, 10 /* Event.Scroll */);
1711
1672
  }
@@ -1727,21 +1688,21 @@ function getPositionNode(x, y) {
1727
1688
  return node;
1728
1689
  }
1729
1690
  function reset$g() {
1730
- state$4 = [];
1691
+ state$5 = [];
1731
1692
  initialTop = null;
1732
1693
  initialBottom = null;
1733
1694
  }
1734
1695
  function process$4(event) {
1735
- schedule$1(encode$3.bind(this, event));
1696
+ schedule(encode$3.bind(this, event));
1736
1697
  }
1737
1698
  function similar(last, current) {
1738
1699
  var dx = last.data.x - current.data.x;
1739
1700
  var dy = last.data.y - current.data.y;
1740
1701
  return (dx * dx + dy * dy < 20 /* Setting.Distance */ * 20 /* Setting.Distance */) && (current.time - last.time < 25 /* Setting.Interval */);
1741
1702
  }
1742
- function compute$9() {
1703
+ function compute$8() {
1743
1704
  var _a, _b;
1744
- compute$9.dn = 14 /* FunctionNames.ScrollCompute */;
1705
+ compute$8.dn = 14 /* FunctionNames.ScrollCompute */;
1745
1706
  if (initialTop) {
1746
1707
  var top_1 = metadata$2(initialTop, null);
1747
1708
  log(31 /* Dimension.InitialScrollTop */, (_a = top_1 === null || top_1 === void 0 ? void 0 : top_1.hash) === null || _a === void 0 ? void 0 : _a.join("." /* Constant.Dot */));
@@ -1751,9 +1712,9 @@ function compute$9() {
1751
1712
  log(32 /* Dimension.InitialScrollBottom */, (_b = bottom === null || bottom === void 0 ? void 0 : bottom.hash) === null || _b === void 0 ? void 0 : _b.join("." /* Constant.Dot */));
1752
1713
  }
1753
1714
  }
1754
- function stop$q() {
1715
+ function stop$r() {
1755
1716
  clearTimeout(timeout$3);
1756
- state$4 = [];
1717
+ state$5 = [];
1757
1718
  initialTop = null;
1758
1719
  initialBottom = null;
1759
1720
  }
@@ -1761,7 +1722,7 @@ function stop$q() {
1761
1722
  var data$b = null;
1762
1723
  var previous = null;
1763
1724
  var timeout$2 = null;
1764
- function start$r() {
1725
+ function start$s() {
1765
1726
  reset$f();
1766
1727
  }
1767
1728
  function observe$6(root) {
@@ -1800,19 +1761,19 @@ function recompute$3(root) {
1800
1761
  timeout$2 = setTimeout(process$3, 500 /* Setting.LookAhead */, 21 /* Event.Selection */);
1801
1762
  }
1802
1763
  function process$3(event) {
1803
- schedule$1(encode$3.bind(this, event));
1764
+ schedule(encode$3.bind(this, event));
1804
1765
  }
1805
1766
  function reset$f() {
1806
1767
  previous = null;
1807
1768
  data$b = { start: 0, startOffset: 0, end: 0, endOffset: 0 };
1808
1769
  }
1809
- function stop$p() {
1770
+ function stop$q() {
1810
1771
  reset$f();
1811
1772
  clearTimeout(timeout$2);
1812
1773
  }
1813
1774
 
1814
- var state$3 = [];
1815
- function start$q() {
1775
+ var state$4 = [];
1776
+ function start$r() {
1816
1777
  reset$e();
1817
1778
  }
1818
1779
  function observe$5(root) {
@@ -1820,18 +1781,18 @@ function observe$5(root) {
1820
1781
  }
1821
1782
  function recompute$2(evt) {
1822
1783
  recompute$2.dn = 16 /* FunctionNames.SubmitRecompute */;
1823
- state$3.push({ time: time(evt), event: 39 /* Event.Submit */, data: { target: target(evt) } });
1824
- schedule$1(encode$3.bind(this, 39 /* Event.Submit */));
1784
+ state$4.push({ time: time(evt), event: 39 /* Event.Submit */, data: { target: target(evt) } });
1785
+ schedule(encode$3.bind(this, 39 /* Event.Submit */));
1825
1786
  }
1826
1787
  function reset$e() {
1827
- state$3 = [];
1788
+ state$4 = [];
1828
1789
  }
1829
- function stop$o() {
1790
+ function stop$p() {
1830
1791
  reset$e();
1831
1792
  }
1832
1793
 
1833
1794
  var data$a;
1834
- function start$p() {
1795
+ function start$q() {
1835
1796
  bind(window, "pagehide", recompute$1);
1836
1797
  }
1837
1798
  function recompute$1(evt) {
@@ -1843,12 +1804,12 @@ function recompute$1(evt) {
1843
1804
  function reset$d() {
1844
1805
  data$a = null;
1845
1806
  }
1846
- function stop$n() {
1807
+ function stop$o() {
1847
1808
  reset$d();
1848
1809
  }
1849
1810
 
1850
1811
  var data$9;
1851
- function start$o() {
1812
+ function start$p() {
1852
1813
  bind(document, "visibilitychange", recompute);
1853
1814
  recompute();
1854
1815
  }
@@ -1861,38 +1822,38 @@ function recompute(evt) {
1861
1822
  function reset$c() {
1862
1823
  data$9 = null;
1863
1824
  }
1864
- function stop$m() {
1825
+ function stop$n() {
1865
1826
  reset$c();
1866
1827
  }
1867
1828
 
1868
- function start$n() {
1869
- start$n.dn = 8 /* FunctionNames.InteractionStart */;
1870
- start$g();
1829
+ function start$o() {
1830
+ start$o.dn = 8 /* FunctionNames.InteractionStart */;
1831
+ start$h();
1832
+ start$y();
1871
1833
  start$x();
1834
+ start$v();
1872
1835
  start$w();
1873
1836
  start$u();
1874
- start$v();
1837
+ start$p();
1875
1838
  start$t();
1876
- start$o();
1877
1839
  start$s();
1840
+ start$z();
1878
1841
  start$r();
1879
- start$y();
1880
1842
  start$q();
1881
- start$p();
1882
1843
  }
1883
- function stop$l() {
1884
- stop$e();
1844
+ function stop$m() {
1845
+ stop$f();
1846
+ stop$w();
1885
1847
  stop$v();
1848
+ stop$t();
1886
1849
  stop$u();
1887
1850
  stop$s();
1888
- stop$t();
1851
+ stop$n();
1889
1852
  stop$r();
1890
- stop$m();
1891
1853
  stop$q();
1854
+ stop$x();
1892
1855
  stop$p();
1893
- stop$w();
1894
1856
  stop$o();
1895
- stop$n();
1896
1857
  }
1897
1858
  function observe$4(root) {
1898
1859
  observe$7(root);
@@ -1912,8 +1873,8 @@ function observe$4(root) {
1912
1873
  var interaction = /*#__PURE__*/Object.freeze({
1913
1874
  __proto__: null,
1914
1875
  observe: observe$4,
1915
- start: start$n,
1916
- stop: stop$l
1876
+ start: start$o,
1877
+ stop: stop$m
1917
1878
  });
1918
1879
 
1919
1880
  // Following code takes an array of tokens and transforms it to optimize for repeating tokens and make it efficient to send over the wire
@@ -1968,7 +1929,10 @@ var styleSheetMap = {};
1968
1929
  var styleTimeMap = {};
1969
1930
  var documentNodes = [];
1970
1931
  var createdSheetIds = [];
1971
- function start$m() {
1932
+ function start$n() {
1933
+ if (config$2.lean && config$2.lite) {
1934
+ return;
1935
+ }
1972
1936
  if (window['CSSStyleSheet'] && CSSStyleSheet.prototype) {
1973
1937
  if (replace === null) {
1974
1938
  replace = CSSStyleSheet.prototype.replace;
@@ -2003,6 +1967,9 @@ function start$m() {
2003
1967
  }
2004
1968
  }
2005
1969
  function checkDocumentStyles(documentNode, timestamp) {
1970
+ if (config$2.lean && config$2.lite) {
1971
+ return;
1972
+ }
2006
1973
  if (documentNodes.indexOf(documentNode) === -1) {
2007
1974
  documentNodes.push(documentNode);
2008
1975
  }
@@ -2038,7 +2005,7 @@ function checkDocumentStyles(documentNode, timestamp) {
2038
2005
  styleTimeMap[documentId] = timestamp;
2039
2006
  }
2040
2007
  }
2041
- function compute$8() {
2008
+ function compute$7() {
2042
2009
  for (var _i = 0, documentNodes_1 = documentNodes; _i < documentNodes_1.length; _i++) {
2043
2010
  var documentNode = documentNodes_1[_i];
2044
2011
  var docId = documentNode == document ? -1 : getId(documentNode);
@@ -2050,7 +2017,7 @@ function reset$b() {
2050
2017
  sheetAdoptionState = [];
2051
2018
  sheetUpdateState = [];
2052
2019
  }
2053
- function stop$k() {
2020
+ function stop$l() {
2054
2021
  styleSheetMap = {};
2055
2022
  styleTimeMap = {};
2056
2023
  documentNodes = [];
@@ -2088,7 +2055,7 @@ function arraysEqual(a, b) {
2088
2055
  return a.every(function (value, index) { return value === b[index]; });
2089
2056
  }
2090
2057
 
2091
- var state$2 = [];
2058
+ var state$3 = [];
2092
2059
  var elementAnimate = null;
2093
2060
  var animationPlay = null;
2094
2061
  var animationPause = null;
@@ -2098,7 +2065,7 @@ var animationFinish = null;
2098
2065
  var animationId = 'clarityAnimationId';
2099
2066
  var operationCount = 'clarityOperationCount';
2100
2067
  var maxOperations = 20;
2101
- function start$l() {
2068
+ function start$m() {
2102
2069
  if (window["Animation"] &&
2103
2070
  window["Animation"].prototype &&
2104
2071
  window["KeyframeEffect"] &&
@@ -2136,10 +2103,10 @@ function start$l() {
2136
2103
  }
2137
2104
  }
2138
2105
  function reset$a() {
2139
- state$2 = [];
2106
+ state$3 = [];
2140
2107
  }
2141
2108
  function track$6(time, id, operation, keyFrames, timing, targetId, timeline) {
2142
- state$2.push({
2109
+ state$3.push({
2143
2110
  time: time,
2144
2111
  event: 44 /* Event.Animation */,
2145
2112
  data: {
@@ -2153,7 +2120,7 @@ function track$6(time, id, operation, keyFrames, timing, targetId, timeline) {
2153
2120
  });
2154
2121
  encode$4(44 /* Event.Animation */);
2155
2122
  }
2156
- function stop$j() {
2123
+ function stop$k() {
2157
2124
  reset$a();
2158
2125
  }
2159
2126
  function overrideAnimationHelper(functionToOverride, name) {
@@ -2208,7 +2175,7 @@ function encode$4 (type, timer, ts) {
2208
2175
  if (timer === void 0) { timer = null; }
2209
2176
  if (ts === void 0) { ts = null; }
2210
2177
  return __awaiter(this, void 0, void 0, function () {
2211
- var eventTime, tokens, _a, d, _i, _b, r, _c, _d, entry, _e, _f, entry, _g, _h, entry, values, _j, values_1, value, state, data, active, suspend, privacy, mangle, keys, _k, keys_1, key, box, factor, attr;
2178
+ var eventTime, tokens, _a, d, _i, _b, r, _c, _d, entry, _e, _f, entry, _g, _h, entry, values, _j, values_1, value, state$1, data, active, suspend, privacy, mangle, keys, _k, keys_1, key, box, factor, attr;
2212
2179
  return __generator(this, function (_l) {
2213
2180
  switch (_l.label) {
2214
2181
  case 0:
@@ -2233,7 +2200,7 @@ function encode$4 (type, timer, ts) {
2233
2200
  queue(tokens);
2234
2201
  return [3 /*break*/, 12];
2235
2202
  case 2:
2236
- for (_i = 0, _b = state$1; _i < _b.length; _i++) {
2203
+ for (_i = 0, _b = state$2; _i < _b.length; _i++) {
2237
2204
  r = _b[_i];
2238
2205
  tokens = [r.time, 7 /* Event.Region */];
2239
2206
  tokens.push(r.data.id);
@@ -2264,7 +2231,7 @@ function encode$4 (type, timer, ts) {
2264
2231
  reset$b();
2265
2232
  return [3 /*break*/, 12];
2266
2233
  case 4:
2267
- for (_g = 0, _h = state$2; _g < _h.length; _g++) {
2234
+ for (_g = 0, _h = state$3; _g < _h.length; _g++) {
2268
2235
  entry = _h[_g];
2269
2236
  tokens = [entry.time, entry.event];
2270
2237
  tokens.push(entry.data.id);
@@ -2279,7 +2246,7 @@ function encode$4 (type, timer, ts) {
2279
2246
  return [3 /*break*/, 12];
2280
2247
  case 5:
2281
2248
  // Check if we are operating within the context of the current page
2282
- if (state$a(timer) === 2 /* Task.Stop */) {
2249
+ if (state(timer) === 2 /* Task.Stop */) {
2283
2250
  return [3 /*break*/, 12];
2284
2251
  }
2285
2252
  values = updates$2();
@@ -2289,14 +2256,14 @@ function encode$4 (type, timer, ts) {
2289
2256
  case 6:
2290
2257
  if (!(_j < values_1.length)) return [3 /*break*/, 10];
2291
2258
  value = values_1[_j];
2292
- state = state$a(timer);
2293
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 8];
2259
+ state$1 = state(timer);
2260
+ if (!(state$1 === 0 /* Task.Wait */)) return [3 /*break*/, 8];
2294
2261
  return [4 /*yield*/, suspend$1(timer)];
2295
2262
  case 7:
2296
- state = _l.sent();
2263
+ state$1 = _l.sent();
2297
2264
  _l.label = 8;
2298
2265
  case 8:
2299
- if (state === 2 /* Task.Stop */) {
2266
+ if (state$1 === 2 /* Task.Stop */) {
2300
2267
  return [3 /*break*/, 10];
2301
2268
  }
2302
2269
  data = value.data;
@@ -2323,7 +2290,7 @@ function encode$4 (type, timer, ts) {
2323
2290
  }
2324
2291
  tokens.push(suspend ? "*M" /* Constant.SuspendMutationTag */ : data[key]);
2325
2292
  if (box && box.length === 2) {
2326
- tokens.push("".concat("#" /* Constant.Hash */).concat(str$1(box[0]), ".").concat(str$1(box[1])));
2293
+ tokens.push("".concat("#" /* Constant.Hash */).concat(str(box[0]), ".").concat(str(box[1])));
2327
2294
  }
2328
2295
  break;
2329
2296
  case "attributes":
@@ -2369,7 +2336,7 @@ function size(value) {
2369
2336
  }
2370
2337
  return value.metadata.size;
2371
2338
  }
2372
- function str$1(input) {
2339
+ function str(input) {
2373
2340
  return input.toString(36);
2374
2341
  }
2375
2342
  function attribute(key, value, privacy) {
@@ -2380,12 +2347,12 @@ var data$8;
2380
2347
  function reset$9() {
2381
2348
  data$8 = null;
2382
2349
  }
2383
- function start$k() {
2350
+ function start$l() {
2384
2351
  reset$9();
2385
- compute$7();
2352
+ compute$6();
2386
2353
  }
2387
- function compute$7() {
2388
- compute$7.dn = 19 /* FunctionNames.DocumentCompute */;
2354
+ function compute$6() {
2355
+ compute$6.dn = 19 /* FunctionNames.DocumentCompute */;
2389
2356
  var body = document.body;
2390
2357
  var d = document.documentElement;
2391
2358
  var bodyClientWidth = body ? body.clientWidth : null;
@@ -2408,13 +2375,13 @@ function compute$7() {
2408
2375
  encode$4(8 /* Event.Document */);
2409
2376
  }
2410
2377
  }
2411
- function stop$i() {
2378
+ function stop$j() {
2412
2379
  reset$9();
2413
2380
  }
2414
2381
 
2415
2382
  function traverse (root, timer, source, timestamp) {
2416
2383
  return __awaiter(this, void 0, void 0, function () {
2417
- var queue, entry, next, state, subnode;
2384
+ var queue, entry, next, state$1, subnode;
2418
2385
  return __generator(this, function (_a) {
2419
2386
  switch (_a.label) {
2420
2387
  case 0:
@@ -2428,14 +2395,14 @@ function traverse (root, timer, source, timestamp) {
2428
2395
  queue.push(next);
2429
2396
  next = next.nextSibling;
2430
2397
  }
2431
- state = state$a(timer);
2432
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 3];
2398
+ state$1 = state(timer);
2399
+ if (!(state$1 === 0 /* Task.Wait */)) return [3 /*break*/, 3];
2433
2400
  return [4 /*yield*/, suspend$1(timer)];
2434
2401
  case 2:
2435
- state = _a.sent();
2402
+ state$1 = _a.sent();
2436
2403
  _a.label = 3;
2437
2404
  case 3:
2438
- if (state === 2 /* Task.Stop */) {
2405
+ if (state$1 === 2 /* Task.Stop */) {
2439
2406
  return [3 /*break*/, 4];
2440
2407
  }
2441
2408
  subnode = processNode(entry, source, timestamp);
@@ -2465,8 +2432,8 @@ var history$4 = {};
2465
2432
  var observedNodes = new WeakMap();
2466
2433
  // We ignore mutations if these attributes are updated
2467
2434
  var IGNORED_ATTRIBUTES = ["data-google-query-id", "data-load-complete", "data-google-container-id"];
2468
- function start$j() {
2469
- start$j.dn = 21 /* FunctionNames.MutationStart */;
2435
+ function start$k() {
2436
+ start$k.dn = 21 /* FunctionNames.MutationStart */;
2470
2437
  observers = new Set();
2471
2438
  queue$2 = [];
2472
2439
  timeout$1 = null;
@@ -2481,7 +2448,7 @@ function start$j() {
2481
2448
  insertRule = CSSStyleSheet.prototype.insertRule;
2482
2449
  CSSStyleSheet.prototype.insertRule = function () {
2483
2450
  if (active()) {
2484
- schedule(this.ownerNode);
2451
+ schedule$1(this.ownerNode);
2485
2452
  }
2486
2453
  return insertRule.apply(this, arguments);
2487
2454
  };
@@ -2490,7 +2457,7 @@ function start$j() {
2490
2457
  mediaInsertRule = CSSMediaRule.prototype.insertRule;
2491
2458
  CSSMediaRule.prototype.insertRule = function () {
2492
2459
  if (active()) {
2493
- schedule(this.parentStyleSheet.ownerNode);
2460
+ schedule$1(this.parentStyleSheet.ownerNode);
2494
2461
  }
2495
2462
  return mediaInsertRule.apply(this, arguments);
2496
2463
  };
@@ -2499,7 +2466,7 @@ function start$j() {
2499
2466
  deleteRule = CSSStyleSheet.prototype.deleteRule;
2500
2467
  CSSStyleSheet.prototype.deleteRule = function () {
2501
2468
  if (active()) {
2502
- schedule(this.ownerNode);
2469
+ schedule$1(this.ownerNode);
2503
2470
  }
2504
2471
  return deleteRule.apply(this, arguments);
2505
2472
  };
@@ -2508,7 +2475,7 @@ function start$j() {
2508
2475
  mediaDeleteRule = CSSMediaRule.prototype.deleteRule;
2509
2476
  CSSMediaRule.prototype.deleteRule = function () {
2510
2477
  if (active()) {
2511
- schedule(this.parentStyleSheet.ownerNode);
2478
+ schedule$1(this.parentStyleSheet.ownerNode);
2512
2479
  }
2513
2480
  return mediaDeleteRule.apply(this, arguments);
2514
2481
  };
@@ -2521,7 +2488,7 @@ function start$j() {
2521
2488
  try {
2522
2489
  Element.prototype.attachShadow = function () {
2523
2490
  if (active()) {
2524
- return schedule(attachShadow.apply(this, arguments));
2491
+ return schedule$1(attachShadow.apply(this, arguments));
2525
2492
  }
2526
2493
  else {
2527
2494
  return attachShadow.apply(this, arguments);
@@ -2559,7 +2526,7 @@ function monitor(frame) {
2559
2526
  bind(frame, "load" /* Constant.LoadEvent */, generate.bind(this, frame, "childList" /* Constant.ChildList */), true);
2560
2527
  }
2561
2528
  }
2562
- function stop$h() {
2529
+ function stop$i() {
2563
2530
  for (var _i = 0, _a = Array.from(observers); _i < _a.length; _i++) {
2564
2531
  var observer = _a[_i];
2565
2532
  if (observer) {
@@ -2592,34 +2559,34 @@ function handle$1(m) {
2592
2559
  var now = time();
2593
2560
  track$7(6 /* Event.Mutation */, now);
2594
2561
  mutations.push({ time: now, mutations: m });
2595
- schedule$1(process$2, 1 /* Priority.High */).then(function () {
2596
- setTimeout(compute$7);
2597
- measure(compute$6)();
2562
+ schedule(process$2, 1 /* Priority.High */).then(function () {
2563
+ setTimeout(compute$6);
2564
+ measure(compute$5)();
2598
2565
  });
2599
2566
  }
2600
2567
  function processMutation(timer, mutation, instance, timestamp) {
2601
2568
  return __awaiter(this, void 0, void 0, function () {
2602
- var state, target, type;
2569
+ var state$1, target, type;
2603
2570
  return __generator(this, function (_a) {
2604
2571
  switch (_a.label) {
2605
2572
  case 0:
2606
- state = state$a(timer);
2607
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 2];
2573
+ state$1 = state(timer);
2574
+ if (!(state$1 === 0 /* Task.Wait */)) return [3 /*break*/, 2];
2608
2575
  return [4 /*yield*/, suspend$1(timer)];
2609
2576
  case 1:
2610
- state = _a.sent();
2577
+ state$1 = _a.sent();
2611
2578
  _a.label = 2;
2612
2579
  case 2:
2613
- if (state === 2 /* Task.Stop */) {
2580
+ if (state$1 === 2 /* Task.Stop */) {
2614
2581
  return [2 /*return*/];
2615
2582
  }
2616
2583
  target = mutation.target;
2617
2584
  type = config$2.throttleDom ? track$5(mutation, timer, instance, timestamp) : mutation.type;
2618
2585
  if (type && target && target.ownerDocument) {
2619
- parse$1(target.ownerDocument);
2586
+ parse(target.ownerDocument);
2620
2587
  }
2621
2588
  if (type && target && target.nodeType == Node.DOCUMENT_FRAGMENT_NODE && target.host) {
2622
- parse$1(target);
2589
+ parse(target);
2623
2590
  }
2624
2591
  switch (type) {
2625
2592
  case "attributes" /* Constant.Attributes */:
@@ -2647,7 +2614,7 @@ function process$2() {
2647
2614
  switch (_d.label) {
2648
2615
  case 0:
2649
2616
  timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
2650
- start$z(timer);
2617
+ start$d(timer);
2651
2618
  _d.label = 1;
2652
2619
  case 1:
2653
2620
  if (!(mutations.length > 0)) return [3 /*break*/, 7];
@@ -2697,7 +2664,7 @@ function process$2() {
2697
2664
  _d.label = 13;
2698
2665
  case 13:
2699
2666
  cleanHistory();
2700
- stop$x(timer);
2667
+ stop$c(timer);
2701
2668
  return [2 /*return*/];
2702
2669
  }
2703
2670
  });
@@ -2769,7 +2736,7 @@ function names(nodes) {
2769
2736
  }
2770
2737
  function processNodeList(list, source, timer, timestamp) {
2771
2738
  return __awaiter(this, void 0, void 0, function () {
2772
- var length, i, node, state;
2739
+ var length, i, node, state$1;
2773
2740
  return __generator(this, function (_a) {
2774
2741
  switch (_a.label) {
2775
2742
  case 0:
@@ -2783,14 +2750,14 @@ function processNodeList(list, source, timer, timestamp) {
2783
2750
  traverse(node, timer, source, timestamp);
2784
2751
  return [3 /*break*/, 5];
2785
2752
  case 2:
2786
- state = state$a(timer);
2787
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 4];
2753
+ state$1 = state(timer);
2754
+ if (!(state$1 === 0 /* Task.Wait */)) return [3 /*break*/, 4];
2788
2755
  return [4 /*yield*/, suspend$1(timer)];
2789
2756
  case 3:
2790
- state = _a.sent();
2757
+ state$1 = _a.sent();
2791
2758
  _a.label = 4;
2792
2759
  case 4:
2793
- if (state === 2 /* Task.Stop */) {
2760
+ if (state$1 === 2 /* Task.Stop */) {
2794
2761
  return [3 /*break*/, 6];
2795
2762
  }
2796
2763
  processNode(node, source, timestamp);
@@ -2808,10 +2775,10 @@ function processThrottledMutations() {
2808
2775
  clearTimeout(throttleDelay);
2809
2776
  }
2810
2777
  throttleDelay = setTimeout(function () {
2811
- schedule$1(process$2, 1 /* Priority.High */);
2778
+ schedule(process$2, 1 /* Priority.High */);
2812
2779
  }, 33 /* Setting.LookAhead */);
2813
2780
  }
2814
- function schedule(node) {
2781
+ function schedule$1(node) {
2815
2782
  // Only schedule manual trigger for this node if it's not already in the queue
2816
2783
  if (queue$2.indexOf(node) < 0) {
2817
2784
  queue$2.push(node);
@@ -2823,11 +2790,11 @@ function schedule(node) {
2823
2790
  clearTimeout(timeout$1);
2824
2791
  }
2825
2792
  timeout$1 = setTimeout(function () {
2826
- trigger$2();
2793
+ trigger$1();
2827
2794
  }, 33 /* Setting.LookAhead */);
2828
2795
  return node;
2829
2796
  }
2830
- function trigger$2() {
2797
+ function trigger$1() {
2831
2798
  for (var _i = 0, queue_1 = queue$2; _i < queue_1.length; _i++) {
2832
2799
  var node = queue_1[_i];
2833
2800
  // Generate a mutation for this node only if it still exists
@@ -2956,7 +2923,7 @@ function processNode (node, source, timestamp) {
2956
2923
  // We check for regions in the beginning when discovering document and
2957
2924
  // later whenever there are new additions or modifications to DOM (mutations)
2958
2925
  if (node === document) {
2959
- parse$1(document);
2926
+ parse(document);
2960
2927
  }
2961
2928
  checkDocumentStyles(node, timestamp);
2962
2929
  observe$2(node);
@@ -2964,7 +2931,7 @@ function processNode (node, source, timestamp) {
2964
2931
  case Node.DOCUMENT_FRAGMENT_NODE:
2965
2932
  var shadowRoot = node;
2966
2933
  if (shadowRoot.host) {
2967
- parse$1(shadowRoot);
2934
+ parse(shadowRoot);
2968
2935
  var type = typeof (shadowRoot.constructor);
2969
2936
  if (type === "function" /* Constant.Function */ && shadowRoot.constructor.toString().indexOf("[native code]" /* Constant.NativeCode */) >= 0) {
2970
2937
  observe$2(shadowRoot);
@@ -3310,11 +3277,11 @@ var iframeMap = null; // Maps iframe's contentDocument => parent iframe element
3310
3277
  var iframeContentMap = null; // Maps parent iframe element => iframe's contentDocument & contentWindow
3311
3278
  var privacyMap = null; // Maps node => Privacy (enum)
3312
3279
  var fraudMap = null; // Maps node => FraudId (number)
3313
- function start$i() {
3280
+ function start$j() {
3314
3281
  reset$7();
3315
- parse$1(document, true);
3282
+ parse(document, true);
3316
3283
  }
3317
- function stop$g() {
3284
+ function stop$h() {
3318
3285
  reset$7();
3319
3286
  }
3320
3287
  function reset$7() {
@@ -3338,7 +3305,7 @@ function reset$7() {
3338
3305
  }
3339
3306
  // We parse new root nodes for any regions or masked nodes in the beginning (document) and
3340
3307
  // later whenever there are new additions or modifications to DOM (mutations)
3341
- function parse$1(root, init) {
3308
+ function parse(root, init) {
3342
3309
  if (init === void 0) { init = false; }
3343
3310
  // Wrap selectors in a try / catch block.
3344
3311
  // It's possible for script to receive invalid selectors, e.g. "'#id'" with extra quotes, and cause the code below to fail
@@ -3413,7 +3380,7 @@ function add(node, parent, data, source) {
3413
3380
  updateImageSize(values[id]);
3414
3381
  track$4(id, source);
3415
3382
  }
3416
- function update$1(node, parent, data, source) {
3383
+ function update(node, parent, data, source) {
3417
3384
  var id = getId(node);
3418
3385
  var parentId = parent ? getId(parent) : null;
3419
3386
  var previousId = getPreviousId(node);
@@ -3687,6 +3654,9 @@ function getPreviousId(node) {
3687
3654
  function track$4(id, source, changed, parentChanged) {
3688
3655
  if (changed === void 0) { changed = true; }
3689
3656
  if (parentChanged === void 0) { parentChanged = false; }
3657
+ if (config$2.lean && config$2.lite) {
3658
+ return;
3659
+ }
3690
3660
  // Keep track of the order in which mutations happened, they may not be sequential
3691
3661
  // Edge case: If an element is added later on, and pre-discovered element is moved as a child.
3692
3662
  // In that case, we need to reorder the pre-discovered element in the update list to keep visualization consistent.
@@ -3700,13 +3670,13 @@ function track$4(id, source, changed, parentChanged) {
3700
3670
  }
3701
3671
  }
3702
3672
 
3703
- var state$1 = [];
3673
+ var state$2 = [];
3704
3674
  var regionMap = null; // Maps region nodes => region name
3705
3675
  var regions = {};
3706
3676
  var queue$1 = [];
3707
3677
  var watch = false;
3708
3678
  var observer$1 = null;
3709
- function start$h() {
3679
+ function start$i() {
3710
3680
  reset$6();
3711
3681
  observer$1 = null;
3712
3682
  regionMap = new WeakMap();
@@ -3751,8 +3721,8 @@ function track$3(id, event) {
3751
3721
  // Process updates to this region, if applicable
3752
3722
  process$1(node, data, interaction, data.visibility);
3753
3723
  }
3754
- function compute$6() {
3755
- compute$6.dn = 24 /* FunctionNames.RegionCompute */;
3724
+ function compute$5() {
3725
+ compute$5.dn = 24 /* FunctionNames.RegionCompute */;
3756
3726
  // Process any regions where we couldn't resolve an "id" for at the time of last intersection observer event
3757
3727
  // This could happen in cases where elements are not yet processed by Clarity's virtual DOM but browser reports a change, regardless.
3758
3728
  // For those cases we add them to the queue and re-process them below
@@ -3763,7 +3733,7 @@ function compute$6() {
3763
3733
  if (id) {
3764
3734
  r.state.data.id = id;
3765
3735
  regions[id] = r.state.data;
3766
- state$1.push(r.state);
3736
+ state$2.push(r.state);
3767
3737
  }
3768
3738
  else {
3769
3739
  q.push(r);
@@ -3771,7 +3741,7 @@ function compute$6() {
3771
3741
  }
3772
3742
  queue$1 = q;
3773
3743
  // Schedule encode only when we have at least one valid data entry
3774
- if (state$1.length > 0) {
3744
+ if (state$2.length > 0) {
3775
3745
  encode$4(7 /* Event.Region */);
3776
3746
  }
3777
3747
  }
@@ -3807,7 +3777,7 @@ function handler$1(entries) {
3807
3777
  }
3808
3778
  }
3809
3779
  }
3810
- if (state$1.length > 0) {
3780
+ if (state$2.length > 0) {
3811
3781
  encode$4(7 /* Event.Region */);
3812
3782
  }
3813
3783
  }
@@ -3821,21 +3791,21 @@ function process$1(n, d, s, v) {
3821
3791
  if (d.id) {
3822
3792
  if ((d.id in regions && updated) || !(d.id in regions)) {
3823
3793
  regions[d.id] = d;
3824
- state$1.push(clone$1(d));
3794
+ state$2.push(clone(d));
3825
3795
  }
3826
3796
  }
3827
3797
  else {
3828
3798
  // Get the time before adding to queue to ensure accurate event time
3829
- queue$1.push({ node: n, state: clone$1(d) });
3799
+ queue$1.push({ node: n, state: clone(d) });
3830
3800
  }
3831
3801
  }
3832
- function clone$1(r) {
3802
+ function clone(r) {
3833
3803
  return { time: time(), data: { id: r.id, interaction: r.interaction, visibility: r.visibility, name: r.name } };
3834
3804
  }
3835
3805
  function reset$6() {
3836
- state$1 = [];
3806
+ state$2 = [];
3837
3807
  }
3838
- function stop$f() {
3808
+ function stop$g() {
3839
3809
  reset$6();
3840
3810
  regionMap = null;
3841
3811
  regions = {};
@@ -3892,7 +3862,7 @@ function encode$3 (type, ts) {
3892
3862
  case 18 /* Event.TouchEnd */:
3893
3863
  case 19 /* Event.TouchMove */:
3894
3864
  case 20 /* Event.TouchCancel */:
3895
- for (_i = 0, _a = state$5; _i < _a.length; _i++) {
3865
+ for (_i = 0, _a = state$6; _i < _a.length; _i++) {
3896
3866
  entry = _a[_i];
3897
3867
  pTarget = metadata$2(entry.data.target, entry.event);
3898
3868
  if (pTarget.id > 0) {
@@ -3913,7 +3883,7 @@ function encode$3 (type, ts) {
3913
3883
  reset$i();
3914
3884
  break;
3915
3885
  case 9 /* Event.Click */:
3916
- for (_b = 0, _c = state$8; _b < _c.length; _b++) {
3886
+ for (_b = 0, _c = state$9; _b < _c.length; _b++) {
3917
3887
  entry = _c[_b];
3918
3888
  cTarget = metadata$2(entry.data.target, entry.event, entry.data.text);
3919
3889
  tokens = [entry.time, entry.event];
@@ -3940,7 +3910,7 @@ function encode$3 (type, ts) {
3940
3910
  reset$l();
3941
3911
  break;
3942
3912
  case 38 /* Event.Clipboard */:
3943
- for (_d = 0, _e = state$7; _d < _e.length; _d++) {
3913
+ for (_d = 0, _e = state$8; _d < _e.length; _d++) {
3944
3914
  entry = _e[_d];
3945
3915
  tokens = [entry.time, entry.event];
3946
3916
  target = metadata$2(entry.data.target, entry.event);
@@ -3968,7 +3938,7 @@ function encode$3 (type, ts) {
3968
3938
  queue(tokens);
3969
3939
  break;
3970
3940
  case 27 /* Event.Input */:
3971
- for (_f = 0, _g = state$6; _f < _g.length; _f++) {
3941
+ for (_f = 0, _g = state$7; _f < _g.length; _f++) {
3972
3942
  entry = _g[_f];
3973
3943
  iTarget = metadata$2(entry.data.target, entry.event, entry.data.value);
3974
3944
  tokens = [entry.time, entry.event];
@@ -3992,7 +3962,7 @@ function encode$3 (type, ts) {
3992
3962
  }
3993
3963
  break;
3994
3964
  case 10 /* Event.Scroll */:
3995
- for (_h = 0, _j = state$4; _h < _j.length; _h++) {
3965
+ for (_h = 0, _j = state$5; _h < _j.length; _h++) {
3996
3966
  entry = _j[_h];
3997
3967
  sTarget = metadata$2(entry.data.target, entry.event);
3998
3968
  top_1 = metadata$2(entry.data.top, entry.event);
@@ -4013,7 +3983,7 @@ function encode$3 (type, ts) {
4013
3983
  reset$g();
4014
3984
  break;
4015
3985
  case 42 /* Event.Change */:
4016
- for (_k = 0, _l = state$9; _k < _l.length; _k++) {
3986
+ for (_k = 0, _l = state$a; _k < _l.length; _k++) {
4017
3987
  entry = _l[_k];
4018
3988
  tokens = [entry.time, entry.event];
4019
3989
  target = metadata$2(entry.data.target, entry.event);
@@ -4029,7 +3999,7 @@ function encode$3 (type, ts) {
4029
3999
  reset$m();
4030
4000
  break;
4031
4001
  case 39 /* Event.Submit */:
4032
- for (_m = 0, _o = state$3; _m < _o.length; _m++) {
4002
+ for (_m = 0, _o = state$4; _m < _o.length; _m++) {
4033
4003
  entry = _o[_m];
4034
4004
  tokens = [entry.time, entry.event];
4035
4005
  target = metadata$2(entry.data.target, entry.event);
@@ -4067,10 +4037,10 @@ function encode$3 (type, ts) {
4067
4037
  });
4068
4038
  }
4069
4039
 
4070
- var state = [];
4040
+ var state$1 = [];
4071
4041
  var updates$1 = [];
4072
- function start$g() {
4073
- state = [];
4042
+ function start$h() {
4043
+ state$1 = [];
4074
4044
  reset$5();
4075
4045
  }
4076
4046
  function reset$5() {
@@ -4079,7 +4049,7 @@ function reset$5() {
4079
4049
  function track$2(time, event, hash, x, y, reaction, context) {
4080
4050
  if (reaction === void 0) { reaction = 1 /* BooleanFlag.True */; }
4081
4051
  if (context === void 0) { context = 0 /* BrowsingContext.Self */; }
4082
- state.push({
4052
+ state$1.push({
4083
4053
  time: time,
4084
4054
  event: 22 /* Event.Timeline */,
4085
4055
  data: {
@@ -4096,12 +4066,12 @@ function track$2(time, event, hash, x, y, reaction, context) {
4096
4066
  // We would still need to capture the last scroll position as part of the baseline event, even when timeline will be empty.
4097
4067
  track$8(event, x, y, time);
4098
4068
  }
4099
- function compute$5() {
4069
+ function compute$4() {
4100
4070
  var temp = [];
4101
4071
  updates$1 = [];
4102
4072
  var max = data$1.start + data$1.duration;
4103
4073
  var min = Math.max(max - 2000 /* Setting.TimelineSpan */, 0);
4104
- for (var _i = 0, state_1 = state; _i < state_1.length; _i++) {
4074
+ for (var _i = 0, state_1 = state$1; _i < state_1.length; _i++) {
4105
4075
  var s = state_1[_i];
4106
4076
  if (s.time >= min) {
4107
4077
  if (s.time <= max) {
@@ -4110,11 +4080,11 @@ function compute$5() {
4110
4080
  temp.push(s);
4111
4081
  }
4112
4082
  }
4113
- state = temp; // Drop events less than the min time
4083
+ state$1 = temp; // Drop events less than the min time
4114
4084
  encode$3(22 /* Event.Timeline */);
4115
4085
  }
4116
- function stop$e() {
4117
- state = [];
4086
+ function stop$f() {
4087
+ state$1 = [];
4118
4088
  reset$5();
4119
4089
  }
4120
4090
 
@@ -4127,7 +4097,7 @@ var transit;
4127
4097
  var active$1;
4128
4098
  var queuedTime = 0;
4129
4099
  var track$1;
4130
- function start$f() {
4100
+ function start$g() {
4131
4101
  active$1 = true;
4132
4102
  discoverBytes = 0;
4133
4103
  playbackBytes = 0;
@@ -4181,7 +4151,7 @@ function queue(tokens, transmit) {
4181
4151
  }
4182
4152
  }
4183
4153
  }
4184
- function stop$d() {
4154
+ function stop$e() {
4185
4155
  clearTimeout(timeout);
4186
4156
  upload(true);
4187
4157
  discoverBytes = 0;
@@ -4207,10 +4177,10 @@ function upload(final) {
4207
4177
  }
4208
4178
  // CAUTION: Ensure "transmit" is set to false in the queue function for following events
4209
4179
  // Otherwise you run a risk of infinite loop.
4210
- compute$6();
4211
4180
  compute$5();
4212
- compute$a();
4213
- compute$8();
4181
+ compute$4();
4182
+ compute$9();
4183
+ compute$7();
4214
4184
  last = final === true;
4215
4185
  e = JSON.stringify(envelope(last));
4216
4186
  a = "[".concat(analysis.join(), "]");
@@ -4388,7 +4358,7 @@ function response(payload) {
4388
4358
  break;
4389
4359
  case "EXTRACT" /* Constant.Extract */:
4390
4360
  if (parts.length > 1) {
4391
- trigger$1(parts[1]);
4361
+ trigger$2(parts[1]);
4392
4362
  }
4393
4363
  break;
4394
4364
  case "SIGNAL" /* Constant.Signal */:
@@ -4402,7 +4372,7 @@ function response(payload) {
4402
4372
 
4403
4373
  var history$3 = {};
4404
4374
  var data$7;
4405
- function start$e() {
4375
+ function start$f() {
4406
4376
  bind(window, "error", handler);
4407
4377
  history$3 = {};
4408
4378
  }
@@ -4471,7 +4441,7 @@ function encode$2 (type) {
4471
4441
 
4472
4442
  var history$2 = {};
4473
4443
  var data$6;
4474
- function start$d() {
4444
+ function start$e() {
4475
4445
  history$2 = {};
4476
4446
  }
4477
4447
  function log$1(code, severity, name, message, stack) {
@@ -4494,196 +4464,270 @@ function log$1(code, severity, name, message, stack) {
4494
4464
  }
4495
4465
  encode$2(33 /* Event.Log */);
4496
4466
  }
4497
- function stop$c() {
4467
+ function stop$d() {
4498
4468
  history$2 = {};
4499
4469
  }
4500
4470
 
4501
- var data$5 = {};
4502
- var keys = new Set();
4503
- var variables = {};
4504
- var selectors = {};
4505
- var hashes = {};
4506
- var validation = {};
4507
- function start$c() {
4508
- reset$4();
4471
+ // Track the start time to be able to compute duration at the end of the task
4472
+ var idleTimeout = 5000;
4473
+ var tracker = {};
4474
+ var queuedTasks = [];
4475
+ var activeTask = null;
4476
+ var pauseTask = null;
4477
+ var resumeResolve = null;
4478
+ function pause$1() {
4479
+ if (pauseTask === null) {
4480
+ pauseTask = new Promise(function (resolve) {
4481
+ resumeResolve = resolve;
4482
+ });
4483
+ }
4509
4484
  }
4510
- // Input string is of the following form:
4511
- // EXTRACT 101|element { "1": ".class1", "2": "~window.a.b", "3": "!abc"}
4512
- // if element is present on the page it will set up event 101 to grab the contents of the class1 selector into component 1,
4513
- // the javascript evaluated contents of window.a.b into component 2,
4514
- // and the contents of Clarity's hash abc into component 3
4515
- function trigger$1(input) {
4516
- try {
4517
- var parts = input && input.length > 0 ? input.split(/ (.*)/) : ["" /* Constant.Empty */];
4518
- var keyparts = parts[0].split(/\|(.*)/);
4519
- var key = parseInt(keyparts[0]);
4520
- var element = keyparts.length > 1 ? keyparts[1] : "" /* Constant.Empty */;
4521
- var values = parts.length > 1 ? JSON.parse(parts[1]) : {};
4522
- variables[key] = {};
4523
- selectors[key] = {};
4524
- hashes[key] = {};
4525
- validation[key] = element;
4526
- for (var v in values) {
4527
- // values is a set of strings for proper JSON parsing, but it's more efficient
4528
- // to interact with them as numbers
4529
- var id = parseInt(v);
4530
- var value = values[v];
4531
- var source = 2 /* ExtractSource.Text */;
4532
- if (value.startsWith("~" /* Constant.Tilde */)) {
4533
- source = 0 /* ExtractSource.Javascript */;
4534
- }
4535
- else if (value.startsWith("!" /* Constant.Bang */)) {
4536
- source = 4 /* ExtractSource.Hash */;
4537
- }
4538
- switch (source) {
4539
- case 0 /* ExtractSource.Javascript */:
4540
- var variable = value.slice(1);
4541
- variables[key][id] = parse(variable);
4542
- break;
4543
- case 2 /* ExtractSource.Text */:
4544
- selectors[key][id] = value;
4545
- break;
4546
- case 4 /* ExtractSource.Hash */:
4547
- var hash_1 = value.slice(1);
4548
- hashes[key][id] = hash_1;
4549
- break;
4550
- }
4485
+ function resume$1() {
4486
+ if (pauseTask) {
4487
+ resumeResolve();
4488
+ pauseTask = null;
4489
+ if (activeTask === null) {
4490
+ run();
4551
4491
  }
4552
4492
  }
4553
- catch (e) {
4554
- log$1(8 /* Code.Config */, 1 /* Severity.Warning */, e ? e.name : null);
4555
- }
4556
4493
  }
4557
- function clone(v) {
4558
- return JSON.parse(JSON.stringify(v));
4494
+ function reset$4() {
4495
+ tracker = {};
4496
+ queuedTasks = [];
4497
+ activeTask = null;
4498
+ pauseTask = null;
4559
4499
  }
4560
- function compute$4() {
4561
- try {
4562
- for (var v in variables) {
4563
- var key = parseInt(v);
4564
- if (validation[key] == "" /* Constant.Empty */ || document.querySelector(validation[key])) {
4565
- var variableData = variables[key];
4566
- for (var v_1 in variableData) {
4567
- var variableKey = parseInt(v_1);
4568
- var value = str(evaluate(clone(variableData[variableKey])));
4569
- if (value) {
4570
- update(key, variableKey, value);
4571
- }
4572
- }
4573
- var selectorData = selectors[key];
4574
- for (var s in selectorData) {
4575
- var shouldMask = false;
4576
- var selectorKey = parseInt(s);
4577
- var selector = selectorData[selectorKey];
4578
- if (selector.startsWith("@" /* Constant.At */)) {
4579
- shouldMask = true;
4580
- selector = selector.slice(1);
4581
- }
4582
- var nodes = document.querySelectorAll(selector);
4583
- if (nodes) {
4584
- var text = Array.from(nodes).map(function (e) { return e.textContent; }).join("<SEP>" /* Constant.Seperator */);
4585
- update(key, selectorKey, (shouldMask ? hash(text).trim() : text).slice(0, 10000 /* Setting.ExtractLimit */));
4586
- }
4587
- }
4588
- var hashData = hashes[key];
4589
- for (var h in hashData) {
4590
- var hashKey = parseInt(h);
4591
- var content = hashText(hashData[hashKey]).trim().slice(0, 10000 /* Setting.ExtractLimit */);
4592
- update(key, hashKey, content);
4500
+ function schedule(task, priority) {
4501
+ if (priority === void 0) { priority = 0 /* Priority.Normal */; }
4502
+ return __awaiter(this, void 0, void 0, function () {
4503
+ var _i, queuedTasks_1, q, promise;
4504
+ return __generator(this, function (_a) {
4505
+ // If this task is already scheduled, skip it
4506
+ for (_i = 0, queuedTasks_1 = queuedTasks; _i < queuedTasks_1.length; _i++) {
4507
+ q = queuedTasks_1[_i];
4508
+ if (q.task === task) {
4509
+ return [2 /*return*/];
4593
4510
  }
4594
4511
  }
4595
- }
4596
- if (keys.size > 0) {
4597
- encode$1(40 /* Event.Extract */);
4598
- }
4512
+ promise = new Promise(function (resolve) {
4513
+ var insert = priority === 1 /* Priority.High */ ? "unshift" : "push";
4514
+ // Queue this task for asynchronous execution later
4515
+ // We also store a unique page identifier (id) along with the task to ensure
4516
+ // ensure that we do not accidentally execute this task in context of a different page
4517
+ queuedTasks[insert]({ task: task, resolve: resolve, id: id() });
4518
+ });
4519
+ // If there is no active task running, and Clarity is not in pause state,
4520
+ // invoke the first task in the queue synchronously. This ensures that we don't yield the thread during unload event
4521
+ if (activeTask === null && pauseTask === null) {
4522
+ run();
4523
+ }
4524
+ return [2 /*return*/, promise];
4525
+ });
4526
+ });
4527
+ }
4528
+ function run() {
4529
+ var entry = queuedTasks.shift();
4530
+ if (entry) {
4531
+ activeTask = entry;
4532
+ entry.task().then(function () {
4533
+ // Bail out if the context in which this task was operating is different from the current page
4534
+ // An example scenario where task could span across pages is Single Page Applications (SPA)
4535
+ // A task that started on page #1, but completes on page #2
4536
+ if (entry.id !== id()) {
4537
+ return;
4538
+ }
4539
+ entry.resolve();
4540
+ activeTask = null; // Reset active task back to null now that the promise is resolved
4541
+ run();
4542
+ }).catch(function (error) {
4543
+ // If one of the scheduled tasks failed, log, recover and continue processing rest of the tasks
4544
+ if (entry.id !== id()) {
4545
+ return;
4546
+ }
4547
+ if (error) {
4548
+ log$1(0 /* Code.RunTask */, 1 /* Severity.Warning */, error.name, error.message, error.stack);
4549
+ }
4550
+ activeTask = null;
4551
+ run();
4552
+ });
4599
4553
  }
4600
- catch (e) {
4601
- log$1(5 /* Code.Selector */, 1 /* Severity.Warning */, e ? e.name : null);
4554
+ }
4555
+ function state(timer) {
4556
+ var id = key(timer);
4557
+ if (id in tracker) {
4558
+ var elapsed = performance.now() - tracker[id].start;
4559
+ return (elapsed > tracker[id].yield) ? 0 /* Task.Wait */ : 1 /* Task.Run */;
4602
4560
  }
4561
+ // If this task is no longer being tracked, send stop message to the caller
4562
+ return 2 /* Task.Stop */;
4603
4563
  }
4604
- function reset$4() {
4605
- keys.clear();
4564
+ function start$d(timer) {
4565
+ tracker[key(timer)] = { start: performance.now(), calls: 0, yield: 30 /* Setting.LongTask */ };
4606
4566
  }
4607
- function update(key, subkey, value) {
4608
- var update = false;
4609
- if (!(key in data$5)) {
4610
- data$5[key] = {};
4611
- update = true;
4612
- }
4613
- if (!isEmpty(hashes[key])
4614
- && (!(subkey in data$5[key]) || data$5[key][subkey] != value)) {
4615
- update = true;
4567
+ function restart$2(timer) {
4568
+ var id = key(timer);
4569
+ if (tracker && tracker[id]) {
4570
+ var c = tracker[id].calls;
4571
+ var y = tracker[id].yield;
4572
+ start$d(timer);
4573
+ tracker[id].calls = c + 1;
4574
+ tracker[id].yield = y;
4616
4575
  }
4617
- data$5[key][subkey] = value;
4618
- if (update) {
4619
- keys.add(key);
4576
+ }
4577
+ function stop$c(timer) {
4578
+ var end = performance.now();
4579
+ var id = key(timer);
4580
+ var duration = end - tracker[id].start;
4581
+ sum(timer.cost, duration);
4582
+ count$1(5 /* Metric.InvokeCount */);
4583
+ // For the first execution, which is synchronous, time is automatically counted towards TotalDuration.
4584
+ // However, for subsequent asynchronous runs, we need to manually update TotalDuration metric.
4585
+ if (tracker[id].calls > 0) {
4586
+ sum(4 /* Metric.TotalCost */, duration);
4620
4587
  }
4621
- return;
4622
4588
  }
4623
- function stop$b() {
4624
- reset$4();
4589
+ function suspend$1(timer) {
4590
+ var _a;
4591
+ return __awaiter(this, void 0, void 0, function () {
4592
+ var id, _b;
4593
+ return __generator(this, function (_c) {
4594
+ switch (_c.label) {
4595
+ case 0:
4596
+ id = key(timer);
4597
+ if (!(id in tracker)) return [3 /*break*/, 2];
4598
+ stop$c(timer);
4599
+ // some customer polyfills for requestIdleCallback return null
4600
+ _b = tracker[id];
4601
+ return [4 /*yield*/, wait()];
4602
+ case 1:
4603
+ // some customer polyfills for requestIdleCallback return null
4604
+ _b.yield = ((_a = (_c.sent())) === null || _a === void 0 ? void 0 : _a.timeRemaining()) || 30 /* Setting.LongTask */;
4605
+ restart$2(timer);
4606
+ _c.label = 2;
4607
+ case 2:
4608
+ // After we are done with suspending task, ensure that we are still operating in the right context
4609
+ // If the task is still being tracked, continue running the task, otherwise ask caller to stop execution
4610
+ return [2 /*return*/, id in tracker ? 1 /* Task.Run */ : 2 /* Task.Stop */];
4611
+ }
4612
+ });
4613
+ });
4625
4614
  }
4626
- function parse(variable) {
4627
- var syntax = [];
4628
- var parts = variable.split("." /* Constant.Dot */);
4629
- while (parts.length > 0) {
4630
- var part = parts.shift();
4631
- var arrayStart = part.indexOf("[" /* Constant.ArrayStart */);
4632
- var conditionStart = part.indexOf("{" /* Constant.ConditionStart */);
4633
- var conditionEnd = part.indexOf("}" /* Constant.ConditionEnd */);
4634
- syntax.push({
4635
- name: arrayStart > 0 ? part.slice(0, arrayStart) : (conditionStart > 0 ? part.slice(0, conditionStart) : part),
4636
- type: arrayStart > 0 ? 1 /* Type.Array */ : (conditionStart > 0 ? 2 /* Type.Object */ : 3 /* Type.Simple */),
4637
- condition: conditionStart > 0 ? part.slice(conditionStart + 1, conditionEnd) : null
4615
+ function key(timer) {
4616
+ return "".concat(timer.id, ".").concat(timer.cost);
4617
+ }
4618
+ function wait() {
4619
+ return __awaiter(this, void 0, void 0, function () {
4620
+ return __generator(this, function (_a) {
4621
+ switch (_a.label) {
4622
+ case 0:
4623
+ if (!pauseTask) return [3 /*break*/, 2];
4624
+ return [4 /*yield*/, pauseTask];
4625
+ case 1:
4626
+ _a.sent();
4627
+ _a.label = 2;
4628
+ case 2: return [2 /*return*/, new Promise(function (resolve) {
4629
+ requestIdleCallback(resolve, { timeout: idleTimeout });
4630
+ })];
4631
+ }
4638
4632
  });
4639
- }
4640
- return syntax;
4633
+ });
4641
4634
  }
4642
- // The function below takes in a variable name in following format: "a.b.c" and safely evaluates its value in javascript context
4643
- // 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,
4644
- // return the value for window["a"]["b"]["c"].
4645
- function evaluate(variable, base) {
4646
- if (base === void 0) { base = window; }
4647
- if (variable.length == 0) {
4648
- return base;
4649
- }
4650
- var part = variable.shift();
4651
- var output;
4652
- if (base && base[part.name]) {
4653
- var obj = base[part.name];
4654
- if (part.type !== 1 /* Type.Array */ && match(obj, part.condition)) {
4655
- output = evaluate(variable, obj);
4635
+ // Use native implementation of requestIdleCallback if it exists.
4636
+ // Otherwise, fall back to a custom implementation using requestAnimationFrame & MessageChannel.
4637
+ // While it's not possible to build a perfect polyfill given the nature of this API, the following code attempts to get close.
4638
+ // Background context: requestAnimationFrame invokes the js code right before: style, layout and paint computation within the frame.
4639
+ // This means, that any code that runs as part of requestAnimationFrame will by default be blocking in nature. Not what we want.
4640
+ // For non-blocking behavior, We need to know when browser has finished painting. This can be accomplished in two different ways (hacks):
4641
+ // (1) Use MessageChannel to pass the message, and browser will receive the message right after paint event has occured.
4642
+ // (2) Use setTimeout call within requestAnimationFrame. This also works, but there's a risk that browser may throttle setTimeout calls.
4643
+ // Given this information, we are currently using (1) from above. More information on (2) as well as some additional context is below:
4644
+ // https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Performance_best_practices_for_Firefox_fe_engineers
4645
+ function requestIdleCallbackPolyfill(callback, options) {
4646
+ var startTime = performance.now();
4647
+ var channel = new MessageChannel();
4648
+ var incoming = channel.port1;
4649
+ var outgoing = channel.port2;
4650
+ incoming.onmessage = function (event) {
4651
+ var currentTime = performance.now();
4652
+ var elapsed = currentTime - startTime;
4653
+ var duration = currentTime - event.data;
4654
+ if (duration > 30 /* Setting.LongTask */ && elapsed < options.timeout) {
4655
+ requestAnimationFrame(function () { outgoing.postMessage(currentTime); });
4656
4656
  }
4657
- else if (Array.isArray(obj)) {
4658
- var filtered = [];
4659
- for (var _i = 0, obj_1 = obj; _i < obj_1.length; _i++) {
4660
- var value = obj_1[_i];
4661
- if (match(value, part.condition)) {
4662
- var op = evaluate(variable, value);
4663
- if (op) {
4664
- filtered.push(op);
4665
- }
4666
- }
4667
- }
4668
- output = filtered;
4657
+ else {
4658
+ var didTimeout_1 = elapsed > options.timeout;
4659
+ callback({
4660
+ didTimeout: didTimeout_1,
4661
+ timeRemaining: function () { return didTimeout_1 ? 30 /* Setting.LongTask */ : Math.max(0, 30 /* Setting.LongTask */ - duration); }
4662
+ });
4669
4663
  }
4670
- return output;
4671
- }
4672
- return null;
4664
+ };
4665
+ requestAnimationFrame(function () { outgoing.postMessage(performance.now()); });
4673
4666
  }
4674
- function str(input) {
4675
- // Automatically trim string to max of Setting.ExtractLimit to avoid fetching long strings
4676
- return input ? JSON.stringify(input).slice(0, 10000 /* Setting.ExtractLimit */) : input;
4667
+ var requestIdleCallback = window["requestIdleCallback"] || requestIdleCallbackPolyfill;
4668
+
4669
+ function start$c() {
4670
+ schedule(discover, 1 /* Priority.High */).then(function () {
4671
+ measure(compute$6)();
4672
+ measure(compute$5)();
4673
+ measure(compute$8)();
4674
+ });
4677
4675
  }
4678
- function match(base, condition) {
4679
- if (condition) {
4680
- var prop = condition.split(":");
4681
- return prop.length > 1 ? base[prop[0]] == prop[1] : base[prop[0]];
4676
+ function discover() {
4677
+ return __awaiter(this, void 0, void 0, function () {
4678
+ var ts, timer;
4679
+ return __generator(this, function (_a) {
4680
+ switch (_a.label) {
4681
+ case 0:
4682
+ ts = time();
4683
+ timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
4684
+ start$d(timer);
4685
+ return [4 /*yield*/, traverse(document, timer, 0 /* Source.Discover */, ts)];
4686
+ case 1:
4687
+ _a.sent();
4688
+ checkDocumentStyles(document, ts);
4689
+ return [4 /*yield*/, encode$4(5 /* Event.Discover */, timer, ts)];
4690
+ case 2:
4691
+ _a.sent();
4692
+ stop$c(timer);
4693
+ return [2 /*return*/];
4694
+ }
4695
+ });
4696
+ });
4697
+ }
4698
+
4699
+ var data$5 = null;
4700
+ function start$b() {
4701
+ if (!config$2.lean && config$2.upgrade) {
4702
+ config$2.upgrade("Config" /* Constant.Config */);
4682
4703
  }
4683
- return true;
4704
+ data$5 = null;
4684
4705
  }
4685
- function isEmpty(obj) {
4686
- return Object.keys(obj).length == 0;
4706
+ // Following call will upgrade the session from lean mode into the full mode retroactively from the start of the page.
4707
+ // As part of the lean mode, we do not send back any layout information - including discovery of DOM and mutations.
4708
+ // However, if there's a need for full fidelity playback, calling this function will disable lean mode
4709
+ // and send all backed up layout events to the server.
4710
+ function upgrade(key) {
4711
+ // Upgrade only if Clarity was successfully activated on the page
4712
+ if (active() && config$2.lean) {
4713
+ config$2.lean = false;
4714
+ data$5 = { key: key };
4715
+ // Update metadata to track we have upgraded this session
4716
+ callback();
4717
+ save();
4718
+ // Callback upgrade handler, if configured
4719
+ if (config$2.upgrade) {
4720
+ config$2.upgrade(key);
4721
+ }
4722
+ encode$1(3 /* Event.Upgrade */);
4723
+ if (config$2.lite) {
4724
+ start$c();
4725
+ start$n();
4726
+ }
4727
+ }
4728
+ }
4729
+ function stop$b() {
4730
+ data$5 = null;
4687
4731
  }
4688
4732
 
4689
4733
  function encode$1 (event) {
@@ -4731,7 +4775,7 @@ function encode$1 (event) {
4731
4775
  queue(tokens, false);
4732
4776
  break;
4733
4777
  case 3 /* Event.Upgrade */:
4734
- tokens.push(data$f.key);
4778
+ tokens.push(data$5.key);
4735
4779
  queue(tokens);
4736
4780
  break;
4737
4781
  case 2 /* Event.Upload */:
@@ -4747,12 +4791,12 @@ function encode$1 (event) {
4747
4791
  queue(tokens);
4748
4792
  break;
4749
4793
  case 34 /* Event.Variable */:
4750
- var variableKeys = Object.keys(data$e);
4794
+ var variableKeys = Object.keys(data$f);
4751
4795
  if (variableKeys.length > 0) {
4752
4796
  for (var _i = 0, variableKeys_1 = variableKeys; _i < variableKeys_1.length; _i++) {
4753
4797
  var v = variableKeys_1[_i];
4754
4798
  tokens.push(v);
4755
- tokens.push(data$e[v]);
4799
+ tokens.push(data$f[v]);
4756
4800
  }
4757
4801
  reset$o();
4758
4802
  queue(tokens, false);
@@ -4804,20 +4848,20 @@ function encode$1 (event) {
4804
4848
  extractKeys.forEach((function (e) {
4805
4849
  tokens.push(e);
4806
4850
  var token = [];
4807
- for (var d in data$5[e]) {
4851
+ for (var d in data$e[e]) {
4808
4852
  var key = parseInt(d, 10);
4809
4853
  token.push(key);
4810
- token.push(data$5[e][d]);
4854
+ token.push(data$e[e][d]);
4811
4855
  }
4812
4856
  tokens.push(token);
4813
4857
  }));
4814
- reset$4();
4858
+ reset$n();
4815
4859
  queue(tokens, false);
4816
4860
  }
4817
4861
  }
4818
4862
 
4819
4863
  var data$4;
4820
- function start$b() {
4864
+ function start$a() {
4821
4865
  data$4 = { check: 0 /* Check.None */ };
4822
4866
  }
4823
4867
  function check$2(bytes) {
@@ -4852,7 +4896,7 @@ function stop$a() {
4852
4896
  var data$3 = null;
4853
4897
  var updates = null;
4854
4898
  var limited = false;
4855
- function start$a() {
4899
+ function start$9() {
4856
4900
  data$3 = {};
4857
4901
  updates = {};
4858
4902
  limited = false;
@@ -4912,7 +4956,7 @@ var data$2 = null;
4912
4956
  var callbacks = [];
4913
4957
  var electron = 0 /* BooleanFlag.False */;
4914
4958
  var rootDomain = null;
4915
- function start$9() {
4959
+ function start$8() {
4916
4960
  var _a, _b, _c;
4917
4961
  rootDomain = null;
4918
4962
  var ua = navigator && "userAgent" in navigator ? navigator.userAgent : "" /* Constant.Empty */;
@@ -5239,7 +5283,7 @@ function setCookie(key, value, time) {
5239
5283
  }
5240
5284
 
5241
5285
  var data$1 = null;
5242
- function start$8() {
5286
+ function start$7() {
5243
5287
  var m = data$2;
5244
5288
  data$1 = {
5245
5289
  version: version$1,
@@ -5381,7 +5425,7 @@ var pushState = null;
5381
5425
  var replaceState = null;
5382
5426
  var url = null;
5383
5427
  var count = 0;
5384
- function start$7() {
5428
+ function start$6() {
5385
5429
  url = getCurrentUrl();
5386
5430
  count = 0;
5387
5431
  bind(window, "popstate", compute$1);
@@ -5435,19 +5479,19 @@ function stop$6() {
5435
5479
  }
5436
5480
 
5437
5481
  var status = false;
5438
- function start$6() {
5482
+ function start$5() {
5439
5483
  status = true;
5440
5484
  start$I();
5441
- reset$n();
5485
+ reset$4();
5442
5486
  reset$1();
5443
5487
  reset$2();
5444
- start$7();
5488
+ start$6();
5445
5489
  }
5446
5490
  function stop$5() {
5447
5491
  stop$6();
5448
5492
  reset$2();
5449
5493
  reset$1();
5450
- reset$n();
5494
+ reset$4();
5451
5495
  stop$F();
5452
5496
  status = false;
5453
5497
  }
@@ -5504,79 +5548,49 @@ function restart() {
5504
5548
  event("clarity" /* Constant.Clarity */, "restart" /* Constant.Restart */);
5505
5549
  }
5506
5550
 
5507
- function start$5() {
5508
- start$5.dn = 3 /* FunctionNames.DiagnosticStart */;
5551
+ function start$4() {
5552
+ start$4.dn = 3 /* FunctionNames.DiagnosticStart */;
5509
5553
  start$A();
5554
+ start$f();
5510
5555
  start$e();
5511
- start$d();
5512
5556
  }
5513
5557
  function stop$4() {
5514
- stop$c();
5558
+ stop$d();
5515
5559
  }
5516
5560
 
5517
5561
  var diagnostic = /*#__PURE__*/Object.freeze({
5518
5562
  __proto__: null,
5519
- start: start$5,
5563
+ start: start$4,
5520
5564
  stop: stop$4
5521
5565
  });
5522
5566
 
5523
- function start$4() {
5524
- schedule$1(discover, 1 /* Priority.High */).then(function () {
5525
- measure(compute$7)();
5526
- measure(compute$6)();
5527
- measure(compute$9)();
5528
- });
5529
- }
5530
- function discover() {
5531
- return __awaiter(this, void 0, void 0, function () {
5532
- var ts, timer;
5533
- return __generator(this, function (_a) {
5534
- switch (_a.label) {
5535
- case 0:
5536
- ts = time();
5537
- timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
5538
- start$z(timer);
5539
- return [4 /*yield*/, traverse(document, timer, 0 /* Source.Discover */, ts)];
5540
- case 1:
5541
- _a.sent();
5542
- checkDocumentStyles(document, ts);
5543
- return [4 /*yield*/, encode$4(5 /* Event.Discover */, timer, ts)];
5544
- case 2:
5545
- _a.sent();
5546
- stop$x(timer);
5547
- return [2 /*return*/];
5548
- }
5549
- });
5550
- });
5551
- }
5552
-
5553
5567
  function start$3() {
5554
5568
  start$3.dn = 20 /* FunctionNames.LayoutStart */;
5555
5569
  // The order below is important
5556
5570
  // and is determined by interdependencies of modules
5557
- start$k();
5558
- start$h();
5571
+ start$l();
5559
5572
  start$i();
5573
+ start$j();
5560
5574
  if (config$2.delayDom) {
5561
5575
  // Lazy load layout module as part of page load time performance improvements experiment
5562
5576
  bind(window, 'load', function () {
5563
- start$j();
5577
+ start$k();
5564
5578
  });
5565
5579
  }
5566
5580
  else {
5567
- start$j();
5581
+ start$k();
5568
5582
  }
5569
- start$4();
5583
+ start$c();
5584
+ start$n();
5570
5585
  start$m();
5571
- start$l();
5572
5586
  }
5573
5587
  function stop$3() {
5574
- stop$f();
5575
5588
  stop$g();
5576
5589
  stop$h();
5577
5590
  stop$i();
5578
- stop$k();
5579
5591
  stop$j();
5592
+ stop$l();
5593
+ stop$k();
5580
5594
  }
5581
5595
 
5582
5596
  var layout = /*#__PURE__*/Object.freeze({
@@ -5874,7 +5888,7 @@ function start(config$1) {
5874
5888
  // Check that browser supports required APIs and we do not attempt to start Clarity multiple times
5875
5889
  if (check()) {
5876
5890
  config(config$1);
5877
- start$6();
5891
+ start$5();
5878
5892
  start$B();
5879
5893
  modules.forEach(function (x) { return measure(x.start)(); });
5880
5894
  // If it's an internal call to start, without explicit configuration,