html2canvas-pro 2.4.0 → 2.4.2
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/html2canvas-pro.cjs +49 -13
- package/dist/html2canvas-pro.cjs.map +1 -1
- package/dist/html2canvas-pro.esm.js +49 -13
- package/dist/html2canvas-pro.esm.js.map +1 -1
- package/dist/html2canvas-pro.js +49 -13
- package/dist/html2canvas-pro.js.map +1 -1
- package/dist/html2canvas-pro.min.js +4 -4
- package/dist/lib/dom/replaced-elements/svg-element-container.js +40 -2
- package/dist/lib/render/canvas/background-renderer.js +20 -9
- package/dist/types/dom/replaced-elements/svg-element-container.d.ts +1 -0
- package/package.json +1 -1
package/dist/html2canvas-pro.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* html2canvas-pro 2.4.
|
|
2
|
+
* html2canvas-pro 2.4.2 <https://yorickshan.github.io/html2canvas-pro/>
|
|
3
3
|
* Copyright (c) 2024-present yorickshan and html2canvas-pro contributors
|
|
4
4
|
* Released under MIT License
|
|
5
5
|
*/
|
|
@@ -8089,6 +8089,39 @@
|
|
|
8089
8089
|
};
|
|
8090
8090
|
//#endregion
|
|
8091
8091
|
//#region src/dom/replaced-elements/svg-element-container.ts
|
|
8092
|
+
const BOX_OFFSET_PROPERTIES = [
|
|
8093
|
+
"position",
|
|
8094
|
+
"inset",
|
|
8095
|
+
"top",
|
|
8096
|
+
"right",
|
|
8097
|
+
"bottom",
|
|
8098
|
+
"left",
|
|
8099
|
+
"inset-inline",
|
|
8100
|
+
"inset-inline-start",
|
|
8101
|
+
"inset-inline-end",
|
|
8102
|
+
"inset-block",
|
|
8103
|
+
"inset-block-start",
|
|
8104
|
+
"inset-block-end",
|
|
8105
|
+
"margin",
|
|
8106
|
+
"margin-top",
|
|
8107
|
+
"margin-right",
|
|
8108
|
+
"margin-bottom",
|
|
8109
|
+
"margin-left",
|
|
8110
|
+
"margin-inline",
|
|
8111
|
+
"margin-inline-start",
|
|
8112
|
+
"margin-inline-end",
|
|
8113
|
+
"margin-block",
|
|
8114
|
+
"margin-block-start",
|
|
8115
|
+
"margin-block-end"
|
|
8116
|
+
];
|
|
8117
|
+
const serializeWithoutBoxOffsets = (serializer, img) => {
|
|
8118
|
+
const style = img.getAttribute("style");
|
|
8119
|
+
BOX_OFFSET_PROPERTIES.forEach((property) => img.style.removeProperty(property));
|
|
8120
|
+
const serialized = serializer.serializeToString(img);
|
|
8121
|
+
if (style === null) img.removeAttribute("style");
|
|
8122
|
+
else img.setAttribute("style", style);
|
|
8123
|
+
return serialized;
|
|
8124
|
+
};
|
|
8092
8125
|
var SVGElementContainer = class extends ElementContainer {
|
|
8093
8126
|
constructor(context, img) {
|
|
8094
8127
|
super(context, img);
|
|
@@ -8096,7 +8129,7 @@
|
|
|
8096
8129
|
const bounds = parseBounds(context, img);
|
|
8097
8130
|
img.setAttribute("width", `${bounds.width}px`);
|
|
8098
8131
|
img.setAttribute("height", `${bounds.height}px`);
|
|
8099
|
-
this.svg = `data:image/svg+xml,${encodeURIComponent(s
|
|
8132
|
+
this.svg = `data:image/svg+xml,${encodeURIComponent(serializeWithoutBoxOffsets(s, img))}`;
|
|
8100
8133
|
this.intrinsicWidth = img.width.baseVal.value;
|
|
8101
8134
|
this.intrinsicHeight = img.height.baseVal.value;
|
|
8102
8135
|
this.context.cache.addImage(this.svg);
|
|
@@ -9703,21 +9736,20 @@
|
|
|
9703
9736
|
}
|
|
9704
9737
|
if (rx > 0 && ry > 0) {
|
|
9705
9738
|
const cacheKey = `rg|${Math.round(x)}x${Math.round(y)}|${Math.round(rx)}x${Math.round(ry)}|${JSON.stringify(backgroundImage.stops)}`;
|
|
9739
|
+
const stops = processColorStops(backgroundImage.stops, rx * 2);
|
|
9740
|
+
const lastStop = stops[stops.length - 1];
|
|
9706
9741
|
let pattern = this.patternCache.get(cacheKey);
|
|
9707
9742
|
if (!pattern) {
|
|
9708
|
-
const
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
offscreen.width = size;
|
|
9712
|
-
offscreen.height = size;
|
|
9743
|
+
const offscreen = (this.canvas.ownerDocument ?? document).createElement("canvas");
|
|
9744
|
+
offscreen.width = Math.ceil(rx * 2);
|
|
9745
|
+
offscreen.height = Math.ceil(ry * 2);
|
|
9713
9746
|
const offCtx = offscreen.getContext("2d");
|
|
9714
9747
|
if (offCtx) {
|
|
9715
|
-
const
|
|
9716
|
-
|
|
9717
|
-
processColorStops(backgroundImage.stops, offRadius * 2).forEach((s) => gradient.addColorStop(s.stop, asString(s.color)));
|
|
9748
|
+
const gradient = offCtx.createRadialGradient(rx, rx, 0, rx, rx, rx);
|
|
9749
|
+
stops.forEach((s) => gradient.addColorStop(s.stop, asString(s.color)));
|
|
9718
9750
|
offCtx.fillStyle = gradient;
|
|
9719
9751
|
if (rx !== ry) offCtx.scale(1, ry / rx);
|
|
9720
|
-
offCtx.fillRect(0, 0,
|
|
9752
|
+
offCtx.fillRect(0, 0, rx * 2, rx * 2);
|
|
9721
9753
|
pattern = this.ctx.createPattern(offscreen, "no-repeat");
|
|
9722
9754
|
this.patternCache.set(cacheKey, pattern);
|
|
9723
9755
|
}
|
|
@@ -9726,9 +9758,13 @@
|
|
|
9726
9758
|
this.path(path);
|
|
9727
9759
|
this.ctx.save();
|
|
9728
9760
|
this.ctx.clip();
|
|
9729
|
-
|
|
9761
|
+
if (lastStop) {
|
|
9762
|
+
this.ctx.fillStyle = asString(lastStop.color);
|
|
9763
|
+
this.ctx.fill();
|
|
9764
|
+
}
|
|
9765
|
+
this.ctx.translate(left + x - rx, top + y - ry);
|
|
9730
9766
|
this.ctx.fillStyle = pattern;
|
|
9731
|
-
this.ctx.fillRect(0, 0,
|
|
9767
|
+
this.ctx.fillRect(0, 0, rx * 2, ry * 2);
|
|
9732
9768
|
this.ctx.restore();
|
|
9733
9769
|
}
|
|
9734
9770
|
}
|