html2canvas-pro 2.3.5 → 2.3.7

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.3.5 <https://yorickshan.github.io/html2canvas-pro/>
2
+ * html2canvas-pro 2.3.7 <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
  */
@@ -7030,14 +7030,19 @@ var DocumentCloner = class {
7030
7030
  }
7031
7031
  if (clone.loading === "lazy") clone.loading = "eager";
7032
7032
  }
7033
- if (isCustomElement(clone) && !isSVGElementNode(clone)) return this.createCustomElementClone(clone);
7033
+ if (isCustomElement(clone) && !isSVGElementNode(clone)) return this.createCustomElementClone(node, clone);
7034
7034
  return clone;
7035
7035
  }
7036
- createCustomElementClone(node) {
7036
+ createCustomElementClone(originalNode, clonedNode) {
7037
7037
  const clone = document.createElement("div");
7038
- clone.className = node.className;
7039
- copyCSSStyles(node.style, clone);
7040
- if (node.shadowRoot) try {
7038
+ clone.className = clonedNode.className;
7039
+ copyCSSStyles(clonedNode.style, clone);
7040
+ const attributes = clonedNode.attributes;
7041
+ for (let i = 0; i < attributes.length; i++) {
7042
+ const attr = attributes[i];
7043
+ if (attr.name !== "class" && attr.name !== "style") clone.setAttribute(attr.name, attr.value);
7044
+ }
7045
+ if (originalNode.shadowRoot) try {
7041
7046
  clone.attachShadow({ mode: "open" });
7042
7047
  } catch (e) {
7043
7048
  this.context.logger.error("Failed to attach shadow root to custom element clone:", e);
@@ -7438,6 +7443,15 @@ var ElementContainer = class {
7438
7443
  this.originalElement = element;
7439
7444
  }
7440
7445
  this.bounds = parseBounds(this.context, element);
7446
+ if (element.tagName === "FIELDSET") {
7447
+ const legend = element.querySelector(":scope > legend");
7448
+ if (legend) {
7449
+ const legendBounds = parseBounds(this.context, legend);
7450
+ this.legendBounds = legendBounds;
7451
+ const borderBoxTop = legendBounds.top + legendBounds.height / 2 - this.styles.borderTopWidth / 2;
7452
+ this.bounds = new Bounds(this.bounds.left, borderBoxTop, this.bounds.width, this.bounds.height - (borderBoxTop - this.bounds.top));
7453
+ }
7454
+ }
7441
7455
  if (isDebugging(element, 4)) this.debugRender = true;
7442
7456
  }
7443
7457
  /**
@@ -9074,6 +9088,7 @@ const measureBaseline = (ctx, fallback) => {
9074
9088
  //#endregion
9075
9089
  //#region src/render/canvas/text-renderer.ts
9076
9090
  const iOSBrokenFonts = ["-apple-system", "system-ui"];
9091
+ const TEXT_OVERFLOW_EPSILON = 1;
9077
9092
  /**
9078
9093
  * Detect CJK (Chinese, Japanese, Korean) characters in a string.
9079
9094
  * CJK characters use the ideographic baseline in browsers, which differs
@@ -9376,7 +9391,7 @@ var TextRenderer = class {
9376
9391
  const firstTop = text.textBounds[0].bounds.top;
9377
9392
  if (!text.textBounds.every((tb) => Math.abs(tb.bounds.top - firstTop) < lineHeight * .5)) return false;
9378
9393
  let fullText = text.textBounds.map((tb) => tb.text).join("").replace(/\s+/g, " ").trim();
9379
- if (this.ctx.measureText(fullText).width <= containerBounds.width) return false;
9394
+ if (this.ctx.measureText(fullText).width <= containerBounds.width + TEXT_OVERFLOW_EPSILON) return false;
9380
9395
  const bounds = new TextBounds(this.truncateTextWithEllipsis(fullText, containerBounds.width, styles.letterSpacing), text.textBounds[0].bounds);
9381
9396
  for (const layer of paintOrder) if (layer === 0) this.renderTextFillWithShadows(bounds, styles, baseline);
9382
9397
  else if (layer === 1) this.renderTextStrokeWithStyle(bounds, styles, baseline);
@@ -10614,10 +10629,38 @@ var CanvasRenderer = class CanvasRenderer {
10614
10629
  }
10615
10630
  let side = 0;
10616
10631
  for (const border of borders) {
10617
- if (border.style !== 0 && !isTransparent(border.color) && border.width > 0) if (border.style === 2) await this.borderRenderer.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 2);
10618
- else if (border.style === 3) await this.borderRenderer.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 3);
10619
- else if (border.style === 4) await this.borderRenderer.renderDoubleBorder(border.color, border.width, side, paint.curves);
10620
- else await this.borderRenderer.renderSolidBorder(border.color, side, paint.curves);
10632
+ if (border.style !== 0 && !isTransparent(border.color) && border.width > 0) {
10633
+ const renderBorderSide = async () => {
10634
+ if (border.style === 2) await this.borderRenderer.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 2);
10635
+ else if (border.style === 3) await this.borderRenderer.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 3);
10636
+ else if (border.style === 4) await this.borderRenderer.renderDoubleBorder(border.color, border.width, side, paint.curves);
10637
+ else await this.borderRenderer.renderSolidBorder(border.color, side, paint.curves);
10638
+ };
10639
+ const legend = paint.container.legendBounds;
10640
+ if (side === 0 && legend) {
10641
+ const bounds = paint.container.bounds;
10642
+ const legendLeft = legend.left - bounds.left;
10643
+ const legendRight = legend.left + legend.width - bounds.left;
10644
+ if (legendLeft > 0) {
10645
+ this.ctx.save();
10646
+ this.ctx.beginPath();
10647
+ this.ctx.rect(bounds.left, bounds.top, legendLeft, bounds.height);
10648
+ this.ctx.clip();
10649
+ await renderBorderSide();
10650
+ this.ctx.restore();
10651
+ }
10652
+ const rightStart = bounds.left + legendRight;
10653
+ const rightWidth = bounds.width - legendRight;
10654
+ if (rightWidth > 0) {
10655
+ this.ctx.save();
10656
+ this.ctx.beginPath();
10657
+ this.ctx.rect(rightStart, bounds.top, rightWidth, bounds.height);
10658
+ this.ctx.clip();
10659
+ await renderBorderSide();
10660
+ this.ctx.restore();
10661
+ }
10662
+ } else await renderBorderSide();
10663
+ }
10621
10664
  side++;
10622
10665
  }
10623
10666
  }