@screeb/rrweb 1.0.16 → 1.0.18

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,15 @@ 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.MouseInteraction && data.type === MouseInteractions.TouchStart) {
8635
+ const mouseData = data;
8636
+ return mouseData.pointerType === PointerTypes.Touch;
8637
+ }
8638
+ return false;
8631
8639
  }
8632
8640
  function getPointerId(d) {
8633
8641
  const pointerId = "pointerId" in d && typeof d.pointerId === "number" ? d.pointerId : -1;
@@ -10327,34 +10335,38 @@ class Replayer {
10327
10335
  return;
10328
10336
  }
10329
10337
  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();
10338
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
10339
+ const maxAge = duration / this.speedService.state.context.timer.speed;
10340
+ 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) {
10341
10351
  ctx.lineWidth = lineWidth;
10342
10352
  ctx.lineCap = lineCap;
10343
10353
  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();
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();
10356
10367
  }
10357
- }, duration / this.speedService.state.context.timer.speed);
10368
+ ctx.globalAlpha = 1;
10369
+ }
10358
10370
  }
10359
10371
  hoverElements(el) {
10360
10372
  const iframeDoc = getIFrameContentDocument(this.iframe);