clarity-visualize 0.8.58 → 0.8.59

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.
@@ -366,8 +366,8 @@ class HeatmapHelper {
366
366
  // Remove scroll and resize event listeners
367
367
  if (this.state && this.state.window) {
368
368
  let win = this.state.window;
369
- win.removeEventListener("scroll", this.redraw, true);
370
- win.removeEventListener("resize", this.redraw, true);
369
+ win.removeEventListener("scroll", this.redraw, { capture: true });
370
+ win.removeEventListener("resize", this.redraw, { capture: true });
371
371
  }
372
372
  };
373
373
  this.clear = () => {
@@ -490,8 +490,8 @@ class HeatmapHelper {
490
490
  canvas.style.position = "absolute" /* Constant.Absolute */;
491
491
  canvas.style.zIndex = `${2147483647 /* Setting.ZIndex */}`;
492
492
  de.appendChild(canvas);
493
- win.addEventListener("scroll", this.redraw, true);
494
- win.addEventListener("resize", this.redraw, true);
493
+ win.addEventListener("scroll", this.redraw, { passive: true, capture: true });
494
+ win.addEventListener("resize", this.redraw, { passive: true, capture: true });
495
495
  this.observer = this.state.window["ResizeObserver"] ? new ResizeObserver(this.redraw) : null;
496
496
  if (this.observer) {
497
497
  this.observer.observe(doc.body);
@@ -658,7 +658,7 @@ class InteractionHelper {
658
658
  this.points = [];
659
659
  this.scrollPointIndex = 0;
660
660
  this.clickAudio = null;
661
- this.visualizedClicks = [];
661
+ this.visualizedClicks = new Map();
662
662
  this.reset = () => {
663
663
  this.points = [];
664
664
  this.scrollPointIndex = 0;
@@ -804,9 +804,10 @@ class InteractionHelper {
804
804
  switch (type) {
805
805
  case 9 /* Data.Event.Click */:
806
806
  title = "Click";
807
- this.visualizedClicks.push({
807
+ const clickElement = this.drawClick(doc, data.x, data.y, title);
808
+ this.visualizedClicks.set(clickElement, {
808
809
  doc: de,
809
- click: this.drawClick(doc, data.x, data.y, title),
810
+ click: clickElement,
810
811
  time: event.time
811
812
  });
812
813
  if (this.state.options.onclickMismatch) {
@@ -831,9 +832,10 @@ class InteractionHelper {
831
832
  break;
832
833
  case 16 /* Data.Event.DoubleClick */:
833
834
  title = "Click";
834
- this.visualizedClicks.push({
835
+ const doubleClickElement = this.drawClick(doc, data.x, data.y, title);
836
+ this.visualizedClicks.set(doubleClickElement, {
835
837
  doc: de,
836
- click: this.drawClick(doc, data.x, data.y, title),
838
+ click: doubleClickElement,
837
839
  time: event.time
838
840
  });
839
841
  p.className = "clarity-pointer-none" /* Constant.PointerNone */;
@@ -842,9 +844,10 @@ class InteractionHelper {
842
844
  case 18 /* Data.Event.TouchEnd */:
843
845
  case 20 /* Data.Event.TouchCancel */:
844
846
  title = "Touch";
845
- this.visualizedClicks.push({
847
+ const touchElement = this.drawTouch(doc, data.x, data.y, title);
848
+ this.visualizedClicks.set(touchElement, {
846
849
  doc: de,
847
- click: this.drawTouch(doc, data.x, data.y, title),
850
+ click: touchElement,
848
851
  time: event.time
849
852
  });
850
853
  p.className = "clarity-pointer-none" /* Constant.PointerNone */;
@@ -867,15 +870,23 @@ class InteractionHelper {
867
870
  };
868
871
  this.clearOldClickVisualizations = (currentTimestamp) => {
869
872
  if (this.vnext) {
870
- while (this.visualizedClicks.length > 10 /* Setting.MaxClicksDisplayed */) {
871
- const visualizedClick = this.visualizedClicks.shift();
872
- this.fadeOutElement(visualizedClick.click, visualizedClick.doc);
873
+ // Track elements to remove to avoid modifying Map during iteration
874
+ const elementsToRemove = [];
875
+ // Calculate how many clicks exceed the maximum allowed
876
+ const excess = Math.max(0, this.visualizedClicks.size - 10 /* Setting.MaxClicksDisplayed */);
877
+ let count = 0;
878
+ // Iterate through visualized clicks and mark old ones for removal
879
+ for (const [element, data] of this.visualizedClicks) {
880
+ count++;
881
+ const isTooOld = currentTimestamp - data.time > 5000 /* Setting.MaxClickDisplayDuration */;
882
+ const exceedsMaxCount = count <= excess;
883
+ if (isTooOld || exceedsMaxCount) {
884
+ elementsToRemove.push(element);
885
+ this.fadeOutElement(element, data.doc);
886
+ }
873
887
  }
874
- var tooOldClicks = this.visualizedClicks.filter(click => currentTimestamp - click.time > 5000 /* Setting.MaxClickDisplayDuration */);
875
- tooOldClicks.forEach(click => {
876
- this.fadeOutElement(click.click, click.doc);
877
- this.visualizedClicks.splice(this.visualizedClicks.indexOf(click), 1);
878
- });
888
+ // Remove marked elements from the Map
889
+ elementsToRemove.forEach(element => this.visualizedClicks.delete(element));
879
890
  }
880
891
  };
881
892
  this.fadeOutElement = (element, document) => {