@screeb/rrweb 1.0.18 → 1.0.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/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
@@ -8535,6 +8535,7 @@ class Replayer {
8535
8535
  this.firstFullSnapshot = null;
8536
8536
  this.newDocumentQueue = [];
8537
8537
  this.pointers = {};
8538
+ this.mouseTailAnimationFrame = null;
8538
8539
  this.lastMouseDownEvent = null;
8539
8540
  this.lastSelectionData = null;
8540
8541
  this.constructedStyleMutations = [];
@@ -8672,6 +8673,53 @@ class Replayer {
8672
8673
  };
8673
8674
  return wrappedCastFn;
8674
8675
  };
8676
+ this.stepMouseTails = (timestamp) => {
8677
+ const { lineCap, lineWidth, strokeStyle, duration } = this.config.mouseTail === true ? defaultMouseTailConfig : Object.assign({}, defaultMouseTailConfig, this.config.mouseTail);
8678
+ const maxAge = duration / this.speedService.state.context.timer.speed;
8679
+ let hasAnyTail = false;
8680
+ Object.values(this.pointers).forEach((pointer) => {
8681
+ if (!pointer.mouseTail) {
8682
+ return;
8683
+ }
8684
+ const mouseTail = pointer.mouseTail;
8685
+ const ctx = mouseTail.getContext("2d");
8686
+ if (!ctx) {
8687
+ return;
8688
+ }
8689
+ pointer.tailPositions = pointer.tailPositions.filter(
8690
+ (p) => timestamp - p.t <= maxAge
8691
+ );
8692
+ ctx.clearRect(0, 0, mouseTail.width, mouseTail.height);
8693
+ if (pointer.tailPositions.length > 1) {
8694
+ hasAnyTail = true;
8695
+ ctx.lineWidth = lineWidth;
8696
+ ctx.lineCap = lineCap;
8697
+ ctx.strokeStyle = strokeStyle;
8698
+ for (let i2 = 1; i2 < pointer.tailPositions.length; i2++) {
8699
+ const prev = pointer.tailPositions[i2 - 1];
8700
+ const curr = pointer.tailPositions[i2];
8701
+ const age = (timestamp - curr.t) / maxAge;
8702
+ const alpha = Math.max(0, 1 - age);
8703
+ if (alpha <= 0) {
8704
+ continue;
8705
+ }
8706
+ ctx.globalAlpha = alpha;
8707
+ ctx.beginPath();
8708
+ ctx.moveTo(prev.x, prev.y);
8709
+ ctx.lineTo(curr.x, curr.y);
8710
+ ctx.stroke();
8711
+ }
8712
+ ctx.globalAlpha = 1;
8713
+ }
8714
+ });
8715
+ if (hasAnyTail) {
8716
+ this.mouseTailAnimationFrame = requestAnimationFrame(
8717
+ this.stepMouseTails
8718
+ );
8719
+ } else {
8720
+ this.mouseTailAnimationFrame = null;
8721
+ }
8722
+ };
8675
8723
  if (!config?.liveMode && events.length < 2) {
8676
8724
  throw new Error("Replayer need at least 2 events.");
8677
8725
  }
@@ -10196,38 +10244,12 @@ class Replayer {
10196
10244
  if (!pointer || !pointer.mouseTail) {
10197
10245
  return;
10198
10246
  }
10199
- const { lineCap, lineWidth, strokeStyle, duration } = this.config.mouseTail === true ? defaultMouseTailConfig : Object.assign({}, defaultMouseTailConfig, this.config.mouseTail);
10200
10247
  const now = typeof performance !== "undefined" ? performance.now() : Date.now();
10201
- const maxAge = duration / this.speedService.state.context.timer.speed;
10202
10248
  pointer.tailPositions.push({ x: position.x, y: position.y, t: now });
10203
- pointer.tailPositions = pointer.tailPositions.filter(
10204
- (p) => now - p.t <= maxAge
10205
- );
10206
- const mouseTail = pointer.mouseTail;
10207
- const ctx = mouseTail.getContext("2d");
10208
- if (!ctx) {
10209
- return;
10210
- }
10211
- ctx.clearRect(0, 0, mouseTail.width, mouseTail.height);
10212
- if (pointer.tailPositions.length > 1) {
10213
- ctx.lineWidth = lineWidth;
10214
- ctx.lineCap = lineCap;
10215
- ctx.strokeStyle = strokeStyle;
10216
- for (let i2 = 1; i2 < pointer.tailPositions.length; i2++) {
10217
- const prev = pointer.tailPositions[i2 - 1];
10218
- const curr = pointer.tailPositions[i2];
10219
- const age = (now - curr.t) / maxAge;
10220
- const alpha = Math.max(0, 1 - age);
10221
- if (alpha <= 0) {
10222
- continue;
10223
- }
10224
- ctx.globalAlpha = alpha;
10225
- ctx.beginPath();
10226
- ctx.moveTo(prev.x, prev.y);
10227
- ctx.lineTo(curr.x, curr.y);
10228
- ctx.stroke();
10229
- }
10230
- ctx.globalAlpha = 1;
10249
+ if (this.mouseTailAnimationFrame === null) {
10250
+ this.mouseTailAnimationFrame = requestAnimationFrame(
10251
+ this.stepMouseTails
10252
+ );
10231
10253
  }
10232
10254
  }
10233
10255
  hoverElements(el) {