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