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