html2canvas-pro 1.5.11 → 1.5.13

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.5.11 <https://yorickshan.github.io/html2canvas-pro/>
2
+ * html2canvas-pro 1.5.13 <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
  */
@@ -3977,24 +3977,44 @@
3977
3977
  if (typeof transformFunction === 'undefined') {
3978
3978
  throw new Error("Attempting to parse an unsupported transform function \"".concat(token.name, "\""));
3979
3979
  }
3980
- return transformFunction(token.values);
3980
+ return transformFunction(_context, token.values);
3981
3981
  }
3982
3982
  return null;
3983
3983
  }
3984
3984
  };
3985
- var matrix = function (args) {
3985
+ var matrix = function (_context, args) {
3986
3986
  var values = args.filter(function (arg) { return arg.type === 17 /* TokenType.NUMBER_TOKEN */; }).map(function (arg) { return arg.number; });
3987
3987
  return values.length === 6 ? values : null;
3988
3988
  };
3989
3989
  // doesn't support 3D transforms at the moment
3990
- var matrix3d = function (args) {
3990
+ var matrix3d = function (_context, args) {
3991
3991
  var values = args.filter(function (arg) { return arg.type === 17 /* TokenType.NUMBER_TOKEN */; }).map(function (arg) { return arg.number; });
3992
3992
  var a1 = values[0], b1 = values[1]; values[2]; values[3]; var a2 = values[4], b2 = values[5]; values[6]; values[7]; values[8]; values[9]; values[10]; values[11]; var a4 = values[12], b4 = values[13]; values[14]; values[15];
3993
3993
  return values.length === 16 ? [a1, b1, a2, b2, a4, b4] : null;
3994
3994
  };
3995
+ var rotate$1 = function (context, args) {
3996
+ if (args.length !== 1) {
3997
+ return null;
3998
+ }
3999
+ var arg = args[0];
4000
+ var radians = 0;
4001
+ if (arg.type === 17 /* TokenType.NUMBER_TOKEN */ && arg.number === 0) {
4002
+ radians = 0;
4003
+ }
4004
+ else if (arg.type === 15 /* TokenType.DIMENSION_TOKEN */) {
4005
+ radians = angle.parse(context, arg);
4006
+ }
4007
+ else {
4008
+ return null;
4009
+ }
4010
+ var cos = Math.cos(radians);
4011
+ var sin = Math.sin(radians);
4012
+ return [cos, sin, -sin, cos, 0, 0];
4013
+ };
3995
4014
  var SUPPORTED_TRANSFORM_FUNCTIONS = {
3996
4015
  matrix: matrix,
3997
- matrix3d: matrix3d
4016
+ matrix3d: matrix3d,
4017
+ rotate: rotate$1
3998
4018
  };
3999
4019
 
4000
4020
  var DEFAULT_VALUE = {
@@ -4017,6 +4037,30 @@
4017
4037
  }
4018
4038
  };
4019
4039
 
4040
+ var rotate = {
4041
+ name: 'rotate',
4042
+ initialValue: 'none',
4043
+ prefix: false,
4044
+ type: 0 /* PropertyDescriptorParsingType.VALUE */,
4045
+ parse: function (_context, token) {
4046
+ if (token.type === 20 /* TokenType.IDENT_TOKEN */ && token.value === 'none') {
4047
+ return null;
4048
+ }
4049
+ if (token.type === 17 /* TokenType.NUMBER_TOKEN */) {
4050
+ if (token.number === 0) {
4051
+ return 0;
4052
+ }
4053
+ }
4054
+ if (token.type === 15 /* TokenType.DIMENSION_TOKEN */) {
4055
+ // Parse angle and convert to degrees for storage
4056
+ var radians = angle.parse(_context, token);
4057
+ // Store as degrees for consistency
4058
+ return (radians * 180) / Math.PI;
4059
+ }
4060
+ return null;
4061
+ }
4062
+ };
4063
+
4020
4064
  var visibility = {
4021
4065
  name: 'visible',
4022
4066
  initialValue: 'none',
@@ -4529,6 +4573,7 @@
4529
4573
  this.textTransform = parse(context, textTransform, declaration.textTransform);
4530
4574
  this.transform = parse(context, transform$1, declaration.transform);
4531
4575
  this.transformOrigin = parse(context, transformOrigin, declaration.transformOrigin);
4576
+ this.rotate = parse(context, rotate, declaration.rotate);
4532
4577
  this.visibility = parse(context, visibility, declaration.visibility);
4533
4578
  this.webkitTextStrokeColor = parse(context, webkitTextStrokeColor, declaration.webkitTextStrokeColor);
4534
4579
  this.webkitTextStrokeWidth = parse(context, webkitTextStrokeWidth, declaration.webkitTextStrokeWidth);
@@ -4543,7 +4588,7 @@
4543
4588
  return isTransparent(this.backgroundColor);
4544
4589
  };
4545
4590
  CSSParsedDeclaration.prototype.isTransformed = function () {
4546
- return this.transform !== null;
4591
+ return this.transform !== null || this.rotate !== null;
4547
4592
  };
4548
4593
  CSSParsedDeclaration.prototype.isPositioned = function () {
4549
4594
  return this.position !== 0 /* POSITION.STATIC */;
@@ -4654,6 +4699,10 @@
4654
4699
  // getBoundingClientRect takes transforms into account
4655
4700
  element.style.transform = 'none';
4656
4701
  }
4702
+ if (this.styles.rotate !== null) {
4703
+ // Handle rotate property similarly to transform
4704
+ element.style.rotate = 'none';
4705
+ }
4657
4706
  }
