html2canvas-pro 1.6.2 → 1.6.4

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 1.6.2 <https://yorickshan.github.io/html2canvas-pro/>
2
+ * html2canvas-pro 1.6.4 <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
  */
@@ -6063,7 +6063,20 @@ class DocumentCloner {
6063
6063
  * */
6064
6064
  const baseUri = documentClone.baseURI;
6065
6065
  documentClone.open();
6066
- documentClone.write(`${serializeDoctype(document.doctype)}<html></html>`);
6066
+ try {
6067
+ // fixing "This document requires 'TrustedHTML' assignment. The action has been blocked." error
6068
+ // @ts-ignore
6069
+ const policy = trustedTypes.createPolicy('my-policy', {
6070
+ createHTML: (string) => string
6071
+ });
6072
+ const rawHTML = serializeDoctype(document.doctype) + '<html></html>';
6073
+ const trustedHTML = policy.createHTML(rawHTML);
6074
+ documentClone.write(trustedHTML);
6075
+ }
6076
+ catch (e) {
6077
+ // if browser does not support trustedTypes
6078
+ documentClone.write(serializeDoctype(document.doctype) + '<html></html>');
6079
+ }
6067
6080
  // Chrome scrolls the parent document for some reason after the write to the cloned window???
6068
6081
  restoreOwnerScroll(this.referenceElement.ownerDocument, scrollX, scrollY);
6069
6082
  /**
@@ -7982,7 +7995,13 @@ class CanvasRenderer extends Renderer {
7982
7995
  const position = backgroundImage.position.length === 0 ? [FIFTY_PERCENT] : backgroundImage.position;
7983
7996
  const x = getAbsoluteValue(position[0], width);
7984
7997
  const y = getAbsoluteValue(position[position.length - 1], height);
7985
- const [rx, ry] = calculateRadius(backgroundImage, x, y, width, height);
7998
+ let [rx, ry] = calculateRadius(backgroundImage, x, y, width, height);
7999
+ // Handle edge case where radial gradient size is 0
8000
+ // Use a minimum value of 0.01 to ensure gradient is still rendered
8001
+ if (rx === 0 || ry === 0) {
8002
+ rx = Math.max(rx, 0.01);
8003
+ ry = Math.max(ry, 0.01);
8004
+ }
7986
8005
  if (rx > 0 && ry > 0) {
7987
8006
  const radialGradient = this.ctx.createRadialGradient(left + x, top + y, 0, left + x, top + y, rx);
7988
8007
  processColorStops(backgroundImage.stops, rx * 2).forEach((colorStop) => radialGradient.addColorStop(colorStop.stop, asString(colorStop.color)));