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