4658
4707
  this.bounds = parseBounds(this.context, element);
4659
4708
  if (isDebugging(element, 4 /* DebuggerType.RENDER */)) {
@@ -6118,16 +6167,27 @@
6118
6167
  }
6119
6168
  });
6120
6169
  }); });
6121
- var adoptedNode = documentClone.adoptNode(this.documentElement);
6122
6170
  /**
6123
6171
  * The baseURI of the document will be lost after documentClone.open().
6124
- * We can avoid it by adding <base> element.
6172
+ * We save it before open() to preserve the original base URI for resource resolution.
6125
6173
  * */
6126
- addBase(adoptedNode, documentClone);
6174
+ var baseUri = documentClone.baseURI;
6127
6175
  documentClone.open();
6128
6176
  documentClone.write("".concat(serializeDoctype(document.doctype), "<html></html>"));
6129
6177
  // Chrome scrolls the parent document for some reason after the write to the cloned window???
6130
6178
  restoreOwnerScroll(this.referenceElement.ownerDocument, scrollX, scrollY);
6179
+ /**
6180
+ * Note: adoptNode() should be called AFTER documentClone.open() and close()
6181
+ *
6182
+ * In Chrome, calling adoptNode() before or during open/write may cause
6183
+ * styles with uppercase characters in class names (e.g. ".MyClass") to not apply correctly.
6184
+ *
6185
+ * Fix:
6186
+ * - Make sure adoptNode() is called after documentClone.open() and close()
6187
+ * - This allows Chrome to properly match and apply all CSS rules including mixed-case class selectors.
6188
+ * */
6189
+ var adoptedNode = documentClone.adoptNode(this.documentElement);
6190
+ addBase(adoptedNode, baseUri);
6131
6191
  documentClone.replaceChild(adoptedNode, documentClone.documentElement);
6132
6192
  documentClone.close();
6133
6193
  return iframeLoad;
@@ -6482,7 +6542,8 @@
6482
6542
  // Edge does not provide value for cssText
6483
6543
  for (var i = style.length - 1; i >= 0; i--) {
6484
6544
  var property = style.item(i);
6485
- if (ignoredStyleProperties.indexOf(property) === -1) {
6545
+ // fix: Chrome_138 ignore custom properties
6546
+ if (ignoredStyleProperties.indexOf(property) === -1 && !property.startsWith('--')) {
6486
6547
  target.style.setProperty(property, style.getPropertyValue(property));
6487
6548
  }
6488
6549
  }
@@ -6536,10 +6597,10 @@
6536
6597
  body.appendChild(style);
6537
6598
  }
6538
6599
  };
6539
- var addBase = function (targetELement, referenceDocument) {
6600
+ var addBase = function (targetELement, baseUri) {
6540
6601
  var _a;
6541
- var baseNode = referenceDocument.createElement('base');
6542
- baseNode.href = referenceDocument.baseURI;
6602
+ var baseNode = targetELement.ownerDocument.createElement('base');
6603
+ baseNode.href = baseUri;
6543
6604
  var headEle = targetELement.getElementsByTagName('head').item(0);
6544
6605
  headEle === null || headEle === void 0 ? void 0 : headEle.insertBefore(baseNode, (_a = headEle === null || headEle === void 0 ? void 0 : headEle.firstChild) !== null && _a !== void 0 ? _a : null);
6545
6606
  };
@@ -7007,6 +7068,17 @@
7007
7068
  if (this.container.styles.opacity < 1) {
7008
7069
  this.effects.push(new OpacityEffect(this.container.styles.opacity));
7009
7070
  }
7071
+ if (this.container.styles.rotate !== null) {
7072
+ var offsetX = this.container.bounds.left + this.container.styles.transformOrigin[0].number;
7073
+ var offsetY = this.container.bounds.top + this.container.styles.transformOrigin[1].number;
7074
+ // Apply rotate property if present
7075
+ var angle = this.container.styles.rotate;
7076
+ var rad = (angle * Math.PI) / 180;
7077
+ var cos = Math.cos(rad);
7078
+ var sin = Math.sin(rad);
7079
+ var rotateMatrix = [cos, sin, -sin, cos, 0, 0];
7080
+ this.effects.push(new TransformEffect(offsetX, offsetY, rotateMatrix));
7081
+ }
7010
7082
  if (this.container.styles.transform !== null) {
7011
7083
  var offsetX = this.container.bounds.left + this.container.styles.transformOrigin[0].number;
7012
7084
  var offsetY = this.container.bounds.top + this.container.styles.transformOrigin[1].number;