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