@glimt/record 0.0.14 → 0.0.15
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 +18 -6
- package/dist/record.cjs.map +1 -1
- package/dist/record.js +18 -6
- package/dist/record.js.map +1 -1
- package/dist/record.umd.cjs +18 -6
- package/dist/record.umd.cjs.map +2 -2
- package/dist/record.umd.min.cjs +23 -23
- package/dist/record.umd.min.cjs.map +3 -3
- package/package.json +1 -1
package/dist/record.cjs
CHANGED
|
@@ -363,19 +363,31 @@ function toLowerCase(str) {
|
|
|
363
363
|
return str.toLowerCase();
|
|
364
364
|
}
|
|
365
365
|
const ORIGINAL_ATTRIBUTE_NAME = "__rrweb_original__";
|
|
366
|
+
const COPY_CANVAS_ON_VOLUME_GREATER_THAN = 25e4;
|
|
367
|
+
function getReadableCanvasContext(canvas) {
|
|
368
|
+
if (canvas.width === 0 || canvas.height === 0) return canvas.getContext("2d");
|
|
369
|
+
if (canvas.width * canvas.height < COPY_CANVAS_ON_VOLUME_GREATER_THAN)
|
|
370
|
+
return canvas.getContext("2d");
|
|
371
|
+
console.log(
|
|
372
|
+
"detected large canvas, copying to offscreen canvas for willReadFrequently"
|
|
373
|
+
);
|
|
374
|
+
const offscreen = document.createElement("canvas");
|
|
375
|
+
offscreen.width = canvas.width;
|
|
376
|
+
offscreen.height = canvas.height;
|
|
377
|
+
const ctx = offscreen.getContext("2d");
|
|
378
|
+
if (ctx) {
|
|
379
|
+
ctx.drawImage(canvas, 0, 0);
|
|
380
|
+
}
|
|
381
|
+
return offscreen.getContext("2d", { willReadFrequently: true });
|
|
382
|
+
}
|
|
366
383
|
function is2DCanvasBlank(canvas) {
|
|
367
|
-
|
|
368
|
-
const ctx = canvas.getContext("2d", {
|
|
369
|
-
willReadFrequently: true
|
|
370
|
-
});
|
|
384
|
+
const ctx = getReadableCanvasContext(canvas);
|
|
371
385
|
if (!ctx) return true;
|
|
372
386
|
const chunkSize = 50;
|
|
373
387
|
for (let x2 = 0; x2 < canvas.width; x2 += chunkSize) {
|
|
374
388
|
for (let y = 0; y < canvas.height; y += chunkSize) {
|
|
375
389
|
const getImageData = ctx.getImageData;
|
|
376
390
|
const originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData;
|
|
377
|
-
console.log("Calling getImageData on ctx:", ctx);
|
|
378
|
-
console.trace();
|
|
379
391
|
const pixelBuffer = new Uint32Array(
|
|
380
392
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
381
393
|
originalGetImageData.call(
|