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.cjs
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
|
*/
|
|
@@ -8086,6 +8086,39 @@ var CanvasElementContainer = class extends ElementContainer {
|
|
|
8086
8086
|
};
|
|
8087
8087
|
//#endregion
|
|
8088
8088
|
//#region src/dom/replaced-elements/svg-element-container.ts
|
|
8089
|
+
const BOX_OFFSET_PROPERTIES = [
|
|
8090
|
+
"position",
|
|
8091
|
+
"inset",
|
|
8092
|
+
"top",
|
|
8093
|
+
"right",
|
|
8094
|
+
"bottom",
|
|
8095
|
+
"left",
|
|
8096
|
+
"inset-inline",
|
|
8097
|
+
"inset-inline-start",
|
|
8098
|
+
"inset-inline-end",
|
|
8099
|
+
"inset-block",
|
|
8100
|
+
"inset-block-start",
|
|
8101
|
+
"inset-block-end",
|
|
8102
|
+
"margin",
|
|
8103
|
+
"margin-top",
|
|
8104
|
+
"margin-right",
|
|
8105
|
+
"margin-bottom",
|
|
8106
|
+
"margin-left",
|
|
8107
|
+
"margin-inline",
|
|
8108
|
+
"margin-inline-start",
|
|
8109
|
+
"margin-inline-end",
|
|
8110
|
+
"margin-block",
|
|
8111
|
+
"margin-block-start",
|
|
8112
|
+
"margin-block-end"
|
|
8113
|
+
];
|
|
8114
|
+
const serializeWithoutBoxOffsets = (serializer, img) => {
|
|
8115
|
+
const style = img.getAttribute("style");
|
|
8116
|
+
BOX_OFFSET_PROPERTIES.forEach((property) => img.style.removeProperty(property));
|
|
8117
|
+
const serialized = serializer.serializeToString(img);
|
|
8118
|
+
if (style === null) img.removeAttribute("style");
|
|
8119
|
+
else img.setAttribute("style", style);
|
|
8120
|
+
return serialized;
|
|
8121
|
+
};
|
|
8089
8122
|
var SVGElementContainer = class extends ElementContainer {
|
|
8090
8123
|
constructor(context, img) {
|
|
8091
8124
|
super(context, img);
|
|
@@ -8093,7 +8126,7 @@ var SVGElementContainer = class extends ElementContainer {
|
|
|
8093
8126
|
const bounds = parseBounds(context, img);
|
|
8094
8127
|
img.setAttribute("width", `${bounds.width}px`);
|
|
8095
8128
|
img.setAttribute("height", `${bounds.height}px`);
|
|
8096
|
-
this.svg = `data:image/svg+xml,${encodeURIComponent(s
|
|
8129
|
+
this.svg = `data:image/svg+xml,${encodeURIComponent(serializeWithoutBoxOffsets(s, img))}`;
|
|
8097
8130
|
this.intrinsicWidth = img.width.baseVal.value;
|
|
8098
8131
|
this.intrinsicHeight = img.height.baseVal.value;
|
|
8099
8132
|
this.context.cache.addImage(this.svg);
|
|
@@ -9700,21 +9733,20 @@ var BackgroundRenderer = class {
|
|
|
9700
9733
|
}
|
|
9701
9734
|
if (rx > 0 && ry > 0) {
|
|
9702
9735
|
const cacheKey = `rg|${Math.round(x)}x${Math.round(y)}|${Math.round(rx)}x${Math.round(ry)}|${JSON.stringify(backgroundImage.stops)}`;
|
|
9736
|
+
const stops = processColorStops(backgroundImage.stops, rx * 2);
|
|
9737
|
+
const lastStop = stops[stops.length - 1];
|
|
9703
9738
|
let pattern = this.patternCache.get(cacheKey);
|
|
9704
9739
|
if (!pattern) {
|
|
9705
|
-
const
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
offscreen.width = size;
|
|
9709
|
-
offscreen.height = size;
|
|
9740
|
+
const offscreen = (this.canvas.ownerDocument ?? document).createElement("canvas");
|
|
9741
|
+
offscreen.width = Math.ceil(rx * 2);
|
|
9742
|
+
offscreen.height = Math.ceil(ry * 2);
|
|
9710
9743
|
const offCtx = offscreen.getContext("2d");
|
|
9711
9744
|
if (offCtx) {
|
|
9712
|
-
const
|
|
9713
|
-
|
|
9714
|
-
processColorStops(backgroundImage.stops, offRadius * 2).forEach((s) => gradient.addColorStop(s.stop, asString(s.color)));
|
|
9745
|
+
const gradient = offCtx.createRadialGradient(rx, rx, 0, rx, rx, rx);
|
|
9746
|
+
stops.forEach((s) => gradient.addColorStop(s.stop, asString(s.color)));
|
|
9715
9747
|
offCtx.fillStyle = gradient;
|
|
9716
9748
|
if (rx !== ry) offCtx.scale(1, ry / rx);
|
|
9717
|
-
offCtx.fillRect(0, 0,
|
|
9749
|
+
offCtx.fillRect(0, 0, rx * 2, rx * 2);
|
|
9718
9750
|
pattern = this.ctx.createPattern(offscreen, "no-repeat");
|
|
9719
9751
|
this.patternCache.set(cacheKey, pattern);
|
|
9720
9752
|
}
|
|
@@ -9723,9 +9755,13 @@ var BackgroundRenderer = class {
|
|
|
9723
9755
|
this.path(path);
|
|
9724
9756
|
this.ctx.save();
|
|
9725
9757
|
this.ctx.clip();
|
|
9726
|
-
|
|
9758
|
+
if (lastStop) {
|
|
9759
|
+
this.ctx.fillStyle = asString(lastStop.color);
|
|
9760
|
+
this.ctx.fill();
|
|
9761
|
+
}
|
|
9762
|
+
this.ctx.translate(left + x - rx, top + y - ry);
|
|
9727
9763
|
this.ctx.fillStyle = pattern;
|
|
9728
|
-
this.ctx.fillRect(0, 0,
|
|
9764
|
+
this.ctx.fillRect(0, 0, rx * 2, ry * 2);
|
|
9729
9765
|
this.ctx.restore();
|
|
9730
9766
|
}
|
|
9731
9767
|
}
|