clarity-js 0.7.16 → 0.7.19

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$H() {
145
+ function start$I() {
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$E() {
153
+ function stop$F() {
154
154
  startTime = 0;
155
155
  }
156
156
 
157
- var version$1 = "0.7.16";
157
+ var version$1 = "0.7.19";
158
158
 
159
159
  // tslint:disable: no-bitwise
160
160
  function hash (input, precision) {
@@ -355,18 +355,18 @@ function redact$1(value) {
355
355
  return array ? array.join("" /* Data.Constant.Empty */) : value;
356
356
  }
357
357
 
358
- var state$b = null;
358
+ var state$c = null;
359
359
  var buffer = null;
360
360
  var update$2 = false;
361
- function start$G() {
361
+ function start$H() {
362
362
  update$2 = false;
363
- reset$r();
363
+ reset$s();
364
364
  }
365
- function reset$r() {
365
+ function reset$s() {
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) {
369
- state$b = { time: time(), event: 4 /* Event.Baseline */, data: {
369
+ state$c = { time: time(), event: 4 /* Event.Baseline */, data: {
370
370
  visible: buffer.visible,
371
371
  docWidth: buffer.docWidth,
372
372
  docHeight: buffer.docHeight,
@@ -424,23 +424,23 @@ function visibility(t, visible) {
424
424
  }
425
425
  update$2 = true;
426
426
  }
427
- function compute$c() {
427
+ function compute$d() {
428
428
  if (update$2) {
429
429
  encode$1(4 /* Event.Baseline */);
430
430
  }
431
431
  }
432
- function stop$D() {
433
- reset$r();
432
+ function stop$E() {
433
+ reset$s();
434
434
  }
435
435
 
436
436
  var baseline = /*#__PURE__*/Object.freeze({
437
437
  __proto__: null,
438
438
  activity: activity,
439
- compute: compute$c,
440
- reset: reset$r,
441
- start: start$G,
442
- get state () { return state$b; },
443
- stop: stop$D,
439
+ compute: compute$d,
440
+ reset: reset$s,
441
+ start: start$H,
442
+ get state () { return state$c; },
443
+ stop: stop$E,
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$F() {
468
+ function start$G() {
469
469
  data$i = {};
470
470
  updates$3 = {};
471
471
  count$1(5 /* Metric.InvokeCount */);
472
472
  }
473
- function stop$C() {
473
+ function stop$D() {
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$b() {
511
+ function compute$c() {
512
512
  encode$1(0 /* Event.Metric */);
513
513
  }
514
- function reset$q() {
514
+ function reset$r() {
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$E() {
529
+ function start$F() {
530
530
  interval = 60000 /* Setting.PingInterval */;
531
531
  last = 0;
532
532
  }
533
- function reset$p() {
533
+ function reset$q() {
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$B() {
551
+ function stop$C() {
552
552
  clearTimeout(timeout$6);
553
553
  last = 0;
554
554
  interval = 0;
@@ -557,16 +557,16 @@ function stop$B() {
557
557
  var ping$1 = /*#__PURE__*/Object.freeze({
558
558
  __proto__: null,
559
559
  get data () { return data$h; },
560
- reset: reset$p,
561
- start: start$E,
562
- stop: stop$B
560
+ reset: reset$q,
561
+ start: start$F,
562
+ stop: stop$C
563
563
  });
564
564
 
565
565
  var data$g = null;
566
- function start$D() {
566
+ function start$E() {
567
567
  data$g = {};
568
568
  }
569
- function stop$A() {
569
+ function stop$B() {
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$a() {
589
+ function compute$b() {
590
590
  encode$1(36 /* Event.Summary */);
591
591
  }
592
- function reset$o() {
592
+ function reset$p() {
593
593
  data$g = {};
594
594
  }
595
595
 
596
596
  var summary = /*#__PURE__*/Object.freeze({
597
597
  __proto__: null,
598
- compute: compute$a,
598
+ compute: compute$b,
599
599
  get data () { return data$g; },
600
- reset: reset$o,
601
- start: start$D,
602
- stop: stop$A,
600
+ reset: reset$p,
601
+ start: start$E,
602
+ stop: stop$B,
603
603
  track: track$7
604
604
  });
605
605
 
606
606
  var data$f = null;
607
- function start$C() {
607
+ function start$D() {
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$z() {
631
+ function stop$A() {
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$C,
639
- stop: stop$z,
638
+ start: start$D,
639
+ stop: stop$A,
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$B() {
698
- reset$n();
697
+ function start$C() {
698
+ reset$o();
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$9() {
753
+ function compute$a() {
754
754
  encode$1(34 /* Event.Variable */);
755
755
  }
756
- function reset$n() {
756
+ function reset$o() {
757
757
  data$e = {};
758
758
  }
759
- function stop$y() {
760
- reset$n();
759
+ function stop$z() {
760
+ reset$o();
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$9,
794
+ compute: compute$a,
795
795
  get data () { return data$e; },
796
796
  identify: identify,
797
- reset: reset$n,
797
+ reset: reset$o,
798
798
  set: set,
799
- start: start$B,
800
- stop: stop$y
799
+ start: start$C,
800
+ stop: stop$z
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$A() {
862
+ function start$B() {
863
863
  // Metric needs to be initialized before we can start measuring. so metric is not wrapped in measure
864
- start$F();
864
+ start$G();
865
865
  modules$1.forEach(function (x) { return measure(x.start)(); });
866
866
  }
867
- function stop$x() {
867
+ function stop$y() {
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$C();
873
+ stop$D();
874
874
  }
875
- function compute$8() {
876
- compute$9();
877
- compute$c();
875
+ function compute$9() {
876
+ compute$a();
877
+ compute$d();
878
878
  compute$2();
879
+ compute$c();
879
880
  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$z() {
887
+ function start$A() {
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$m() {
911
+ function reset$n() {
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$m
1000
+ reset: reset$n
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$y() {
1020
- reset$l();
1019
+ function start$z() {
1020
+ reset$m();
1021
1021
  parse$1(document, true);
1022
1022
  }
1023
- function stop$w() {
1024
- reset$l();
1023
+ function stop$x() {
1024
+ reset$m();
1025
1025
  }
1026
- function reset$l() {
1026
+ function reset$m() {
1027
1027
  index = 1;
1028
1028
  values = [];
1029
1029
  updateMap = [];
@@ -1039,7 +1039,7 @@ function reset$l() {
1039
1039
  iframeMap = new WeakMap();
1040
1040
  privacyMap = new WeakMap();
1041
1041
  fraudMap = new WeakMap();
1042
- reset$m();
1042
+ reset$n();
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$c(e, "".concat(x[0])); }); }); // Regions
1058
+ config$1.regions.forEach(function (x) { return root.querySelectorAll(x[1]).forEach(function (e) { return observe$1(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$c(node, data.attributes["data-clarity-region" /* Constant.RegionData */]);
1097
+ observe$1(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$y,
1379
- stop: stop$w,
1378
+ start: start$z,
1379
+ stop: stop$x,
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$k() {
1407
+ function reset$l() {
1408
1408
  tracker = {};
1409
1409
  queuedTasks = [];
1410
1410
  activeTask = null;
@@ -1465,7 +1465,7 @@ function run() {
1465
1465
  });
1466
1466
  }
1467
1467
  }
1468
- function state$a(timer) {
1468
+ function state$b(timer) {
1469
1469
  var id = key(timer);
1470
1470
  if (id in tracker) {
1471
1471
  var elapsed = performance.now() - tracker[id].start;
@@ -1474,7 +1474,7 @@ function state$a(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$x(timer) {
1477
+ function start$y(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$x(timer);
1485
+ start$y(timer);
1486
1486
  tracker[id].calls = c + 1;
1487
1487
  tracker[id].yield = y;
1488
1488
  }
1489
1489
  }
1490
- function stop$v(timer) {
1490
+ function stop$w(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$v(timer);
1510
+ stop$w(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$j() {
1623
+ function reset$k() {
1624
1624
  data$c = null;
1625
1625
  }
1626
- function start$w() {
1627
- reset$j();
1628
- compute$7();
1626
+ function start$x() {
1627
+ reset$k();
1628
+ compute$8();
1629
1629
  }
1630
- function compute$7() {
1630
+ function compute$8() {
1631
1631
  var body = document.body;
1632
1632
  var d = document.documentElement;
1633
1633
  var bodyClientWidth = body ? body.clientWidth : null;
@@ -1650,436 +1650,256 @@ function compute$7() {
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
+ }
1653
1676
  function stop$u() {
1654
1677
  reset$j();
1655
1678
  }
1656
1679
 
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
+ }
1695
+
1696
+ var UserInputTags = ["input", "textarea", "radio", "button", "canvas"];
1657
1697
  var state$9 = [];
1658
- var animationPlay = null;
1659
- var animationPause = null;
1660
- var animationCancel = null;
1661
- var animationFinish = null;
1662
- var animationId = 'clarityAnimationId';
1663
- var operationCount = 'clarityOperationCount';
1664
- var maxOperations = 20;
1665
1698
  function start$v() {
1666
- if (window["Animation"] &&
1667
- window["KeyframeEffect"] &&
1668
- window["KeyframeEffect"].prototype.getKeyframes &&
1669
- window["KeyframeEffect"].prototype.getTiming) {
1670
- reset$i();
1671
- overrideAnimationHelper(animationPlay, "play");
1672
- overrideAnimationHelper(animationPause, "pause");
1673
- overrideAnimationHelper(animationCancel, "cancel");
1674
- overrideAnimationHelper(animationFinish, "finish");
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));
1675
1751
  }
1676
1752
  }
1677
- function reset$i() {
1678
- state$9 = [];
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;
1762
+ }
1763
+ return null;
1679
1764
  }
1680
- function track$5(time, id, operation, keyFrames, timing, targetId, timeline) {
1681
- state$9.push({
1682
- time: time,
1683
- event: 44 /* Event.Animation */,
1684
- data: {
1685
- id: id,
1686
- operation: operation,
1687
- keyFrames: keyFrames,
1688
- timing: timing,
1689
- targetId: targetId,
1690
- timeline: timeline
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 */);
1691
1775
  }
1692
- });
1693
- encode$4(44 /* Event.Animation */);
1776
+ }
1777
+ return output;
1694
1778
  }
1695
- function stop$t() {
1696
- reset$i();
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 */;
1784
+ }
1785
+ }
1786
+ return 1 /* BooleanFlag.True */;
1697
1787
  }
1698
- function overrideAnimationHelper(functionToOverride, name) {
1699
- if (functionToOverride === null) {
1700
- functionToOverride = Animation.prototype[name];
1701
- Animation.prototype[name] = function () {
1702
- if (active()) {
1703
- var effect = this.effect;
1704
- if (effect.getKeyframes && effect.getTiming) {
1705
- if (!this[animationId]) {
1706
- this[animationId] = shortid();
1707
- this[operationCount] = 0;
1708
- var keyframes = effect.getKeyframes();
1709
- var timing = effect.getTiming();
1710
- track$5(time(), this[animationId], 0 /* AnimationOperation.Create */, JSON.stringify(keyframes), JSON.stringify(timing), getId(this.effect.target));
1711
- }
1712
- if (this[operationCount]++ < maxOperations) {
1713
- var operation = null;
1714
- switch (name) {
1715
- case "play":
1716
- operation = 1 /* AnimationOperation.Play */;
1717
- break;
1718
- case "pause":
1719
- operation = 2 /* AnimationOperation.Pause */;
1720
- break;
1721
- case "cancel":
1722
- operation = 3 /* AnimationOperation.Cancel */;
1723
- break;
1724
- case "finish":
1725
- operation = 4 /* AnimationOperation.Finish */;
1726
- break;
1727
- }
1728
- if (operation) {
1729
- track$5(time(), this[animationId], operation);
1730
- }
1731
- }
1732
- }
1733
- }
1734
- return functionToOverride.apply(this, arguments);
1735
- };
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
+ }
1736
1806
  }
1737
- }
1738
-
1739
- function encode$4 (type, timer, ts) {
1740
- if (timer === void 0) { timer = null; }
1741
- if (ts === void 0) { ts = null; }
1742
- return __awaiter(this, void 0, void 0, function () {
1743
- var eventTime, tokens, _a, d, _i, _b, r, _c, _d, entry, values, _e, values_1, value, state, data, active, suspend, privacy, mangle, keys, _f, keys_1, key, box, factor, attr;
1744
- return __generator(this, function (_g) {
1745
- switch (_g.label) {
1746
- case 0:
1747
- eventTime = ts || time();
1748
- tokens = [eventTime, type];
1749
- _a = type;
1750
- switch (_a) {
1751
- case 8 /* Event.Document */: return [3 /*break*/, 1];
1752
- case 7 /* Event.Region */: return [3 /*break*/, 2];
1753
- case 44 /* Event.Animation */: return [3 /*break*/, 3];
1754
- case 5 /* Event.Discover */: return [3 /*break*/, 4];
1755
- case 6 /* Event.Mutation */: return [3 /*break*/, 4];
1756
- }
1757
- return [3 /*break*/, 11];
1758
- case 1:
1759
- d = data$c;
1760
- tokens.push(d.width);
1761
- tokens.push(d.height);
1762
- track$8(type, d.width, d.height);
1763
- queue(tokens);
1764
- return [3 /*break*/, 11];
1765
- case 2:
1766
- for (_i = 0, _b = state$8; _i < _b.length; _i++) {
1767
- r = _b[_i];
1768
- tokens = [r.time, 7 /* Event.Region */];
1769
- tokens.push(r.data.id);
1770
- tokens.push(r.data.interaction);
1771
- tokens.push(r.data.visibility);
1772
- tokens.push(r.data.name);
1773
- queue(tokens);
1774
- }
1775
- reset$h();
1776
- return [3 /*break*/, 11];
1777
- case 3:
1778
- for (_c = 0, _d = state$9; _c < _d.length; _c++) {
1779
- entry = _d[_c];
1780
- tokens = [entry.time, entry.event];
1781
- tokens.push(entry.data.id);
1782
- tokens.push(entry.data.operation);
1783
- tokens.push(entry.data.keyFrames);
1784
- tokens.push(entry.data.timing);
1785
- tokens.push(entry.data.timeline);
1786
- tokens.push(entry.data.targetId);
1787
- queue(tokens);
1788
- }
1789
- reset$i();
1790
- return [3 /*break*/, 11];
1791
- case 4:
1792
- // Check if we are operating within the context of the current page
1793
- if (state$a(timer) === 2 /* Task.Stop */) {
1794
- return [3 /*break*/, 11];
1795
- }
1796
- values = updates$2();
1797
- if (!(values.length > 0)) return [3 /*break*/, 10];
1798
- _e = 0, values_1 = values;
1799
- _g.label = 5;
1800
- case 5:
1801
- if (!(_e < values_1.length)) return [3 /*break*/, 9];
1802
- value = values_1[_e];
1803
- state = state$a(timer);
1804
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 7];
1805
- return [4 /*yield*/, suspend$1(timer)];
1806
- case 6:
1807
- state = _g.sent();
1808
- _g.label = 7;
1809
- case 7:
1810
- if (state === 2 /* Task.Stop */) {
1811
- return [3 /*break*/, 9];
1812
- }
1813
- data = value.data;
1814
- active = value.metadata.active;
1815
- suspend = value.metadata.suspend;
1816
- privacy = value.metadata.privacy;
1817
- mangle = shouldMangle(value);
1818
- keys = active ? ["tag", "attributes", "value"] : ["tag"];
1819
- for (_f = 0, keys_1 = keys; _f < keys_1.length; _f++) {
1820
- key = keys_1[_f];
1821
- if (data[key]) {
1822
- switch (key) {
1823
- case "tag":
1824
- box = size(value);
1825
- factor = mangle ? -1 : 1;
1826
- tokens.push(value.id * factor);
1827
- if (value.parent && active) {
1828
- tokens.push(value.parent);
1829
- }
1830
- if (value.previous && active) {
1831
- tokens.push(value.previous);
1832
- }
1833
- tokens.push(suspend ? "*M" /* Constant.SuspendMutationTag */ : data[key]);
1834
- if (box && box.length === 2) {
1835
- tokens.push("".concat("#" /* Constant.Hash */).concat(str$1(box[0]), ".").concat(str$1(box[1])));
1836
- }
1837
- break;
1838
- case "attributes":
1839
- for (attr in data[key]) {
1840
- if (data[key][attr] !== undefined) {
1841
- tokens.push(attribute(attr, data[key][attr], privacy));
1842
- }
1843
- }
1844
- break;
1845
- case "value":
1846
- check$4(value.metadata.fraud, value.id, data[key]);
1847
- tokens.push(text$1(data[key], data.tag, privacy, mangle));
1848
- break;
1849
- }
1850
- }
1851
- }
1852
- _g.label = 8;
1853
- case 8:
1854
- _e++;
1855
- return [3 /*break*/, 5];
1856
- case 9:
1857
- if (type === 6 /* Event.Mutation */) {
1858
- activity(eventTime);
1859
- }
1860
- queue(tokenize(tokens), !config$1.lean);
1861
- _g.label = 10;
1862
- case 10: return [3 /*break*/, 11];
1863
- case 11: return [2 /*return*/];
1864
- }
1865
- });
1866
- });
1867
- }
1868
- function shouldMangle(value) {
1869
- var privacy = value.metadata.privacy;
1870
- return value.data.tag === "*T" /* Constant.TextTag */ && !(privacy === 0 /* Privacy.None */ || privacy === 1 /* Privacy.Sensitive */);
1807
+ return box;
1871
1808
  }
1872
- function size(value) {
1873
- if (value.metadata.size !== null && value.metadata.size.length === 0) {
1874
- var img = getNode(value.id);
1875
- if (img) {
1876
- return [Math.floor(img.offsetWidth * 100 /* Setting.BoxPrecision */), Math.floor(img.offsetHeight * 100 /* Setting.BoxPrecision */)];
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 */;
1877
1815
  }
1878
1816
  }
1879
- return value.metadata.size;
1817
+ return 0 /* BrowsingContext.Self */;
1880
1818
  }
1881
- function str$1(input) {
1882
- return input.toString(36);
1819
+ function reset$i() {
1820
+ state$9 = [];
1883
1821
  }
1884
- function attribute(key, value, privacy) {
1885
- return "".concat(key, "=").concat(text$1(value, key.indexOf("data-" /* Constant.DataAttribute */) === 0 ? "data-" /* Constant.DataAttribute */ : key, privacy));
1822
+ function stop$t() {
1823
+ reset$i();
1886
1824
  }
1887
1825
 
1888
1826
  var state$8 = [];
1889
- var regionMap = null; // Maps region nodes => region name
1890
- var regions = {};
1891
- var queue$2 = [];
1892
- var watch = false;
1893
- var observer$1 = null;
1894
1827
  function start$u() {
1895
1828
  reset$h();
1896
- observer$1 = null;
1897
- regionMap = new WeakMap();
1898
- regions = {};
1899
- queue$2 = [];
1900
- watch = window["IntersectionObserver"] ? true : false;
1901
1829
  }
1902
- function observe$c(node, name) {
1903
- if (regionMap.has(node) === false) {
1904
- regionMap.set(node, name);
1905
- observer$1 = observer$1 === null && watch ? new IntersectionObserver(handler$3, {
1906
- // Get notified as intersection continues to change
1907
- // This allows us to process regions that get partially hidden during the lifetime of the page
1908
- // See: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#creating_an_intersection_observer
1909
- // By default, intersection observers only fire an event when even a single pixel is visible and not thereafter.
1910
- threshold: [0, 0.2, 0.4, 0.6, 0.8, 1]
1911
- }) : observer$1;
1912
- if (observer$1 && node && node.nodeType === Node.ELEMENT_NODE) {
1913
- observer$1.observe(node);
1914
- }
1915
- }
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);
1916
1834
  }
1917
- function exists(node) {
1918
- // Check if regionMap is not null before looking up a node
1919
- // Since, dom module stops after region module, it's possible that we may set regionMap to be null
1920
- // and still attempt to call exists on a late coming DOM mutation (or addition), effectively causing a script error
1921
- return regionMap && regionMap.has(node);
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 */));
1922
1838
  }
1923
- function track$4(id, event) {
1924
- var node = getNode(id);
1925
- var data = id in regions ? regions[id] : { id: id, visibility: 0 /* RegionVisibility.Rendered */, interaction: 16 /* InteractionState.None */, name: regionMap.get(node) };
1926
- // Determine the interaction state based on incoming event
1927
- var interaction = 16 /* InteractionState.None */;
1928
- switch (event) {
1929
- case 9 /* Event.Click */:
1930
- interaction = 20 /* InteractionState.Clicked */;
1931
- break;
1932
- case 27 /* Event.Input */:
1933
- interaction = 30 /* InteractionState.Input */;
1934
- break;
1935
- }
1936
- // Process updates to this region, if applicable
1937
- process$6(node, data, interaction, data.visibility);
1839
+ function reset$h() {
1840
+ state$8 = [];
1938
1841
  }
1939
- function compute$6() {
1940
- // Process any regions where we couldn't resolve an "id" for at the time of last intersection observer event
1941
- // This could happen in cases where elements are not yet processed by Clarity's virtual DOM but browser reports a change, regardless.
1942
- // For those cases we add them to the queue and re-process them below
1943
- var q = [];
1944
- for (var _i = 0, queue_1 = queue$2; _i < queue_1.length; _i++) {
1945
- var r = queue_1[_i];
1946
- var id = getId(r.node);
1947
- if (!(id in regions)) {
1948
- if (id) {
1949
- r.data.id = id;
1950
- regions[id] = r.data;
1951
- state$8.push(clone$1(r.data));
1952
- }
1953
- else {
1954
- q.push(r);
1955
- }
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();
1850
+ }
1851
+ function observe$9(root) {
1852
+ bind(root, "input", recompute$6, true);
1853
+ }
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;
1956
1864
  }
1957
- }
1958
- queue$2 = q;
1959
- // Schedule encode only when we have at least one valid data entry
1960
- if (state$8.length > 0) {
1961
- encode$4(7 /* Event.Region */);
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();
1869
+ }
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 */);
1962
1873
  }
1963
1874
  }
1964
- function handler$3(entries) {
1965
- for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
1966
- var entry = entries_1[_i];
1967
- var target = entry.target;
1968
- var rect = entry.boundingClientRect;
1969
- var overlap = entry.intersectionRect;
1970
- var viewport = entry.rootBounds;
1971
- // Only capture regions that have non-zero width or height to avoid tracking and sending regions
1972
- // that cannot ever be seen by the user. In some cases, websites will have a multiple copy of the same region
1973
- // like search box - one for desktop, and another for mobile. In those cases, CSS media queries determine which one should be visible.
1974
- // 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
1975
- if (regionMap.has(target) && rect.width + rect.height > 0 && viewport.width > 0 && viewport.height > 0) {
1976
- var id = target ? getId(target) : null;
1977
- var data = id in regions ? regions[id] : { id: id, name: regionMap.get(target), interaction: 16 /* InteractionState.None */, visibility: 0 /* RegionVisibility.Rendered */ };
1978
- // For regions that have relatively smaller area, we look at intersection ratio and see the overlap relative to element's area
1979
- // However, for larger regions, area of regions could be bigger than viewport and therefore comparison is relative to visible area
1980
- var viewportRatio = overlap ? (overlap.width * overlap.height * 1.0) / (viewport.width * viewport.height) : 0;
1981
- var visible = viewportRatio > 0.05 /* Setting.ViewportIntersectionRatio */ || entry.intersectionRatio > 0.8 /* Setting.IntersectionRatio */;
1982
- // If an element is either visible or was visible and has been scrolled to the end
1983
- // 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.
1984
- // 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
1985
- var scrolledToEnd = (visible || data.visibility == 10 /* RegionVisibility.Visible */) && Math.abs(rect.top) + viewport.height > rect.height;
1986
- // Process updates to this region, if applicable
1987
- process$6(target, data, data.interaction, (scrolledToEnd ?
1988
- 13 /* RegionVisibility.ScrolledToEnd */ :
1989
- (visible ? 10 /* RegionVisibility.Visible */ : 0 /* RegionVisibility.Rendered */)));
1990
- // Stop observing this element now that we have already received scrolled signal
1991
- if (data.visibility >= 13 /* RegionVisibility.ScrolledToEnd */ && observer$1) {
1992
- observer$1.unobserve(target);
1993
- }
1994
- }
1995
- }
1996
- if (state$8.length > 0) {
1997
- encode$4(7 /* Event.Region */);
1998
- }
1999
- }
2000
- function process$6(n, d, s, v) {
2001
- // Check if received a state that supersedes existing state
2002
- var updated = s > d.interaction || v > d.visibility;
2003
- d.interaction = s > d.interaction ? s : d.interaction;
2004
- d.visibility = v > d.visibility ? v : d.visibility;
2005
- // If the corresponding node is already discovered, update the internal state
2006
- // Otherwise, track it in a queue to reprocess later.
2007
- if (d.id) {
2008
- if ((d.id in regions && updated) || !(d.id in regions)) {
2009
- regions[d.id] = d;
2010
- state$8.push(clone$1(d));
2011
- }
2012
- }
2013
- else {
2014
- queue$2.push({ node: n, data: d });
2015
- }
2016
- }
2017
- function clone$1(r) {
2018
- return { time: time(), data: { id: r.id, interaction: r.interaction, visibility: r.visibility, name: r.name } };
2019
- }
2020
- function reset$h() {
2021
- state$8 = [];
2022
- }
2023
- function stop$s() {
2024
- reset$h();
2025
- regionMap = null;
2026
- regions = {};
2027
- queue$2 = [];
2028
- if (observer$1) {
2029
- observer$1.disconnect();
2030
- observer$1 = null;
2031
- }
2032
- watch = false;
2033
- }
2034
-
2035
- var state$7 = [];
2036
- function start$t() {
2037
- reset$g();
2038
- }
2039
- function observe$b(root) {
2040
- bind(root, "change", recompute$8, true);
2041
- }
2042
- function recompute$8(evt) {
2043
- var element = target(evt);
2044
- if (element) {
2045
- var value = element.value;
2046
- 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 */;
2047
- state$7.push({ time: time(evt), event: 42 /* Event.Change */, data: { target: target(evt), type: element.type, value: value, checksum: checksum } });
2048
- schedule$1(encode$3.bind(this, 42 /* Event.Change */));
2049
- }
1875
+ function process$6(event) {
1876
+ schedule$1(encode$3.bind(this, event));
2050
1877
  }
2051
1878
  function reset$g() {
2052
1879
  state$7 = [];
2053
1880
  }
2054
1881
  function stop$r() {
1882
+ clearTimeout(timeout$5);
2055
1883
  reset$g();
2056
1884
  }
2057
1885
 
2058
- function offset(element) {
2059
- var output = { x: 0, y: 0 };
2060
- // Walk up the chain to ensure we compute offset distance correctly
2061
- // In case where we may have nested IFRAMEs, we keep walking up until we get to the top most parent page
2062
- if (element && element.offsetParent) {
2063
- do {
2064
- var parent_1 = element.offsetParent;
2065
- var frame = parent_1 === null ? iframe(element.ownerDocument) : null;
2066
- output.x += element.offsetLeft;
2067
- output.y += element.offsetTop;
2068
- element = frame ? frame : parent_1;
2069
- } while (element);
2070
- }
2071
- return output;
2072
- }
2073
-
2074
- var UserInputTags = ["input", "textarea", "radio", "button", "canvas"];
2075
1886
  var state$6 = [];
1887
+ var timeout$4 = null;
2076
1888
  function start$s() {
2077
1889
  reset$f();
2078
1890
  }
2079
- function observe$a(root) {
2080
- bind(root, "click", handler$2.bind(this, 9 /* Event.Click */, root), true);
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);
2081
1901
  }
2082
- function handler$2(event, root, evt) {
1902
+ function mouse(event, root, evt) {
2083
1903
  var frame = iframe(root);
2084
1904
  var d = frame ? frame.contentDocument.documentElement : document.documentElement;
2085
1905
  var x = "pageX" in evt ? Math.round(evt.pageX) : ("clientX" in evt ? Math.round(evt["clientX"] + d.scrollLeft) : null);
@@ -2090,299 +1910,101 @@ function handler$2(event, root, evt) {
2090
1910
  x = x ? x + Math.round(distance.x) : x;
2091
1911
  y = y ? y + Math.round(distance.y) : y;
2092
1912
  }
2093
- var t = target(evt);
2094
- // Find nearest anchor tag (<a/>) parent if current target node is part of one
2095
- // If present, we use the returned link element to populate text and link properties below
2096
- var a = link(t);
2097
- // Get layout rectangle for the target element
2098
- var l = layout$1(t);
2099
- // Reference: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail
2100
- // This property helps differentiate between a keyboard navigation vs. pointer click
2101
- // In case of a keyboard navigation, we use center of target element as (x,y)
2102
- if (evt.detail === 0 && l) {
2103
- x = Math.round(l.x + (l.w / 2));
2104
- y = Math.round(l.y + (l.h / 2));
2105
- }
2106
- var eX = l ? Math.max(Math.floor(((x - l.x) / l.w) * 32767 /* Setting.ClickPrecision */), 0) : 0;
2107
- var eY = l ? Math.max(Math.floor(((y - l.y) / l.h) * 32767 /* Setting.ClickPrecision */), 0) : 0;
2108
1913
  // Check for null values before processing this event
2109
1914
  if (x !== null && y !== null) {
2110
- state$6.push({
2111
- time: time(evt),
2112
- event: event,
2113
- data: {
2114
- target: t,
2115
- x: x,
2116
- y: y,
2117
- eX: eX,
2118
- eY: eY,
2119
- button: evt.button,
2120
- reaction: reaction(t),
2121
- context: context(a),
2122
- text: text(t),
2123
- link: a ? a.href : null,
2124
- hash: null,
2125
- trust: evt.isTrusted ? 1 /* BooleanFlag.True */ : 0 /* BooleanFlag.False */
2126
- }
2127
- });
2128
- schedule$1(encode$3.bind(this, event));
1915
+ handler$2({ time: time(evt), event: event, data: { target: target(evt), x: x, y: y } });
2129
1916
  }
2130
1917
  }
2131
- function link(node) {
2132
- while (node && node !== document) {
2133
- if (node.nodeType === Node.ELEMENT_NODE) {
2134
- var element = node;
2135
- if (element.tagName === "A") {
2136
- return element;
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 } });
2137
1933
  }
2138
1934
  }
2139
- node = node.parentNode;
2140
- }
2141
- return null;
2142
- }
2143
- function text(element) {
2144
- var output = null;
2145
- if (element) {
2146
- // Grab text using "textContent" for most HTMLElements, however, use "value" for HTMLInputElements and "alt" for HTMLImageElement.
2147
- var t = element.textContent || element.value || element.alt;
2148
- if (t) {
2149
- // Replace multiple occurrence of space characters with a single white space
2150
- // Also, trim any spaces at the beginning or at the end of string
2151
- // Finally, send only first few characters as specified by the Setting
2152
- output = t.replace(/\s+/g, " " /* Constant.Space */).trim().substr(0, 25 /* Setting.ClickText */);
2153
- }
2154
- }
2155
- return output;
2156
- }
2157
- function reaction(element) {
2158
- if (element.nodeType === Node.ELEMENT_NODE) {
2159
- var tag = element.tagName.toLowerCase();
2160
- if (UserInputTags.indexOf(tag) >= 0) {
2161
- return 0 /* BooleanFlag.False */;
2162
- }
2163
1935
  }
2164
- return 1 /* BooleanFlag.True */;
2165
1936
  }
2166
- function layout$1(element) {
2167
- var box = null;
2168
- var de = document.documentElement;
2169
- if (typeof element.getBoundingClientRect === "function") {
2170
- // getBoundingClientRect returns rectangle relative positioning to viewport
2171
- var rect = element.getBoundingClientRect();
2172
- if (rect && rect.width > 0 && rect.height > 0) {
2173
- // Add viewport's scroll position to rectangle to get position relative to document origin
2174
- // Also: using Math.floor() instead of Math.round() because in Edge,
2175
- // getBoundingClientRect returns partial pixel values (e.g. 162.5px) and Chrome already
2176
- // floors the value (e.g. 162px). This keeps consistent behavior across browsers.
2177
- box = {
2178
- x: Math.floor(rect.left + ("pageXOffset" in window ? window.pageXOffset : de.scrollLeft)),
2179
- y: Math.floor(rect.top + ("pageYOffset" in window ? window.pageYOffset : de.scrollTop)),
2180
- w: Math.floor(rect.width),
2181
- h: Math.floor(rect.height)
2182
- };
2183
- }
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;
2184
1955
  }
2185
- return box;
2186
1956
  }
2187
- function context(a) {
2188
- if (a && a.hasAttribute("target" /* Constant.Target */)) {
2189
- switch (a.getAttribute("target" /* Constant.Target */)) {
2190
- case "_blank" /* Constant.Blank */: return 1 /* BrowsingContext.Blank */;
2191
- case "_parent" /* Constant.Parent */: return 2 /* BrowsingContext.Parent */;
2192
- case "_top" /* Constant.Top */: return 3 /* BrowsingContext.Top */;
2193
- }
2194
- }
2195
- return 0 /* BrowsingContext.Self */;
1957
+ function process$5(event) {
1958
+ schedule$1(encode$3.bind(this, event));
2196
1959
  }
2197
1960
  function reset$f() {
2198
1961
  state$6 = [];
2199
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
+ }
2200
1971
  function stop$q() {
2201
- reset$f();
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);
1976
+ }
2202
1977
  }
2203
1978
 
2204
- var state$5 = [];
1979
+ var data$b;
2205
1980
  function start$r() {
2206
- reset$e();
1981
+ bind(window, "resize", recompute$5);
1982
+ recompute$5();
2207
1983
  }
2208
- function observe$9(root) {
2209
- bind(root, "cut", recompute$7.bind(this, 0 /* Clipboard.Cut */), true);
2210
- bind(root, "copy", recompute$7.bind(this, 1 /* Clipboard.Copy */), true);
2211
- bind(root, "paste", recompute$7.bind(this, 2 /* Clipboard.Paste */), true);
2212
- }
2213
- function recompute$7(action, evt) {
2214
- state$5.push({ time: time(evt), event: 38 /* Event.Clipboard */, data: { target: target(evt), action: action } });
2215
- schedule$1(encode$3.bind(this, 38 /* Event.Clipboard */));
1984
+ function recompute$5() {
1985
+ var de = document.documentElement;
1986
+ // window.innerWidth includes width of the scrollbar and is not a true representation of the viewport width.
1987
+ // Therefore, when possible, use documentElement's clientWidth property.
1988
+ data$b = {
1989
+ width: de && "clientWidth" in de ? Math.min(de.clientWidth, window.innerWidth) : window.innerWidth,
1990
+ height: de && "clientHeight" in de ? Math.min(de.clientHeight, window.innerHeight) : window.innerHeight,
1991
+ };
1992
+ encode$3(11 /* Event.Resize */);
2216
1993
  }
2217
1994
  function reset$e() {
2218
- state$5 = [];
1995
+ data$b = null;
2219
1996
  }
2220
1997
  function stop$p() {
2221
1998
  reset$e();
2222
1999
  }
2223
2000
 
2224
- var timeout$5 = null;
2225
- var state$4 = [];
2226
- function start$q() {
2227
- reset$d();
2228
- }
2229
- function observe$8(root) {
2230
- bind(root, "input", recompute$6, true);
2231
- }
2232
- function recompute$6(evt) {
2233
- var input = target(evt);
2234
- var value = get(input);
2235
- if (input && input.type && value) {
2236
- var v = input.value;
2237
- switch (input.type) {
2238
- case "radio":
2239
- case "checkbox":
2240
- v = input.checked ? "true" : "false";
2241
- break;
2242
- }
2243
- var data = { target: input, value: v };
2244
- // 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.
2245
- if (state$4.length > 0 && (state$4[state$4.length - 1].data.target === data.target)) {
2246
- state$4.pop();
2247
- }
2248
- state$4.push({ time: time(evt), event: 27 /* Event.Input */, data: data });
2249
- clearTimeout(timeout$5);
2250
- timeout$5 = setTimeout(process$5, 1000 /* Setting.InputLookAhead */, 27 /* Event.Input */);
2251
- }
2252
- }
2253
- function process$5(event) {
2254
- schedule$1(encode$3.bind(this, event));
2255
- }
2256
- function reset$d() {
2257
- state$4 = [];
2258
- }
2259
- function stop$o() {
2260
- clearTimeout(timeout$5);
2261
- reset$d();
2262
- }
2263
-
2264
- var state$3 = [];
2265
- var timeout$4 = null;
2266
- function start$p() {
2267
- reset$c();
2268
- }
2269
- function observe$7(root) {
2270
- bind(root, "mousedown", mouse.bind(this, 13 /* Event.MouseDown */, root), true);
2271
- bind(root, "mouseup", mouse.bind(this, 14 /* Event.MouseUp */, root), true);
2272
- bind(root, "mousemove", mouse.bind(this, 12 /* Event.MouseMove */, root), true);
2273
- bind(root, "wheel", mouse.bind(this, 15 /* Event.MouseWheel */, root), true);
2274
- bind(root, "dblclick", mouse.bind(this, 16 /* Event.DoubleClick */, root), true);
2275
- bind(root, "touchstart", touch.bind(this, 17 /* Event.TouchStart */, root), true);
2276
- bind(root, "touchend", touch.bind(this, 18 /* Event.TouchEnd */, root), true);
2277
- bind(root, "touchmove", touch.bind(this, 19 /* Event.TouchMove */, root), true);
2278
- bind(root, "touchcancel", touch.bind(this, 20 /* Event.TouchCancel */, root), true);
2279
- }
2280
- function mouse(event, root, evt) {
2281
- var frame = iframe(root);
2282
- var d = frame ? frame.contentDocument.documentElement : document.documentElement;
2283
- var x = "pageX" in evt ? Math.round(evt.pageX) : ("clientX" in evt ? Math.round(evt["clientX"] + d.scrollLeft) : null);
2284
- var y = "pageY" in evt ? Math.round(evt.pageY) : ("clientY" in evt ? Math.round(evt["clientY"] + d.scrollTop) : null);
2285
- // In case of iframe, we adjust (x,y) to be relative to top parent's origin
2286
- if (frame) {
2287
- var distance = offset(frame);
2288
- x = x ? x + Math.round(distance.x) : x;
2289
- y = y ? y + Math.round(distance.y) : y;
2290
- }
2291
- // Check for null values before processing this event
2292
- if (x !== null && y !== null) {
2293
- handler$1({ time: time(evt), event: event, data: { target: target(evt), x: x, y: y } });
2294
- }
2295
- }
2296
- function touch(event, root, evt) {
2297
- var frame = iframe(root);
2298
- var d = frame ? frame.contentDocument.documentElement : document.documentElement;
2299
- var touches = evt.changedTouches;
2300
- var t = time(evt);
2301
- if (touches) {
2302
- for (var i = 0; i < touches.length; i++) {
2303
- var entry = touches[i];
2304
- var x = "clientX" in entry ? Math.round(entry["clientX"] + d.scrollLeft) : null;
2305
- var y = "clientY" in entry ? Math.round(entry["clientY"] + d.scrollTop) : null;
2306
- x = x && frame ? x + Math.round(frame.offsetLeft) : x;
2307
- y = y && frame ? y + Math.round(frame.offsetTop) : y;
2308
- // Check for null values before processing this event
2309
- if (x !== null && y !== null) {
2310
- handler$1({ time: t, event: event, data: { target: target(evt), x: x, y: y } });
2311
- }
2312
- }
2313
- }
2314
- }
2315
- function handler$1(current) {
2316
- switch (current.event) {
2317
- case 12 /* Event.MouseMove */:
2318
- case 15 /* Event.MouseWheel */:
2319
- case 19 /* Event.TouchMove */:
2320
- var length_1 = state$3.length;
2321
- var last = length_1 > 1 ? state$3[length_1 - 2] : null;
2322
- if (last && similar$1(last, current)) {
2323
- state$3.pop();
2324
- }
2325
- state$3.push(current);
2326
- clearTimeout(timeout$4);
2327
- timeout$4 = setTimeout(process$4, 500 /* Setting.LookAhead */, current.event);
2328
- break;
2329
- default:
2330
- state$3.push(current);
2331
- process$4(current.event);
2332
- break;
2333
- }
2334
- }
2335
- function process$4(event) {
2336
- schedule$1(encode$3.bind(this, event));
2337
- }
2338
- function reset$c() {
2339
- state$3 = [];
2340
- }
2341
- function similar$1(last, current) {
2342
- var dx = last.data.x - current.data.x;
2343
- var dy = last.data.y - current.data.y;
2344
- var distance = Math.sqrt(dx * dx + dy * dy);
2345
- var gap = current.time - last.time;
2346
- var match = current.data.target === last.data.target;
2347
- return current.event === last.event && match && distance < 20 /* Setting.Distance */ && gap < 25 /* Setting.Interval */;
2348
- }
2349
- function stop$n() {
2350
- clearTimeout(timeout$4);
2351
- // Send out any pending pointer events in the pipeline
2352
- if (state$3.length > 0) {
2353
- process$4(state$3[state$3.length - 1].event);
2354
- }
2355
- }
2356
-
2357
- var data$b;
2358
- function start$o() {
2359
- bind(window, "resize", recompute$5);
2360
- recompute$5();
2361
- }
2362
- function recompute$5() {
2363
- var de = document.documentElement;
2364
- // window.innerWidth includes width of the scrollbar and is not a true representation of the viewport width.
2365
- // Therefore, when possible, use documentElement's clientWidth property.
2366
- data$b = {
2367
- width: de && "clientWidth" in de ? Math.min(de.clientWidth, window.innerWidth) : window.innerWidth,
2368
- height: de && "clientHeight" in de ? Math.min(de.clientHeight, window.innerHeight) : window.innerHeight,
2369
- };
2370
- encode$3(11 /* Event.Resize */);
2371
- }
2372
- function reset$b() {
2373
- data$b = null;
2374
- }
2375
- function stop$m() {
2376
- reset$b();
2377
- }
2378
-
2379
- var state$2 = [];
2001
+ var state$5 = [];
2380
2002
  var timeout$3 = null;
2381
- function start$n() {
2382
- state$2 = [];
2003
+ function start$q() {
2004
+ state$5 = [];
2383
2005
  recompute$4();
2384
2006
  }
2385
- function observe$6(root) {
2007
+ function observe$7(root) {
2386
2008
  var frame = iframe(root);
2387
2009
  var node = frame ? frame.contentWindow : (root === document ? window : root);
2388
2010
  bind(node, "scroll", recompute$4, true);
@@ -2408,19 +2030,19 @@ function recompute$4(event) {
2408
2030
  if ((event === null && x === 0 && y === 0) || (x === null || y === null)) {
2409
2031
  return;
2410
2032
  }
2411
- var length = state$2.length;
2412
- var last = length > 1 ? state$2[length - 2] : null;
2033
+ var length = state$5.length;
2034
+ var last = length > 1 ? state$5[length - 2] : null;
2413
2035
  if (last && similar(last, current)) {
2414
- state$2.pop();
2036
+ state$5.pop();
2415
2037
  }
2416
- state$2.push(current);
2038
+ state$5.push(current);
2417
2039
  clearTimeout(timeout$3);
2418
- timeout$3 = setTimeout(process$3, 500 /* Setting.LookAhead */, 10 /* Event.Scroll */);
2040
+ timeout$3 = setTimeout(process$4, 500 /* Setting.LookAhead */, 10 /* Event.Scroll */);
2419
2041
  }
2420
- function reset$a() {
2421
- state$2 = [];
2042
+ function reset$d() {
2043
+ state$5 = [];
2422
2044
  }
2423
- function process$3(event) {
2045
+ function process$4(event) {
2424
2046
  schedule$1(encode$3.bind(this, event));
2425
2047
  }
2426
2048
  function similar(last, current) {
@@ -2428,18 +2050,18 @@ function similar(last, current) {
2428
2050
  var dy = last.data.y - current.data.y;
2429
2051
  return (dx * dx + dy * dy < 20 /* Setting.Distance */ * 20 /* Setting.Distance */) && (current.time - last.time < 25 /* Setting.Interval */);
2430
2052
  }
2431
- function stop$l() {
2053
+ function stop$o() {
2432
2054
  clearTimeout(timeout$3);
2433
- state$2 = [];
2055
+ state$5 = [];
2434
2056
  }
2435
2057
 
2436
2058
  var data$a = null;
2437
2059
  var previous = null;
2438
2060
  var timeout$2 = null;
2439
- function start$m() {
2440
- reset$9();
2061
+ function start$p() {
2062
+ reset$c();
2441
2063
  }
2442
- function observe$5(root) {
2064
+ function observe$6(root) {
2443
2065
  bind(root, "selectstart", recompute$3.bind(this, root), true);
2444
2066
  bind(root, "selectionchange", recompute$3.bind(this, root), true);
2445
2067
  }
@@ -2461,7 +2083,7 @@ function recompute$3(root) {
2461
2083
  var startNode = data$a.start ? data$a.start : null;
2462
2084
  if (previous !== null && data$a.start !== null && startNode !== current.anchorNode) {
2463
2085
  clearTimeout(timeout$2);
2464
- process$2(21 /* Event.Selection */);
2086
+ process$3(21 /* Event.Selection */);
2465
2087
  }
2466
2088
  data$a = {
2467
2089
  start: current.anchorNode,
@@ -2471,40 +2093,40 @@ function recompute$3(root) {
2471
2093
  };
2472
2094
  previous = current;
2473
2095
  clearTimeout(timeout$2);
2474
- timeout$2 = setTimeout(process$2, 500 /* Setting.LookAhead */, 21 /* Event.Selection */);
2096
+ timeout$2 = setTimeout(process$3, 500 /* Setting.LookAhead */, 21 /* Event.Selection */);
2475
2097
  }
2476
- function process$2(event) {
2098
+ function process$3(event) {
2477
2099
  schedule$1(encode$3.bind(this, event));
2478
2100
  }
2479
- function reset$9() {
2101
+ function reset$c() {
2480
2102
  previous = null;
2481
2103
  data$a = { start: 0, startOffset: 0, end: 0, endOffset: 0 };
2482
2104
  }
2483
- function stop$k() {
2484
- reset$9();
2105
+ function stop$n() {
2106
+ reset$c();
2485
2107
  clearTimeout(timeout$2);
2486
2108
  }
2487
2109
 
2488
- var state$1 = [];
2489
- function start$l() {
2490
- reset$8();
2110
+ var state$4 = [];
2111
+ function start$o() {
2112
+ reset$b();
2491
2113
  }
2492
- function observe$4(root) {
2114
+ function observe$5(root) {
2493
2115
  bind(root, "submit", recompute$2, true);
2494
2116
  }
2495
2117
  function recompute$2(evt) {
2496
- state$1.push({ time: time(evt), event: 39 /* Event.Submit */, data: { target: target(evt) } });
2118
+ state$4.push({ time: time(evt), event: 39 /* Event.Submit */, data: { target: target(evt) } });
2497
2119
  schedule$1(encode$3.bind(this, 39 /* Event.Submit */));
2498
2120
  }
2499
- function reset$8() {
2500
- state$1 = [];
2121
+ function reset$b() {
2122
+ state$4 = [];
2501
2123
  }
2502
- function stop$j() {
2503
- reset$8();
2124
+ function stop$m() {
2125
+ reset$b();
2504
2126
  }
2505
2127
 
2506
2128
  var data$9;
2507
- function start$k() {
2129
+ function start$n() {
2508
2130
  bind(window, "pagehide", recompute$1);
2509
2131
  }
2510
2132
  function recompute$1(evt) {
@@ -2512,15 +2134,15 @@ function recompute$1(evt) {
2512
2134
  encode$3(26 /* Event.Unload */, time(evt));
2513
2135
  stop();
2514
2136
  }
2515
- function reset$7() {
2137
+ function reset$a() {
2516
2138
  data$9 = null;
2517
2139
  }
2518
- function stop$i() {
2519
- reset$7();
2140
+ function stop$l() {
2141
+ reset$a();
2520
2142
  }
2521
2143
 
2522
2144
  var data$8;
2523
- function start$j() {
2145
+ function start$m() {
2524
2146
  bind(document, "visibilitychange", recompute);
2525
2147
  recompute();
2526
2148
  }
@@ -2529,63 +2151,398 @@ function recompute(evt) {
2529
2151
  data$8 = { visible: "visibilityState" in document ? document.visibilityState : "default" };
2530
2152
  encode$3(28 /* Event.Visibility */, time(evt));
2531
2153
  }
2532
- function reset$6() {
2154
+ function reset$9() {
2533
2155
  data$8 = null;
2534
2156
  }
2535
- function stop$h() {
2536
- reset$6();
2537
- }
2538
-
2539
- function start$i() {
2540
- start$g();
2541
- start$s();
2542
- start$r();
2543
- start$p();
2544
- start$q();
2545
- start$o();
2546
- start$j();
2547
- start$n();
2548
- start$m();
2549
- start$t();
2550
- start$l();
2551
- start$k();
2157
+ function stop$k() {
2158
+ reset$9();
2159
+ }
2160
+
2161
+ function start$l() {
2162
+ start$g();
2163
+ start$v();
2164
+ start$u();
2165
+ start$s();
2166
+ start$t();
2167
+ start$r();
2168
+ start$m();
2169
+ start$q();
2170
+ start$p();
2171
+ start$w();
2172
+ start$o();
2173
+ start$n();
2174
+ }
2175
+ function stop$j() {
2176
+ stop$e();
2177
+ stop$t();
2178
+ stop$s();
2179
+ stop$q();
2180
+ stop$r();
2181
+ stop$p();
2182
+ stop$k();
2183
+ stop$o();
2184
+ stop$n();
2185
+ stop$u();
2186
+ 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
+ });
2552
2502
  }
2553
- function stop$g() {
2554
- stop$e();
2555
- stop$q();
2556
- stop$p();
2557
- stop$n();
2558
- stop$o();
2559
- stop$m();
2560
- stop$h();
2561
- stop$l();
2562
- stop$k();
2563
- stop$r();
2564
- stop$j();
2565
- stop$i();
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;
2566
2516
  }
2567
- function observe$3(root) {
2568
- observe$6(root);
2569
- // Only monitor following interactions if the root node is a document
2570
- // In case of shadow DOM, following events automatically bubble up to the parent document.
2571
- if (root.nodeType === Node.DOCUMENT_NODE) {
2572
- observe$a(root);
2573
- observe$9(root);
2574
- observe$7(root);
2575
- observe$8(root);
2576
- observe$5(root);
2577
- observe$b(root);
2578
- observe$4(root);
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
+ }
2579
2529
  }
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
+ }]);
2580
2544
  }
2581
2545
 
2582
- var interaction = /*#__PURE__*/Object.freeze({
2583
- __proto__: null,
2584
- observe: observe$3,
2585
- start: start$i,
2586
- stop: stop$g
2587
- });
2588
-
2589
2546
  var digitsRegex = /[^0-9\.]/g;
2590
2547
  /* JSON+LD (Linked Data) Recursive Parser */
2591
2548
  function ld(json) {
@@ -2686,6 +2643,7 @@ function processNode (node, source) {
2686
2643
  // later whenever there are new additions or modifications to DOM (mutations)
2687
2644
  if (node === document)
2688
2645
  parse$1(document);
2646
+ checkDocumentStyles(node);
2689
2647
  observe$2(node);
2690
2648
  break;
2691
2649
  case Node.DOCUMENT_FRAGMENT_NODE:
@@ -2700,11 +2658,6 @@ function processNode (node, source) {
2700
2658
  // In future we may decide to proxy "attachShadow" call to gain access, but at the moment, we don't want to
2701
2659
  // cause any unintended side effect to the page. We will re-evaluate after we gather more real world data on this.
2702
2660
  var style = "" /* Constant.Empty */;
2703
- var adoptedStyleSheets = "adoptedStyleSheets" in shadowRoot ? shadowRoot["adoptedStyleSheets"] : [];
2704
- for (var _i = 0, adoptedStyleSheets_1 = adoptedStyleSheets; _i < adoptedStyleSheets_1.length; _i++) {
2705
- var styleSheet = adoptedStyleSheets_1[_i];
2706
- style += getCssRules(styleSheet);
2707
- }
2708
2661
  var fragmentData = { tag: "*S" /* Constant.ShadowDomTag */, attributes: { style: style } };
2709
2662
  dom[call](node, shadowRoot.host, fragmentData, source);
2710
2663
  }
@@ -2714,6 +2667,7 @@ function processNode (node, source) {
2714
2667
  // the same way we observe real shadow DOM nodes (encapsulation provided by the browser).
2715
2668
  dom[call](node, shadowRoot.host, { tag: "*P" /* Constant.PolyfillShadowDomTag */, attributes: {} }, source);
2716
2669
  }
2670
+ checkDocumentStyles(node);
2717
2671
  }
2718
2672
  break;
2719
2673
  case Node.TEXT_NODE:
@@ -2842,8 +2796,8 @@ function observe$2(root) {
2842
2796
  if (has(root)) {
2843
2797
  return;
2844
2798
  }
2845
- observe$1(root); // Observe mutations for this root node
2846
- observe$3(root); // Observe interactions for this root node
2799
+ observe$3(root); // Observe mutations for this root node
2800
+ observe$4(root); // Observe interactions for this root node
2847
2801
  }
2848
2802
  function getStyleValue(style) {
2849
2803
  // Call trim on the text content to ensure we do not process white spaces ( , \n, \r\n, \t, etc.)
@@ -2893,339 +2847,511 @@ function getAttributes(element) {
2893
2847
  return output;
2894
2848
  }
2895
2849
 
2896
- function traverse (root, timer, source) {
2897
- return __awaiter(this, void 0, void 0, function () {
2898
- var queue, entry, next, state, subnode;
2899
- return __generator(this, function (_a) {
2900
- switch (_a.label) {
2901
- case 0:
2902
- queue = [root];
2903
- _a.label = 1;
2904
- case 1:
2905
- if (!(queue.length > 0)) return [3 /*break*/, 4];
2906
- entry = queue.shift();
2907
- next = entry.firstChild;
2908
- while (next) {
2909
- queue.push(next);
2910
- next = next.nextSibling;
2911
- }
2912
- state = state$a(timer);
2913
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 3];
2914
- return [4 /*yield*/, suspend$1(timer)];
2915
- case 2:
2916
- state = _a.sent();
2917
- _a.label = 3;
2918
- case 3:
2919
- if (state === 2 /* Task.Stop */) {
2920
- return [3 /*break*/, 4];
2921
- }
2922
- subnode = processNode(entry, source);
2923
- if (subnode) {
2924
- queue.push(subnode);
2925
- }
2926
- return [3 /*break*/, 1];
2927
- case 4: return [2 /*return*/];
2928
- }
2929
- });
2930
- });
2931
- }
2932
-
2933
- var observers = [];
2934
- var mutations = [];
2935
- var insertRule = null;
2936
- var deleteRule = null;
2937
- var attachShadow = null;
2938
- var queue$1 = [];
2939
- var timeout$1 = null;
2940
- var activePeriod = null;
2941
- var history$4 = {};
2942
- function start$h() {
2943
- observers = [];
2944
- queue$1 = [];
2945
- timeout$1 = null;
2946
- activePeriod = 0;
2947
- history$4 = {};
2948
- // Some popular open source libraries, like styled-components, optimize performance
2949
- // by injecting CSS using insertRule API vs. appending text node. A side effect of
2950
- // using javascript API is that it doesn't trigger DOM mutation and therefore we
2951
- // need to override the insertRule API and listen for changes manually.
2952
- if (insertRule === null) {
2953
- insertRule = CSSStyleSheet.prototype.insertRule;
2954
- CSSStyleSheet.prototype.insertRule = function () {
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 () {
2955
2860
  if (active()) {
2956
- schedule(this.ownerNode);
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]);
2957
2867
  }
2958
- return insertRule.apply(this, arguments);
2868
+ return replace.apply(this, arguments);
2959
2869
  };
2960
2870
  }
2961
- if (deleteRule === null) {
2962
- deleteRule = CSSStyleSheet.prototype.deleteRule;
2963
- CSSStyleSheet.prototype.deleteRule = function () {
2871
+ if (replaceSync === null) {
2872
+ replaceSync = CSSStyleSheet.prototype.replaceSync;
2873
+ CSSStyleSheet.prototype.replaceSync = function () {
2964
2874
  if (active()) {
2965
- schedule(this.ownerNode);
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]);
2966
2881
  }
2967
- return deleteRule.apply(this, arguments);
2882
+ return replaceSync.apply(this, arguments);
2968
2883
  };
2969
2884
  }
2970
- // Add a hook to attachShadow API calls
2971
- // In case we are unable to add a hook and browser throws an exception,
2972
- // reset attachShadow variable and resume processing like before
2973
- if (attachShadow === null) {
2974
- attachShadow = Element.prototype.attachShadow;
2975
- try {
2976
- Element.prototype.attachShadow = function () {
2977
- if (active()) {
2978
- return schedule(attachShadow.apply(this, arguments));
2979
- }
2980
- else {
2981
- return attachShadow.apply(this, arguments);
2982
- }
2983
- };
2984
- }
2985
- catch (_a) {
2986
- attachShadow = null;
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));
2987
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;
2988
2910
  }
2989
2911
  }
2990
- function observe$1(node) {
2991
- // Create a new observer for every time a new DOM tree (e.g. root document or shadowdom root) is discovered on the page
2992
- // In the case of shadow dom, any mutations that happen within the shadow dom are not bubbled up to the host document
2993
- // For this reason, we need to wire up mutations every time we see a new shadow dom.
2994
- // Also, wrap it inside a try / catch. In certain browsers (e.g. legacy Edge), observer on shadow dom can throw errors
2995
- try {
2996
- var m = api("MutationObserver" /* Constant.MutationObserver */);
2997
- var observer = m in window ? new window[m](measure(handle$1)) : null;
2998
- if (observer) {
2999
- observer.observe(node, { attributes: true, childList: true, characterData: true, subtree: true });
3000
- observers.push(observer);
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
3001
2943
  }
2944
+ });
2945
+ encode$4(45 /* Event.StyleSheetAdoption */);
2946
+ }
2947
+ function arraysEqual(a, b) {
2948
+ if (a.length !== b.length) {
2949
+ return false;
3002
2950
  }
3003
- catch (e) {
3004
- log$1(2 /* Code.MutationObserver */, 0 /* Severity.Info */, e ? e.name : null);
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");
3005
2972
  }
3006
2973
  }
3007
- function monitor(frame) {
3008
- // Bind to iframe's onload event so we get notified anytime there's an update to iframe content.
3009
- // This includes cases where iframe location is updated without explicitly updating src attribute
3010
- // E.g. iframe.contentWindow.location.href = "new-location";
3011
- if (has(frame) === false) {
3012
- bind(frame, "load" /* Constant.LoadEvent */, generate.bind(this, frame, "childList" /* Constant.ChildList */), true);
3013
- }
2974
+ function reset$7() {
2975
+ state$2 = [];
3014
2976
  }
3015
- function stop$f() {
3016
- for (var _i = 0, observers_1 = observers; _i < observers_1.length; _i++) {
3017
- var observer = observers_1[_i];
3018
- if (observer) {
3019
- observer.disconnect();
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
3020
2988
  }
3021
- }
3022
- observers = [];
3023
- history$4 = {};
3024
- mutations = [];
3025
- queue$1 = [];
3026
- activePeriod = 0;
3027
- timeout$1 = null;
3028
- }
3029
- function active$2() {
3030
- activePeriod = time() + 3000 /* Setting.MutationActivePeriod */;
3031
- }
3032
- function handle$1(m) {
3033
- // Queue up mutation records for asynchronous processing
3034
- var now = time();
3035
- track$7(6 /* Event.Mutation */, now);
3036
- mutations.push({ time: now, mutations: m });
3037
- schedule$1(process$1, 1 /* Priority.High */).then(function () {
3038
- setTimeout(compute$7);
3039
- measure(compute$6)();
3040
2989
  });
2990
+ encode$4(44 /* Event.Animation */);
2991
+ }
2992
+ function stop$g() {
2993
+ reset$7();
3041
2994
  }
3042
- function process$1() {
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; }
3043
3040
  return __awaiter(this, void 0, void 0, function () {
3044
- var timer, record, instance, _i, _a, mutation, state, target, type, value;
3045
- return __generator(this, function (_b) {
3046
- switch (_b.label) {
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) {
3047
3044
  case 0:
3048
- timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
3049
- start$x(timer);
3050
- _b.label = 1;
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];
3051
3058
  case 1:
3052
- if (!(mutations.length > 0)) return [3 /*break*/, 8];
3053
- record = mutations.shift();
3054
- instance = time();
3055
- _i = 0, _a = record.mutations;
3056
- _b.label = 2;
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];
3057
3065
  case 2:
3058
- if (!(_i < _a.length)) return [3 /*break*/, 6];
3059
- mutation = _a[_i];
3060
- state = state$a(timer);
3061
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 4];
3062
- return [4 /*yield*/, suspend$1(timer)];
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];
3063
3077
  case 3:
3064
- state = _b.sent();
3065
- _b.label = 4;
3066
- case 4:
3067
- if (state === 2 /* Task.Stop */) {
3068
- return [3 /*break*/, 6];
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);
3069
3085
  }
3070
- target = mutation.target;
3071
- type = track$3(mutation, timer, instance);
3072
- if (type && target && target.ownerDocument) {
3073
- parse$1(target.ownerDocument);
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);
3074
3096
  }
3075
- if (type && target && target.nodeType == Node.DOCUMENT_FRAGMENT_NODE && target.host) {
3076
- parse$1(target);
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);
3077
3110
  }
3078
- switch (type) {
3079
- case "attributes" /* Constant.Attributes */:
3080
- processNode(target, 3 /* Source.Attributes */);
3081
- break;
3082
- case "characterData" /* Constant.CharacterData */:
3083
- processNode(target, 4 /* Source.CharacterData */);
3084
- break;
3085
- case "childList" /* Constant.ChildList */:
3086
- processNodeList(mutation.addedNodes, 1 /* Source.ChildListAdd */, timer);
3087
- processNodeList(mutation.removedNodes, 2 /* Source.ChildListRemove */, timer);
3088
- break;
3089
- case "suspend" /* Constant.Suspend */:
3090
- value = get(target);
3091
- if (value) {
3092
- value.metadata.suspend = true;
3093
- }
3094
- break;
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];
3095
3117
  }
3096
- _b.label = 5;
3097
- case 5:
3098
- _i++;
3099
- return [3 /*break*/, 2];
3100
- case 6: return [4 /*yield*/, encode$4(6 /* Event.Mutation */, timer, record.time)];
3118
+ values = updates$2();
3119
+ if (!(values.length > 0)) return [3 /*break*/, 12];
3120
+ _j = 0, values_1 = values;
3121
+ _l.label = 7;
3101
3122
  case 7:
3102
- _b.sent();
3103
- return [3 /*break*/, 1];
3123
+ if (!(_j < values_1.length)) return [3 /*break*/, 11];
3124
+ value = values_1[_j];
3125
+ state = state$b(timer);
3126
+ if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 9];
3127
+ return [4 /*yield*/, suspend$1(timer)];
3104
3128
  case 8:
3105
- stop$v(timer);
3106
- return [2 /*return*/];
3129
+ state = _l.sent();
3130
+ _l.label = 9;
3131
+ case 9:
3132
+ 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
+ }
3173
+ }
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);
3181
+ }
3182
+ queue(tokenize(tokens), !config$1.lean);
3183
+ _l.label = 12;
3184
+ case 12: return [3 /*break*/, 13];
3185
+ case 13: return [2 /*return*/];
3107
3186
  }
3108
3187
  });
3109
3188
  });
3110
3189
  }
3111
- function track$3(m, timer, instance) {
3112
- var value = m.target ? get(m.target.parentNode) : null;
3113
- // Check if the parent is already discovered and that the parent is not the document root
3114
- if (value && value.data.tag !== "HTML" /* Constant.HTML */) {
3115
- var inactive = time() > activePeriod;
3116
- var target = get(m.target);
3117
- var element = target && target.selector ? target.selector.join() : m.target.nodeName;
3118
- var parent_1 = value.selector ? value.selector.join() : "" /* Constant.Empty */;
3119
- // We use selector, instead of id, to determine the key (signature for the mutation) because in some cases
3120
- // repeated mutations can cause elements to be destroyed and then recreated as new DOM nodes
3121
- // In those cases, IDs will change however the selector (which is relative to DOM xPath) remains the same
3122
- var key = [parent_1, element, m.attributeName, names(m.addedNodes), names(m.removedNodes)].join();
3123
- // Initialize an entry if it doesn't already exist
3124
- history$4[key] = key in history$4 ? history$4[key] : [0, instance];
3125
- var h = history$4[key];
3126
- // Lookup any pending nodes queued up for removal, and process them now if we suspended a mutation before
3127
- if (inactive === false && h[0] >= 10 /* Setting.MutationSuspendThreshold */) {
3128
- processNodeList(h[2], 2 /* Source.ChildListRemove */, timer);
3129
- }
3130
- // Update the counter
3131
- h[0] = inactive ? (h[1] === instance ? h[0] : h[0] + 1) : 1;
3132
- h[1] = instance;
3133
- // Return updated mutation type based on if we have already hit the threshold or not
3134
- if (h[0] === 10 /* Setting.MutationSuspendThreshold */) {
3135
- // Store a reference to removedNodes so we can process them later
3136
- // when we resume mutations again on user interactions
3137
- h[2] = m.removedNodes;
3138
- return "suspend" /* Constant.Suspend */;
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 */)];
3139
3199
  }
3140
- else if (h[0] > 10 /* Setting.MutationSuspendThreshold */) {
3141
- return "" /* Constant.Empty */;
3200
+ }
3201
+ return value.metadata.size;
3202
+ }
3203
+ function str$1(input) {
3204
+ return input.toString(36);
3205
+ }
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 = {};
3221
+ queue$1 = [];
3222
+ watch = window["IntersectionObserver"] ? true : false;
3223
+ }
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);
3142
3236
  }
3143
3237
  }
3144
- return m.type;
3145
3238
  }
3146
- function names(nodes) {
3147
- var output = [];
3148
- for (var i = 0; nodes && i < nodes.length; i++) {
3149
- output.push(nodes[i].nodeName);
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;
3150
3257
  }
3151
- return output.join();
3258
+ // Process updates to this region, if applicable
3259
+ process$1(node, data, interaction, data.visibility);
3152
3260
  }
3153
- function processNodeList(list, source, timer) {
3154
- return __awaiter(this, void 0, void 0, function () {
3155
- var length, i, state;
3156
- return __generator(this, function (_a) {
3157
- switch (_a.label) {
3158
- case 0:
3159
- length = list ? list.length : 0;
3160
- i = 0;
3161
- _a.label = 1;
3162
- case 1:
3163
- if (!(i < length)) return [3 /*break*/, 6];
3164
- if (!(source === 1 /* Source.ChildListAdd */)) return [3 /*break*/, 2];
3165
- traverse(list[i], timer, source);
3166
- return [3 /*break*/, 5];
3167
- case 2:
3168
- state = state$a(timer);
3169
- if (!(state === 0 /* Task.Wait */)) return [3 /*break*/, 4];
3170
- return [4 /*yield*/, suspend$1(timer)];
3171
- case 3:
3172
- state = _a.sent();
3173
- _a.label = 4;
3174
- case 4:
3175
- if (state === 2 /* Task.Stop */) {
3176
- return [3 /*break*/, 6];
3177
- }
3178
- processNode(list[i], source);
3179
- _a.label = 5;
3180
- case 5:
3181
- i++;
3182
- return [3 /*break*/, 1];
3183
- case 6: return [2 /*return*/];
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));
3184
3274
  }
3185
- });
3186
- });
3187
- }
3188
- function schedule(node) {
3189
- // Only schedule manual trigger for this node if it's not already in the queue
3190
- if (queue$1.indexOf(node) < 0) {
3191
- queue$1.push(node);
3275
+ else {
3276
+ q.push(r);
3277
+ }
3278
+ }
3192
3279
  }
3193
- // Cancel any previous trigger before scheduling a new one.
3194
- // It's common for a webpage to call multiple synchronous "insertRule" / "deleteRule" calls.
3195
- // And in those cases we do not wish to monitor changes multiple times for the same node.
3196
- if (timeout$1) {
3197
- clearTimeout(timeout$1);
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 */);
3198
3284
  }
3199
- timeout$1 = setTimeout(function () { trigger$2(); }, 33 /* Setting.LookAhead */);
3200
- return node;
3201
3285
  }
3202
- function trigger$2() {
3203
- for (var _i = 0, queue_1 = queue$1; _i < queue_1.length; _i++) {
3204
- var node = queue_1[_i];
3205
- // Generate a mutation for this node only if it still exists
3206
- if (node) {
3207
- var shadowRoot = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
3208
- // Skip re-processing shadowRoot if it was already discovered
3209
- if (shadowRoot && has(node)) {
3210
- continue;
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);
3211
3315
  }
3212
- generate(node, shadowRoot ? "childList" /* Constant.ChildList */ : "characterData" /* Constant.CharacterData */);
3213
3316
  }
3214
3317
  }
3215
- queue$1 = [];
3318
+ if (state$1.length > 0) {
3319
+ encode$4(7 /* Event.Region */);
3320
+ }
3216
3321
  }
3217
- function generate(target, type) {
3218
- measure(handle$1)([{
3219
- addedNodes: [target],
3220
- attributeName: null,
3221
- attributeNamespace: null,
3222
- nextSibling: null,
3223
- oldValue: null,
3224
- previousSibling: null,
3225
- removedNodes: [],
3226
- target: target,
3227
- type: type
3228
- }]);
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));
3333
+ }
3334
+ }
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
+ queue$1 = [];
3350
+ if (observer$1) {
3351
+ observer$1.disconnect();
3352
+ observer$1 = null;
3353
+ }
3354
+ watch = false;
3229
3355
  }
3230
3356
 
3231
3357
  function target(evt) {
@@ -3246,7 +3372,7 @@ function metadata$2(node, event, text) {
3246
3372
  output.hash = value.hash;
3247
3373
  output.privacy = metadata_1.privacy;
3248
3374
  if (value.region) {
3249
- track$4(value.region, event);
3375
+ track$3(value.region, event);
3250
3376
  }
3251
3377
  if (metadata_1.fraud) {
3252
3378
  check$4(metadata_1.fraud, value.id, text || value.data.value);
@@ -3273,7 +3399,7 @@ function encode$3 (type, ts) {
3273
3399
  case 18 /* Event.TouchEnd */:
3274
3400
  case 19 /* Event.TouchMove */:
3275
3401
  case 20 /* Event.TouchCancel */:
3276
- for (_i = 0, _a = state$3; _i < _a.length; _i++) {
3402
+ for (_i = 0, _a = state$6; _i < _a.length; _i++) {
3277
3403
  entry = _a[_i];
3278
3404
  pTarget = metadata$2(entry.data.target, entry.event);
3279
3405
  if (pTarget.id > 0) {
@@ -3285,10 +3411,10 @@ function encode$3 (type, ts) {
3285
3411
  track$8(entry.event, entry.data.x, entry.data.y);
3286
3412
  }
3287
3413
  }
3288
- reset$c();
3414
+ reset$f();
3289
3415
  break;
3290
3416
  case 9 /* Event.Click */:
3291
- for (_b = 0, _c = state$6; _b < _c.length; _b++) {
3417
+ for (_b = 0, _c = state$9; _b < _c.length; _b++) {
3292
3418
  entry = _c[_b];
3293
3419
  cTarget = metadata$2(entry.data.target, entry.event, entry.data.text);
3294
3420
  tokens = [entry.time, entry.event];
@@ -3308,10 +3434,10 @@ function encode$3 (type, ts) {
3308
3434
  queue(tokens);
3309
3435
  track$2(entry.time, entry.event, cHash, entry.data.x, entry.data.y, entry.data.reaction, entry.data.context);
3310
3436
  }
3311
- reset$f();
3437
+ reset$i();
3312
3438
  break;
3313
3439
  case 38 /* Event.Clipboard */:
3314
- for (_d = 0, _e = state$5; _d < _e.length; _d++) {
3440
+ for (_d = 0, _e = state$8; _d < _e.length; _d++) {
3315
3441
  entry = _e[_d];
3316
3442
  tokens = [entry.time, entry.event];
3317
3443
  target = metadata$2(entry.data.target, entry.event);
@@ -3321,24 +3447,24 @@ function encode$3 (type, ts) {
3321
3447
  queue(tokens);
3322
3448
  }
3323
3449
  }
3324
- reset$e();
3450
+ reset$h();
3325
3451
  break;
3326
3452
  case 11 /* Event.Resize */:
3327
3453
  r = data$b;
3328
3454
  tokens.push(r.width);
3329
3455
  tokens.push(r.height);
3330
3456
  track$8(type, r.width, r.height);
3331
- reset$b();
3457
+ reset$e();
3332
3458
  queue(tokens);
3333
3459
  break;
3334
3460
  case 26 /* Event.Unload */:
3335
3461
  u = data$9;
3336
3462
  tokens.push(u.name);
3337
- reset$7();
3463
+ reset$a();
3338
3464
  queue(tokens);
3339
3465
  break;
3340
3466
  case 27 /* Event.Input */:
3341
- for (_f = 0, _g = state$4; _f < _g.length; _f++) {
3467
+ for (_f = 0, _g = state$7; _f < _g.length; _f++) {
3342
3468
  entry = _g[_f];
3343
3469
  iTarget = metadata$2(entry.data.target, entry.event, entry.data.value);
3344
3470
  tokens = [entry.time, entry.event];
@@ -3346,7 +3472,7 @@ function encode$3 (type, ts) {
3346
3472
  tokens.push(text$1(entry.data.value, "input", iTarget.privacy));
3347
3473
  queue(tokens);
3348
3474
  }
3349
- reset$d();
3475
+ reset$g();
3350
3476
  break;
3351
3477
  case 21 /* Event.Selection */:
3352
3478
  s = data$a;
@@ -3357,12 +3483,12 @@ function encode$3 (type, ts) {
3357
3483
  tokens.push(s.startOffset);
3358
3484
  tokens.push(endTarget.id);
3359
3485
  tokens.push(s.endOffset);
3360
- reset$9();
3486
+ reset$c();
3361
3487
  queue(tokens);
3362
3488
  }
3363
3489
  break;
3364
3490
  case 10 /* Event.Scroll */:
3365
- for (_h = 0, _j = state$2; _h < _j.length; _h++) {
3491
+ for (_h = 0, _j = state$5; _h < _j.length; _h++) {
3366
3492
  entry = _j[_h];
3367
3493
  sTarget = metadata$2(entry.data.target, entry.event);
3368
3494
  if (sTarget.id > 0) {
@@ -3374,10 +3500,10 @@ function encode$3 (type, ts) {
3374
3500
  track$8(entry.event, entry.data.x, entry.data.y);
3375
3501
  }
3376
3502
  }
3377
- reset$a();
3503
+ reset$d();
3378
3504
  break;
3379
3505
  case 42 /* Event.Change */:
3380
- for (_k = 0, _l = state$7; _k < _l.length; _k++) {
3506
+ for (_k = 0, _l = state$a; _k < _l.length; _k++) {
3381
3507
  entry = _l[_k];
3382
3508
  tokens = [entry.time, entry.event];
3383
3509
  target = metadata$2(entry.data.target, entry.event);
@@ -3390,10 +3516,10 @@ function encode$3 (type, ts) {
3390
3516
  queue(tokens);
3391
3517
  }
3392
3518
  }
3393
- reset$g();
3519
+ reset$j();
3394
3520
  break;
3395
3521
  case 39 /* Event.Submit */:
3396
- for (_m = 0, _o = state$1; _m < _o.length; _m++) {
3522
+ for (_m = 0, _o = state$4; _m < _o.length; _m++) {
3397
3523
  entry = _o[_m];
3398
3524
  tokens = [entry.time, entry.event];
3399
3525
  target = metadata$2(entry.data.target, entry.event);
@@ -3402,7 +3528,7 @@ function encode$3 (type, ts) {
3402
3528
  queue(tokens);
3403
3529
  }
3404
3530
  }
3405
- reset$8();
3531
+ reset$b();
3406
3532
  break;
3407
3533
  case 22 /* Event.Timeline */:
3408
3534
  for (_p = 0, _q = updates$1; _p < _q.length; _p++) {
@@ -3423,7 +3549,7 @@ function encode$3 (type, ts) {
3423
3549
  tokens.push(v.visible);
3424
3550
  queue(tokens);
3425
3551
  visibility(t, v.visible);
3426
- reset$6();
3552
+ reset$9();
3427
3553
  break;
3428
3554
  }
3429
3555
  return [2 /*return*/];
@@ -3513,6 +3639,8 @@ function queue(tokens, transmit) {
3513
3639
  case 37 /* Event.Box */:
3514
3640
  case 6 /* Event.Mutation */:
3515
3641
  case 43 /* Event.Snapshot */:
3642
+ case 45 /* Event.StyleSheetAdoption */:
3643
+ case 46 /* Event.StyleSheetUpdate */:
3516
3644
  playbackBytes += event_1.length;
3517
3645
  playback.push(event_1);
3518
3646
  break;
@@ -3535,7 +3663,7 @@ function queue(tokens, transmit) {
3535
3663
  // We enrich the data going out with the existing upload. In these cases, call to upload comes with 'transmit' set to false.
3536
3664
  if (transmit && timeout === null) {
3537
3665
  if (type !== 25 /* Event.Ping */) {
3538
- reset$p();
3666
+ reset$q();
3539
3667
  }
3540
3668
  timeout = setTimeout(upload, gap);
3541
3669
  queuedTime = now;
@@ -3571,7 +3699,8 @@ function upload(final) {
3571
3699
  // Otherwise you run a risk of infinite loop.
3572
3700
  compute$6();
3573
3701
  compute$5();
3574
- compute$8();
3702
+ compute$9();
3703
+ compute$7();
3575
3704
  last = final === true;
3576
3705
  e = JSON.stringify(envelope(last));
3577
3706
  a = "[".concat(analysis.join(), "]");
@@ -4039,7 +4168,7 @@ function encode$1 (event) {
4039
4168
  var tokens = [t, event];
4040
4169
  switch (event) {
4041
4170
  case 4 /* Event.Baseline */:
4042
- var b = state$b;
4171
+ var b = state$c;
4043
4172
  if (b) {
4044
4173
  tokens = [b.time, b.event];
4045
4174
  tokens.push(b.data.visible);
@@ -4054,7 +4183,7 @@ function encode$1 (event) {
4054
4183
  tokens.push(b.data.activityTime);
4055
4184
  queue(tokens, false);
4056
4185
  }
4057
- reset$r();
4186
+ reset$s();
4058
4187
  break;
4059
4188
  case 25 /* Event.Ping */:
4060
4189
  tokens.push(data$h.gap);
@@ -4088,7 +4217,7 @@ function encode$1 (event) {
4088
4217
  tokens.push(v);
4089
4218
  tokens.push(data$e[v]);
4090
4219
  }
4091
- reset$n();
4220
+ reset$o();
4092
4221
  queue(tokens, false);
4093
4222
  }
4094
4223
  break;
@@ -4103,7 +4232,7 @@ function encode$1 (event) {
4103
4232
  // However, for data over the wire, we round it off to milliseconds precision.
4104
4233
  tokens.push(Math.round(updates$3[m]));
4105
4234
  }
4106
- reset$q();
4235
+ reset$r();
4107
4236
  queue(tokens, false);
4108
4237
  }
4109
4238
  break;
@@ -4129,7 +4258,7 @@ function encode$1 (event) {
4129
4258
  tokens.push(key);
4130
4259
  tokens.push([].concat.apply([], data$g[e]));
4131
4260
  }
4132
- reset$o();
4261
+ reset$p();
4133
4262
  queue(tokens, false);
4134
4263
  }
4135
4264
  break;
@@ -4451,25 +4580,51 @@ function user() {
4451
4580
  return output;
4452
4581
  }
4453
4582
  function getCookie(key) {
4583
+ var _a;
4454
4584
  if (supported(document, "cookie" /* Constant.Cookie */)) {
4455
4585
  var cookies = document.cookie.split(";" /* Constant.Semicolon */);
4456
4586
  if (cookies) {
4457
4587
  for (var i = 0; i < cookies.length; i++) {
4458
4588
  var pair = cookies[i].split("=" /* Constant.Equals */);
4459
4589
  if (pair.length > 1 && pair[0] && pair[0].trim() === key) {
4460
- return pair[1];
4590
+ // Some browsers automatically url encode cookie values if they are not url encoded.
4591
+ // We therefore encode and decode cookie values ourselves.
4592
+ // For backwards compatability we need to consider 3 cases:
4593
+ // * Cookie was previously not encoded by Clarity and browser did not encode it
4594
+ // * Cookie was previously not encoded by Clarity and browser encoded it once or more
4595
+ // * Cookie was previously encoded by Clarity and browser did not encode it
4596
+ var _b = decodeCookieValue(pair[1]), isEncoded = _b[0], decodedValue = _b[1];
4597
+ while (isEncoded) {
4598
+ _a = decodeCookieValue(decodedValue), isEncoded = _a[0], decodedValue = _a[1];
4599
+ }
4600
+ return decodedValue;
4461
4601
  }
4462
4602
  }
4463
4603
  }
4464
4604
  }
4465
4605
  return null;
4466
4606
  }
4607
+ function decodeCookieValue(value) {
4608
+ try {
4609
+ var decodedValue = decodeURIComponent(value);
4610
+ return [decodedValue != value, decodedValue];
4611
+ }
4612
+ catch (_a) {
4613
+ }
4614
+ return [false, value];
4615
+ }
4616
+ function encodeCookieValue(value) {
4617
+ return encodeURIComponent(value);
4618
+ }
4467
4619
  function setCookie(key, value, time) {
4468
4620
  if (config$1.track && ((navigator && navigator.cookieEnabled) || supported(document, "cookie" /* Constant.Cookie */))) {
4621
+ // Some browsers automatically url encode cookie values if they are not url encoded.
4622
+ // We therefore encode and decode cookie values ourselves.
4623
+ var encodedValue = encodeCookieValue(value);
4469
4624
  var expiry = new Date();
4470
4625
  expiry.setDate(expiry.getDate() + time);
4471
4626
  var expires = expiry ? "expires=" /* Constant.Expires */ + expiry.toUTCString() : "" /* Constant.Empty */;
4472
- var cookie = "".concat(key, "=").concat(value).concat(";" /* Constant.Semicolon */).concat(expires).concat(";path=/" /* Constant.Path */);
4627
+ var cookie = "".concat(key, "=").concat(encodedValue).concat(";" /* Constant.Semicolon */).concat(expires).concat(";path=/" /* Constant.Path */);
4473
4628
  try {
4474
4629
  // Attempt to get the root domain only once and fall back to writing cookie on the current domain.
4475
4630
  if (rootDomain === null) {
@@ -4672,8 +4827,8 @@ function stop$6() {
4672
4827
  var status = false;
4673
4828
  function start$6() {
4674
4829
  status = true;
4675
- start$H();
4676
- reset$k();
4830
+ start$I();
4831
+ reset$l();
4677
4832
  reset$1();
4678
4833
  reset$2();
4679
4834
  start$7();
@@ -4682,8 +4837,8 @@ function stop$5() {
4682
4837
  stop$6();
4683
4838
  reset$2();
4684
4839
  reset$1();
4685
- reset$k();
4686
- stop$E();
4840
+ reset$l();
4841
+ stop$F();
4687
4842
  status = false;
4688
4843
  }
4689
4844
  function active() {
@@ -4737,7 +4892,7 @@ function restart() {
4737
4892
  }
4738
4893
 
4739
4894
  function start$5() {
4740
- start$z();
4895
+ start$A();
4741
4896
  start$e();
4742
4897
  start$d();
4743
4898
  }
@@ -4753,7 +4908,7 @@ var diagnostic = /*#__PURE__*/Object.freeze({
4753
4908
 
4754
4909
  function start$4() {
4755
4910
  schedule$1(discover, 1 /* Priority.High */).then(function () {
4756
- measure(compute$7)();
4911
+ measure(compute$8)();
4757
4912
  measure(compute$6)();
4758
4913
  });
4759
4914
  }
@@ -4765,14 +4920,15 @@ function discover() {
4765
4920
  case 0:
4766
4921
  ts = time();
4767
4922
  timer = { id: id(), cost: 3 /* Metric.LayoutCost */ };
4768
- start$x(timer);
4923
+ start$y(timer);
4769
4924
  return [4 /*yield*/, traverse(document, timer, 0 /* Source.Discover */)];
4770
4925
  case 1:
4771
4926
  _a.sent();
4927
+ checkDocumentStyles(document);
4772
4928
  return [4 /*yield*/, encode$4(5 /* Event.Discover */, timer, ts)];
4773
4929
  case 2:
4774
4930
  _a.sent();
4775
- stop$v(timer);
4931
+ stop$w(timer);
4776
4932
  return [2 /*return*/];
4777
4933
  }
4778
4934
  });
@@ -4782,19 +4938,21 @@ function discover() {
4782
4938
  function start$3() {
4783
4939
  // The order below is important
4784
4940
  // and is determined by interdependencies of modules
4785
- start$w();
4786
- start$u();
4787
- start$y();
4941
+ start$x();
4788
4942
  start$h();
4943
+ start$z();
4944
+ start$k();
4789
4945
  start$4();
4790
- start$v();
4946
+ start$j();
4947
+ start$i();
4791
4948
  }
4792
4949
  function stop$3() {
4793
- stop$s();
4794
- stop$w();
4795
4950
  stop$f();
4796
- stop$u();
4797
- stop$t();
4951
+ stop$x();
4952
+ stop$i();
4953
+ stop$v();
4954
+ stop$h();
4955
+ stop$g();
4798
4956
  }
4799
4957
 
4800
4958
  var layout = /*#__PURE__*/Object.freeze({
@@ -4988,7 +5146,7 @@ function start(config$1) {
4988
5146
  if (check()) {
4989
5147
  config(config$1);
4990
5148
  start$6();
4991
- start$A();
5149
+ start$B();
4992
5150
  modules.forEach(function (x) { return measure(x.start)(); });
4993
5151
  // If it's an internal call to start, without explicit configuration,
4994
5152
  // re-process any newly accumulated items in the queue
@@ -5019,7 +5177,7 @@ function stop() {
5019
5177
  if (active()) {
5020
5178
  // Stop modules in the reverse order of their initialization and start queuing up items again
5021
5179
  modules.slice().reverse().forEach(function (x) { return measure(x.stop)(); });
5022
- stop$x();
5180
+ stop$y();
5023
5181
  stop$5();
5024
5182
  setup();
5025
5183
  }