@screeb/rrweb 1.0.18 → 1.0.20

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.
@@ -8329,7 +8329,7 @@ function createPlayerService(context, { getCastFn, applyEventsSynchronously, emi
8329
8329
  }
8330
8330
  events.splice(insertionIndex, 0, event);
8331
8331
  }
8332
- const isSync = event.timestamp < baselineTime;
8332
+ const isSync = event.timestamp < baselineTime || !timer.isActive();
8333
8333
  const castFn = getCastFn(event, isSync);
8334
8334
  if (isSync) {
8335
8335
  castFn();
@@ -8655,6 +8655,7 @@ class Replayer {
8655
8655
  this.firstFullSnapshot = null;
8656
8656
  this.newDocumentQueue = [];
8657
8657
  this.pointers = {};
8658
+ this.mouseTailAnimationFrame = null;
8658
8659
  this.lastMouseDownEvent = null;
8659
8660
  this.lastSelectionData = null;
8660
8661
  this.constructedStyleMutations = [];
@@ -8793,6 +8794,53 @@ class Replayer {
8793
8794
  };
8794
8795
  return wrappedCastFn;
8795
8796
  };
8797
+ this.stepMouseTails = (timestamp) => {
8798
+ const { lineCap, lineWidth, strokeStyle, duration } = this.config.mouseTail === true ? defaultMouseTailConfig : Object.assign({}, defaultMouseTailConfig, this.config.mouseTail);
8799
+ const maxAge = duration / this.speedService.state.context.timer.speed;
8800
+ let hasAnyTail = false;
8801
+ Object.values(this.pointers).forEach((pointer) => {
8802
+ if (!pointer.mouseTail) {
8803
+ return;
8804
+ }
8805
+ const mouseTail = pointer.mouseTail;
8806
+ const ctx = mouseTail.getContext("2d");
8807
+ if (!ctx) {
8808
+ return;
8809
+ }
8810
+ pointer.tailPositions = pointer.tailPositions.filter(
8811
+ (p) => timestamp - p.t <= maxAge
8812
+ );
8813
+ ctx.clearRect(0, 0, mouseTail.width, mouseTail.height);
8814
+ if (pointer.tailPositions.length > 1) {
8815
+ hasAnyTail = true;
8816
+ ctx.lineWidth = lineWidth;
8817
+ ctx.lineCap = lineCap;
8818
+ ctx.strokeStyle = strokeStyle;
8819
+ for (let i2 = 1; i2 < pointer.tailPositions.length; i2++) {
8820
+ const prev = pointer.tailPositions[i2 - 1];
8821
+ const curr = pointer.tailPositions[i2];
8822
+ const age = (timestamp - curr.t) / maxAge;
8823
+ const alpha = Math.max(0, 1 - age);
8824
+ if (alpha <= 0) {
8825
+ continue;
8826
+ }
8827
+ ctx.globalAlpha = alpha;
8828
+ ctx.beginPath();
8829
+ ctx.moveTo(prev.x, prev.y);
8830
+ ctx.lineTo(curr.x, curr.y);
8831
+ ctx.stroke();
8832
+ }
8833
+ ctx.globalAlpha = 1;
8834
+ }
8835
+ });
8836
+ if (hasAnyTail) {
8837
+ this.mouseTailAnimationFrame = requestAnimationFrame(
8838
+ this.stepMouseTails
8839
+ );
8840
+ } else {
8841
+ this.mouseTailAnimationFrame = null;
8842
+ }
8843
+ };
8796
8844
  if (!config?.liveMode && events.length < 2) {
8797
8845
  throw new Error("Replayer need at least 2 events.");
8798
8846
  }
@@ -10334,38 +10382,12 @@ class Replayer {
10334
10382
  if (!pointer || !pointer.mouseTail) {
10335
10383
  return;
10336
10384
  }
10337
- const { lineCap, lineWidth, strokeStyle, duration } = this.config.mouseTail === true ? defaultMouseTailConfig : Object.assign({}, defaultMouseTailConfig, this.config.mouseTail);
10338
10385
  const now = typeof performance !== "undefined" ? performance.now() : Date.now();
10339
- const maxAge = duration / this.speedService.state.context.timer.speed;
10340
10386
  pointer.tailPositions.push({ x: position.x, y: position.y, t: now });
10341
- pointer.tailPositions = pointer.tailPositions.filter(
10342
- (p) => now - p.t <= maxAge
10343
- );
10344
- const mouseTail = pointer.mouseTail;
10345
- const ctx = mouseTail.getContext("2d");
10346
- if (!ctx) {
10347
- return;
10348
- }
10349
- ctx.clearRect(0, 0, mouseTail.width, mouseTail.height);
10350
- if (pointer.tailPositions.length > 1) {
10351
- ctx.lineWidth = lineWidth;
10352
- ctx.lineCap = lineCap;
10353
- ctx.strokeStyle = strokeStyle;
10354
- for (let i2 = 1; i2 < pointer.tailPositions.length; i2++) {
10355
- const prev = pointer.tailPositions[i2 - 1];
10356
- const curr = pointer.tailPositions[i2];
10357
- const age = (now - curr.t) / maxAge;
10358
- const alpha = Math.max(0, 1 - age);
10359
- if (alpha <= 0) {
10360
- continue;
10361
- }
10362
- ctx.globalAlpha = alpha;
10363
- ctx.beginPath();
10364
- ctx.moveTo(prev.x, prev.y);
10365
- ctx.lineTo(curr.x, curr.y);
10366
- ctx.stroke();
10367
- }
10368
- ctx.globalAlpha = 1;
10387
+ if (this.mouseTailAnimationFrame === null) {
10388
+ this.mouseTailAnimationFrame = requestAnimationFrame(
10389
+ this.stepMouseTails
10390
+ );
10369
10391
  }
10370
10392
  }
10371
10393
  hoverElements(el) {