clarity-js 0.7.19 → 0.7.21

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.
@@ -140,7 +140,7 @@ function api(method) {
140
140
  }
141
141
 
142
142
  var startTime = 0;
143
- function start$I() {
143
+ function start$H() {
144
144
  startTime = performance.now();
145
145
  }
146
146
  function time(event) {
@@ -148,11 +148,11 @@ function time(event) {
148
148
  var ts = event && event.timeStamp > 0 ? event.timeStamp : performance.now();
149
149
  return Math.max(Math.round(ts - startTime), 0);
150
150
  }
151
- function stop$F() {
151
+ function stop$E() {
152
152
  startTime = 0;
153
153
  }
154
154
 
155
- var version$1 = "0.7.19";
155
+ var version$1 = "0.7.21";
156
156
 
157
157
  // tslint:disable: no-bitwise
158
158
  function hash (input, precision) {
@@ -356,11 +356,11 @@ function redact$1(value) {
356
356
  var state$c = null;
357
357
  var buffer = null;
358
358
  var update$2 = false;
359
- function start$H() {
359
+ function start$G() {
360
360
  update$2 = false;
361
- reset$s();
361
+ reset$r();
362
362
  }
363
- function reset$s() {
363
+ function reset$r() {
364
364
  // Baseline state holds the previous values - if it is updated in the current payload,
365
365
  // reset the state to current value after sending the previous state
366
366
  if (update$2) {
@@ -422,23 +422,23 @@ function visibility(t, visible) {
422
422
  }
423
423
  update$2 = true;
424
424
  }
425
- function compute$d() {
425
+ function compute$c() {
426
426
  if (update$2) {
427
427
  encode$1(4 /* Event.Baseline */);
428
428
  }
429
429
  }
430
- function stop$E() {
431
- reset$s();
430
+ function stop$D() {
431
+ reset$r();
432
432
  }
433
433
 
434
434
  var baseline = /*#__PURE__*/Object.freeze({
435
435
  __proto__: null,
436
436
  activity: activity,
437
- compute: compute$d,
438
- reset: reset$s,
439
- start: start$H,
437
+ compute: compute$c,
438
+ reset: reset$r,
439
+ start: start$G,
440
440
  get state () { return state$c; },
441
- stop: stop$E,
441
+ stop: stop$D,
442
442
  track: track$8,
443
443
  visibility: visibility
444
444
  });
@@ -463,12 +463,12 @@ function event(a, b) {
463
463
 
464
464
  var data$i = null;
465
465
  var updates$3 = null;
466
- function start$G() {
466
+ function start$F() {
467
467
  data$i = {};
468
468
  updates$3 = {};
469
469
  count$1(5 /* Metric.InvokeCount */);
470
470
  }
471
- function stop$D() {
471
+ function stop$C() {
472
472
  data$i = {};
473
473
  updates$3 = {};
474
474
  }
@@ -506,10 +506,10 @@ function max(metric, value) {
506
506
  }
507
507
  }
508
508
  }
509
- function compute$c() {
509
+ function compute$b() {
510
510
  encode$1(0 /* Event.Metric */);
511
511
  }
512
- function reset$r() {
512
+ function reset$q() {
513
513
  updates$3 = {};
514
514
  }
515
515
 
@@ -524,11 +524,11 @@ var data$h;
524
524
  var last = 0;
525
525
  var interval = 0;
526
526
  var timeout$6 = null;
527
- function start$F() {
527
+ function start$E() {
528
528
  interval = 60000 /* Setting.PingInterval */;
529
529
  last = 0;
530
530
  }
531
- function reset$q() {
531
+ function reset$p() {
532
532
  if (timeout$6) {
533
533
  clearTimeout(timeout$6);
534
534
  }
@@ -546,7 +546,7 @@ function ping() {
546
546
  suspend();
547
547
  }
548
548
  }
549
- function stop$C() {
549
+ function stop$B() {
550
550
  clearTimeout(timeout$6);
551
551
  last = 0;
552
552
  interval = 0;
@@ -555,16 +555,16 @@ function stop$C() {
555
555
  var ping$1 = /*#__PURE__*/Object.freeze({
556
556
  __proto__: null,
557
557
  get data () { return data$h; },
558
- reset: reset$q,
559
- start: start$F,
560
- stop: stop$C
558
+ reset: reset$p,
559
+ start: start$E,
560
+ stop: stop$B
561
561
  });
562
562
 
563
563
  var data$g = null;
564
- function start$E() {
564
+ function start$D() {
565
565
  data$g = {};
566
566
  }
567
- function stop$B() {
567
+ function stop$A() {
568
568
  data$g = {};
569
569
  }
570
570
  function track$7(event, time) {
@@ -584,25 +584,25 @@ function track$7(event, time) {
584
584
  }
585
585
  }
586
586
  }
587
- function compute$b() {
587
+ function compute$a() {
588
588
  encode$1(36 /* Event.Summary */);
589
589
  }
590
- function reset$p() {
590
+ function reset$o() {
591
591
  data$g = {};
592
592
  }
593
593
 
594
594
  var summary = /*#__PURE__*/Object.freeze({
595
595
  __proto__: null,
596
- compute: compute$b,
596
+ compute: compute$a,
597
597
  get data () { return data$g; },
598
- reset: reset$p,
599
- start: start$E,
600
- stop: stop$B,
598
+ reset: reset$o,
599
+ start: start$D,
600
+ stop: stop$A,
601
601
  track: track$7
602
602
  });
603
603
 
604
604
  var data$f = null;
605
- function start$D() {
605
+ function start$C() {
606
606
  if (!config$1.lean && config$1.upgrade) {
607
607
  config$1.upgrade("Config" /* Constant.Config */);
608
608
  }
@@ -626,15 +626,15 @@ function upgrade(key) {
626
626
  encode$1(3 /* Event.Upgrade */);
627
627
  }
628
628
  }
629
- function stop$A() {
629
+ function stop$z() {
630
630
  data$f = null;
631
631
  }
632
632
 
633
633
  var upgrade$1 = /*#__PURE__*/Object.freeze({
634
634
  __proto__: null,
635
635
  get data () { return data$f; },
636
- start: start$D,
637
- stop: stop$A,
636
+ start: start$C,
637
+ stop: stop$z,
638
638
  upgrade: upgrade
639
639
  });
640
640
 
@@ -692,8 +692,8 @@ function __generator(thisArg, body) {
692
692
  }
693
693
 
694
694
  var data$e = null;
695
- function start$C() {
696
- reset$o();
695
+ function start$B() {
696
+ reset$n();
697
697
  }
698
698
  function set(variable, value) {
699
699
  var values = typeof value === "string" /* Constant.String */ ? [value] : value;
@@ -748,14 +748,14 @@ function log$2(variable, value) {
748
748
  data$e[variable] = validValues;
749
749
  }
750
750
  }
751
- function compute$a() {
751
+ function compute$9() {
752
752
  encode$1(34 /* Event.Variable */);
753
753
  }
754
- function reset$o() {
754
+ function reset$n() {
755
755
  data$e = {};
756
756
  }
757
- function stop$z() {
758
- reset$o();
757
+ function stop$y() {
758
+ reset$n();
759
759
  }
760
760
  function redact(input) {
761
761
  return input && input.length >= 5 /* Setting.WordLength */ ?
@@ -789,13 +789,13 @@ function detect(input) {
789
789
 
790
790
  var variable = /*#__PURE__*/Object.freeze({
791
791
  __proto__: null,
792
- compute: compute$a,
792
+ compute: compute$9,
793
793
  get data () { return data$e; },
794
794
  identify: identify,
795
- reset: reset$o,
795
+ reset: reset$n,
796
796
  set: set,
797
- start: start$C,
798
- stop: stop$z
797
+ start: start$B,
798
+ stop: stop$y
799
799
  });
800
800
 
801
801
  var supported$1 = "CompressionStream" /* Constant.CompressionStream */ in window;
@@ -857,32 +857,32 @@ function read(stream) {
857
857
  }
858
858
 
859
859
  var modules$1 = [baseline, dimension, variable, limit, summary, metadata$1, envelope$1, upload$1, ping$1, upgrade$1, extract];
860
- function start$B() {
860
+ function start$A() {
861
861
  // Metric needs to be initialized before we can start measuring. so metric is not wrapped in measure
862
- start$G();
862
+ start$F();
863
863
  modules$1.forEach(function (x) { return measure(x.start)(); });
864
864
  }
865
- function stop$y() {
865
+ function stop$x() {
866
866
  // Stop modules in the reverse order of their initialization
867
867
  // The ordering below should respect inter-module dependency.
868
868
  // E.g. if upgrade depends on upload, then upgrade needs to end before upload.
869
869
  // Similarly, if upload depends on metadata, upload needs to end before metadata.
870
870
  modules$1.slice().reverse().forEach(function (x) { return measure(x.stop)(); });
871
- stop$D();
871
+ stop$C();
872
872
  }
873
- function compute$9() {
874
- compute$a();
875
- compute$d();
876
- compute$2();
873
+ function compute$8() {
874
+ compute$9();
877
875
  compute$c();
876
+ compute$2();
878
877
  compute$b();
878
+ compute$a();
879
879
  compute$3();
880
880
  compute$4();
881
881
  }
882
882
 
883
883
  var history$5 = [];
884
884
  var data$d;
885
- function start$A() {
885
+ function start$z() {
886
886
  history$5 = [];
887
887
  max(26 /* Metric.Automation */, navigator.webdriver ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */);
888
888
  try {
@@ -906,7 +906,7 @@ function check$4(id, target, input) {
906
906
 
907
907
  var excludeClassNames = "load,active,fixed,visible,focus,show,collaps,animat" /* Constant.ExcludeClassNames */.split("," /* Constant.Comma */);
908
908
  var selectorMap = {};
909
- function reset$n() {
909
+ function reset$m() {
910
910
  selectorMap = {};
911
911
  }
912
912
  function get$1(input, type) {
@@ -995,7 +995,7 @@ function filter(value) {
995
995
  var selector = /*#__PURE__*/Object.freeze({
996
996
  __proto__: null,
997
997
  get: get$1,
998
- reset: reset$n
998
+ reset: reset$m
999
999
  });
1000
1000
 
1001
1001
  var index = 1;
@@ -1014,14 +1014,14 @@ var idMap = null; // Maps node => id.
1014
1014
  var iframeMap = null; // Maps iframe's contentDocument => parent iframe element
1015
1015
  var privacyMap = null; // Maps node => Privacy (enum)
1016
1016
  var fraudMap = null; // Maps node => FraudId (number)
1017
- function start$z() {
1018
- reset$m();
1017
+ function start$y() {
1018
+ reset$l();
1019
1019
  parse$1(document, true);
1020
1020
  }
1021
- function stop$x() {
1022
- reset$m();
1021
+ function stop$w() {
1022
+ reset$l();
1023
1023
  }
1024
- function reset$m() {
1024
+ function reset$l() {
1025
1025
  index = 1;
1026
1026
  values = [];
1027
1027
  updateMap = [];
@@ -1037,7 +1037,7 @@ function reset$m() {
1037
1037
  iframeMap = new WeakMap();
1038
1038
  privacyMap = new WeakMap();
1039
1039
  fraudMap = new WeakMap();
1040
- reset$n();
1040
+ reset$m();
1041
1041
  }
1042
1042
  // We parse new root nodes for any regions or masked nodes in the beginning (document) and
1043
1043
  // later whenever there are new additions or modifications to DOM (mutations)
@@ -1053,7 +1053,7 @@ function parse$1(root, init) {
1053
1053
  // Since mutations may happen on leaf nodes too, e.g. text nodes, which may not support all selector APIs.
1054
1054
  // We ensure that the root note supports querySelectorAll API before executing the code below to identify new regions.
1055
1055
  if ("querySelectorAll" in root) {
1056
- config$1.regions.forEach(function (x) { return root.querySelectorAll(x[1]).forEach(function (e) { return observe$1(e, "".concat(x[0])); }); }); // Regions
1056
+ config$1.regions.forEach(function (x) { return root.querySelectorAll(x[1]).forEach(function (e) { return observe$c(e, "".concat(x[0])); }); }); // Regions
1057
1057
  config$1.mask.forEach(function (x) { return root.querySelectorAll(x).forEach(function (e) { return privacyMap.set(e, 3 /* Privacy.TextImage */); }); }); // Masked Elements
1058
1058
  config$1.checksum.forEach(function (x) { return root.querySelectorAll(x[1]).forEach(function (e) { return fraudMap.set(e, x[0]); }); }); // Fraud Checksum Check
1059
1059
  unmask.forEach(function (x) { return root.querySelectorAll(x).forEach(function (e) { return privacyMap.set(e, 0 /* Privacy.None */); }); }); // Unmasked Elements
@@ -1092,7 +1092,7 @@ function add(node, parent, data, source) {
1092
1092
  }
1093
1093
  // If there's an explicit region attribute set on the element, use it to mark a region on the page
1094
1094
  if (data.attributes && "data-clarity-region" /* Constant.RegionData */ in data.attributes) {
1095
- observe$1(node, data.attributes["data-clarity-region" /* Constant.RegionData */]);
1095
+ observe$c(node, data.attributes["data-clarity-region" /* Constant.RegionData */]);
1096
1096
  regionId = id;
1097
1097
  }
1098
1098
  nodesMap.set(id, node);
@@ -1373,8 +1373,8 @@ var dom = /*#__PURE__*/Object.freeze({
1373
1373
  lookup: lookup,
1374
1374
  parse: parse$1,
1375
1375
  sameorigin: sameorigin,
1376
- start: start$z,
1377
- stop: stop$x,
1376
+ start: start$y,
1377
+ stop: stop$w,
1378
1378
  update: update$1,
1379
1379
  updates: updates$2
1380
1380
  });
@@ -1402,7 +1402,7 @@ function resume$1() {
1402
1402
  }
1403
1403
  }
1404
1404
  }
1405
- function reset$l() {
1405
+ function reset$k() {
1406
1406
  tracker = {};
1407
1407
  queuedTasks = [];
1408
1408
  activeTask = null;
@@ -1472,7 +1472,7 @@ function state$b(timer) {
1472
1472
  // If this task is no longer being tracked, send stop message to the caller
1473
1473
  return 2 /* Task.Stop */;
1474
1474
  }
1475
- function start$y(timer) {
1475
+ function start$x(timer) {
1476
1476
  tracker[key(timer)] = { start: performance.now(), calls: 0, yield: 30 /* Setting.LongTask */ };
1477
1477
  }
1478
1478
  function restart$2(timer) {
@@ -1480,12 +1480,12 @@ function restart$2(timer) {
1480
1480
  if (tracker && tracker[id]) {
1481
1481
  var c = tracker[id].calls;
1482
1482
  var y = tracker[id].yield;
1483
- start$y(timer);
1483
+ start$x(timer);
1484
1484
  tracker[id].calls = c + 1;
1485
1485
  tracker[id].yield = y;
1486
1486
  }
1487
1487
  }
1488
- function stop$w(timer) {
1488
+ function stop$v(timer) {
1489
1489
  var end = performance.now();
1490
1490
  var id = key(timer);
1491
1491
  var duration = end - tracker[id].start;
@@ -1505,7 +1505,7 @@ function suspend$1(timer) {
1505
1505
  case 0:
1506
1506
  id = key(timer);
1507
1507
  if (!(id in tracker)) return [3 /*break*/, 2];
1508
- stop$w(timer);
1508
+ stop$v(timer);
1509
1509
  _a = tracker[id];
1510
1510
  return [4 /*yield*/, wait()];
1511
1511
  case 1:
@@ -1618,14 +1618,14 @@ function tokenize (tokens) {
1618
1618
  }
1619
1619
 
1620
1620
  var data$c;
1621
- function reset$k() {
1621
+ function reset$j() {
1622
1622
  data$c = null;
1623
1623
  }
1624
- function start$x() {
1625
- reset$k();
1626
- compute$8();
1624
+ function start$w() {
1625
+ reset$j();
1626
+ compute$7();
1627
1627
  }
1628
- function compute$8() {
1628
+ function compute$7() {
1629
1629
  var body = document.body;
1630
1630
  var d = document.documentElement;
1631
1631
  var bodyClientWidth = body ? body.clientWidth : null;
@@ -1648,256 +1648,461 @@ function compute$8() {
1648
1648
  encode$4(8 /* Event.Document */);
1649
1649
  }
1650
1650
  }
1651
- function stop$v() {
1652
- reset$k();
1653
- }
1654
-
1655
- var state$a = [];
1656
- function start$w() {
1657
- reset$j();
1658
- }
1659
- function observe$c(root) {
1660
- bind(root, "change", recompute$8, true);
1661
- }
1662
- function recompute$8(evt) {
1663
- var element = target(evt);
1664
- if (element) {
1665
- var value = element.value;
1666
- var checksum = value && value.length >= 5 /* Setting.WordLength */ && config$1.fraud && "password,secret,pass,social,ssn,code,hidden" /* Mask.Exclude */.indexOf(element.type) === -1 ? hash(value, 24 /* Setting.ChecksumPrecision */) : "" /* Constant.Empty */;
1667
- state$a.push({ time: time(evt), event: 42 /* Event.Change */, data: { target: target(evt), type: element.type, value: value, checksum: checksum } });
1668
- schedule$1(encode$3.bind(this, 42 /* Event.Change */));
1669
- }
1670
- }
1671
- function reset$j() {
1672
- state$a = [];
1673
- }
1674
1651
  function stop$u() {
1675
1652
  reset$j();
1676
1653
  }
1677
1654
 
1678
- function offset(element) {
1679
- var output = { x: 0, y: 0 };
1680
- // Walk up the chain to ensure we compute offset distance correctly
1681
- // In case where we may have nested IFRAMEs, we keep walking up until we get to the top most parent page
1682
- if (element && element.offsetParent) {
1683
- do {
1684
- var parent_1 = element.offsetParent;
1685
- var frame = parent_1 === null ? iframe(element.ownerDocument) : null;
1686
- output.x += element.offsetLeft;
1687
- output.y += element.offsetTop;
1688
- element = frame ? frame : parent_1;
1689
- } while (element);
1690
- }
1691
- return output;
1692
- }
1655
+ var state$a = [];
1693
1656
 
1694
- var UserInputTags = ["input", "textarea", "radio", "button", "canvas"];
1695
1657
  var state$9 = [];
1658
+ var animationPlay = null;
1659
+ var animationPause = null;
1660
+ var animationCancel = null;
1661
+ var animationFinish = null;
1662
+ var animationId = 'clarityAnimationId';
1663
+ var operationCount = 'clarityOperationCount';
1664
+ var maxOperations = 20;
1696
1665
  function start$v() {
1697
- reset$i();
1698
- }
1699
- function observe$b(root) {
1700
- bind(root, "click", handler$3.bind(this, 9 /* Event.Click */, root), true);
1701
- }
1702
- function handler$3(event, root, evt) {
1703
- var frame = iframe(root);
1704
- var d = frame ? frame.contentDocument.documentElement : document.documentElement;
1705
- var x = "pageX" in evt ? Math.round(evt.pageX) : ("clientX" in evt ? Math.round(evt["clientX"] + d.scrollLeft) : null);
1706
- var y = "pageY" in evt ? Math.round(evt.pageY) : ("clientY" in evt ? Math.round(evt["clientY"] + d.scrollTop) : null);
1707
- // In case of iframe, we adjust (x,y) to be relative to top parent's origin
1708
- if (frame) {
1709
- var distance = offset(frame);
1710
- x = x ? x + Math.round(distance.x) : x;
1711
- y = y ? y + Math.round(distance.y) : y;
1712
- }
1713
- var t = target(evt);
1714
- // Find nearest anchor tag (<a/>) parent if current target node is part of one
1715
- // If present, we use the returned link element to populate text and link properties below
1716
- var a = link(t);
1717
- // Get layout rectangle for the target element
1718
- var l = layout$1(t);
1719
- // Reference: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
1720
- // This property helps differentiate between a keyboard navigation vs. pointer click
1721
- // In case of a keyboard navigation, we use center of target element as (x,y)
1722
- if (evt.detail === 0 && l) {
1723
- x = Math.round(l.x + (l.w / 2));
1724
- y = Math.round(l.y + (l.h / 2));
1725
- }
1726
- var eX = l ? Math.max(Math.floor(((x - l.x) / l.w) * 32767 /* Setting.ClickPrecision */), 0) : 0;
1727
- var eY = l ? Math.max(Math.floor(((y - l.y) / l.h) * 32767 /* Setting.ClickPrecision */), 0) : 0;
1728
- // Check for null values before processing this event
1729
- if (x !== null && y !== null) {
1730
- state$9.push({
1731
- time: time(evt),
1732
- event: event,
1733
- data: {
1734
- target: t,
1735
- x: x,
1736
- y: y,
1737
- eX: eX,
1738
- eY: eY,
1739
- button: evt.button,
1740
- reaction: reaction(t),
1741
- context: context(a),
1742
- text: text(t),
1743
- link: a ? a.href : null,
1744
- hash: null,
1745
- trust: evt.isTrusted ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */
1746
- }
1747
- });
1748
- schedule$1(encode$3.bind(this, event));
1749
- }
1750
- }
1751
- function link(node) {
1752
- while (node && node !== document) {
1753
- if (node.nodeType === Node.ELEMENT_NODE) {
1754
- var element = node;
1755
- if (element.tagName === "A") {
1756
- return element;
1757
- }
1758
- }
1759
- node = node.parentNode;
1666
+ if (window["Animation"] &&
1667
+ window["KeyframeEffect"] &&
1668
+ window["KeyframeEffect"].prototype.getKeyframes &&
1669
+ window["KeyframeEffect"].prototype.getTiming) {
1670
+ reset$i();
1671
+ overrideAnimationHelper(animationPlay, "play");
1672
+ overrideAnimationHelper(animationPause, "pause");
1673
+ overrideAnimationHelper(animationCancel, "cancel");
1674
+ overrideAnimationHelper(animationFinish, "finish");
1760
1675
  }
1761
- return null;
1762
1676
  }
1763
- function text(element) {
1764
- var output = null;
1765
- if (element) {
1766
- // Grab text using "textContent" for most HTMLElements, however, use "value" for HTMLInputElements and "alt" for HTMLImageElement.
1767
- var t = element.textContent || element.value || element.alt;
1768
- if (t) {
1769
- // Replace multiple occurrence of space characters with a single white space
1770
- // Also, trim any spaces at the beginning or at the end of string
1771
- // Finally, send only first few characters as specified by the Setting
1772
- output = t.replace(/\s+/g, " " /* Constant.Space */).trim().substr(0, 25 /* Setting.ClickText */);
1773
- }
1774
- }
1775
- return output;
1677
+ function reset$i() {
1678
+ state$9 = [];
1776
1679
  }
1777
- function reaction(element) {
1778
- if (element.nodeType === Node.ELEMENT_NODE) {
1779
- var tag = element.tagName.toLowerCase();
1780
- if (UserInputTags.indexOf(tag) >= 0) {
1781
- return 0 /* BooleanFlag.False */;
1680
+ function track$5(time, id, operation, keyFrames, timing, targetId, timeline) {
1681
+ state$9.push({
1682
+ time: time,
1683
+ event: 44 /* Event.Animation */,
1684
+ data: {
1685
+ id: id,
1686
+ operation: operation,
1687
+ keyFrames: keyFrames,
1688
+ timing: timing,
1689
+ targetId: targetId,
1690
+ timeline: timeline
1782
1691
  }
1783
- }
1784
- return 1 /* BooleanFlag.True */;
1692
+ });
1693
+ encode$4(44 /* Event.Animation */);
1785
1694
  }
1786
- function layout$1(element) {
1787
- var box = null;
1788
- var de = document.documentElement;
1789
- if (typeof element.getBoundingClientRect === "function") {
1790
- // getBoundingClientRect returns rectangle relative positioning to viewport
1791
- var rect = element.getBoundingClientRect();
1792
- if (rect && rect.width > 0 && rect.height > 0) {
1793
- // Add viewport's scroll position to rectangle to get position relative to document origin
1794
- // Also: using Math.floor() instead of Math.round() because in Edge,
1795
- // getBoundingClientRect returns partial pixel values (e.g. 162.5px) and Chrome already
1796
- // floors the value (e.g. 162px). This keeps consistent behavior across browsers.
1797
- box = {
1798
- x: Math.floor(rect.left + ("pageXOffset" in window ? window.pageXOffset : de.scrollLeft)),
1799
- y: Math.floor(rect.top + ("pageYOffset" in window ? window.pageYOffset : de.scrollTop)),
1800
- w: Math.floor(rect.width),
1801
- h: Math.floor(rect.height)
1802
- };
1803
- }
1804
- }
1805
- return box;
1695
+ function stop$t() {
1696
+ reset$i();
1806
1697
  }
1807
- function context(a) {
1808
- if (a && a.hasAttribute("target" /* Constant.Target */)) {
1809
- switch (a.getAttribute("target" /* Constant.Target */)) {
1810
- case "_blank" /* Constant.Blank */: return 1 /* BrowsingContext.Blank */;
1811
- case "_parent" /* Constant.Parent */: return 2 /* BrowsingContext.Parent */;
1812
- case "_top" /* Constant.Top */: return 3 /* BrowsingContext.Top */;
1698
+ function overrideAnimationHelper(functionToOverride, name) {
1699
+ if (functionToOverride === null) {
1700
+ functionToOverride = Animation.prototype[name];
1701
+ Animation.prototype[name] = function () {
1702
+ if (active()) {
1703
+ var effect = this.effect;
1704
+ var target = getId(this.effect.target);
1705
+ if (target !== null && effect.getKeyframes && effect.getTiming) {
1706
+ if (!this[animationId]) {
1707
+ this[animationId] = shortid();
1708
+ this[operationCount] = 0;
1709
+ var keyframes = effect.getKeyframes();
1710
+ var timing = effect.getTiming();
1711
+ track$5(time(), this[animationId], 0 /* AnimationOperation.Create */, JSON.stringify(keyframes), JSON.stringify(timing), target);
1712
+ }
1713
+ if (this[operationCount]++ < maxOperations) {
1714
+ var operation = null;
1715
+ switch (name) {
1716
+ case "play":
1717
+ operation = 1 /* AnimationOperation.Play */;
1718
+ break;
1719
+ case "pause":
1720
+ operation = 2 /* AnimationOperation.Pause */;
1721
+ break;
1722
+ case "cancel":
1723
+ operation = 3 /* AnimationOperation.Cancel */;
1724
+ break;
1725
+ case "finish":
1726
+ operation = 4 /* AnimationOperation.Finish */;
1727
+ break;
1728
+ }
1729
+ if (operation) {
1730
+ track$5(time(), this[animationId], operation);
1731
+ }
1732
+ }
1733
+ }
1734
+ }
1735
+ return functionToOverride.apply(this, arguments);
1736
+ };
1737
+ }
1738
+ }
1739
+
1740
+ function encode$4 (type, timer, ts) {
1741
+ if (timer === void 0) { timer = null; }
1742
+ if (ts === void 0) { ts = null; }
1743
+ return __awaiter(this, void 0, void 0, function () {
1744
+ 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;
1745
+ return __generator(this, function (_l) {
1746
+ switch (_l.label) {
1747
+ case 0:
1748
+ eventTime = ts || time();
1749
+ tokens = [eventTime, type];
1750
+ _a = type;
1751
+ switch (_a) {
1752
+ case 8 /* Event.Document */: return [3 /*break*/, 1];
1753
+ case 7 /* Event.Region */: return [3 /*break*/, 2];
1754
+ case 45 /* Event.StyleSheetAdoption */: return [3 /*break*/, 3];
1755
+ case 46 /* Event.StyleSheetUpdate */: return [3 /*break*/, 4];
1756
+ case 44 /* Event.Animation */: return [3 /*break*/, 5];
1757
+ case 5 /* Event.Discover */: return [3 /*break*/, 6];
1758
+ case 6 /* Event.Mutation */: return [3 /*break*/, 6];
1759
+ }
1760
+ return [3 /*break*/, 13];
1761
+ case 1:
1762
+ d = data$c;
1763
+ tokens.push(d.width);
1764
+ tokens.push(d.height);
1765
+ track$8(type, d.width, d.height);
1766
+ queue(tokens);
1767
+ return [3 /*break*/, 13];
1768
+ case 2:
1769
+ for (_i = 0, _b = state$8; _i < _b.length; _i++) {
1770
+ r = _b[_i];
1771
+ tokens = [r.time, 7 /* Event.Region */];
1772
+ tokens.push(r.data.id);
1773
+ tokens.push(r.data.interaction);
1774
+ tokens.push(r.data.visibility);
1775
+ tokens.push(r.data.name);
1776
+ queue(tokens);
1777
+ }
1778
+ reset$h();
1779
+ return [3 /*break*/, 13];
1780
+ case 3:
1781
+ for (_c = 0, _d = state$a; _c < _d.length; _c++) {
1782
+ entry = _d[_c];
1783
+ tokens = [entry.time, entry.event];
1784
+ tokens.push(entry.data.id);
1785
+ tokens.push(entry.data.operation);
1786
+ tokens.push(entry.data.newIds);
1787
+ queue(tokens);
1788
+ }
1789
+ return [3 /*break*/, 13];
1790
+ case 4:
1791
+ for (_e = 0, _f = state$a; _e < _f.length; _e++) {
1792
+ entry = _f[_e];
1793
+ tokens = [entry.time, entry.event];
1794
+ tokens.push(entry.data.id);
1795
+ tokens.push(entry.data.operation);
1796
+ tokens.push(entry.data.cssRules);
1797
+ queue(tokens);
1798
+ }
1799
+ _l.label = 5;
1800
+ case 5:
1801
+ for (_g = 0, _h = state$9; _g < _h.length; _g++) {
1802
+ entry = _h[_g];
1803
+ tokens = [entry.time, entry.event];
1804
+ tokens.push(entry.data.id);
1805
+ tokens.push(entry.data.operation);
1806
+ tokens.push(entry.data.keyFrames);
1807
+ tokens.push(entry.data.timing);
1808
+ tokens.push(entry.data.timeline);
1809
+ tokens.push(entry.data.targetId);
1810
+ queue(tokens);
1811
+ }
1812
+ reset$i();
1813
+ return [3 /*break*/, 13];
1814
+ case 6:
1815
+ // Check if we are operating within the context of the current page
1816
+ if (state$b(timer) === 2 /* Task.Stop */) {
1817
+ return [3 /*break*/, 13];
1818
+ }
1819
+ values = updates$2();
1820
+ if (!(values.length > 0)) return [3 /*break*/, 12];
1821
+ _j = 0, values_1 = values;
1822
+ _l.label = 7;
1823
+ case 7:
1824
+ if (!(_j < values_1.length)) return [3 /*break*/, 11];
1825
+ value = values_1[_j];
1826
+ state = state$b(timer);
1827
+ if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 9];
1828
+ return [4 /*yield*/, suspend$1(timer)];
1829
+ case 8:
1830
+ state = _l.sent();
1831
+ _l.label = 9;
1832
+ case 9:
1833
+ if (state === 2 /* Task.Stop */) {
1834
+ return [3 /*break*/, 11];
1835
+ }
1836
+ data = value.data;
1837
+ active = value.metadata.active;
1838
+ suspend = value.metadata.suspend;
1839
+ privacy = value.metadata.privacy;
1840
+ mangle = shouldMangle(value);
1841
+ keys = active ? ["tag", "attributes", "value"] : ["tag"];
1842
+ for (_k = 0, keys_1 = keys; _k < keys_1.length; _k++) {
1843
+ key = keys_1[_k];
1844
+ if (data[key]) {
1845
+ switch (key) {
1846
+ case "tag":
1847
+ box = size(value);
1848
+ factor = mangle ? -1 : 1;
1849
+ tokens.push(value.id * factor);
1850
+ if (value.parent && active) {
1851
+ tokens.push(value.parent);
1852
+ }
1853
+ if (value.previous && active) {
1854
+ tokens.push(value.previous);
1855
+ }
1856
+ tokens.push(suspend ? "*M" /* Constant.SuspendMutationTag */ : data[key]);
1857
+ if (box && box.length === 2) {
1858
+ tokens.push("".concat("#" /* Constant.Hash */).concat(str$1(box[0]), ".").concat(str$1(box[1])));
1859
+ }
1860
+ break;
1861
+ case "attributes":
1862
+ for (attr in data[key]) {
1863
+ if (data[key][attr] !== undefined) {
1864
+ tokens.push(attribute(attr, data[key][attr], privacy));
1865
+ }
1866
+ }
1867
+ break;
1868
+ case "value":
1869
+ check$4(value.metadata.fraud, value.id, data[key]);
1870
+ tokens.push(text$1(data[key], data.tag, privacy, mangle));
1871
+ break;
1872
+ }
1873
+ }
1874
+ }
1875
+ _l.label = 10;
1876
+ case 10:
1877
+ _j++;
1878
+ return [3 /*break*/, 7];
1879
+ case 11:
1880
+ if (type === 6 /* Event.Mutation */) {
1881
+ activity(eventTime);
1882
+ }
1883
+ queue(tokenize(tokens), !config$1.lean);
1884
+ _l.label = 12;
1885
+ case 12: return [3 /*break*/, 13];
1886
+ case 13: return [2 /*return*/];
1887
+ }
1888
+ });
1889
+ });
1890
+ }
1891
+ function shouldMangle(value) {
1892
+ var privacy = value.metadata.privacy;
1893
+ return value.data.tag === "*T" /* Constant.TextTag */ && !(privacy === 0 /* Privacy.None */ || privacy === 1 /* Privacy.Sensitive */);
1894
+ }
1895
+ function size(value) {
1896
+ if (value.metadata.size !== null && value.metadata.size.length === 0) {
1897
+ var img = getNode(value.id);
1898
+ if (img) {
1899
+ return [Math.floor(img.offsetWidth * 100 /* Setting.BoxPrecision */), Math.floor(img.offsetHeight * 100 /* Setting.BoxPrecision */)];
1813
1900
  }
1814
1901
  }
1815
- return 0 /* BrowsingContext.Self */;
1902
+ return value.metadata.size;
1816
1903
  }
1817
- function reset$i() {
1818
- state$9 = [];
1904
+ function str$1(input) {
1905
+ return input.toString(36);
1819
1906
  }
1820
- function stop$t() {
1821
- reset$i();
1907
+ function attribute(key, value, privacy) {
1908
+ return "".concat(key, "=").concat(text$1(value, key.indexOf("data-" /* Constant.DataAttribute */) === 0 ? "data-" /* Constant.DataAttribute */ : key, privacy));
1822
1909
  }
1823
1910
 
1824
1911
  var state$8 = [];
1912
+ var regionMap = null; // Maps region nodes => region name
1913
+ var regions = {};
1914
+ var queue$2 = [];
1915
+ var watch = false;
1916
+ var observer$1 = null;
1825
1917
  function start$u() {
1826
1918
  reset$h();
1919
+ observer$1 = null;
1920
+ regionMap = new WeakMap();
1921
+ regions = {};
1922
+ queue$2 = [];
1923
+ watch = window["IntersectionObserver"] ? true : false;
1827
1924
  }
1828
- function observe$a(root) {
1829
- bind(root, "cut", recompute$7.bind(this, 0 /* Clipboard.Cut */), true);
1830
- bind(root, "copy", recompute$7.bind(this, 1 /* Clipboard.Copy */), true);
1831
- bind(root, "paste", recompute$7.bind(this, 2 /* Clipboard.Paste */), true);
1832
- }
1833
- function recompute$7(action, evt) {
1834
- state$8.push({ time: time(evt), event: 38 /* Event.Clipboard */, data: { target: target(evt), action: action } });
1835
- schedule$1(encode$3.bind(this, 38 /* Event.Clipboard */));
1925
+ function observe$c(node, name) {
1926
+ if (regionMap.has(node) === false) {
1927
+ regionMap.set(node, name);
1928
+ observer$1 = observer$1 === null && watch ? new IntersectionObserver(handler$3, {
1929
+ // Get notified as intersection continues to change
1930
+ // This allows us to process regions that get partially hidden during the lifetime of the page
1931
+ // See: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#creating_an_intersection_observer
1932
+ // By default, intersection observers only fire an event when even a single pixel is visible and not thereafter.
1933
+ threshold: [0, 0.2, 0.4, 0.6, 0.8, 1]
1934
+ }) : observer$1;
1935
+ if (observer$1 && node && node.nodeType === Node.ELEMENT_NODE) {
1936
+ observer$1.observe(node);
1937
+ }
1938
+ }
1836
1939
  }
1837
- function reset$h() {
1838
- state$8 = [];
1940
+ function exists(node) {
1941
+ // Check if regionMap is not null before looking up a node
1942
+ // Since, dom module stops after region module, it's possible that we may set regionMap to be null
1943
+ // and still attempt to call exists on a late coming DOM mutation (or addition), effectively causing a script error
1944
+ return regionMap && regionMap.has(node);
1839
1945
  }
1840
- function stop$s() {
1841
- reset$h();
1842
- }
1843
-
1844
- var timeout$5 = null;
1845
- var state$7 = [];
1846
- function start$t() {
1847
- reset$g();
1946
+ function track$4(id, event) {
1947
+ var node = getNode(id);
1948
+ var data = id in regions ? regions[id] : { id: id, visibility: 0 /* RegionVisibility.Rendered */, interaction: 16 /* InteractionState.None */, name: regionMap.get(node) };
1949
+ // Determine the interaction state based on incoming event
1950
+ var interaction = 16 /* InteractionState.None */;
1951
+ switch (event) {
1952
+ case 9 /* Event.Click */:
1953
+ interaction = 20 /* InteractionState.Clicked */;
1954
+ break;
1955
+ case 27 /* Event.Input */:
1956
+ interaction = 30 /* InteractionState.Input */;
1957
+ break;
1958
+ }
1959
+ // Process updates to this region, if applicable
1960
+ process$6(node, data, interaction, data.visibility);
1848
1961
  }
1849
- function observe$9(root) {
1850
- bind(root, "input", recompute$6, true);
1962
+ function compute$6() {
1963
+ // Process any regions where we couldn't resolve an "id" for at the time of last intersection observer event
1964
+ // This could happen in cases where elements are not yet processed by Clarity's virtual DOM but browser reports a change, regardless.
1965
+ // For those cases we add them to the queue and re-process them below
1966
+ var q = [];
1967
+ for (var _i = 0, queue_1 = queue$2; _i < queue_1.length; _i++) {
1968
+ var r = queue_1[_i];
1969
+ var id = getId(r.node);
1970
+ if (!(id in regions)) {
1971
+ if (id) {
1972
+ r.data.id = id;
1973
+ regions[id] = r.data;
1974
+ state$8.push(clone$1(r.data));
1975
+ }
1976
+ else {
1977
+ q.push(r);
1978
+ }
1979
+ }
1980
+ }
1981
+ queue$2 = q;
1982
+ // Schedule encode only when we have at least one valid data entry
1983
+ if (state$8.length > 0) {
1984
+ encode$4(7 /* Event.Region */);
1985
+ }
1851
1986
  }
1852
- function recompute$6(evt) {
1853
- var input = target(evt);
1854
- var value = get(input);
1855
- if (input && input.type && value) {
1856
- var v = input.value;
1857
- switch (input.type) {
1858
- case "radio":
1859
- case "checkbox":
1860
- v = input.checked ? "true" : "false";
1861
- break;
1987
+ function handler$3(entries) {
1988
+ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
1989
+ var entry = entries_1[_i];
1990
+ var target = entry.target;
1991
+ var rect = entry.boundingClientRect;
1992
+ var overlap = entry.intersectionRect;
1993
+ var viewport = entry.rootBounds;
1994
+ // Only capture regions that have non-zero width or height to avoid tracking and sending regions
1995
+ // that cannot ever be seen by the user. In some cases, websites will have a multiple copy of the same region
1996
+ // like search box - one for desktop, and another for mobile. In those cases, CSS media queries determine which one should be visible.
1997
+ // Also, if these regions ever become non-zero width or height (through AJAX, user action or orientation change) - we will automatically start monitoring them from that point onwards
1998
+ if (regionMap.has(target) && rect.width + rect.height > 0 && viewport.width > 0 && viewport.height > 0) {
1999
+ var id = target ? getId(target) : null;
2000
+ var data = id in regions ? regions[id] : { id: id, name: regionMap.get(target), interaction: 16 /* InteractionState.None */, visibility: 0 /* RegionVisibility.Rendered */ };
2001
+ // For regions that have relatively smaller area, we look at intersection ratio and see the overlap relative to element's area
2002
+ // However, for larger regions, area of regions could be bigger than viewport and therefore comparison is relative to visible area
2003
+ var viewportRatio = overlap ? (overlap.width * overlap.height * 1.0) / (viewport.width * viewport.height) : 0;
2004
+ var visible = viewportRatio > 0.05 /* Setting.ViewportIntersectionRatio */ || entry.intersectionRatio > 0.8 /* Setting.IntersectionRatio */;
2005
+ // If an element is either visible or was visible and has been scrolled to the end
2006
+ // i.e. Scrolled to end is determined by if the starting position of the element + the window height is more than the total element height.
2007
+ // starting position is relative to the viewport - so Intersection observer returns a negative value for rect.top to indicate that the element top is above the viewport
2008
+ var scrolledToEnd = (visible || data.visibility == 10 /* RegionVisibility.Visible */) && Math.abs(rect.top) + viewport.height > rect.height;
2009
+ // Process updates to this region, if applicable
2010
+ process$6(target, data, data.interaction, (scrolledToEnd ?
2011
+ 13 /* RegionVisibility.ScrolledToEnd */ :
2012
+ (visible ? 10 /* RegionVisibility.Visible */ : 0 /* RegionVisibility.Rendered */)));
2013
+ // Stop observing this element now that we have already received scrolled signal
2014
+ if (data.visibility >= 13 /* RegionVisibility.ScrolledToEnd */ && observer$1) {
2015
+ observer$1.unobserve(target);
2016
+ }
1862
2017
  }
1863
- var data = { target: input, value: v };
1864
- // 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.
1865
- if (state$7.length > 0 && (state$7[state$7.length - 1].data.target === data.target)) {
1866
- state$7.pop();
2018
+ }
2019
+ if (state$8.length > 0) {
2020
+ encode$4(7 /* Event.Region */);
2021
+ }
2022
+ }
2023
+ function process$6(n, d, s, v) {
2024
+ // Check if received a state that supersedes existing state
2025
+ var updated = s > d.interaction || v > d.visibility;
2026
+ d.interaction = s > d.interaction ? s : d.interaction;
2027
+ d.visibility = v > d.visibility ? v : d.visibility;
2028
+ // If the corresponding node is already discovered, update the internal state
2029
+ // Otherwise, track it in a queue to reprocess later.
2030
+ if (d.id) {
2031
+ if ((d.id in regions && updated) || !(d.id in regions)) {
2032
+ regions[d.id] = d;
2033
+ state$8.push(clone$1(d));
1867
2034
  }
1868
- state$7.push({ time: time(evt), event: 27 /* Event.Input */, data: data });
1869
- clearTimeout(timeout$5);
1870
- timeout$5 = setTimeout(process$6, 1000 /* Setting.InputLookAhead */, 27 /* Event.Input */);
2035
+ }
2036
+ else {
2037
+ queue$2.push({ node: n, data: d });
1871
2038
  }
1872
2039
  }
1873
- function process$6(event) {
1874
- schedule$1(encode$3.bind(this, event));
2040
+ function clone$1(r) {
2041
+ return { time: time(), data: { id: r.id, interaction: r.interaction, visibility: r.visibility, name: r.name } };
2042
+ }
2043
+ function reset$h() {
2044
+ state$8 = [];
2045
+ }
2046
+ function stop$s() {
2047
+ reset$h();
2048
+ regionMap = null;
2049
+ regions = {};
2050
+ queue$2 = [];
2051
+ if (observer$1) {
2052
+ observer$1.disconnect();
2053
+ observer$1 = null;
2054
+ }
2055
+ watch = false;
2056
+ }
2057
+
2058
+ var state$7 = [];
2059
+ function start$t() {
2060
+ reset$g();
2061
+ }
2062
+ function observe$b(root) {
2063
+ bind(root, "change", recompute$8, true);
2064
+ }
2065
+ function recompute$8(evt) {
2066
+ var element = target(evt);
2067
+ if (element) {
2068
+ var value = element.value;
2069
+ var checksum = value && value.length >= 5 /* Setting.WordLength */ && config$1.fraud && "password,secret,pass,social,ssn,code,hidden" /* Mask.Exclude */.indexOf(element.type) === -1 ? hash(value, 24 /* Setting.ChecksumPrecision */) : "" /* Constant.Empty */;
2070
+ state$7.push({ time: time(evt), event: 42 /* Event.Change */, data: { target: target(evt), type: element.type, value: value, checksum: checksum } });
2071
+ schedule$1(encode$3.bind(this, 42 /* Event.Change */));
2072
+ }
1875
2073
  }
1876
2074
  function reset$g() {
1877
2075
  state$7 = [];
1878
2076
  }
1879
2077
  function stop$r() {
1880
- clearTimeout(timeout$5);
1881
2078
  reset$g();
1882
2079
  }
1883
2080
 
2081
+ function offset(element) {
2082
+ var output = { x: 0, y: 0 };
2083
+ // Walk up the chain to ensure we compute offset distance correctly
2084
+ // In case where we may have nested IFRAMEs, we keep walking up until we get to the top most parent page
2085
+ if (element && element.offsetParent) {
2086
+ do {
2087
+ var parent_1 = element.offsetParent;
2088
+ var frame = parent_1 === null ? iframe(element.ownerDocument) : null;
2089
+ output.x += element.offsetLeft;
2090
+ output.y += element.offsetTop;
2091
+ element = frame ? frame : parent_1;
2092
+ } while (element);
2093
+ }
2094
+ return output;
2095
+ }
2096
+
2097
+ var UserInputTags = ["input", "textarea", "radio", "button", "canvas"];
1884
2098
  var state$6 = [];
1885
- var timeout$4 = null;
1886
2099
  function start$s() {
1887
2100
  reset$f();
1888
2101
  }
1889
- function observe$8(root) {
1890
- bind(root, "mousedown", mouse.bind(this, 13 /* Event.MouseDown */, root), true);
1891
- bind(root, "mouseup", mouse.bind(this, 14 /* Event.MouseUp */, root), true);
1892
- bind(root, "mousemove", mouse.bind(this, 12 /* Event.MouseMove */, root), true);
1893
- bind(root, "wheel", mouse.bind(this, 15 /* Event.MouseWheel */, root), true);
1894
- bind(root, "dblclick", mouse.bind(this, 16 /* Event.DoubleClick */, root), true);
1895
- bind(root, "touchstart", touch.bind(this, 17 /* Event.TouchStart */, root), true);
1896
- bind(root, "touchend", touch.bind(this, 18 /* Event.TouchEnd */, root), true);
1897
- bind(root, "touchmove", touch.bind(this, 19 /* Event.TouchMove */, root), true);
1898
- bind(root, "touchcancel", touch.bind(this, 20 /* Event.TouchCancel */, root), true);
2102
+ function observe$a(root) {
2103
+ bind(root, "click", handler$2.bind(this, 9 /* Event.Click */, root), true);
1899
2104
  }
1900
- function mouse(event, root, evt) {
2105
+ function handler$2(event, root, evt) {
1901
2106
  var frame = iframe(root);
1902
2107
  var d = frame ? frame.contentDocument.documentElement : document.documentElement;
1903
2108
  var x = "pageX" in evt ? Math.round(evt.pageX) : ("clientX" in evt ? Math.round(evt["clientX"] + d.scrollLeft) : null);
@@ -1908,74 +2113,272 @@ function mouse(event, root, evt) {
1908
2113
  x = x ? x + Math.round(distance.x) : x;
1909
2114
  y = y ? y + Math.round(distance.y) : y;
1910
2115
  }
2116
+ var t = target(evt);
2117
+ // Find nearest anchor tag (<a/>) parent if current target node is part of one
2118
+ // If present, we use the returned link element to populate text and link properties below
2119
+ var a = link(t);
2120
+ // Get layout rectangle for the target element
2121
+ var l = layout$1(t);
2122
+ // Reference: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
2123
+ // This property helps differentiate between a keyboard navigation vs. pointer click
2124
+ // In case of a keyboard navigation, we use center of target element as (x,y)
2125
+ if (evt.detail === 0 && l) {
2126
+ x = Math.round(l.x + (l.w / 2));
2127
+ y = Math.round(l.y + (l.h / 2));
2128
+ }
2129
+ var eX = l ? Math.max(Math.floor(((x - l.x) / l.w) * 32767 /* Setting.ClickPrecision */), 0) : 0;
2130
+ var eY = l ? Math.max(Math.floor(((y - l.y) / l.h) * 32767 /* Setting.ClickPrecision */), 0) : 0;
1911
2131
  // Check for null values before processing this event
1912
2132
  if (x !== null && y !== null) {
1913
- handler$2({ time: time(evt), event: event, data: { target: target(evt), x: x, y: y } });
2133
+ state$6.push({
2134
+ time: time(evt),
2135
+ event: event,
2136
+ data: {
2137
+ target: t,
2138
+ x: x,
2139
+ y: y,
2140
+ eX: eX,
2141
+ eY: eY,
2142
+ button: evt.button,
2143
+ reaction: reaction(t),
2144
+ context: context(a),
2145
+ text: text(t),
2146
+ link: a ? a.href : null,
2147
+ hash: null,
2148
+ trust: evt.isTrusted ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */
2149
+ }
2150
+ });
2151
+ schedule$1(encode$3.bind(this, event));
1914
2152
  }
1915
2153
  }
1916
- function touch(event, root, evt) {
1917
- var frame = iframe(root);
1918
- var d = frame ? frame.contentDocument.documentElement : document.documentElement;
1919
- var touches = evt.changedTouches;
1920
- var t = time(evt);
1921
- if (touches) {
1922
- for (var i = 0; i < touches.length; i++) {
1923
- var entry = touches[i];
1924
- var x = "clientX" in entry ? Math.round(entry["clientX"] + d.scrollLeft) : null;
1925
- var y = "clientY" in entry ? Math.round(entry["clientY"] + d.scrollTop) : null;
1926
- x = x && frame ? x + Math.round(frame.offsetLeft) : x;
1927
- y = y && frame ? y + Math.round(frame.offsetTop) : y;
1928
- // Check for null values before processing this event
1929
- if (x !== null && y !== null) {
1930
- handler$2({ time: t, event: event, data: { target: target(evt), x: x, y: y } });
2154
+ function link(node) {
2155
+ while (node && node !== document) {
2156
+ if (node.nodeType === Node.ELEMENT_NODE) {
2157
+ var element = node;
2158
+ if (element.tagName === "A") {
2159
+ return element;
1931
2160
  }
1932
2161
  }
2162
+ node = node.parentNode;
1933
2163
  }
2164
+ return null;
1934
2165
  }
1935
- function handler$2(current) {
1936
- switch (current.event) {
1937
- case 12 /* Event.MouseMove */:
1938
- case 15 /* Event.MouseWheel */:
1939
- case 19 /* Event.TouchMove */:
1940
- var length_1 = state$6.length;
1941
- var last = length_1 > 1 ? state$6[length_1 - 2] : null;
1942
- if (last && similar$1(last, current)) {
1943
- state$6.pop();
1944
- }
1945
- state$6.push(current);
1946
- clearTimeout(timeout$4);
1947
- timeout$4 = setTimeout(process$5, 500 /* Setting.LookAhead */, current.event);
1948
- break;
1949
- default:
1950
- state$6.push(current);
1951
- process$5(current.event);
1952
- break;
2166
+ function text(element) {
2167
+ var output = null;
2168
+ if (element) {
2169
+ // Grab text using "textContent" for most HTMLElements, however, use "value" for HTMLInputElements and "alt" for HTMLImageElement.
2170
+ var t = element.textContent || element.value || element.alt;
2171
+ if (t) {
2172
+ // Replace multiple occurrence of space characters with a single white space
2173
+ // Also, trim any spaces at the beginning or at the end of string
2174
+ // Finally, send only first few characters as specified by the Setting
2175
+ output = t.replace(/\s+/g, " " /* Constant.Space */).trim().substr(0, 25 /* Setting.ClickText */);
2176
+ }
1953
2177
  }
2178
+ return output;
1954
2179
  }
1955
- function process$5(event) {
1956
- schedule$1(encode$3.bind(this, event));
1957
- }
1958
- function reset$f() {
1959
- state$6 = [];
1960
- }
1961
- function similar$1(last, current) {
1962
- var dx = last.data.x - current.data.x;
1963
- var dy = last.data.y - current.data.y;
1964
- var distance = Math.sqrt(dx * dx + dy * dy);
1965
- var gap = current.time - last.time;
1966
- var match = current.data.target === last.data.target;
1967
- return current.event === last.event && match && distance < 20 /* Setting.Distance */ && gap < 25 /* Setting.Interval */;
1968
- }
1969
- function stop$q() {
1970
- clearTimeout(timeout$4);
1971
- // Send out any pending pointer events in the pipeline
1972
- if (state$6.length > 0) {
1973
- process$5(state$6[state$6.length - 1].event);
2180
+ function reaction(element) {
2181
+ if (element.nodeType === Node.ELEMENT_NODE) {
2182
+ var tag = element.tagName.toLowerCase();
2183
+ if (UserInputTags.indexOf(tag) >= 0) {
2184
+ return 0 /* BooleanFlag.False */;
2185
+ }
1974
2186
  }
2187
+ return 1 /* BooleanFlag.True */;
2188
+ }
2189
+ function layout$1(element) {
2190
+ var box = null;
2191
+ var de = document.documentElement;
2192
+ if (typeof element.getBoundingClientRect === "function") {
2193
+ // getBoundingClientRect returns rectangle relative positioning to viewport
2194
+ var rect = element.getBoundingClientRect();
2195
+ if (rect && rect.width > 0 && rect.height > 0) {
2196
+ // Add viewport's scroll position to rectangle to get position relative to document origin
2197
+ // Also: using Math.floor() instead of Math.round() because in Edge,
2198
+ // getBoundingClientRect returns partial pixel values (e.g. 162.5px) and Chrome already
2199
+ // floors the value (e.g. 162px). This keeps consistent behavior across browsers.
2200
+ box = {
2201
+ x: Math.floor(rect.left + ("pageXOffset" in window ? window.pageXOffset : de.scrollLeft)),
2202
+ y: Math.floor(rect.top + ("pageYOffset" in window ? window.pageYOffset : de.scrollTop)),
2203
+ w: Math.floor(rect.width),
2204
+ h: Math.floor(rect.height)
2205
+ };
2206
+ }
2207
+ }
2208
+ return box;
2209
+ }
2210
+ function context(a) {
2211
+ if (a && a.hasAttribute("target" /* Constant.Target */)) {
2212
+ switch (a.getAttribute("target" /* Constant.Target */)) {
2213
+ case "_blank" /* Constant.Blank */: return 1 /* BrowsingContext.Blank */;
2214
+ case "_parent" /* Constant.Parent */: return 2 /* BrowsingContext.Parent */;
2215
+ case "_top" /* Constant.Top */: return 3 /* BrowsingContext.Top */;
2216
+ }
2217
+ }
2218
+ return 0 /* BrowsingContext.Self */;
2219
+ }
2220
+ function reset$f() {
2221
+ state$6 = [];
2222
+ }
2223
+ function stop$q() {
2224
+ reset$f();
1975
2225
  }
1976
2226
 
1977
- var data$b;
2227
+ var state$5 = [];
1978
2228
  function start$r() {
2229
+ reset$e();
2230
+ }
2231
+ function observe$9(root) {
2232
+ bind(root, "cut", recompute$7.bind(this, 0 /* Clipboard.Cut */), true);
2233
+ bind(root, "copy", recompute$7.bind(this, 1 /* Clipboard.Copy */), true);
2234
+ bind(root, "paste", recompute$7.bind(this, 2 /* Clipboard.Paste */), true);
2235
+ }
2236
+ function recompute$7(action, evt) {
2237
+ state$5.push({ time: time(evt), event: 38 /* Event.Clipboard */, data: { target: target(evt), action: action } });
2238
+ schedule$1(encode$3.bind(this, 38 /* Event.Clipboard */));
2239
+ }
2240
+ function reset$e() {
2241
+ state$5 = [];
2242
+ }
2243
+ function stop$p() {
2244
+ reset$e();
2245
+ }
2246
+
2247
+ var timeout$5 = null;
2248
+ var state$4 = [];
2249
+ function start$q() {
2250
+ reset$d();
2251
+ }
2252
+ function observe$8(root) {
2253
+ bind(root, "input", recompute$6, true);
2254
+ }
2255
+ function recompute$6(evt) {
2256
+ var input = target(evt);
2257
+ var value = get(input);
2258
+ if (input && input.type && value) {
2259
+ var v = input.value;
2260
+ switch (input.type) {
2261
+ case "radio":
2262
+ case "checkbox":
2263
+ v = input.checked ? "true" : "false";
2264
+ break;
2265
+ }
2266
+ var data = { target: input, value: v };
2267
+ // 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.
2268
+ if (state$4.length > 0 && (state$4[state$4.length - 1].data.target === data.target)) {
2269
+ state$4.pop();
2270
+ }
2271
+ state$4.push({ time: time(evt), event: 27 /* Event.Input */, data: data });
2272
+ clearTimeout(timeout$5);
2273
+ timeout$5 = setTimeout(process$5, 1000 /* Setting.InputLookAhead */, 27 /* Event.Input */);
2274
+ }
2275
+ }
2276
+ function process$5(event) {
2277
+ schedule$1(encode$3.bind(this, event));
2278
+ }
2279
+ function reset$d() {
2280
+ state$4 = [];
2281
+ }
2282
+ function stop$o() {
2283
+ clearTimeout(timeout$5);
2284
+ reset$d();
2285
+ }
2286
+
2287
+ var state$3 = [];
2288
+ var timeout$4 = null;
2289
+ function start$p() {
2290
+ reset$c();
2291
+ }
2292
+ function observe$7(root) {
2293
+ bind(root, "mousedown", mouse.bind(this, 13 /* Event.MouseDown */, root), true);
2294
+ bind(root, "mouseup", mouse.bind(this, 14 /* Event.MouseUp */, root), true);
2295
+ bind(root, "mousemove", mouse.bind(this, 12 /* Event.MouseMove */, root), true);
2296
+ bind(root, "wheel", mouse.bind(this, 15 /* Event.MouseWheel */, root), true);
2297
+ bind(root, "dblclick", mouse.bind(this, 16 /* Event.DoubleClick */, root), true);
2298
+ bind(root, "touchstart", touch.bind(this, 17 /* Event.TouchStart */, root), true);
2299
+ bind(root, "touchend", touch.bind(this, 18 /* Event.TouchEnd */, root), true);
2300
+ bind(root, "touchmove", touch.bind(this, 19 /* Event.TouchMove */, root), true);
2301
+ bind(root, "touchcancel", touch.bind(this, 20 /* Event.TouchCancel */, root), true);
2302
+ }
2303
+ function mouse(event, root, evt) {
2304
+ var frame = iframe(root);
2305
+ var d = frame ? frame.contentDocument.documentElement : document.documentElement;
2306
+ var x = "pageX" in evt ? Math.round(evt.pageX) : ("clientX" in evt ? Math.round(evt["clientX"] + d.scrollLeft) : null);
2307
+ var y = "pageY" in evt ? Math.round(evt.pageY) : ("clientY" in evt ? Math.round(evt["clientY"] + d.scrollTop) : null);
2308
+ // In case of iframe, we adjust (x,y) to be relative to top parent's origin
2309
+ if (frame) {
2310
+ var distance = offset(frame);
2311
+ x = x ? x + Math.round(distance.x) : x;
2312
+ y = y ? y + Math.round(distance.y) : y;
2313
+ }
2314
+ // Check for null values before processing this event
2315
+ if (x !== null && y !== null) {
2316
+ handler$1({ time: time(evt), event: event, data: { target: target(evt), x: x, y: y } });
2317
+ }
2318
+ }
2319
+ function touch(event, root, evt) {
2320
+ var frame = iframe(root);
2321
+ var d = frame ? frame.contentDocument.documentElement : document.documentElement;
2322
+ var touches = evt.changedTouches;
2323
+ var t = time(evt);
2324
+ if (touches) {
2325
+ for (var i = 0; i < touches.length; i++) {
2326
+ var entry = touches[i];
2327
+ var x = "clientX" in entry ? Math.round(entry["clientX"] + d.scrollLeft) : null;
2328
+ var y = "clientY" in entry ? Math.round(entry["clientY"] + d.scrollTop) : null;
2329
+ x = x && frame ? x + Math.round(frame.offsetLeft) : x;
2330
+ y = y && frame ? y + Math.round(frame.offsetTop) : y;
2331
+ // Check for null values before processing this event
2332
+ if (x !== null && y !== null) {
2333
+ handler$1({ time: t, event: event, data: { target: target(evt), x: x, y: y } });
2334
+ }
2335
+ }
2336
+ }
2337
+ }
2338
+ function handler$1(current) {
2339
+ switch (current.event) {
2340
+ case 12 /* Event.MouseMove */:
2341
+ case 15 /* Event.MouseWheel */:
2342
+ case 19 /* Event.TouchMove */:
2343
+ var length_1 = state$3.length;
2344
+ var last = length_1 > 1 ? state$3[length_1 - 2] : null;
2345
+ if (last && similar$1(last, current)) {
2346
+ state$3.pop();
2347
+ }
2348
+ state$3.push(current);
2349
+ clearTimeout(timeout$4);
2350
+ timeout$4 = setTimeout(process$4, 500 /* Setting.LookAhead */, current.event);
2351
+ break;
2352
+ default:
2353
+ state$3.push(current);
2354
+ process$4(current.event);
2355
+ break;
2356
+ }
2357
+ }
2358
+ function process$4(event) {
2359
+ schedule$1(encode$3.bind(this, event));
2360
+ }
2361
+ function reset$c() {
2362
+ state$3 = [];
2363
+ }
2364
+ function similar$1(last, current) {
2365
+ var dx = last.data.x - current.data.x;
2366
+ var dy = last.data.y - current.data.y;
2367
+ var distance = Math.sqrt(dx * dx + dy * dy);
2368
+ var gap = current.time - last.time;
2369
+ var match = current.data.target === last.data.target;
2370
+ return current.event === last.event && match && distance < 20 /* Setting.Distance */ && gap < 25 /* Setting.Interval */;
2371
+ }
2372
+ function stop$n() {
2373
+ clearTimeout(timeout$4);
2374
+ // Send out any pending pointer events in the pipeline
2375
+ if (state$3.length > 0) {
2376
+ process$4(state$3[state$3.length - 1].event);
2377
+ }
2378
+ }
2379
+
2380
+ var data$b;
2381
+ function start$o() {
1979
2382
  bind(window, "resize", recompute$5);
1980
2383
  recompute$5();
1981
2384
  }
@@ -1989,20 +2392,20 @@ function recompute$5() {
1989
2392
  };
1990
2393
  encode$3(11 /* Event.Resize */);
1991
2394
  }
1992
- function reset$e() {
2395
+ function reset$b() {
1993
2396
  data$b = null;
1994
2397
  }
1995
- function stop$p() {
1996
- reset$e();
2398
+ function stop$m() {
2399
+ reset$b();
1997
2400
  }
1998
2401
 
1999
- var state$5 = [];
2402
+ var state$2 = [];
2000
2403
  var timeout$3 = null;
2001
- function start$q() {
2002
- state$5 = [];
2404
+ function start$n() {
2405
+ state$2 = [];
2003
2406
  recompute$4();
2004
2407
  }
2005
- function observe$7(root) {
2408
+ function observe$6(root) {
2006
2409
  var frame = iframe(root);
2007
2410
  var node = frame ? frame.contentWindow : (root === document ? window : root);
2008
2411
  bind(node, "scroll", recompute$4, true);
@@ -2028,19 +2431,19 @@ function recompute$4(event) {
2028
2431
  if ((event === null && x === 0 && y === 0) || (x === null || y === null)) {
2029
2432
  return;
2030
2433
  }
2031
- var length = state$5.length;
2032
- var last = length > 1 ? state$5[length - 2] : null;
2434
+ var length = state$2.length;
2435
+ var last = length > 1 ? state$2[length - 2] : null;
2033
2436
  if (last && similar(last, current)) {
2034
- state$5.pop();
2437
+ state$2.pop();
2035
2438
  }
2036
- state$5.push(current);
2439
+ state$2.push(current);
2037
2440
  clearTimeout(timeout$3);
2038
- timeout$3 = setTimeout(process$4, 500 /* Setting.LookAhead */, 10 /* Event.Scroll */);
2441
+ timeout$3 = setTimeout(process$3, 500 /* Setting.LookAhead */, 10 /* Event.Scroll */);
2039
2442
  }
2040
- function reset$d() {
2041
- state$5 = [];
2443
+ function reset$a() {
2444
+ state$2 = [];
2042
2445
  }
2043
- function process$4(event) {
2446
+ function process$3(event) {
2044
2447
  schedule$1(encode$3.bind(this, event));
2045
2448
  }
2046
2449
  function similar(last, current) {
@@ -2048,18 +2451,18 @@ function similar(last, current) {
2048
2451
  var dy = last.data.y - current.data.y;
2049
2452
  return (dx * dx + dy * dy < 20 /* Setting.Distance */ * 20 /* Setting.Distance */) && (current.time - last.time < 25 /* Setting.Interval */);
2050
2453
  }
2051
- function stop$o() {
2454
+ function stop$l() {
2052
2455
  clearTimeout(timeout$3);
2053
- state$5 = [];
2456
+ state$2 = [];
2054
2457
  }
2055
2458
 
2056
2459
  var data$a = null;
2057
2460
  var previous = null;
2058
2461
  var timeout$2 = null;
2059
- function start$p() {
2060
- reset$c();
2462
+ function start$m() {
2463
+ reset$9();
2061
2464
  }
2062
- function observe$6(root) {
2465
+ function observe$5(root) {
2063
2466
  bind(root, "selectstart", recompute$3.bind(this, root), true);
2064
2467
  bind(root, "selectionchange", recompute$3.bind(this, root), true);
2065
2468
  }
@@ -2081,7 +2484,7 @@ function recompute$3(root) {
2081
2484
  var startNode = data$a.start ? data$a.start : null;
2082
2485
  if (previous !== null && data$a.start !== null && startNode !== current.anchorNode) {
2083
2486
  clearTimeout(timeout$2);
2084
- process$3(21 /* Event.Selection */);
2487
+ process$2(21 /* Event.Selection */);
2085
2488
  }
2086
2489
  data$a = {
2087
2490
  start: current.anchorNode,
@@ -2091,40 +2494,40 @@ function recompute$3(root) {
2091
2494
  };
2092
2495
  previous = current;
2093
2496
  clearTimeout(timeout$2);
2094
- timeout$2 = setTimeout(process$3, 500 /* Setting.LookAhead */, 21 /* Event.Selection */);
2497
+ timeout$2 = setTimeout(process$2, 500 /* Setting.LookAhead */, 21 /* Event.Selection */);
2095
2498
  }
2096
- function process$3(event) {
2499
+ function process$2(event) {
2097
2500
  schedule$1(encode$3.bind(this, event));
2098
2501
  }
2099
- function reset$c() {
2502
+ function reset$9() {
2100
2503
  previous = null;
2101
2504
  data$a = { start: 0, startOffset: 0, end: 0, endOffset: 0 };
2102
2505
  }
2103
- function stop$n() {
2104
- reset$c();
2506
+ function stop$k() {
2507
+ reset$9();
2105
2508
  clearTimeout(timeout$2);
2106
2509
  }
2107
2510
 
2108
- var state$4 = [];
2109
- function start$o() {
2110
- reset$b();
2511
+ var state$1 = [];
2512
+ function start$l() {
2513
+ reset$8();
2111
2514
  }
2112
- function observe$5(root) {
2515
+ function observe$4(root) {
2113
2516
  bind(root, "submit", recompute$2, true);
2114
2517
  }
2115
2518
  function recompute$2(evt) {
2116
- state$4.push({ time: time(evt), event: 39 /* Event.Submit */, data: { target: target(evt) } });
2519
+ state$1.push({ time: time(evt), event: 39 /* Event.Submit */, data: { target: target(evt) } });
2117
2520
  schedule$1(encode$3.bind(this, 39 /* Event.Submit */));
2118
2521
  }
2119
- function reset$b() {
2120
- state$4 = [];
2522
+ function reset$8() {
2523
+ state$1 = [];
2121
2524
  }
2122
- function stop$m() {
2123
- reset$b();
2525
+ function stop$j() {
2526
+ reset$8();
2124
2527
  }
2125
2528
 
2126
2529
  var data$9;
2127
- function start$n() {
2530
+ function start$k() {
2128
2531
  bind(window, "pagehide", recompute$1);
2129
2532
  }
2130
2533
  function recompute$1(evt) {
@@ -2132,15 +2535,15 @@ function recompute$1(evt) {
2132
2535
  encode$3(26 /* Event.Unload */, time(evt));
2133
2536
  stop();
2134
2537
  }
2135
- function reset$a() {
2538
+ function reset$7() {
2136
2539
  data$9 = null;
2137
2540
  }
2138
- function stop$l() {
2139
- reset$a();
2541
+ function stop$i() {
2542
+ reset$7();
2140
2543
  }
2141
2544
 
2142
2545
  var data$8;
2143
- function start$m() {
2546
+ function start$j() {
2144
2547
  bind(document, "visibilitychange", recompute);
2145
2548
  recompute();
2146
2549
  }
@@ -2149,398 +2552,63 @@ function recompute(evt) {
2149
2552
  data$8 = { visible: "visibilityState" in document ? document.visibilityState : "default" };
2150
2553
  encode$3(28 /* Event.Visibility */, time(evt));
2151
2554
  }
2152
- function reset$9() {
2555
+ function reset$6() {
2153
2556
  data$8 = null;
2154
2557
  }
2155
- function stop$k() {
2156
- reset$9();
2558
+ function stop$h() {
2559
+ reset$6();
2157
2560
  }
2158
2561
 
2159
- function start$l() {
2562
+ function start$i() {
2160
2563
  start$g();
2161
- start$v();
2162
- start$u();
2163
2564
  start$s();
2164
- start$t();
2165
2565
  start$r();
2166
- start$m();
2167
- start$q();
2168
2566
  start$p();
2169
- start$w();
2567
+ start$q();
2170
2568
  start$o();
2569
+ start$j();
2171
2570
  start$n();
2571
+ start$m();
2572
+ start$t();
2573
+ start$l();
2574
+ start$k();
2172
2575
  }
2173
- function stop$j() {
2576
+ function stop$g() {
2174
2577
  stop$e();
2175
- stop$t();
2176
- stop$s();
2177
2578
  stop$q();
2178
- stop$r();
2179
2579
  stop$p();
2180
- stop$k();
2181
- stop$o();
2182
2580
  stop$n();
2183
- stop$u();
2581
+ stop$o();
2184
2582
  stop$m();
2185
- stop$l();
2186
- }
2187
- function observe$4(root) {
2188
- observe$7(root);
2189
- // Only monitor following interactions if the root node is a document
2190
- // In case of shadow DOM, following events automatically bubble up to the parent document.
2191
- if (root.nodeType === Node.DOCUMENT_NODE) {
2192
- observe$b(root);
2193
- observe$a(root);
2194
- observe$8(root);
2195
- observe$9(root);
2196
- observe$6(root);
2197
- observe$c(root);
2198
- observe$5(root);
2199
- }
2200
- }
2201
-
2202
- var interaction = /*#__PURE__*/Object.freeze({
2203
- __proto__: null,
2204
- observe: observe$4,
2205
- start: start$l,
2206
- stop: stop$j
2207
- });
2208
-
2209
- function traverse (root, timer, source) {
2210
- return __awaiter(this, void 0, void 0, function () {
2211
- var queue, entry, next, state, subnode;
2212
- return __generator(this, function (_a) {
2213
- switch (_a.label) {
2214
- case 0:
2215
- queue = [root];
2216
- _a.label = 1;
2217
- case 1:
2218
- if (!(queue.length > 0)) return [3 /*break*/, 4];
2219
- entry = queue.shift();
2220
- next = entry.firstChild;
2221
- while (next) {
2222
- queue.push(next);
2223
- next = next.nextSibling;
2224
- }
2225
- state = state$b(timer);
2226
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 3];
2227
- return [4 /*yield*/, suspend$1(timer)];
2228
- case 2:
2229
- state = _a.sent();
2230
- _a.label = 3;
2231
- case 3:
2232
- if (state === 2 /* Task.Stop */) {
2233
- return [3 /*break*/, 4];
2234
- }
2235
- subnode = processNode(entry, source);
2236
- if (subnode) {
2237
- queue.push(subnode);
2238
- }
2239
- return [3 /*break*/, 1];
2240
- case 4: return [2 /*return*/];
2241
- }
2242
- });
2243
- });
2244
- }
2245
-
2246
- var observers = [];
2247
- var mutations = [];
2248
- var insertRule = null;
2249
- var deleteRule = null;
2250
- var attachShadow = null;
2251
- var queue$2 = [];
2252
- var timeout$1 = null;
2253
- var activePeriod = null;
2254
- var history$4 = {};
2255
- function start$k() {
2256
- observers = [];
2257
- queue$2 = [];
2258
- timeout$1 = null;
2259
- activePeriod = 0;
2260
- history$4 = {};
2261
- // Some popular open source libraries, like styled-components, optimize performance
2262
- // by injecting CSS using insertRule API vs. appending text node. A side effect of
2263
- // using javascript API is that it doesn't trigger DOM mutation and therefore we
2264
- // need to override the insertRule API and listen for changes manually.
2265
- if (insertRule === null) {
2266
- insertRule = CSSStyleSheet.prototype.insertRule;
2267
- CSSStyleSheet.prototype.insertRule = function () {
2268
- if (active()) {
2269
- schedule(this.ownerNode);
2270
- }
2271
- return insertRule.apply(this, arguments);
2272
- };
2273
- }
2274
- if (deleteRule === null) {
2275
- deleteRule = CSSStyleSheet.prototype.deleteRule;
2276
- CSSStyleSheet.prototype.deleteRule = function () {
2277
- if (active()) {
2278
- schedule(this.ownerNode);
2279
- }
2280
- return deleteRule.apply(this, arguments);
2281
- };
2282
- }
2283
- // Add a hook to attachShadow API calls
2284
- // In case we are unable to add a hook and browser throws an exception,
2285
- // reset attachShadow variable and resume processing like before
2286
- if (attachShadow === null) {
2287
- attachShadow = Element.prototype.attachShadow;
2288
- try {
2289
- Element.prototype.attachShadow = function () {
2290
- if (active()) {
2291
- return schedule(attachShadow.apply(this, arguments));
2292
- }
2293
- else {
2294
- return attachShadow.apply(this, arguments);
2295
- }
2296
- };
2297
- }
2298
- catch (_a) {
2299
- attachShadow = null;
2300
- }
2301
- }
2302
- }
2303
- function observe$3(node) {
2304
- // Create a new observer for every time a new DOM tree (e.g. root document or shadowdom root) is discovered on the page
2305
- // In the case of shadow dom, any mutations that happen within the shadow dom are not bubbled up to the host document
2306
- // For this reason, we need to wire up mutations every time we see a new shadow dom.
2307
- // Also, wrap it inside a try / catch. In certain browsers (e.g. legacy Edge), observer on shadow dom can throw errors
2308
- try {
2309
- var m = api("MutationObserver" /* Constant.MutationObserver */);
2310
- var observer = m in window ? new window[m](measure(handle$1)) : null;
2311
- if (observer) {
2312
- observer.observe(node, { attributes: true, childList: true, characterData: true, subtree: true });
2313
- observers.push(observer);
2314
- }
2315
- }
2316
- catch (e) {
2317
- log$1(2 /* Code.MutationObserver */, 0 /* Severity.Info */, e ? e.name : null);
2318
- }
2319
- }
2320
- function monitor(frame) {
2321
- // Bind to iframe's onload event so we get notified anytime there's an update to iframe content.
2322
- // This includes cases where iframe location is updated without explicitly updating src attribute
2323
- // E.g. iframe.contentWindow.location.href = "new-location";
2324
- if (has(frame) === false) {
2325
- bind(frame, "load" /* Constant.LoadEvent */, generate.bind(this, frame, "childList" /* Constant.ChildList */), true);
2326
- }
2327
- }
2328
- function stop$i() {
2329
- for (var _i = 0, observers_1 = observers; _i < observers_1.length; _i++) {
2330
- var observer = observers_1[_i];
2331
- if (observer) {
2332
- observer.disconnect();
2333
- }
2334
- }
2335
- observers = [];
2336
- history$4 = {};
2337
- mutations = [];
2338
- queue$2 = [];
2339
- activePeriod = 0;
2340
- timeout$1 = null;
2341
- }
2342
- function active$2() {
2343
- activePeriod = time() + 3000 /* Setting.MutationActivePeriod */;
2344
- }
2345
- function handle$1(m) {
2346
- // Queue up mutation records for asynchronous processing
2347
- var now = time();
2348
- track$7(6 /* Event.Mutation */, now);
2349
- mutations.push({ time: now, mutations: m });
2350
- schedule$1(process$2, 1 /* Priority.High */).then(function () {
2351
- setTimeout(compute$8);
2352
- measure(compute$6)();
2353
- });
2354
- }
2355
- function process$2() {
2356
- return __awaiter(this, void 0, void 0, function () {
2357
- var timer, record, instance, _i, _a, mutation, state, target, type, value;
2358
- return __generator(this, function (_b) {
2359
- switch (_b.label) {
2360
- case 0:
2361
- timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
2362
- start$y(timer);
2363
- _b.label = 1;
2364
- case 1:
2365
- if (!(mutations.length > 0)) return [3 /*break*/, 8];
2366
- record = mutations.shift();
2367
- instance = time();
2368
- _i = 0, _a = record.mutations;
2369
- _b.label = 2;
2370
- case 2:
2371
- if (!(_i < _a.length)) return [3 /*break*/, 6];
2372
- mutation = _a[_i];
2373
- state = state$b(timer);
2374
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 4];
2375
- return [4 /*yield*/, suspend$1(timer)];
2376
- case 3:
2377
- state = _b.sent();
2378
- _b.label = 4;
2379
- case 4:
2380
- if (state === 2 /* Task.Stop */) {
2381
- return [3 /*break*/, 6];
2382
- }
2383
- target = mutation.target;
2384
- type = track$5(mutation, timer, instance);
2385
- if (type && target && target.ownerDocument) {
2386
- parse$1(target.ownerDocument);
2387
- }
2388
- if (type && target && target.nodeType == Node.DOCUMENT_FRAGMENT_NODE && target.host) {
2389
- parse$1(target);
2390
- }
2391
- switch (type) {
2392
- case "attributes" /* Constant.Attributes */:
2393
- processNode(target, 3 /* Source.Attributes */);
2394
- break;
2395
- case "characterData" /* Constant.CharacterData */:
2396
- processNode(target, 4 /* Source.CharacterData */);
2397
- break;
2398
- case "childList" /* Constant.ChildList */:
2399
- processNodeList(mutation.addedNodes, 1 /* Source.ChildListAdd */, timer);
2400
- processNodeList(mutation.removedNodes, 2 /* Source.ChildListRemove */, timer);
2401
- break;
2402
- case "suspend" /* Constant.Suspend */:
2403
- value = get(target);
2404
- if (value) {
2405
- value.metadata.suspend = true;
2406
- }
2407
- break;
2408
- }
2409
- _b.label = 5;
2410
- case 5:
2411
- _i++;
2412
- return [3 /*break*/, 2];
2413
- case 6: return [4 /*yield*/, encode$4(6 /* Event.Mutation */, timer, record.time)];
2414
- case 7:
2415
- _b.sent();
2416
- return [3 /*break*/, 1];
2417
- case 8:
2418
- stop$w(timer);
2419
- return [2 /*return*/];
2420
- }
2421
- });
2422
- });
2423
- }
2424
- function track$5(m, timer, instance) {
2425
- var value = m.target ? get(m.target.parentNode) : null;
2426
- // Check if the parent is already discovered and that the parent is not the document root
2427
- if (value && value.data.tag !== "HTML" /* Constant.HTML */) {
2428
- var inactive = time() > activePeriod;
2429
- var target = get(m.target);
2430
- var element = target && target.selector ? target.selector.join() : m.target.nodeName;
2431
- var parent_1 = value.selector ? value.selector.join() : "" /* Constant.Empty */;
2432
- // We use selector, instead of id, to determine the key (signature for the mutation) because in some cases
2433
- // repeated mutations can cause elements to be destroyed and then recreated as new DOM nodes
2434
- // In those cases, IDs will change however the selector (which is relative to DOM xPath) remains the same
2435
- var key = [parent_1, element, m.attributeName, names(m.addedNodes), names(m.removedNodes)].join();
2436
- // Initialize an entry if it doesn't already exist
2437
- history$4[key] = key in history$4 ? history$4[key] : [0, instance];
2438
- var h = history$4[key];
2439
- // Lookup any pending nodes queued up for removal, and process them now if we suspended a mutation before
2440
- if (inactive === false && h[0] >= 10 /* Setting.MutationSuspendThreshold */) {
2441
- processNodeList(h[2], 2 /* Source.ChildListRemove */, timer);
2442
- }
2443
- // Update the counter
2444
- h[0] = inactive ? (h[1] === instance ? h[0] : h[0] + 1) : 1;
2445
- h[1] = instance;
2446
- // Return updated mutation type based on if we have already hit the threshold or not
2447
- if (h[0] === 10 /* Setting.MutationSuspendThreshold */) {
2448
- // Store a reference to removedNodes so we can process them later
2449
- // when we resume mutations again on user interactions
2450
- h[2] = m.removedNodes;
2451
- return "suspend" /* Constant.Suspend */;
2452
- }
2453
- else if (h[0] > 10 /* Setting.MutationSuspendThreshold */) {
2454
- return "" /* Constant.Empty */;
2455
- }
2456
- }
2457
- return m.type;
2458
- }
2459
- function names(nodes) {
2460
- var output = [];
2461
- for (var i = 0; nodes && i < nodes.length; i++) {
2462
- output.push(nodes[i].nodeName);
2463
- }
2464
- return output.join();
2465
- }
2466
- function processNodeList(list, source, timer) {
2467
- return __awaiter(this, void 0, void 0, function () {
2468
- var length, i, state;
2469
- return __generator(this, function (_a) {
2470
- switch (_a.label) {
2471
- case 0:
2472
- length = list ? list.length : 0;
2473
- i = 0;
2474
- _a.label = 1;
2475
- case 1:
2476
- if (!(i < length)) return [3 /*break*/, 6];
2477
- if (!(source === 1 /* Source.ChildListAdd */)) return [3 /*break*/, 2];
2478
- traverse(list[i], timer, source);
2479
- return [3 /*break*/, 5];
2480
- case 2:
2481
- state = state$b(timer);
2482
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 4];
2483
- return [4 /*yield*/, suspend$1(timer)];
2484
- case 3:
2485
- state = _a.sent();
2486
- _a.label = 4;
2487
- case 4:
2488
- if (state === 2 /* Task.Stop */) {
2489
- return [3 /*break*/, 6];
2490
- }
2491
- processNode(list[i], source);
2492
- _a.label = 5;
2493
- case 5:
2494
- i++;
2495
- return [3 /*break*/, 1];
2496
- case 6: return [2 /*return*/];
2497
- }
2498
- });
2499
- });
2500
- }
2501
- function schedule(node) {
2502
- // Only schedule manual trigger for this node if it's not already in the queue
2503
- if (queue$2.indexOf(node) < 0) {
2504
- queue$2.push(node);
2505
- }
2506
- // Cancel any previous trigger before scheduling a new one.
2507
- // It's common for a webpage to call multiple synchronous "insertRule" / "deleteRule" calls.
2508
- // And in those cases we do not wish to monitor changes multiple times for the same node.
2509
- if (timeout$1) {
2510
- clearTimeout(timeout$1);
2511
- }
2512
- timeout$1 = setTimeout(function () { trigger$2(); }, 33 /* Setting.LookAhead */);
2513
- return node;
2583
+ stop$h();
2584
+ stop$l();
2585
+ stop$k();
2586
+ stop$r();
2587
+ stop$j();
2588
+ stop$i();
2514
2589
  }
2515
- function trigger$2() {
2516
- for (var _i = 0, queue_1 = queue$2; _i < queue_1.length; _i++) {
2517
- var node = queue_1[_i];
2518
- // Generate a mutation for this node only if it still exists
2519
- if (node) {
2520
- var shadowRoot = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
2521
- // Skip re-processing shadowRoot if it was already discovered
2522
- if (shadowRoot && has(node)) {
2523
- continue;
2524
- }
2525
- generate(node, shadowRoot ? "childList" /* Constant.ChildList */ : "characterData" /* Constant.CharacterData */);
2526
- }
2590
+ function observe$3(root) {
2591
+ observe$6(root);
2592
+ // Only monitor following interactions if the root node is a document
2593
+ // In case of shadow DOM, following events automatically bubble up to the parent document.
2594
+ if (root.nodeType === Node.DOCUMENT_NODE) {
2595
+ observe$a(root);
2596
+ observe$9(root);
2597
+ observe$7(root);
2598
+ observe$8(root);
2599
+ observe$5(root);
2600
+ observe$b(root);
2601
+ observe$4(root);
2527
2602
  }
2528
- queue$2 = [];
2529
- }
2530
- function generate(target, type) {
2531
- measure(handle$1)([{
2532
- addedNodes: [target],
2533
- attributeName: null,
2534
- attributeNamespace: null,
2535
- nextSibling: null,
2536
- oldValue: null,
2537
- previousSibling: null,
2538
- removedNodes: [],
2539
- target: target,
2540
- type: type
2541
- }]);
2542
2603
  }
2543
2604
 
2605
+ var interaction = /*#__PURE__*/Object.freeze({
2606
+ __proto__: null,
2607
+ observe: observe$3,
2608
+ start: start$i,
2609
+ stop: stop$g
2610
+ });
2611
+
2544
2612
  var digitsRegex = /[^0-9\.]/g;
2545
2613
  /* JSON+LD (Linked Data) Recursive Parser */
2546
2614
  function ld(json) {
@@ -2641,7 +2709,6 @@ function processNode (node, source) {
2641
2709
  // later whenever there are new additions or modifications to DOM (mutations)
2642
2710
  if (node === document)
2643
2711
  parse$1(document);
2644
- checkDocumentStyles(node);
2645
2712
  observe$2(node);
2646
2713
  break;
2647
2714
  case Node.DOCUMENT_FRAGMENT_NODE:
@@ -2665,7 +2732,6 @@ function processNode (node, source) {
2665
2732
  // the same way we observe real shadow DOM nodes (encapsulation provided by the browser).
2666
2733
  dom[call](node, shadowRoot.host, { tag: "*P" /* Constant.PolyfillShadowDomTag */, attributes: {} }, source);
2667
2734
  }
2668
- checkDocumentStyles(node);
2669
2735
  }
2670
2736
  break;
2671
2737
  case Node.TEXT_NODE:
@@ -2794,8 +2860,8 @@ function observe$2(root) {
2794
2860
  if (has(root)) {
2795
2861
  return;
2796
2862
  }
2797
- observe$3(root); // Observe mutations for this root node
2798
- observe$4(root); // Observe interactions for this root node
2863
+ observe$1(root); // Observe mutations for this root node
2864
+ observe$3(root); // Observe interactions for this root node
2799
2865
  }
2800
2866
  function getStyleValue(style) {
2801
2867
  // Call trim on the text content to ensure we do not process white spaces ( , \n, \r\n, \t, etc.)
@@ -2845,511 +2911,339 @@ function getAttributes(element) {
2845
2911
  return output;
2846
2912
  }
2847
2913
 
2848
- var state$3 = [];
2849
- var replace = null;
2850
- var replaceSync = null;
2851
- var styleSheetId = 'claritySheetId';
2852
- var styleSheetMap = {};
2853
- function start$j() {
2854
- reset$8();
2855
- if (replace === null) {
2856
- replace = CSSStyleSheet.prototype.replace;
2857
- CSSStyleSheet.prototype.replace = function () {
2858
- if (active()) {
2859
- if (!this[styleSheetId]) {
2860
- this[styleSheetId] = shortid();
2861
- // need to pass a create style sheet event (don't add it to any nodes, but do create it)
2862
- trackStyleChange(time(), this[styleSheetId], 0 /* StyleSheetOperation.Create */);
2863
- }
2864
- trackStyleChange(time(), this[styleSheetId], 1 /* StyleSheetOperation.Replace */, arguments[0]);
2865
- }
2866
- return replace.apply(this, arguments);
2867
- };
2868
- }
2869
- if (replaceSync === null) {
2870
- replaceSync = CSSStyleSheet.prototype.replaceSync;
2871
- CSSStyleSheet.prototype.replaceSync = function () {
2872
- if (active()) {
2873
- if (!this[styleSheetId]) {
2874
- this[styleSheetId] = shortid();
2875
- // need to pass a create style sheet event (don't add it to any nodes, but do create it)
2876
- trackStyleChange(time(), this[styleSheetId], 0 /* StyleSheetOperation.Create */);
2877
- }
2878
- trackStyleChange(time(), this[styleSheetId], 2 /* StyleSheetOperation.ReplaceSync */, arguments[0]);
2879
- }
2880
- return replaceSync.apply(this, arguments);
2881
- };
2882
- }
2883
- }
2884
- function checkDocumentStyles(documentNode) {
2885
- if (!(documentNode === null || documentNode === void 0 ? void 0 : documentNode.adoptedStyleSheets)) {
2886
- // if we don't have adoptedStyledSheets on the Node passed to us, we can short circuit.
2887
- return;
2888
- }
2889
- var currentStyleSheets = [];
2890
- for (var _i = 0, _a = documentNode.adoptedStyleSheets; _i < _a.length; _i++) {
2891
- var styleSheet = _a[_i];
2892
- // if we haven't seen this style sheet, create it and pass a replaceSync with its contents
2893
- if (!styleSheet[styleSheetId]) {
2894
- styleSheet[styleSheetId] = shortid();
2895
- trackStyleChange(time(), styleSheet[styleSheetId], 0 /* StyleSheetOperation.Create */);
2896
- trackStyleChange(time(), styleSheet[styleSheetId], 2 /* StyleSheetOperation.ReplaceSync */, getCssRules(styleSheet));
2897
- }
2898
- currentStyleSheets.push(styleSheet[styleSheetId]);
2899
- }
2900
- var documentId = getId(documentNode, true);
2901
- if (!styleSheetMap[documentId]) {
2902
- styleSheetMap[documentId] = [];
2903
- }
2904
- if (!arraysEqual(currentStyleSheets, styleSheetMap[documentId])) {
2905
- // Using -1 to signify the root document node as we don't track that as part of our nodeMap
2906
- trackStyleAdoption(time(), documentNode == document ? -1 : getId(documentNode), 3 /* StyleSheetOperation.SetAdoptedStyles */, currentStyleSheets);
2907
- styleSheetMap[documentId] = currentStyleSheets;
2908
- }
2909
- }
2910
- function compute$7() {
2911
- checkDocumentStyles(document);
2912
- Object.keys(styleSheetMap).forEach(function (x) { return checkDocumentStyles(getNode(parseInt(x, 10))); });
2913
- }
2914
- function reset$8() {
2915
- state$3 = [];
2916
- }
2917
- function stop$h() {
2918
- styleSheetMap = {};
2919
- reset$8();
2920
- }
2921
- function trackStyleChange(time, id, operation, cssRules) {
2922
- state$3.push({
2923
- time: time,
2924
- event: 46 /* Event.StyleSheetUpdate */,
2925
- data: {
2926
- id: id,
2927
- operation: operation,
2928
- cssRules: cssRules
2929
- }
2930
- });
2931
- encode$4(46 /* Event.StyleSheetUpdate */);
2932
- }
2933
- function trackStyleAdoption(time, id, operation, newIds) {
2934
- state$3.push({
2935
- time: time,
2936
- event: 45 /* Event.StyleSheetAdoption */,
2937
- data: {
2938
- id: id,
2939
- operation: operation,
2940
- newIds: newIds
2941
- }
2942
- });
2943
- encode$4(45 /* Event.StyleSheetAdoption */);
2944
- }
2945
- function arraysEqual(a, b) {
2946
- if (a.length !== b.length) {
2947
- return false;
2948
- }
2949
- return a.every(function (value, index) { return value === b[index]; });
2950
- }
2951
-
2952
- var state$2 = [];
2953
- var animationPlay = null;
2954
- var animationPause = null;
2955
- var animationCancel = null;
2956
- var animationFinish = null;
2957
- var animationId = 'clarityAnimationId';
2958
- var operationCount = 'clarityOperationCount';
2959
- var maxOperations = 20;
2960
- function start$i() {
2961
- if (window["Animation"] &&
2962
- window["KeyframeEffect"] &&
2963
- window["KeyframeEffect"].prototype.getKeyframes &&
2964
- window["KeyframeEffect"].prototype.getTiming) {
2965
- reset$7();
2966
- overrideAnimationHelper(animationPlay, "play");
2967
- overrideAnimationHelper(animationPause, "pause");
2968
- overrideAnimationHelper(animationCancel, "cancel");
2969
- overrideAnimationHelper(animationFinish, "finish");
2970
- }
2971
- }
2972
- function reset$7() {
2973
- state$2 = [];
2974
- }
2975
- function track$4(time, id, operation, keyFrames, timing, targetId, timeline) {
2976
- state$2.push({
2977
- time: time,
2978
- event: 44 /* Event.Animation */,
2979
- data: {
2980
- id: id,
2981
- operation: operation,
2982
- keyFrames: keyFrames,
2983
- timing: timing,
2984
- targetId: targetId,
2985
- timeline: timeline
2986
- }
2987
- });
2988
- encode$4(44 /* Event.Animation */);
2989
- }
2990
- function stop$g() {
2991
- reset$7();
2992
- }
2993
- function overrideAnimationHelper(functionToOverride, name) {
2994
- if (functionToOverride === null) {
2995
- functionToOverride = Animation.prototype[name];
2996
- Animation.prototype[name] = function () {
2997
- if (active()) {
2998
- var effect = this.effect;
2999
- var target = getId(this.effect.target);
3000
- if (target !== null && effect.getKeyframes && effect.getTiming) {
3001
- if (!this[animationId]) {
3002
- this[animationId] = shortid();
3003
- this[operationCount] = 0;
3004
- var keyframes = effect.getKeyframes();
3005
- var timing = effect.getTiming();
3006
- track$4(time(), this[animationId], 0 /* AnimationOperation.Create */, JSON.stringify(keyframes), JSON.stringify(timing), target);
3007
- }
3008
- if (this[operationCount]++ < maxOperations) {
3009
- var operation = null;
3010
- switch (name) {
3011
- case "play":
3012
- operation = 1 /* AnimationOperation.Play */;
3013
- break;
3014
- case "pause":
3015
- operation = 2 /* AnimationOperation.Pause */;
3016
- break;
3017
- case "cancel":
3018
- operation = 3 /* AnimationOperation.Cancel */;
3019
- break;
3020
- case "finish":
3021
- operation = 4 /* AnimationOperation.Finish */;
3022
- break;
3023
- }
3024
- if (operation) {
3025
- track$4(time(), this[animationId], operation);
3026
- }
3027
- }
3028
- }
3029
- }
3030
- return functionToOverride.apply(this, arguments);
3031
- };
3032
- }
3033
- }
3034
-
3035
- function encode$4 (type, timer, ts) {
3036
- if (timer === void 0) { timer = null; }
3037
- if (ts === void 0) { ts = null; }
2914
+ function traverse (root, timer, source) {
3038
2915
  return __awaiter(this, void 0, void 0, function () {
3039
- 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;
3040
- return __generator(this, function (_l) {
3041
- switch (_l.label) {
2916
+ var queue, entry, next, state, subnode;
2917
+ return __generator(this, function (_a) {
2918
+ switch (_a.label) {
3042
2919
  case 0:
3043
- eventTime = ts || time();
3044
- tokens = [eventTime, type];
3045
- _a = type;
3046
- switch (_a) {
3047
- case 8 /* Event.Document */: return [3 /*break*/, 1];
3048
- case 7 /* Event.Region */: return [3 /*break*/, 2];
3049
- case 45 /* Event.StyleSheetAdoption */: return [3 /*break*/, 3];
3050
- case 46 /* Event.StyleSheetUpdate */: return [3 /*break*/, 4];
3051
- case 44 /* Event.Animation */: return [3 /*break*/, 5];
3052
- case 5 /* Event.Discover */: return [3 /*break*/, 6];
3053
- case 6 /* Event.Mutation */: return [3 /*break*/, 6];
3054
- }
3055
- return [3 /*break*/, 13];
2920
+ queue = [root];
2921
+ _a.label = 1;
3056
2922
  case 1:
3057
- d = data$c;
3058
- tokens.push(d.width);
3059
- tokens.push(d.height);
3060
- track$8(type, d.width, d.height);
3061
- queue(tokens);
3062
- return [3 /*break*/, 13];
3063
- case 2:
3064
- for (_i = 0, _b = state$1; _i < _b.length; _i++) {
3065
- r = _b[_i];
3066
- tokens = [r.time, 7 /* Event.Region */];
3067
- tokens.push(r.data.id);
3068
- tokens.push(r.data.interaction);
3069
- tokens.push(r.data.visibility);
3070
- tokens.push(r.data.name);
3071
- queue(tokens);
3072
- }
3073
- reset$6();
3074
- return [3 /*break*/, 13];
3075
- case 3:
3076
- for (_c = 0, _d = state$3; _c < _d.length; _c++) {
3077
- entry = _d[_c];
3078
- tokens = [entry.time, entry.event];
3079
- tokens.push(entry.data.id);
3080
- tokens.push(entry.data.operation);
3081
- tokens.push(entry.data.newIds);
3082
- queue(tokens);
3083
- }
3084
- reset$8();
3085
- return [3 /*break*/, 13];
3086
- case 4:
3087
- for (_e = 0, _f = state$3; _e < _f.length; _e++) {
3088
- entry = _f[_e];
3089
- tokens = [entry.time, entry.event];
3090
- tokens.push(entry.data.id);
3091
- tokens.push(entry.data.operation);
3092
- tokens.push(entry.data.cssRules);
3093
- queue(tokens);
3094
- }
3095
- reset$8();
3096
- _l.label = 5;
3097
- case 5:
3098
- for (_g = 0, _h = state$2; _g < _h.length; _g++) {
3099
- entry = _h[_g];
3100
- tokens = [entry.time, entry.event];
3101
- tokens.push(entry.data.id);
3102
- tokens.push(entry.data.operation);
3103
- tokens.push(entry.data.keyFrames);
3104
- tokens.push(entry.data.timing);
3105
- tokens.push(entry.data.timeline);
3106
- tokens.push(entry.data.targetId);
3107
- queue(tokens);
3108
- }
3109
- reset$7();
3110
- return [3 /*break*/, 13];
3111
- case 6:
3112
- // Check if we are operating within the context of the current page
3113
- if (state$b(timer) === 2 /* Task.Stop */) {
3114
- return [3 /*break*/, 13];
3115
- }
3116
- values = updates$2();
3117
- if (!(values.length > 0)) return [3 /*break*/, 12];
3118
- _j = 0, values_1 = values;
3119
- _l.label = 7;
3120
- case 7:
3121
- if (!(_j < values_1.length)) return [3 /*break*/, 11];
3122
- value = values_1[_j];
2923
+ if (!(queue.length > 0)) return [3 /*break*/, 4];
2924
+ entry = queue.shift();
2925
+ next = entry.firstChild;
2926
+ while (next) {
2927
+ queue.push(next);
2928
+ next = next.nextSibling;
2929
+ }
3123
2930
  state = state$b(timer);
3124
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 9];
2931
+ if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 3];
3125
2932
  return [4 /*yield*/, suspend$1(timer)];
3126
- case 8:
3127
- state = _l.sent();
3128
- _l.label = 9;
3129
- case 9:
2933
+ case 2:
2934
+ state = _a.sent();
2935
+ _a.label = 3;
2936
+ case 3:
3130
2937
  if (state === 2 /* Task.Stop */) {
3131
- return [3 /*break*/, 11];
3132
- }
3133
- data = value.data;
3134
- active = value.metadata.active;
3135
- suspend = value.metadata.suspend;
3136
- privacy = value.metadata.privacy;
3137
- mangle = shouldMangle(value);
3138
- keys = active ? ["tag", "attributes", "value"] : ["tag"];
3139
- for (_k = 0, keys_1 = keys; _k < keys_1.length; _k++) {
3140
- key = keys_1[_k];
3141
- if (data[key]) {
3142
- switch (key) {
3143
- case "tag":
3144
- box = size(value);
3145
- factor = mangle ? -1 : 1;
3146
- tokens.push(value.id * factor);
3147
- if (value.parent && active) {
3148
- tokens.push(value.parent);
3149
- }
3150
- if (value.previous && active) {
3151
- tokens.push(value.previous);
3152
- }
3153
- tokens.push(suspend ? "*M" /* Constant.SuspendMutationTag */ : data[key]);
3154
- if (box && box.length === 2) {
3155
- tokens.push("".concat("#" /* Constant.Hash */).concat(str$1(box[0]), ".").concat(str$1(box[1])));
3156
- }
3157
- break;
3158
- case "attributes":
3159
- for (attr in data[key]) {
3160
- if (data[key][attr] !== undefined) {
3161
- tokens.push(attribute(attr, data[key][attr], privacy));
3162
- }
3163
- }
3164
- break;
3165
- case "value":
3166
- check$4(value.metadata.fraud, value.id, data[key]);
3167
- tokens.push(text$1(data[key], data.tag, privacy, mangle));
3168
- break;
3169
- }
3170
- }
2938
+ return [3 /*break*/, 4];
3171
2939
  }
3172
- _l.label = 10;
3173
- case 10:
3174
- _j++;
3175
- return [3 /*break*/, 7];
3176
- case 11:
3177
- if (type === 6 /* Event.Mutation */) {
3178
- activity(eventTime);
2940
+ subnode = processNode(entry, source);
2941
+ if (subnode) {
2942
+ queue.push(subnode);
3179
2943
  }
3180
- queue(tokenize(tokens), !config$1.lean);
3181
- _l.label = 12;
3182
- case 12: return [3 /*break*/, 13];
3183
- case 13: return [2 /*return*/];
2944
+ return [3 /*break*/, 1];
2945
+ case 4: return [2 /*return*/];
3184
2946
  }
3185
2947
  });
3186
2948
  });
2949
+ }
2950
+
2951
+ var observers = [];
2952
+ var mutations = [];
2953
+ var insertRule = null;
2954
+ var deleteRule = null;
2955
+ var attachShadow = null;
2956
+ var queue$1 = [];
2957
+ var timeout$1 = null;
2958
+ var activePeriod = null;
2959
+ var history$4 = {};
2960
+ function start$h() {
2961
+ observers = [];
2962
+ queue$1 = [];
2963
+ timeout$1 = null;
2964
+ activePeriod = 0;
2965
+ history$4 = {};
2966
+ // Some popular open source libraries, like styled-components, optimize performance
2967
+ // by injecting CSS using insertRule API vs. appending text node. A side effect of
2968
+ // using javascript API is that it doesn't trigger DOM mutation and therefore we
2969
+ // need to override the insertRule API and listen for changes manually.
2970
+ if (insertRule === null) {
2971
+ insertRule = CSSStyleSheet.prototype.insertRule;
2972
+ CSSStyleSheet.prototype.insertRule = function () {
2973
+ if (active()) {
2974
+ schedule(this.ownerNode);
2975
+ }
2976
+ return insertRule.apply(this, arguments);
2977
+ };
2978
+ }
2979
+ if (deleteRule === null) {
2980
+ deleteRule = CSSStyleSheet.prototype.deleteRule;
2981
+ CSSStyleSheet.prototype.deleteRule = function () {
2982
+ if (active()) {
2983
+ schedule(this.ownerNode);
2984
+ }
2985
+ return deleteRule.apply(this, arguments);
2986
+ };
2987
+ }
2988
+ // Add a hook to attachShadow API calls
2989
+ // In case we are unable to add a hook and browser throws an exception,
2990
+ // reset attachShadow variable and resume processing like before
2991
+ if (attachShadow === null) {
2992
+ attachShadow = Element.prototype.attachShadow;
2993
+ try {
2994
+ Element.prototype.attachShadow = function () {
2995
+ if (active()) {
2996
+ return schedule(attachShadow.apply(this, arguments));
2997
+ }
2998
+ else {
2999
+ return attachShadow.apply(this, arguments);
3000
+ }
3001
+ };
3002
+ }
3003
+ catch (_a) {
3004
+ attachShadow = null;
3005
+ }
3006
+ }
3187
3007
  }
3188
- function shouldMangle(value) {
3189
- var privacy = value.metadata.privacy;
3190
- return value.data.tag === "*T" /* Constant.TextTag */ && !(privacy === 0 /* Privacy.None */ || privacy === 1 /* Privacy.Sensitive */);
3191
- }
3192
- function size(value) {
3193
- if (value.metadata.size !== null && value.metadata.size.length === 0) {
3194
- var img = getNode(value.id);
3195
- if (img) {
3196
- return [Math.floor(img.offsetWidth * 100 /* Setting.BoxPrecision */), Math.floor(img.offsetHeight * 100 /* Setting.BoxPrecision */)];
3008
+ function observe$1(node) {
3009
+ // Create a new observer for every time a new DOM tree (e.g. root document or shadowdom root) is discovered on the page
3010
+ // In the case of shadow dom, any mutations that happen within the shadow dom are not bubbled up to the host document
3011
+ // For this reason, we need to wire up mutations every time we see a new shadow dom.
3012
+ // Also, wrap it inside a try / catch. In certain browsers (e.g. legacy Edge), observer on shadow dom can throw errors
3013
+ try {
3014
+ var m = api("MutationObserver" /* Constant.MutationObserver */);
3015
+ var observer = m in window ? new window[m](measure(handle$1)) : null;
3016
+ if (observer) {
3017
+ observer.observe(node, { attributes: true, childList: true, characterData: true, subtree: true });
3018
+ observers.push(observer);
3197
3019
  }
3198
3020
  }
3199
- return value.metadata.size;
3021
+ catch (e) {
3022
+ log$1(2 /* Code.MutationObserver */, 0 /* Severity.Info */, e ? e.name : null);
3023
+ }
3200
3024
  }
3201
- function str$1(input) {
3202
- return input.toString(36);
3025
+ function monitor(frame) {
3026
+ // Bind to iframe's onload event so we get notified anytime there's an update to iframe content.
3027
+ // This includes cases where iframe location is updated without explicitly updating src attribute
3028
+ // E.g. iframe.contentWindow.location.href = "new-location";
3029
+ if (has(frame) === false) {
3030
+ bind(frame, "load" /* Constant.LoadEvent */, generate.bind(this, frame, "childList" /* Constant.ChildList */), true);
3031
+ }
3203
3032
  }
3204
- function attribute(key, value, privacy) {
3205
- return "".concat(key, "=").concat(text$1(value, key.indexOf("data-" /* Constant.DataAttribute */) === 0 ? "data-" /* Constant.DataAttribute */ : key, privacy));
3206
- }
3207
-
3208
- var state$1 = [];
3209
- var regionMap = null; // Maps region nodes => region name
3210
- var regions = {};
3211
- var queue$1 = [];
3212
- var watch = false;
3213
- var observer$1 = null;
3214
- function start$h() {
3215
- reset$6();
3216
- observer$1 = null;
3217
- regionMap = new WeakMap();
3218
- regions = {};
3033
+ function stop$f() {
3034
+ for (var _i = 0, observers_1 = observers; _i < observers_1.length; _i++) {
3035
+ var observer = observers_1[_i];
3036
+ if (observer) {
3037
+ observer.disconnect();
3038
+ }
3039
+ }
3040
+ observers = [];
3041
+ history$4 = {};
3042
+ mutations = [];
3219
3043
  queue$1 = [];
3220
- watch = window["IntersectionObserver"] ? true : false;
3044
+ activePeriod = 0;
3045
+ timeout$1 = null;
3046
+ }
3047
+ function active$2() {
3048
+ activePeriod = time() + 3000 /* Setting.MutationActivePeriod */;
3049
+ }
3050
+ function handle$1(m) {
3051
+ // Queue up mutation records for asynchronous processing
3052
+ var now = time();
3053
+ track$7(6 /* Event.Mutation */, now);
3054
+ mutations.push({ time: now, mutations: m });
3055
+ schedule$1(process$1, 1 /* Priority.High */).then(function () {
3056
+ setTimeout(compute$7);
3057
+ measure(compute$6)();
3058
+ });
3059
+ }
3060
+ function process$1() {
3061
+ return __awaiter(this, void 0, void 0, function () {
3062
+ var timer, record, instance, _i, _a, mutation, state, target, type, value;
3063
+ return __generator(this, function (_b) {
3064
+ switch (_b.label) {
3065
+ case 0:
3066
+ timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
3067
+ start$x(timer);
3068
+ _b.label = 1;
3069
+ case 1:
3070
+ if (!(mutations.length > 0)) return [3 /*break*/, 8];
3071
+ record = mutations.shift();
3072
+ instance = time();
3073
+ _i = 0, _a = record.mutations;
3074
+ _b.label = 2;
3075
+ case 2:
3076
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
3077
+ mutation = _a[_i];
3078
+ state = state$b(timer);
3079
+ if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 4];
3080
+ return [4 /*yield*/, suspend$1(timer)];
3081
+ case 3:
3082
+ state = _b.sent();
3083
+ _b.label = 4;
3084
+ case 4:
3085
+ if (state === 2 /* Task.Stop */) {
3086
+ return [3 /*break*/, 6];
3087
+ }
3088
+ target = mutation.target;
3089
+ type = track$3(mutation, timer, instance);
3090
+ if (type && target && target.ownerDocument) {
3091
+ parse$1(target.ownerDocument);
3092
+ }
3093
+ if (type && target && target.nodeType == Node.DOCUMENT_FRAGMENT_NODE && target.host) {
3094
+ parse$1(target);
3095
+ }
3096
+ switch (type) {
3097
+ case "attributes" /* Constant.Attributes */:
3098
+ processNode(target, 3 /* Source.Attributes */);
3099
+ break;
3100
+ case "characterData" /* Constant.CharacterData */:
3101
+ processNode(target, 4 /* Source.CharacterData */);
3102
+ break;
3103
+ case "childList" /* Constant.ChildList */:
3104
+ processNodeList(mutation.addedNodes, 1 /* Source.ChildListAdd */, timer);
3105
+ processNodeList(mutation.removedNodes, 2 /* Source.ChildListRemove */, timer);
3106
+ break;
3107
+ case "suspend" /* Constant.Suspend */:
3108
+ value = get(target);
3109
+ if (value) {
3110
+ value.metadata.suspend = true;
3111
+ }
3112
+ break;
3113
+ }
3114
+ _b.label = 5;
3115
+ case 5:
3116
+ _i++;
3117
+ return [3 /*break*/, 2];
3118
+ case 6: return [4 /*yield*/, encode$4(6 /* Event.Mutation */, timer, record.time)];
3119
+ case 7:
3120
+ _b.sent();
3121
+ return [3 /*break*/, 1];
3122
+ case 8:
3123
+ stop$v(timer);
3124
+ return [2 /*return*/];
3125
+ }
3126
+ });
3127
+ });
3221
3128
  }
3222
- function observe$1(node, name) {
3223
- if (regionMap.has(node) === false) {
3224
- regionMap.set(node, name);
3225
- observer$1 = observer$1 === null && watch ? new IntersectionObserver(handler$1, {
3226
- // Get notified as intersection continues to change
3227
- // This allows us to process regions that get partially hidden during the lifetime of the page
3228
- // See: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#creating_an_intersection_observer
3229
- // By default, intersection observers only fire an event when even a single pixel is visible and not thereafter.
3230
- threshold: [0, 0.2, 0.4, 0.6, 0.8, 1]
3231
- }) : observer$1;
3232
- if (observer$1 && node && node.nodeType === Node.ELEMENT_NODE) {
3233
- observer$1.observe(node);
3129
+ function track$3(m, timer, instance) {
3130
+ var value = m.target ? get(m.target.parentNode) : null;
3131
+ // Check if the parent is already discovered and that the parent is not the document root
3132
+ if (value && value.data.tag !== "HTML" /* Constant.HTML */) {
3133
+ var inactive = time() > activePeriod;
3134
+ var target = get(m.target);
3135
+ var element = target && target.selector ? target.selector.join() : m.target.nodeName;
3136
+ var parent_1 = value.selector ? value.selector.join() : "" /* Constant.Empty */;
3137
+ // We use selector, instead of id, to determine the key (signature for the mutation) because in some cases
3138
+ // repeated mutations can cause elements to be destroyed and then recreated as new DOM nodes
3139
+ // In those cases, IDs will change however the selector (which is relative to DOM xPath) remains the same
3140
+ var key = [parent_1, element, m.attributeName, names(m.addedNodes), names(m.removedNodes)].join();
3141
+ // Initialize an entry if it doesn't already exist
3142
+ history$4[key] = key in history$4 ? history$4[key] : [0, instance];
3143
+ var h = history$4[key];
3144
+ // Lookup any pending nodes queued up for removal, and process them now if we suspended a mutation before
3145
+ if (inactive === false && h[0] >= 10 /* Setting.MutationSuspendThreshold */) {
3146
+ processNodeList(h[2], 2 /* Source.ChildListRemove */, timer);
3147
+ }
3148
+ // Update the counter
3149
+ h[0] = inactive ? (h[1] === instance ? h[0] : h[0] + 1) : 1;
3150
+ h[1] = instance;
3151
+ // Return updated mutation type based on if we have already hit the threshold or not
3152
+ if (h[0] === 10 /* Setting.MutationSuspendThreshold */) {
3153
+ // Store a reference to removedNodes so we can process them later
3154
+ // when we resume mutations again on user interactions
3155
+ h[2] = m.removedNodes;
3156
+ return "suspend" /* Constant.Suspend */;
3157
+ }
3158
+ else if (h[0] > 10 /* Setting.MutationSuspendThreshold */) {
3159
+ return "" /* Constant.Empty */;
3234
3160
  }
3235
3161
  }
3162
+ return m.type;
3236
3163
  }
3237
- function exists(node) {
3238
- // Check if regionMap is not null before looking up a node
3239
- // Since, dom module stops after region module, it's possible that we may set regionMap to be null
3240
- // and still attempt to call exists on a late coming DOM mutation (or addition), effectively causing a script error
3241
- return regionMap && regionMap.has(node);
3242
- }
3243
- function track$3(id, event) {
3244
- var node = getNode(id);
3245
- var data = id in regions ? regions[id] : { id: id, visibility: 0 /* RegionVisibility.Rendered */, interaction: 16 /* InteractionState.None */, name: regionMap.get(node) };
3246
- // Determine the interaction state based on incoming event
3247
- var interaction = 16 /* InteractionState.None */;
3248
- switch (event) {
3249
- case 9 /* Event.Click */:
3250
- interaction = 20 /* InteractionState.Clicked */;
3251
- break;
3252
- case 27 /* Event.Input */:
3253
- interaction = 30 /* InteractionState.Input */;
3254
- break;
3164
+ function names(nodes) {
3165
+ var output = [];
3166
+ for (var i = 0; nodes && i < nodes.length; i++) {
3167
+ output.push(nodes[i].nodeName);
3255
3168
  }
3256
- // Process updates to this region, if applicable
3257
- process$1(node, data, interaction, data.visibility);
3169
+ return output.join();
3258
3170
  }
3259
- function compute$6() {
3260
- // Process any regions where we couldn't resolve an "id" for at the time of last intersection observer event
3261
- // This could happen in cases where elements are not yet processed by Clarity's virtual DOM but browser reports a change, regardless.
3262
- // For those cases we add them to the queue and re-process them below
3263
- var q = [];
3264
- for (var _i = 0, queue_1 = queue$1; _i < queue_1.length; _i++) {
3265
- var r = queue_1[_i];
3266
- var id = getId(r.node);
3267
- if (!(id in regions)) {
3268
- if (id) {
3269
- r.data.id = id;
3270
- regions[id] = r.data;
3271
- state$1.push(clone$1(r.data));
3272
- }
3273
- else {
3274
- q.push(r);
3171
+ function processNodeList(list, source, timer) {
3172
+ return __awaiter(this, void 0, void 0, function () {
3173
+ var length, i, state;
3174
+ return __generator(this, function (_a) {
3175
+ switch (_a.label) {
3176
+ case 0:
3177
+ length = list ? list.length : 0;
3178
+ i = 0;
3179
+ _a.label = 1;
3180
+ case 1:
3181
+ if (!(i < length)) return [3 /*break*/, 6];
3182
+ if (!(source === 1 /* Source.ChildListAdd */)) return [3 /*break*/, 2];
3183
+ traverse(list[i], timer, source);
3184
+ return [3 /*break*/, 5];
3185
+ case 2:
3186
+ state = state$b(timer);
3187
+ if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 4];
3188
+ return [4 /*yield*/, suspend$1(timer)];
3189
+ case 3:
3190
+ state = _a.sent();
3191
+ _a.label = 4;
3192
+ case 4:
3193
+ if (state === 2 /* Task.Stop */) {
3194
+ return [3 /*break*/, 6];
3195
+ }
3196
+ processNode(list[i], source);
3197
+ _a.label = 5;
3198
+ case 5:
3199
+ i++;
3200
+ return [3 /*break*/, 1];
3201
+ case 6: return [2 /*return*/];
3275
3202
  }
3276
- }
3277
- }
3278
- queue$1 = q;
3279
- // Schedule encode only when we have at least one valid data entry
3280
- if (state$1.length > 0) {
3281
- encode$4(7 /* Event.Region */);
3282
- }
3203
+ });
3204
+ });
3283
3205
  }
3284
- function handler$1(entries) {
3285
- for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
3286
- var entry = entries_1[_i];
3287
- var target = entry.target;
3288
- var rect = entry.boundingClientRect;
3289
- var overlap = entry.intersectionRect;
3290
- var viewport = entry.rootBounds;
3291
- // Only capture regions that have non-zero width or height to avoid tracking and sending regions
3292
- // that cannot ever be seen by the user. In some cases, websites will have a multiple copy of the same region
3293
- // like search box - one for desktop, and another for mobile. In those cases, CSS media queries determine which one should be visible.
3294
- // Also, if these regions ever become non-zero width or height (through AJAX, user action or orientation change) - we will automatically start monitoring them from that point onwards
3295
- if (regionMap.has(target) && rect.width + rect.height > 0 && viewport.width > 0 && viewport.height > 0) {
3296
- var id = target ? getId(target) : null;
3297
- var data = id in regions ? regions[id] : { id: id, name: regionMap.get(target), interaction: 16 /* InteractionState.None */, visibility: 0 /* RegionVisibility.Rendered */ };
3298
- // For regions that have relatively smaller area, we look at intersection ratio and see the overlap relative to element's area
3299
- // However, for larger regions, area of regions could be bigger than viewport and therefore comparison is relative to visible area
3300
- var viewportRatio = overlap ? (overlap.width * overlap.height * 1.0) / (viewport.width * viewport.height) : 0;
3301
- var visible = viewportRatio > 0.05 /* Setting.ViewportIntersectionRatio */ || entry.intersectionRatio > 0.8 /* Setting.IntersectionRatio */;
3302
- // If an element is either visible or was visible and has been scrolled to the end
3303
- // i.e. Scrolled to end is determined by if the starting position of the element + the window height is more than the total element height.
3304
- // starting position is relative to the viewport - so Intersection observer returns a negative value for rect.top to indicate that the element top is above the viewport
3305
- var scrolledToEnd = (visible || data.visibility == 10 /* RegionVisibility.Visible */) && Math.abs(rect.top) + viewport.height > rect.height;
3306
- // Process updates to this region, if applicable
3307
- process$1(target, data, data.interaction, (scrolledToEnd ?
3308
- 13 /* RegionVisibility.ScrolledToEnd */ :
3309
- (visible ? 10 /* RegionVisibility.Visible */ : 0 /* RegionVisibility.Rendered */)));
3310
- // Stop observing this element now that we have already received scrolled signal
3311
- if (data.visibility >= 13 /* RegionVisibility.ScrolledToEnd */ && observer$1) {
3312
- observer$1.unobserve(target);
3313
- }
3314
- }
3206
+ function schedule(node) {
3207
+ // Only schedule manual trigger for this node if it's not already in the queue
3208
+ if (queue$1.indexOf(node) < 0) {
3209
+ queue$1.push(node);
3315
3210
  }
3316
- if (state$1.length > 0) {
3317
- encode$4(7 /* Event.Region */);
3211
+ // Cancel any previous trigger before scheduling a new one.
3212
+ // It's common for a webpage to call multiple synchronous "insertRule" / "deleteRule" calls.
3213
+ // And in those cases we do not wish to monitor changes multiple times for the same node.
3214
+ if (timeout$1) {
3215
+ clearTimeout(timeout$1);
3318
3216
  }
3217
+ timeout$1 = setTimeout(function () { trigger$2(); }, 33 /* Setting.LookAhead */);
3218
+ return node;
3319
3219
  }
3320
- function process$1(n, d, s, v) {
3321
- // Check if received a state that supersedes existing state
3322
- var updated = s > d.interaction || v > d.visibility;
3323
- d.interaction = s > d.interaction ? s : d.interaction;
3324
- d.visibility = v > d.visibility ? v : d.visibility;
3325
- // If the corresponding node is already discovered, update the internal state
3326
- // Otherwise, track it in a queue to reprocess later.
3327
- if (d.id) {
3328
- if ((d.id in regions && updated) || !(d.id in regions)) {
3329
- regions[d.id] = d;
3330
- state$1.push(clone$1(d));
3220
+ function trigger$2() {
3221
+ for (var _i = 0, queue_1 = queue$1; _i < queue_1.length; _i++) {
3222
+ var node = queue_1[_i];
3223
+ // Generate a mutation for this node only if it still exists
3224
+ if (node) {
3225
+ var shadowRoot = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
3226
+ // Skip re-processing shadowRoot if it was already discovered
3227
+ if (shadowRoot && has(node)) {
3228
+ continue;
3229
+ }
3230
+ generate(node, shadowRoot ? "childList" /* Constant.ChildList */ : "characterData" /* Constant.CharacterData */);
3331
3231
  }
3332
3232
  }
3333
- else {
3334
- queue$1.push({ node: n, data: d });
3335
- }
3336
- }
3337
- function clone$1(r) {
3338
- return { time: time(), data: { id: r.id, interaction: r.interaction, visibility: r.visibility, name: r.name } };
3339
- }
3340
- function reset$6() {
3341
- state$1 = [];
3342
- }
3343
- function stop$f() {
3344
- reset$6();
3345
- regionMap = null;
3346
- regions = {};
3347
3233
  queue$1 = [];
3348
- if (observer$1) {
3349
- observer$1.disconnect();
3350
- observer$1 = null;
3351
- }
3352
- watch = false;
3234
+ }
3235
+ function generate(target, type) {
3236
+ measure(handle$1)([{
3237
+ addedNodes: [target],
3238
+ attributeName: null,
3239
+ attributeNamespace: null,
3240
+ nextSibling: null,
3241
+ oldValue: null,
3242
+ previousSibling: null,
3243
+ removedNodes: [],
3244
+ target: target,
3245
+ type: type
3246
+ }]);
3353
3247
  }
3354
3248
 
3355
3249
  function target(evt) {
@@ -3370,7 +3264,7 @@ function metadata$2(node, event, text) {
3370
3264
  output.hash = value.hash;
3371
3265
  output.privacy = metadata_1.privacy;
3372
3266
  if (value.region) {
3373
- track$3(value.region, event);
3267
+ track$4(value.region, event);
3374
3268
  }
3375
3269
  if (metadata_1.fraud) {
3376
3270
  check$4(metadata_1.fraud, value.id, text || value.data.value);
@@ -3397,7 +3291,7 @@ function encode$3 (type, ts) {
3397
3291
  case 18 /* Event.TouchEnd */:
3398
3292
  case 19 /* Event.TouchMove */:
3399
3293
  case 20 /* Event.TouchCancel */:
3400
- for (_i = 0, _a = state$6; _i < _a.length; _i++) {
3294
+ for (_i = 0, _a = state$3; _i < _a.length; _i++) {
3401
3295
  entry = _a[_i];
3402
3296
  pTarget = metadata$2(entry.data.target, entry.event);
3403
3297
  if (pTarget.id > 0) {
@@ -3409,10 +3303,10 @@ function encode$3 (type, ts) {
3409
3303
  track$8(entry.event, entry.data.x, entry.data.y);
3410
3304
  }
3411
3305
  }
3412
- reset$f();
3306
+ reset$c();
3413
3307
  break;
3414
3308
  case 9 /* Event.Click */:
3415
- for (_b = 0, _c = state$9; _b < _c.length; _b++) {
3309
+ for (_b = 0, _c = state$6; _b < _c.length; _b++) {
3416
3310
  entry = _c[_b];
3417
3311
  cTarget = metadata$2(entry.data.target, entry.event, entry.data.text);
3418
3312
  tokens = [entry.time, entry.event];
@@ -3432,10 +3326,10 @@ function encode$3 (type, ts) {
3432
3326
  queue(tokens);
3433
3327
  track$2(entry.time, entry.event, cHash, entry.data.x, entry.data.y, entry.data.reaction, entry.data.context);
3434
3328
  }
3435
- reset$i();
3329
+ reset$f();
3436
3330
  break;
3437
3331
  case 38 /* Event.Clipboard */:
3438
- for (_d = 0, _e = state$8; _d < _e.length; _d++) {
3332
+ for (_d = 0, _e = state$5; _d < _e.length; _d++) {
3439
3333
  entry = _e[_d];
3440
3334
  tokens = [entry.time, entry.event];
3441
3335
  target = metadata$2(entry.data.target, entry.event);
@@ -3445,24 +3339,24 @@ function encode$3 (type, ts) {
3445
3339
  queue(tokens);
3446
3340
  }
3447
3341
  }
3448
- reset$h();
3342
+ reset$e();
3449
3343
  break;
3450
3344
  case 11 /* Event.Resize */:
3451
3345
  r = data$b;
3452
3346
  tokens.push(r.width);
3453
3347
  tokens.push(r.height);
3454
3348
  track$8(type, r.width, r.height);
3455
- reset$e();
3349
+ reset$b();
3456
3350
  queue(tokens);
3457
3351
  break;
3458
3352
  case 26 /* Event.Unload */:
3459
3353
  u = data$9;
3460
3354
  tokens.push(u.name);
3461
- reset$a();
3355
+ reset$7();
3462
3356
  queue(tokens);
3463
3357
  break;
3464
3358
  case 27 /* Event.Input */:
3465
- for (_f = 0, _g = state$7; _f < _g.length; _f++) {
3359
+ for (_f = 0, _g = state$4; _f < _g.length; _f++) {
3466
3360
  entry = _g[_f];
3467
3361
  iTarget = metadata$2(entry.data.target, entry.event, entry.data.value);
3468
3362
  tokens = [entry.time, entry.event];
@@ -3470,7 +3364,7 @@ function encode$3 (type, ts) {
3470
3364
  tokens.push(text$1(entry.data.value, "input", iTarget.privacy));
3471
3365
  queue(tokens);
3472
3366
  }
3473
- reset$g();
3367
+ reset$d();
3474
3368
  break;
3475
3369
  case 21 /* Event.Selection */:
3476
3370
  s = data$a;
@@ -3481,12 +3375,12 @@ function encode$3 (type, ts) {
3481
3375
  tokens.push(s.startOffset);
3482
3376
  tokens.push(endTarget.id);
3483
3377
  tokens.push(s.endOffset);
3484
- reset$c();
3378
+ reset$9();
3485
3379
  queue(tokens);
3486
3380
  }
3487
3381
  break;
3488
3382
  case 10 /* Event.Scroll */:
3489
- for (_h = 0, _j = state$5; _h < _j.length; _h++) {
3383
+ for (_h = 0, _j = state$2; _h < _j.length; _h++) {
3490
3384
  entry = _j[_h];
3491
3385
  sTarget = metadata$2(entry.data.target, entry.event);
3492
3386
  if (sTarget.id > 0) {
@@ -3498,10 +3392,10 @@ function encode$3 (type, ts) {
3498
3392
  track$8(entry.event, entry.data.x, entry.data.y);
3499
3393
  }
3500
3394
  }
3501
- reset$d();
3395
+ reset$a();
3502
3396
  break;
3503
3397
  case 42 /* Event.Change */:
3504
- for (_k = 0, _l = state$a; _k < _l.length; _k++) {
3398
+ for (_k = 0, _l = state$7; _k < _l.length; _k++) {
3505
3399
  entry = _l[_k];
3506
3400
  tokens = [entry.time, entry.event];
3507
3401
  target = metadata$2(entry.data.target, entry.event);
@@ -3514,10 +3408,10 @@ function encode$3 (type, ts) {
3514
3408
  queue(tokens);
3515
3409
  }
3516
3410
  }
3517
- reset$j();
3411
+ reset$g();
3518
3412
  break;
3519
3413
  case 39 /* Event.Submit */:
3520
- for (_m = 0, _o = state$4; _m < _o.length; _m++) {
3414
+ for (_m = 0, _o = state$1; _m < _o.length; _m++) {
3521
3415
  entry = _o[_m];
3522
3416
  tokens = [entry.time, entry.event];
3523
3417
  target = metadata$2(entry.data.target, entry.event);
@@ -3526,7 +3420,7 @@ function encode$3 (type, ts) {
3526
3420
  queue(tokens);
3527
3421
  }
3528
3422
  }
3529
- reset$b();
3423
+ reset$8();
3530
3424
  break;
3531
3425
  case 22 /* Event.Timeline */:
3532
3426
  for (_p = 0, _q = updates$1; _p < _q.length; _p++) {
@@ -3547,7 +3441,7 @@ function encode$3 (type, ts) {
3547
3441
  tokens.push(v.visible);
3548
3442
  queue(tokens);
3549
3443
  visibility(t, v.visible);
3550
- reset$9();
3444
+ reset$6();
3551
3445
  break;
3552
3446
  }
3553
3447
  return [2 /*return*/];
@@ -3661,7 +3555,7 @@ function queue(tokens, transmit) {
3661
3555
  // We enrich the data going out with the existing upload. In these cases, call to upload comes with 'transmit' set to false.
3662
3556
  if (transmit && timeout === null) {
3663
3557
  if (type !== 25 /* Event.Ping */) {
3664
- reset$q();
3558
+ reset$p();
3665
3559
  }
3666
3560
  timeout = setTimeout(upload, gap);
3667
3561
  queuedTime = now;
@@ -3697,8 +3591,7 @@ function upload(final) {
3697
3591
  // Otherwise you run a risk of infinite loop.
3698
3592
  compute$6();
3699
3593
  compute$5();
3700
- compute$9();
3701
- compute$7();
3594
+ compute$8();
3702
3595
  last = final === true;
3703
3596
  e = JSON.stringify(envelope(last));
3704
3597
  a = "[".concat(analysis.join(), "]");
@@ -4181,7 +4074,7 @@ function encode$1 (event) {
4181
4074
  tokens.push(b.data.activityTime);
4182
4075
  queue(tokens, false);
4183
4076
  }
4184
- reset$s();
4077
+ reset$r();
4185
4078
  break;
4186
4079
  case 25 /* Event.Ping */:
4187
4080
  tokens.push(data$h.gap);
@@ -4215,7 +4108,7 @@ function encode$1 (event) {
4215
4108
  tokens.push(v);
4216
4109
  tokens.push(data$e[v]);
4217
4110
  }
4218
- reset$o();
4111
+ reset$n();
4219
4112
  queue(tokens, false);
4220
4113
  }
4221
4114
  break;
@@ -4230,7 +4123,7 @@ function encode$1 (event) {
4230
4123
  // However, for data over the wire, we round it off to milliseconds precision.
4231
4124
  tokens.push(Math.round(updates$3[m]));
4232
4125
  }
4233
- reset$r();
4126
+ reset$q();
4234
4127
  queue(tokens, false);
4235
4128
  }
4236
4129
  break;
@@ -4256,7 +4149,7 @@ function encode$1 (event) {
4256
4149
  tokens.push(key);
4257
4150
  tokens.push([].concat.apply([], data$g[e]));
4258
4151
  }
4259
- reset$p();
4152
+ reset$o();
4260
4153
  queue(tokens, false);
4261
4154
  }
4262
4155
  break;
@@ -4825,8 +4718,8 @@ function stop$6() {
4825
4718
  var status = false;
4826
4719
  function start$6() {
4827
4720
  status = true;
4828
- start$I();
4829
- reset$l();
4721
+ start$H();
4722
+ reset$k();
4830
4723
  reset$1();
4831
4724
  reset$2();
4832
4725
  start$7();
@@ -4835,8 +4728,8 @@ function stop$5() {
4835
4728
  stop$6();
4836
4729
  reset$2();
4837
4730
  reset$1();
4838
- reset$l();
4839
- stop$F();
4731
+ reset$k();
4732
+ stop$E();
4840
4733
  status = false;
4841
4734
  }
4842
4735
  function active() {
@@ -4890,7 +4783,7 @@ function restart() {
4890
4783
  }
4891
4784
 
4892
4785
  function start$5() {
4893
- start$A();
4786
+ start$z();
4894
4787
  start$e();
4895
4788
  start$d();
4896
4789
  }
@@ -4906,7 +4799,7 @@ var diagnostic = /*#__PURE__*/Object.freeze({
4906
4799
 
4907
4800
  function start$4() {
4908
4801
  schedule$1(discover, 1 /* Priority.High */).then(function () {
4909
- measure(compute$8)();
4802
+ measure(compute$7)();
4910
4803
  measure(compute$6)();
4911
4804
  });
4912
4805
  }
@@ -4918,15 +4811,14 @@ function discover() {
4918
4811
  case 0:
4919
4812
  ts = time();
4920
4813
  timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
4921
- start$y(timer);
4814
+ start$x(timer);
4922
4815
  return [4 /*yield*/, traverse(document, timer, 0 /* Source.Discover */)];
4923
4816
  case 1:
4924
4817
  _a.sent();
4925
- checkDocumentStyles(document);
4926
4818
  return [4 /*yield*/, encode$4(5 /* Event.Discover */, timer, ts)];
4927
4819
  case 2:
4928
4820
  _a.sent();
4929
- stop$w(timer);
4821
+ stop$v(timer);
4930
4822
  return [2 /*return*/];
4931
4823
  }
4932
4824
  });
@@ -4936,21 +4828,19 @@ function discover() {
4936
4828
  function start$3() {
4937
4829
  // The order below is important
4938
4830
  // and is determined by interdependencies of modules
4939
- start$x();
4831
+ start$w();
4832
+ start$u();
4833
+ start$y();
4940
4834
  start$h();
4941
- start$z();
4942
- start$k();
4943
4835
  start$4();
4944
- start$j();
4945
- start$i();
4836
+ start$v();
4946
4837
  }
4947
4838
  function stop$3() {
4839
+ stop$s();
4840
+ stop$w();
4948
4841
  stop$f();
4949
- stop$x();
4950
- stop$i();
4951
- stop$v();
4952
- stop$h();
4953
- stop$g();
4842
+ stop$u();
4843
+ stop$t();
4954
4844
  }
4955
4845
 
4956
4846
  var layout = /*#__PURE__*/Object.freeze({
@@ -5144,7 +5034,7 @@ function start(config$1) {
5144
5034
  if (check()) {
5145
5035
  config(config$1);
5146
5036
  start$6();
5147
- start$B();
5037
+ start$A();
5148
5038
  modules.forEach(function (x) { return measure(x.start)(); });
5149
5039
  // If it's an internal call to start, without explicit configuration,
5150
5040
  // re-process any newly accumulated items in the queue
@@ -5175,7 +5065,7 @@ function stop() {
5175
5065
  if (active()) {
5176
5066
  // Stop modules in the reverse order of their initialization and start queuing up items again
5177
5067
  modules.slice().reverse().forEach(function (x) { return measure(x.stop)(); });
5178
- stop$y();
5068
+ stop$x();
5179
5069
  stop$5();
5180
5070
  setup();
5181
5071
  }