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
  */
@@ -7037,14 +7037,19 @@
7037
7037
  }
7038
7038
  if (clone.loading === "lazy") clone.loading = "eager";
7039
7039
  }
7040
- if (isCustomElement(clone) && !isSVGElementNode(clone)) return this.createCustomElementClone(clone);
7040
+ if (isCustomElement(clone) && !isSVGElementNode(clone)) return this.createCustomElementClone(node, clone);
7041
7041
  return clone;
7042
7042
  }
7043
- createCustomElementClone(node) {
7043
+ createCustomElementClone(originalNode, clonedNode) {
7044
7044
  const clone = document.createElement("div");
7045
- clone.className = node.className;
7046
- copyCSSStyles(node.style, clone);
7047
- if (node.shadowRoot) try {
7045
+ clone.className = clonedNode.className;
7046
+ copyCSSStyles(clonedNode.style, clone);
7047
+ const attributes = clonedNode.attributes;
7048
+ for (let i = 0; i < attributes.length; i++) {
7049
+ const attr = attributes[i];
7050
+ if (attr.name !== "class" && attr.name !== "style") clone.setAttribute(attr.name, attr.value);
7051
+ }
7052
+ if (originalNode.shadowRoot) try {
7048
7053
  clone.attachShadow({ mode: "open" });
7049
7054
  } catch (e) {
7050
7055
  this.context.logger.error("Failed to attach shadow root to custom element clone:", e);
@@ -7445,6 +7450,15 @@
7445
7450
  this.originalElement = element;
7446
7451
  }
7447
7452
  this.bounds = parseBounds(this.context, element);
7453
+ if (element.tagName === "FIELDSET") {
7454
+ const legend = element.querySelector(":scope > legend");
7455
+ if (legend) {
7456
+ const legendBounds = parseBounds(this.context, legend);
7457
+ this.legendBounds = legendBounds;
7458
+ const borderBoxTop = legendBounds.top + legendBounds.height / 2 - this.styles.borderTopWidth / 2;
7459
+ this.bounds = new Bounds(this.bounds.left, borderBoxTop, this.bounds.width, this.bounds.height - (borderBoxTop - this.bounds.top));
7460
+ }
7461
+ }
7448
7462
  if (isDebugging(element, 4)) this.debugRender = true;
7449
7463
  }
7450
7464
  /**
@@ -9081,6 +9095,7 @@
9081
9095
  //#endregion
9082
9096
  //#region src/render/canvas/text-renderer.ts
9083
9097
  const iOSBrokenFonts = ["-apple-system", "system-ui"];
9098
+ const TEXT_OVERFLOW_EPSILON = 1;
9084
9099
  /**
9085
9100
  * Detect CJK (Chinese, Japanese, Korean) characters in a string.
9086
9101
  * CJK characters use the ideographic baseline in browsers, which differs
@@ -9383,7 +9398,7 @@
9383
9398
  const firstTop = text.textBounds[0].bounds.top;
9384
9399
  if (!text.textBounds.every((tb) => Math.abs(tb.bounds.top - firstTop) < lineHeight * .5)) return false;
9385
9400
  let fullText = text.textBounds.map((tb) => tb.text).join("").replace(/\s+/g, " ").trim();
9386
- if (this.ctx.measureText(fullText).width <= containerBounds.width) return false;
9401
+ if (this.ctx.measureText(fullText).width <= containerBounds.width + TEXT_OVERFLOW_EPSILON) return false;
9387
9402
  const bounds = new TextBounds(this.truncateTextWithEllipsis(fullText, containerBounds.width, styles.letterSpacing), text.textBounds[0].bounds);
9388
9403
  for (const layer of paintOrder) if (layer === 0) this.renderTextFillWithShadows(bounds, styles, baseline);
9389
9404
  else if (layer === 1) this.renderTextStrokeWithStyle(bounds, styles, baseline);
@@ -10621,10 +10636,38 @@
10621
10636
  }
10622
10637
  let side = 0;
10623
10638
  for (const border of borders) {
10624
- 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);
10625
- else if (border.style === 3) await this.borderRenderer.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 3);
10626
- else if (border.style === 4) await this.borderRenderer.renderDoubleBorder(border.color, border.width, side, paint.curves);
10627
- else await this.borderRenderer.renderSolidBorder(border.color, side, paint.curves);
10639
+ if (border.style !== 0 && !isTransparent(border.color) && border.width > 0) {
10640
+ const renderBorderSide = async () => {
10641
+ if (border.style === 2) await this.borderRenderer.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 2);
10642
+ else if (border.style === 3) await this.borderRenderer.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 3);
10643
+ else if (border.style === 4) await this.borderRenderer.renderDoubleBorder(border.color, border.width, side, paint.curves);
10644
+ else await this.borderRenderer.renderSolidBorder(border.color, side, paint.curves);
10645
+ };
10646
+ const legend = paint.container.legendBounds;
10647
+ if (side === 0 && legend) {
10648
+ const bounds = paint.container.bounds;
10649
+ const legendLeft = legend.left - bounds.left;
10650
+ const legendRight = legend.left + legend.width - bounds.left;
10651
+ if (legendLeft > 0) {
10652
+ this.ctx.save();
10653
+ this.ctx.beginPath();
10654
+ this.ctx.rect(bounds.left, bounds.top, legendLeft, bounds.height);
10655
+ this.ctx.clip();
10656
+ await renderBorderSide();
10657
+ this.ctx.restore();
10658
+ }
10659
+ const rightStart = bounds.left + legendRight;
10660
+ const rightWidth = bounds.width - legendRight;
10661
+ if (rightWidth > 0) {
10662
+ this.ctx.save();
10663
+ this.ctx.beginPath();
10664
+ this.ctx.rect(rightStart, bounds.top, rightWidth, bounds.height);
10665
+ this.ctx.clip();
10666
+ await renderBorderSide();
10667
+ this.ctx.restore();
10668
+ }
10669
+ } else await renderBorderSide();
10670
+ }
10628
10671
  side++;
10629
10672
  }
10630
10673
  }