@glimt/record 0.0.15 → 0.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.
@@ -397,12 +397,8 @@ function toLowerCase(str) {
397
397
  const ORIGINAL_ATTRIBUTE_NAME = "__rrweb_original__";
398
398
  const COPY_CANVAS_ON_VOLUME_GREATER_THAN = 25e4;
399
399
  function getReadableCanvasContext(canvas) {
400
- if (canvas.width === 0 || canvas.height === 0) return canvas.getContext("2d");
401
400
  if (canvas.width * canvas.height < COPY_CANVAS_ON_VOLUME_GREATER_THAN)
402
401
  return canvas.getContext("2d");
403
- console.log(
404
- "detected large canvas, copying to offscreen canvas for willReadFrequently"
405
- );
406
402
  const offscreen = document.createElement("canvas");
407
403
  offscreen.width = canvas.width;
408
404
  offscreen.height = canvas.height;
@@ -413,24 +409,23 @@ function getReadableCanvasContext(canvas) {
413
409
  return offscreen.getContext("2d", { willReadFrequently: true });
414
410
  }
415
411
  function is2DCanvasBlank(canvas) {
412
+ if (canvas.width === 0 || canvas.height === 0) return true;
416
413
  const ctx = getReadableCanvasContext(canvas);
417
414
  if (!ctx) return true;
418
- const chunkSize = 50;
415
+ const chunkSize = canvas.width > 512 || canvas.height > 512 ? 100 : 50;
416
+ const getImageData = ctx.getImageData;
417
+ const originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData;
419
418
  for (let x2 = 0; x2 < canvas.width; x2 += chunkSize) {
419
+ const w = Math.min(chunkSize, canvas.width - x2);
420
420
  for (let y = 0; y < canvas.height; y += chunkSize) {
421
- const getImageData = ctx.getImageData;
422
- const originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData;
421
+ const h = Math.min(chunkSize, canvas.height - y);
423
422
  const pixelBuffer = new Uint32Array(
424
423
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
425
- originalGetImageData.call(
426
- ctx,
427
- x2,
428
- y,
429
- Math.min(chunkSize, canvas.width - x2),
430
- Math.min(chunkSize, canvas.height - y)
431
- ).data.buffer
424
+ originalGetImageData.call(ctx, x2, y, w, h).data.buffer
432
425
  );
433
- if (pixelBuffer.some((pixel) => pixel !== 0)) return false;
426
+ for (let i2 = 0; i2 < pixelBuffer.length; i2++) {
427
+ if (pixelBuffer[i2] !== 0) return false;
428
+ }
434
429
  }
435
430
  }
436
431
  return true;
@@ -1043,7 +1038,10 @@ function serializeElementNode(n2, options) {
1043
1038
  }
1044
1039
  if (tagName === "canvas" && recordCanvas) {
1045
1040
  if (n2.__context === "2d") {
1046
- if (!is2DCanvasBlank(n2)) {
1041
+ console.time("canvas-blank-check");
1042
+ const tempBoolean = !is2DCanvasBlank(n2);
1043
+ console.timeEnd("canvas-blank-check");
1044
+ if (tempBoolean) {
1047
1045
  attributes.rr_dataURL = n2.toDataURL(
1048
1046
  dataURLOptions.type,
1049
1047
  dataURLOptions.quality