@posthog/rrweb-snapshot 0.0.29 → 0.0.30
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/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/rrweb-snapshot.cjs +57 -3
- package/dist/rrweb-snapshot.cjs.map +1 -1
- package/dist/rrweb-snapshot.js +57 -3
- package/dist/rrweb-snapshot.js.map +1 -1
- package/dist/rrweb-snapshot.umd.cjs +57 -3
- package/dist/rrweb-snapshot.umd.cjs.map +2 -2
- package/dist/rrweb-snapshot.umd.min.cjs +23 -23
- package/dist/rrweb-snapshot.umd.min.cjs.map +3 -3
- package/package.json +1 -1
package/dist/rrweb-snapshot.js
CHANGED
|
@@ -468,6 +468,36 @@ function absolutifyURLs(cssText, href) {
|
|
|
468
468
|
}
|
|
469
469
|
);
|
|
470
470
|
}
|
|
471
|
+
const STRIPED_PLACEHOLDER_SVG = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxkZWZzPgogICAgPHBhdHRlcm4gaWQ9InN0cmlwZXMiIHBhdHRlcm5Vbml0cz0idXNlclNwYWNlT25Vc2UiIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiI+CiAgICAgIDxyZWN0IHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgZmlsbD0iYmxhY2siLz4KICAgICAgPHBhdGggZD0iTTggMEgxNkwwIDE2VjhMOCAwWiIgZmlsbD0iIzJEMkQyRCIvPgogICAgICA8cGF0aCBkPSJNMTYgOFYxNkg4TDE2IDhaIiBmaWxsPSIjMkQyRDJEIi8+CiAgICA8L3BhdHRlcm4+CiAgPC9kZWZzPgogIDxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjc3RyaXBlcykiLz4KPC9zdmc+Cg==";
|
|
472
|
+
const MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION = 4096;
|
|
473
|
+
function recompressBase64Image(img, dataURL, type, quality) {
|
|
474
|
+
if (!img.complete || img.naturalWidth === 0) {
|
|
475
|
+
return dataURL;
|
|
476
|
+
}
|
|
477
|
+
if (img.naturalWidth > MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION || img.naturalHeight > MAX_IMAGE_DIMENSION_FOR_RECOMPRESSION) {
|
|
478
|
+
return dataURL;
|
|
479
|
+
}
|
|
480
|
+
try {
|
|
481
|
+
const canvas = document.createElement("canvas");
|
|
482
|
+
canvas.width = img.naturalWidth;
|
|
483
|
+
canvas.height = img.naturalHeight;
|
|
484
|
+
const ctx = canvas.getContext("2d");
|
|
485
|
+
if (!ctx) {
|
|
486
|
+
return dataURL;
|
|
487
|
+
}
|
|
488
|
+
ctx.drawImage(img, 0, 0);
|
|
489
|
+
const recompressed = canvas.toDataURL(type || "image/webp", quality ?? 0.4);
|
|
490
|
+
return recompressed;
|
|
491
|
+
} catch (err) {
|
|
492
|
+
return dataURL;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function checkDataURLSize(dataURL, maxLength) {
|
|
496
|
+
if (!maxLength || dataURL.length <= maxLength) {
|
|
497
|
+
return dataURL;
|
|
498
|
+
}
|
|
499
|
+
return STRIPED_PLACEHOLDER_SVG;
|
|
500
|
+
}
|
|
471
501
|
let _id = 1;
|
|
472
502
|
const tagNameRegex = new RegExp("[^a-z0-9-_:]");
|
|
473
503
|
const IGNORED_NODE = -2;
|
|
@@ -566,12 +596,32 @@ function getHref(doc, customHref) {
|
|
|
566
596
|
a.setAttribute("href", customHref);
|
|
567
597
|
return a.href;
|
|
568
598
|
}
|
|
569
|
-
function transformAttribute(doc, tagName, name, value) {
|
|
599
|
+
function transformAttribute(doc, tagName, name, value, element, dataURLOptions) {
|
|
570
600
|
if (!value) {
|
|
571
601
|
return value;
|
|
572
602
|
}
|
|
573
603
|
if (name === "src" || name === "href" && !(tagName === "use" && value[0] === "#")) {
|
|
574
|
-
|
|
604
|
+
const transformedValue = absoluteToDoc(doc, value);
|
|
605
|
+
if (tagName === "img" && transformedValue.startsWith("data:") && element) {
|
|
606
|
+
const img = element;
|
|
607
|
+
let processedDataURL = transformedValue;
|
|
608
|
+
if ((dataURLOptions == null ? void 0 : dataURLOptions.type) || (dataURLOptions == null ? void 0 : dataURLOptions.quality) !== void 0) {
|
|
609
|
+
processedDataURL = recompressBase64Image(
|
|
610
|
+
img,
|
|
611
|
+
transformedValue,
|
|
612
|
+
dataURLOptions.type,
|
|
613
|
+
dataURLOptions.quality
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
if (dataURLOptions == null ? void 0 : dataURLOptions.maxBase64ImageLength) {
|
|
617
|
+
processedDataURL = checkDataURLSize(
|
|
618
|
+
processedDataURL,
|
|
619
|
+
dataURLOptions.maxBase64ImageLength
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
return processedDataURL;
|
|
623
|
+
}
|
|
624
|
+
return transformedValue;
|
|
575
625
|
} else if (name === "xlink:href" && value[0] !== "#") {
|
|
576
626
|
return absoluteToDoc(doc, value);
|
|
577
627
|
} else if (name === "background" && (tagName === "table" || tagName === "td" || tagName === "th")) {
|
|
@@ -862,7 +912,9 @@ function serializeElementNode(n, options) {
|
|
|
862
912
|
doc,
|
|
863
913
|
tagName,
|
|
864
914
|
toLowerCase(attr.name),
|
|
865
|
-
attr.value
|
|
915
|
+
attr.value,
|
|
916
|
+
n,
|
|
917
|
+
dataURLOptions
|
|
866
918
|
);
|
|
867
919
|
}
|
|
868
920
|
}
|
|
@@ -5734,6 +5786,7 @@ export {
|
|
|
5734
5786
|
absolutifyURLs,
|
|
5735
5787
|
adaptCssForReplay,
|
|
5736
5788
|
buildNodeWithSN,
|
|
5789
|
+
checkDataURLSize,
|
|
5737
5790
|
classMatchesRegex,
|
|
5738
5791
|
cleanupSnapshot,
|
|
5739
5792
|
createCache,
|
|
@@ -5754,6 +5807,7 @@ export {
|
|
|
5754
5807
|
maskInputValue,
|
|
5755
5808
|
needMaskingText,
|
|
5756
5809
|
rebuild,
|
|
5810
|
+
recompressBase64Image,
|
|
5757
5811
|
serializeNodeWithId,
|
|
5758
5812
|
snapshot,
|
|
5759
5813
|
stringifyRule,
|