@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.
package/dist/rrweb.d.cts CHANGED
@@ -375,6 +375,7 @@ export declare class Replayer {
375
375
  private firstFullSnapshot;
376
376
  private newDocumentQueue;
377
377
  private pointers;
378
+ private mouseTailAnimationFrame;
378
379
  private lastMouseDownEvent;
379
380
  private lastHoveredRootNode;
380
381
  private lastSelectionData;
@@ -423,6 +424,7 @@ export declare class Replayer {
423
424
  private legacy_resolveMissingNode;
424
425
  private moveAndHover;
425
426
  private drawMouseTail;
427
+ private stepMouseTails;
426
428
  private hoverElements;
427
429
  private isUserInteraction;
428
430
  private backToNormal;
package/dist/rrweb.d.ts CHANGED
@@ -375,6 +375,7 @@ export declare class Replayer {
375
375
  private firstFullSnapshot;
376
376
  private newDocumentQueue;
377
377
  private pointers;
378
+ private mouseTailAnimationFrame;
378
379
  private lastMouseDownEvent;
379
380
  private lastHoveredRootNode;
380
381
  private lastSelectionData;
@@ -423,6 +424,7 @@ export declare class Replayer {
423
424
  private legacy_resolveMissingNode;
424
425
  private moveAndHover;
425
426
  private drawMouseTail;
427
+ private stepMouseTails;
426
428
  private hoverElements;
427
429
  private isUserInteraction;
428
430
  private backToNormal;
package/dist/rrweb.js CHANGED
@@ -8507,7 +8507,18 @@ const defaultMouseTailConfig = {
8507
8507
  strokeStyle: "red"
8508
8508
  };
8509
8509
  function indicatesTouchDevice(e2) {
8510
- return e2.type == EventType.IncrementalSnapshot && (e2.data.source == IncrementalSource.TouchMove || e2.data.source == IncrementalSource.MouseInteraction && e2.data.type == MouseInteractions.TouchStart);
8510
+ if (e2.type !== EventType.IncrementalSnapshot) {
8511
+ return false;
8512
+ }
8513
+ const data = e2.data;
8514
+ if (data.source === IncrementalSource.TouchMove) {
8515
+ return true;
8516
+ }
8517
+ if (data.source === IncrementalSource.MouseInteraction && data.type === MouseInteractions.TouchStart) {
8518
+ const mouseData = data;
8519
+ return mouseData.pointerType === PointerTypes.Touch;
8520
+ }
8521
+ return false;
8511
8522
  }
8512
8523
  function getPointerId(d) {
8513
8524
  const pointerId = "pointerId" in d && typeof d.pointerId === "number" ? d.pointerId : -1;
@@ -8527,6 +8538,7 @@ class Replayer {
8527
8538
  this.firstFullSnapshot = null;
8528
8539
  this.newDocumentQueue = [];
8529
8540
  this.pointers = {};
8541
+ this.mouseTailAnimationFrame = null;
8530
8542
  this.lastMouseDownEvent = null;
8531
8543
  this.lastSelectionData = null;
8532
8544
  this.constructedStyleMutations = [];
@@ -8664,6 +8676,53 @@ class Replayer {
8664
8676
  };
8665
8677
  return wrappedCastFn;
8666
8678
  };
8679
+ this.stepMouseTails = (timestamp) => {
8680
+ const { lineCap, lineWidth, strokeStyle, duration } = this.config.mouseTail === true ? defaultMouseTailConfig : Object.assign({}, defaultMouseTailConfig, this.config.mouseTail);
8681
+ const maxAge = duration / this.speedService.state.context.timer.speed;
8682
+ let hasAnyTail = false;
8683
+ Object.values(this.pointers).forEach((pointer) => {
8684
+ if (!pointer.mouseTail) {
8685
+ return;
8686
+ }
8687
+ const mouseTail = pointer.mouseTail;
8688
+ const ctx = mouseTail.getContext("2d");
8689
+ if (!ctx) {
8690
+ return;
8691
+ }
8692
+ pointer.tailPositions = pointer.tailPositions.filter(
8693
+ (p) => timestamp - p.t <= maxAge
8694
+ );
8695
+ ctx.clearRect(0, 0, mouseTail.width, mouseTail.height);
8696
+ if (pointer.tailPositions.length > 1) {
8697
+ hasAnyTail = true;
8698
+ ctx.lineWidth = lineWidth;
8699
+ ctx.lineCap = lineCap;
8700
+ ctx.strokeStyle = strokeStyle;
8701
+ for (let i2 = 1; i2 < pointer.tailPositions.length; i2++) {
8702
+ const prev = pointer.tailPositions[i2 - 1];
8703
+ const curr = pointer.tailPositions[i2];
8704
+ const age = (timestamp - curr.t) / maxAge;
8705
+ const alpha = Math.max(0, 1 - age);
8706
+ if (alpha <= 0) {
8707
+ continue;
8708
+ }
8709
+ ctx.globalAlpha = alpha;
8710
+ ctx.beginPath();
8711
+ ctx.moveTo(prev.x, prev.y);
8712
+ ctx.lineTo(curr.x, curr.y);
8713
+ ctx.stroke();
8714
+ }
8715
+ ctx.globalAlpha = 1;
8716
+ }
8717
+ });
8718
+ if (hasAnyTail) {
8719
+ this.mouseTailAnimationFrame = requestAnimationFrame(
8720
+ this.stepMouseTails
8721
+ );
8722
+ } else {
8723
+ this.mouseTailAnimationFrame = null;
8724
+ }
8725
+ };
8667
8726
  if (!config?.liveMode && events.length < 2) {
8668
8727
  throw new Error("Replayer need at least 2 events.");
8669
8728
  }
@@ -10188,35 +10247,13 @@ class Replayer {
10188
10247
  if (!pointer || !pointer.mouseTail) {
10189
10248
  return;
10190
10249
  }
10191
- const { lineCap, lineWidth, strokeStyle, duration } = this.config.mouseTail === true ? defaultMouseTailConfig : Object.assign({}, defaultMouseTailConfig, this.config.mouseTail);
10192
- const draw = () => {
10193
- if (!pointer || !pointer.mouseTail) {
10194
- return;
10195
- }
10196
- const mouseTail = pointer.mouseTail;
10197
- const ctx = mouseTail.getContext("2d");
10198
- if (!ctx || !pointer.tailPositions.length) {
10199
- return;
10200
- }
10201
- ctx.clearRect(0, 0, mouseTail.width, mouseTail.height);
10202
- ctx.beginPath();
10203
- ctx.lineWidth = lineWidth;
10204
- ctx.lineCap = lineCap;
10205
- ctx.strokeStyle = strokeStyle;
10206
- ctx.moveTo(pointer.tailPositions[0].x, pointer.tailPositions[0].y);
10207
- pointer.tailPositions.forEach((p) => ctx.lineTo(p.x, p.y));
10208
- ctx.stroke();
10209
- };
10210
- pointer.tailPositions.push(position);
10211
- draw();
10212
- setTimeout$1(() => {
10213
- if (pointerId in this.pointers) {
10214
- pointer.tailPositions = pointer.tailPositions.filter(
10215
- (p) => p !== position
10216
- );
10217
- draw();
10218
- }
10219
- }, duration / this.speedService.state.context.timer.speed);
10250
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
10251
+ pointer.tailPositions.push({ x: position.x, y: position.y, t: now });
10252
+ if (this.mouseTailAnimationFrame === null) {
10253
+ this.mouseTailAnimationFrame = requestAnimationFrame(
10254
+ this.stepMouseTails
10255
+ );
10256
+ }
10220
10257
  }
10221
10258
  hoverElements(el) {
10222
10259
  const iframeDoc = getIFrameContentDocument(this.iframe);