@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.
package/dist/rrweb.js CHANGED
@@ -8507,7 +8507,15 @@ 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.MouseInteraction && data.type === MouseInteractions.TouchStart) {
8515
+ const mouseData = data;
8516
+ return mouseData.pointerType === PointerTypes.Touch;
8517
+ }
8518
+ return false;
8511
8519
  }
8512
8520
  function getPointerId(d) {
8513
8521
  const pointerId = "pointerId" in d && typeof d.pointerId === "number" ? d.pointerId : -1;
@@ -10189,34 +10197,38 @@ class Replayer {
10189
10197
  return;
10190
10198
  }
10191
10199
  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();
10200
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
10201
+ const maxAge = duration / this.speedService.state.context.timer.speed;
10202
+ 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) {
10203
10213
  ctx.lineWidth = lineWidth;
10204
10214
  ctx.lineCap = lineCap;
10205
10215
  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();
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();
10218
10229
  }
10219
- }, duration / this.speedService.state.context.timer.speed);
10230
+ ctx.globalAlpha = 1;
10231
+ }
10220
10232
  }
10221
10233
  hoverElements(el) {
10222
10234
  const iframeDoc = getIFrameContentDocument(this.iframe);