html2canvas-pro 1.5.5 → 1.5.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.
package/README.md CHANGED
@@ -1,19 +1,36 @@
1
- # html2canvas-pro
2
-
3
- [![npm version](https://badgen.net/npm/v/html2canvas-pro)](https://npm.im/html2canvas-pro) [![npm downloads](https://badgen.net/npm/dm/html2canvas-pro)](https://npm.im/html2canvas-pro)
4
-
5
- > A fork of [niklasvh/html2canvas](https://github.com/niklasvh/html2canvas) with some new features. If you found this helpful, don't forget to leave a star.
6
-
7
- ## 🌟 Why html2canvas-pro?
8
-
9
- html2canvas-pro has several advantages over html2canvas, including:
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/yorickshan/html2canvas-pro/main/docs/public/logo.png" height="150">
3
+ </p>
4
+ <h1 align="center">
5
+ html2canvas-pro
6
+ </h1>
7
+ <p align="center">
8
+ Next generation JavaScript screenshots tool.
9
+ <p>
10
+ <p align="center">
11
+ <a href="https://github.com/yorickshan/html2canvas-pro/actions/workflows/ci.yml"><img src="https://github.com/yorickshan/html2canvas-pro/actions/workflows/ci.yml/badge.svg?branch=main" alt="build status"></a>
12
+ <a href=https://npm.im/html2canvas-pro><img src="https://badgen.net/npm/v/html2canvas-pro" alt="npm version"></a>
13
+ <a href=http://npm.im/html2canvas-pro><img src="https://badgen.net/npm/dm/html2canvas-pro" alt="npm downloads"></a>
14
+ <a href="https://www.jsdelivr.com/package/npm/html2canvas-pro"><img src="https://data.jsdelivr.com/v1/package/npm/html2canvas-pro/badge" /></a>
15
+ <p>
16
+ <p align="center">
17
+ <a href="https://yorickshan.github.io/html2canvas-pro/">Documentation</a> | <a href="https://yorickshan.github.io/html2canvas-pro/getting-started.html">Getting Started</a>
18
+ </p>
19
+ <br>
20
+
21
+ ## Why html2canvas-pro?
22
+
23
+ html2canvas-pro is a fork of [niklasvh/html2canvas](https://github.com/niklasvh/html2canvas) that includes various fixes and new features. It offers several advantages over the original html2canvas, such as:
10
24
  - support color function ```color()``` (including relative colors)
11
25
  - support color function ```lab()```
12
26
  - support color function ```lch()```
13
27
  - support color function ```oklab()```
14
28
  - support color function ```oklch()```
15
29
  - Support object-fit of ```<img/>```
16
- - Fixed some known [issues](./CHANGELOG.md)
30
+ - Fixed some [issues](./CHANGELOG.md)
31
+
32
+ If you found this helpful, don't forget to
33
+ leave a star 🌟.
17
34
 
18
35
  ## Installation
19
36
 
@@ -27,7 +44,7 @@ pnpm / yarn add html2canvas-pro
27
44
  import html2canvas from 'html2canvas-pro';
28
45
  ```
29
46
 
30
- To render an `element` with html2canvas with some (optional) [options](/docs/configuration.md), simply call `html2canvas(element, options);`
47
+ To render an `element` with html2canvas-pro with some (optional) [options](/docs/configuration.md), simply call `html2canvas(element, options);`
31
48
 
32
49
  ```javascript
33
50
  html2canvas(document.body).then(function(canvas) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * html2canvas-pro 1.5.5 <undefined>
2
+ * undefined 1.5.7 <https://yorickshan.github.io/html2canvas-pro/>
3
3
  * Copyright (c) 2024 yorickshan <https://github.com/yorickshan>
4
4
  * Released under MIT License
5
5
  */
@@ -2554,7 +2554,7 @@ var _color = function (context, args) {
2554
2554
  .replace(/r|x/, color[0].toString())
2555
2555
  .replace(/g|y/, color[1].toString())
2556
2556
  .replace(/b|z/, color[2].toString());
2557
- return eval(expression);
2557
+ return new Function('return ' + expression)();
2558
2558
  }
2559
2559
  }
2560
2560
  return null;
@@ -5569,7 +5569,8 @@ var LIST_OWNERS = ['OL', 'UL', 'MENU'];
5569
5569
  var parseNodeTree = function (context, node, parent, root) {
5570
5570
  for (var childNode = node.firstChild, nextNode = void 0; childNode; childNode = nextNode) {
5571
5571
  nextNode = childNode.nextSibling;
5572
- if (isTextNode(childNode) && childNode.data.trim().length > 0) {
5572
+ // Fixes #2238 #1624 - Fix the issue of TextNode content being overlooked in rendering due to being perceived as blank by trim().
5573
+ if (isTextNode(childNode) && childNode.data.length > 0) {
5573
5574
  parent.textNodes.push(new TextContainer(context, childNode, parent.styles));
5574
5575
  }
5575
5576
  else if (isElementNode(childNode)) {
@@ -7559,7 +7560,15 @@ var CanvasRenderer = /** @class */ (function (_super) {
7559
7560
  CanvasRenderer.prototype.renderTextWithLetterSpacing = function (text, letterSpacing, baseline) {
7560
7561
  var _this = this;
7561
7562
  if (letterSpacing === 0) {
7562
- this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
7563
+ // Fixed an issue with characters moving up in non-Firefox.
7564
+ // https://github.com/niklasvh/html2canvas/issues/2107#issuecomment-692462900
7565
+ if (navigator.userAgent.indexOf('Firefox') === -1) {
7566
+ this.ctx.textBaseline = 'ideographic';
7567
+ this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + text.bounds.height);
7568
+ }
7569
+ else {
7570
+ this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
7571
+ }
7563
7572
  }
7564
7573
  else {
7565
7574
  var letters = segmentGraphemes(text.text);
@@ -7585,15 +7594,15 @@ var CanvasRenderer = /** @class */ (function (_super) {
7585
7594
  };
7586
7595
  CanvasRenderer.prototype.renderTextNode = function (text, styles) {
7587
7596
  return __awaiter(this, void 0, void 0, function () {
7588
- var _a, font, fontFamily, fontSize, _b, baseline, middle, paintOrder;
7597
+ var _a, font, fontFamily, fontSize, baseline, paintOrder;
7589
7598
  var _this = this;
7590
- return __generator(this, function (_c) {
7599
+ return __generator(this, function (_b) {
7591
7600
  _a = this.createFontStyle(styles), font = _a[0], fontFamily = _a[1], fontSize = _a[2];
7592
7601
  this.ctx.font = font;
7593
7602
  this.ctx.direction = styles.direction === 1 /* DIRECTION.RTL */ ? 'rtl' : 'ltr';
7594
7603
  this.ctx.textAlign = 'left';
7595
7604
  this.ctx.textBaseline = 'alphabetic';
7596
- _b = this.fontMetrics.getMetrics(fontFamily, fontSize), baseline = _b.baseline, middle = _b.middle;
7605
+ baseline = this.fontMetrics.getMetrics(fontFamily, fontSize).baseline;
7597
7606
  paintOrder = styles.paintOrder;
7598
7607
  text.textBounds.forEach(function (text) {
7599
7608
  paintOrder.forEach(function (paintOrderLayer) {
@@ -7620,20 +7629,18 @@ var CanvasRenderer = /** @class */ (function (_super) {
7620
7629
  }
7621
7630
  if (styles.textDecorationLine.length) {
7622
7631
  _this.ctx.fillStyle = asString(styles.textDecorationColor || styles.color);
7632
+ var decorationLineHeight_1 = 1;
7623
7633
  styles.textDecorationLine.forEach(function (textDecorationLine) {
7634
+ // Fix the issue where textDecorationLine exhibits x-axis positioning errors on high-resolution devices due to varying devicePixelRatio, corrected by using relative values of element heights.
7624
7635
  switch (textDecorationLine) {
7625
7636
  case 1 /* TEXT_DECORATION_LINE.UNDERLINE */:
7626
- // Draws a line at the baseline of the font
7627
- // TODO As some browsers display the line as more than 1px if the font-size is big,
7628
- // need to take that into account both in position and size
7629
- _this.ctx.fillRect(text.bounds.left, Math.round(text.bounds.top + baseline), text.bounds.width, 1);
7637
+ _this.ctx.fillRect(text.bounds.left, text.bounds.top + text.bounds.height - decorationLineHeight_1, text.bounds.width, decorationLineHeight_1);
7630
7638
  break;
7631
7639
  case 2 /* TEXT_DECORATION_LINE.OVERLINE */:
7632
- _this.ctx.fillRect(text.bounds.left, Math.round(text.bounds.top), text.bounds.width, 1);
7640
+ _this.ctx.fillRect(text.bounds.left, text.bounds.top, text.bounds.width, decorationLineHeight_1);
7633
7641
  break;
7634
7642
  case 3 /* TEXT_DECORATION_LINE.LINE_THROUGH */:
7635
- // TODO try and find exact position for line-through
7636
- _this.ctx.fillRect(text.bounds.left, Math.ceil(text.bounds.top + middle), text.bounds.width, 1);
7643
+ _this.ctx.fillRect(text.bounds.left, text.bounds.top + (text.bounds.height / 2 - decorationLineHeight_1 / 2), text.bounds.width, decorationLineHeight_1);
7637
7644
  break;
7638
7645
  }
7639
7646
  });
@@ -8759,5 +8766,5 @@ var parseBackgroundColor = function (context, element, backgroundColorOverride)
8759
8766
  : defaultBackgroundColor;
8760
8767
  };
8761
8768
 
8762
- export default html2canvas;
8769
+ export { html2canvas as default };
8763
8770
  //# sourceMappingURL=html2canvas-pro.esm.js.map