@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.cjs CHANGED
@@ -8509,7 +8509,15 @@ 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.MouseInteraction && data.type === MouseInteractions.TouchStart) {
8517
+ const mouseData = data;
8518
+ return mouseData.pointerType === PointerTypes.Touch;
8519
+ }
8520
+ return false;
8513
8521
  }
8514
8522
  function getPointerId(d) {
8515
8523
  const pointerId = "pointerId" in d && typeof d.pointerId === "number" ? d.pointerId : -1;
@@ -10191,34 +10199,38 @@ class Replayer {
10191
10199
  return;
10192
10200
  }
10193
10201
  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();
10202
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
10203
+ const maxAge = duration / this.speedService.state.context.timer.speed;
10204
+ pointer.tailPositions.push({ x: position.x, y: position.y, t: now });
10205
+ pointer.tailPositions = pointer.tailPositions.filter(
10206
+ (p) => now - p.t <= maxAge
10207
+ );
10208
+ const mouseTail = pointer.mouseTail;
10209
+ const ctx = mouseTail.getContext("2d");
10210
+ if (!ctx) {
10211
+ return;
10212
+ }
10213
+ ctx.clearRect(0, 0, mouseTail.width, mouseTail.height);
10214
+ if (pointer.tailPositions.length > 1) {
10205
10215
  ctx.lineWidth = lineWidth;
10206
10216
  ctx.lineCap = lineCap;
10207
10217
  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();
10218
+ for (let i2 = 1; i2 < pointer.tailPositions.length; i2++) {
10219
+ const prev = pointer.tailPositions[i2 - 1];
10220
+ const curr = pointer.tailPositions[i2];
10221
+ const age = (now - curr.t) / maxAge;
10222
+ const alpha = Math.max(0, 1 - age);
10223
+ if (alpha <= 0) {
10224
+ continue;
10225
+ }
10226
+ ctx.globalAlpha = alpha;
10227
+ ctx.beginPath();
10228
+ ctx.moveTo(prev.x, prev.y);
10229
+ ctx.lineTo(curr.x, curr.y);
10230
+ ctx.stroke();
10220
10231
  }
10221
- }, duration / this.speedService.state.context.timer.speed);
10232
+ ctx.globalAlpha = 1;
10233
+ }
10222
10234
  }
10223
10235
  hoverElements(el) {
10224
10236
  const iframeDoc = getIFrameContentDocument(this.iframe);