@screeb/rrweb 1.0.16 → 1.0.17

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.
@@ -8627,7 +8627,18 @@ const defaultMouseTailConfig = {
8627
8627
  strokeStyle: "red"
8628
8628
  };
8629
8629
  function indicatesTouchDevice(e2) {
8630
- return e2.type == EventType.IncrementalSnapshot && (e2.data.source == IncrementalSource.TouchMove || e2.data.source == IncrementalSource.MouseInteraction && e2.data.type == MouseInteractions.TouchStart);
8630
+ if (e2.type !== EventType.IncrementalSnapshot) {
8631
+ return false;
8632
+ }
8633
+ const data = e2.data;
8634
+ if (data.source === IncrementalSource.TouchMove) {
8635
+ return true;
8636
+ }
8637
+ if (data.source === IncrementalSource.MouseInteraction && data.type === MouseInteractions.TouchStart) {
8638
+ const mouseData = data;
8639
+ return mouseData.pointerType === PointerTypes.Touch;
8640
+ }
8641
+ return false;
8631
8642
  }
8632
8643
  function getPointerId(d) {
8633
8644
  const pointerId = "pointerId" in d && typeof d.pointerId === "number" ? d.pointerId : -1;
@@ -8647,6 +8658,7 @@ class Replayer {
8647
8658
  this.firstFullSnapshot = null;
8648
8659
  this.newDocumentQueue = [];
8649
8660
  this.pointers = {};
8661
+ this.mouseTailAnimationFrame = null;
8650
8662
  this.lastMouseDownEvent = null;
8651
8663
  this.lastSelectionData = null;
8652
8664
  this.constructedStyleMutations = [];
@@ -8785,6 +8797,53 @@ class Replayer {
8785
8797
  };
8786
8798
  return wrappedCastFn;
8787
8799
  };
8800
+ this.stepMouseTails = (timestamp) => {
8801
+ const { lineCap, lineWidth, strokeStyle, duration } = this.config.mouseTail === true ? defaultMouseTailConfig : Object.assign({}, defaultMouseTailConfig, this.config.mouseTail);
8802
+ const maxAge = duration / this.speedService.state.context.timer.speed;
8803
+ let hasAnyTail = false;
8804
+ Object.values(this.pointers).forEach((pointer) => {
8805
+ if (!pointer.mouseTail) {
8806
+ return;
8807
+ }
8808
+ const mouseTail = pointer.mouseTail;
8809
+ const ctx = mouseTail.getContext("2d");
8810
+ if (!ctx) {
8811
+ return;
8812
+ }
8813
+ pointer.tailPositions = pointer.tailPositions.filter(
8814
+ (p) => timestamp - p.t <= maxAge
8815
+ );
8816
+ ctx.clearRect(0, 0, mouseTail.width, mouseTail.height);
8817
+ if (pointer.tailPositions.length > 1) {
8818
+ hasAnyTail = true;
8819
+ ctx.lineWidth = lineWidth;
8820
+ ctx.lineCap = lineCap;
8821
+ ctx.strokeStyle = strokeStyle;
8822
+ for (let i2 = 1; i2 < pointer.tailPositions.length; i2++) {
8823
+ const prev = pointer.tailPositions[i2 - 1];
8824
+ const curr = pointer.tailPositions[i2];
8825
+ const age = (timestamp - curr.t) / maxAge;
8826
+ const alpha = Math.max(0, 1 - age);
8827
+ if (alpha <= 0) {
8828
+ continue;
8829
+ }
8830
+ ctx.globalAlpha = alpha;
8831
+ ctx.beginPath();
8832
+ ctx.moveTo(prev.x, prev.y);
8833
+ ctx.lineTo(curr.x, curr.y);
8834
+ ctx.stroke();
8835
+ }
8836
+ ctx.globalAlpha = 1;
8837
+ }
8838
+ });
8839
+ if (hasAnyTail) {
8840
+ this.mouseTailAnimationFrame = requestAnimationFrame(
8841
+ this.stepMouseTails
8842
+ );
8843
+ } else {
8844
+ this.mouseTailAnimationFrame = null;
8845
+ }
8846
+ };
8788
8847
  if (!config?.liveMode && events.length < 2) {
8789
8848
  throw new Error("Replayer need at least 2 events.");
8790
8849
  }
@@ -10326,35 +10385,13 @@ class Replayer {
10326
10385
  if (!pointer || !pointer.mouseTail) {
10327
10386
  return;
10328
10387
  }
10329
- const { lineCap, lineWidth, strokeStyle, duration } = this.config.mouseTail === true ? defaultMouseTailConfig : Object.assign({}, defaultMouseTailConfig, this.config.mouseTail);
10330
- const draw = () => {
10331
- if (!pointer || !pointer.mouseTail) {
10332
- return;
10333
- }
10334
- const mouseTail = pointer.mouseTail;
10335
- const ctx = mouseTail.getContext("2d");
10336
- if (!ctx || !pointer.tailPositions.length) {
10337
- return;
10338
- }
10339
- ctx.clearRect(0, 0, mouseTail.width, mouseTail.height);
10340
- ctx.beginPath();
10341
- ctx.lineWidth = lineWidth;
10342
- ctx.lineCap = lineCap;
10343
- ctx.strokeStyle = strokeStyle;
10344
- ctx.moveTo(pointer.tailPositions[0].x, pointer.tailPositions[0].y);
10345
- pointer.tailPositions.forEach((p) => ctx.lineTo(p.x, p.y));
10346
- ctx.stroke();
10347
- };
10348
- pointer.tailPositions.push(position);
10349
- draw();
10350
- setTimeout$1(() => {
10351
- if (pointerId in this.pointers) {
10352
- pointer.tailPositions = pointer.tailPositions.filter(
10353
- (p) => p !== position
10354
- );
10355
- draw();
10356
- }
10357
- }, duration / this.speedService.state.context.timer.speed);
10388
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
10389
+ pointer.tailPositions.push({ x: position.x, y: position.y, t: now });
10390
+ if (this.mouseTailAnimationFrame === null) {
10391
+ this.mouseTailAnimationFrame = requestAnimationFrame(
10392
+ this.stepMouseTails
10393
+ );
10394
+ }
10358
10395
  }
10359
10396
  hoverElements(el) {
10360
10397
  const iframeDoc = getIFrameContentDocument(this.iframe);