@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.
package/dist/record.cjs CHANGED
@@ -365,12 +365,8 @@ function toLowerCase(str) {
365
365
  const ORIGINAL_ATTRIBUTE_NAME = "__rrweb_original__";
366
366
  const COPY_CANVAS_ON_VOLUME_GREATER_THAN = 25e4;
367
367
  function getReadableCanvasContext(canvas) {
368
- if (canvas.width === 0 || canvas.height === 0) return canvas.getContext("2d");
369
368
  if (canvas.width * canvas.height < COPY_CANVAS_ON_VOLUME_GREATER_THAN)
370
369
  return canvas.getContext("2d");
371
- console.log(
372
- "detected large canvas, copying to offscreen canvas for willReadFrequently"
373
- );
374
370
  const offscreen = document.createElement("canvas");
375
371
  offscreen.width = canvas.width;
376
372
  offscreen.height = canvas.height;
@@ -381,24 +377,23 @@ function getReadableCanvasContext(canvas) {
381
377
  return offscreen.getContext("2d", { willReadFrequently: true });
382
378
  }
383
379
  function is2DCanvasBlank(canvas) {
380
+ if (canvas.width === 0 || canvas.height === 0) return true;
384
381
  const ctx = getReadableCanvasContext(canvas);
385
382
  if (!ctx) return true;
386
- const chunkSize = 50;
383
+ const chunkSize = canvas.width > 512 || canvas.height > 512 ? 100 : 50;
384
+ const getImageData = ctx.getImageData;
385
+ const originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData;
387
386
  for (let x2 = 0; x2 < canvas.width; x2 += chunkSize) {
387
+ const w = Math.min(chunkSize, canvas.width - x2);
388
388
  for (let y = 0; y < canvas.height; y += chunkSize) {
389
- const getImageData = ctx.getImageData;
390
- const originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData;
389
+ const h = Math.min(chunkSize, canvas.height - y);
391
390
  const pixelBuffer = new Uint32Array(
392
391
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
393
- originalGetImageData.call(
394
- ctx,
395
- x2,
396
- y,
397
- Math.min(chunkSize, canvas.width - x2),
398
- Math.min(chunkSize, canvas.height - y)
399
- ).data.buffer
392
+ originalGetImageData.call(ctx, x2, y, w, h).data.buffer
400
393
  );
401
- if (pixelBuffer.some((pixel) => pixel !== 0)) return false;
394
+ for (let i2 = 0; i2 < pixelBuffer.length; i2++) {
395
+ if (pixelBuffer[i2] !== 0) return false;
396
+ }
402
397
  }
403
398
  }
404
399
  return true;
@@ -1010,7 +1005,10 @@ function serializeElementNode(n2, options) {
1010
1005
  }
1011
1006
  if (tagName === "canvas" && recordCanvas) {
1012
1007
  if (n2.__context === "2d") {
1013
- if (!is2DCanvasBlank(n2)) {
1008
+ console.time("canvas-blank-check");
1009
+ const tempBoolean = !is2DCanvasBlank(n2);
1010
+ console.timeEnd("canvas-blank-check");
1011
+ if (tempBoolean) {
1014
1012
  attributes.rr_dataURL = n2.toDataURL(
1015
1013
  dataURLOptions.type,
1016
1014
  dataURLOptions.quality