dompdf.js 1.0.3 → 1.1.0

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.
Files changed (38) hide show
  1. package/.vscode/settings.json +5 -0
  2. package/README.md +168 -79
  3. package/dist/dom/element-container.d.ts +4 -2
  4. package/dist/dompdf.esm.js +614 -462
  5. package/dist/dompdf.esm.js.map +1 -1
  6. package/dist/dompdf.js +614 -462
  7. package/dist/dompdf.js.map +1 -1
  8. package/dist/index.d.ts +1 -3
  9. package/dist/lib/__tests__/index.js.map +1 -1
  10. package/dist/lib/css/property-descriptors/border-style.js.map +1 -1
  11. package/dist/lib/css/types/color.js.map +1 -1
  12. package/dist/lib/dom/element-container.js +3 -1
  13. package/dist/lib/dom/element-container.js.map +1 -1
  14. package/dist/lib/dom/node-parser.js +15 -7
  15. package/dist/lib/dom/node-parser.js.map +1 -1
  16. package/dist/lib/dom/replaced-elements/iframe-element-container.js.map +1 -1
  17. package/dist/lib/index.js +107 -42
  18. package/dist/lib/index.js.map +1 -1
  19. package/dist/lib/render/canvas/foreignobject-renderer.js.map +1 -1
  20. package/dist/lib/render/canvas/pdf-renderer.js +276 -472
  21. package/dist/lib/render/canvas/pdf-renderer.js.map +1 -1
  22. package/dist/lib/render/page-format-map.js +54 -0
  23. package/dist/lib/render/page-format-map.js.map +1 -0
  24. package/dist/lib/render/paginate.js +172 -0
  25. package/dist/lib/render/paginate.js.map +1 -0
  26. package/dist/render/canvas/pdf-renderer.d.ts +41 -16
  27. package/dist/render/page-format-map.d.ts +4 -0
  28. package/dist/render/paginate.d.ts +3 -0
  29. package/dist/types/dom/element-container.d.ts +4 -2
  30. package/dist/types/index.d.ts +1 -3
  31. package/dist/types/render/canvas/pdf-renderer.d.ts +41 -16
  32. package/dist/types/render/page-format-map.d.ts +4 -0
  33. package/dist/types/render/paginate.d.ts +3 -0
  34. package/package.json +135 -134
  35. package/dist/lib/render/canvas/canvas-renderer2.js +0 -1415
  36. package/dist/lib/render/canvas/canvas-renderer2.js.map +0 -1
  37. package/dist/render/canvas/canvas-renderer2.d.ts +0 -81
  38. package/dist/types/render/canvas/canvas-renderer2.d.ts +0 -81
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * dompdf.js 1.0.3 <https://dompdfjs.lisky.com.cn>
2
+ * dompdf.js 1.1.0 <https://dompdfjs.lisky.com.cn>
3
3
  * Copyright (c) 2025 lfc <https://dompdfjs.lisky.com.cn/>
4
4
  * Released under MIT License
5
5
  */
@@ -3491,6 +3491,27 @@ snapdom.download = async (el, options = {}) => {
3491
3491
  return await capture.download({ format, filename, backgroundColor });
3492
3492
  };
3493
3493
 
3494
+ var elementDebuggerAttribute$1 = 'data-html2canvas-debug';
3495
+ var getElementDebugType$1 = function (element) {
3496
+ var attribute = element.getAttribute(elementDebuggerAttribute$1);
3497
+ switch (attribute) {
3498
+ case 'all':
3499
+ return 1 /* DebuggerType.ALL */;
3500
+ case 'clone':
3501
+ return 2 /* DebuggerType.CLONE */;
3502
+ case 'parse':
3503
+ return 3 /* DebuggerType.PARSE */;
3504
+ case 'render':
3505
+ return 4 /* DebuggerType.RENDER */;
3506
+ default:
3507
+ return 0 /* DebuggerType.NONE */;
3508
+ }
3509
+ };
3510
+ var isDebugging$1 = function (element, type) {
3511
+ var elementType = getElementDebugType$1(element);
3512
+ return elementType === 1 /* DebuggerType.ALL */ || type === elementType;
3513
+ };
3514
+
3494
3515
  var backgroundClip$1 = {
3495
3516
  name: 'background-clip',
3496
3517
  initialValue: 'border-box',
@@ -3782,12 +3803,6 @@ var prefixRadialGradient$1 = function (context, tokens) {
3782
3803
  return { size: size, shape: shape, stops: stops, position: position, type: 2 /* CSSImageType.RADIAL_GRADIENT */ };
3783
3804
  };
3784
3805
 
3785
- var isLinearGradient$1 = function (background) {
3786
- return background.type === 1 /* CSSImageType.LINEAR_GRADIENT */;
3787
- };
3788
- var isRadialGradient$1 = function (background) {
3789
- return background.type === 2 /* CSSImageType.RADIAL_GRADIENT */;
3790
- };
3791
3806
  var image$1 = {
3792
3807
  name: 'image',
3793
3808
  parse: function (context, value) {
@@ -5112,27 +5127,6 @@ var parse$1 = function (context, descriptor, style) {
5112
5127
  }
5113
5128
  };
5114
5129
 
5115
- var elementDebuggerAttribute$1 = 'data-html2canvas-debug';
5116
- var getElementDebugType$1 = function (element) {
5117
- var attribute = element.getAttribute(elementDebuggerAttribute$1);
5118
- switch (attribute) {
5119
- case 'all':
5120
- return 1 /* DebuggerType.ALL */;
5121
- case 'clone':
5122
- return 2 /* DebuggerType.CLONE */;
5123
- case 'parse':
5124
- return 3 /* DebuggerType.PARSE */;
5125
- case 'render':
5126
- return 4 /* DebuggerType.RENDER */;
5127
- default:
5128
- return 0 /* DebuggerType.NONE */;
5129
- }
5130
- };
5131
- var isDebugging$1 = function (element, type) {
5132
- var elementType = getElementDebugType$1(element);
5133
- return elementType === 1 /* DebuggerType.ALL */ || type === elementType;
5134
- };
5135
-
5136
5130
  var ElementContainer$1 = /** @class */ (function () {
5137
5131
  function ElementContainer(context, element) {
5138
5132
  this.context = context;
@@ -5141,6 +5135,8 @@ var ElementContainer$1 = /** @class */ (function () {
5141
5135
  this.flags = 0;
5142
5136
  this.foreignobjectrendering = false;
5143
5137
  this.parentforeignobjectrendering = false;
5138
+ this.divisionDisable = false;
5139
+ this.offset = 0;
5144
5140
  if (isDebugging$1(element, 3 /* DebuggerType.PARSE */)) {
5145
5141
  debugger;
5146
5142
  }
@@ -5910,7 +5906,9 @@ var parseNodeTree$1 = function (context, node, parent, root, foreignObjectRender
5910
5906
  }
5911
5907
  else if (isElementNode$1(childNode)) {
5912
5908
  if (isSlotElement$1(childNode) && childNode.assignedNodes) {
5913
- childNode.assignedNodes().forEach(function (childNode) { return parseNodeTree$1(context, childNode, parent, root, foreignObjectRendererList); });
5909
+ childNode
5910
+ .assignedNodes()
5911
+ .forEach(function (childNode) { return parseNodeTree$1(context, childNode, parent, root, foreignObjectRendererList); });
5914
5912
  }
5915
5913
  else {
5916
5914
  var container = createContainer$1(context, childNode);
@@ -5922,9 +5920,14 @@ var parseNodeTree$1 = function (context, node, parent, root, foreignObjectRender
5922
5920
  else if (createsStackingContext$1(container.styles)) {
5923
5921
  container.flags |= 2 /* FLAGS.CREATES_STACKING_CONTEXT */;
5924
5922
  }
5925
- if (isElementNode$1(childNode) && (childNode.hasAttribute('foreignobjectrendering') || parent.foreignobjectrendering)) {
5923
+ if (isElementNode$1(childNode) &&
5924
+ (childNode.hasAttribute('foreignobjectrendering') || parent.foreignobjectrendering)) {
5926
5925
  container.foreignobjectrendering = true;
5927
5926
  }
5927
+ if (isElementNode$1(childNode) &&
5928
+ (childNode.hasAttribute('divisionDisable') || parent.divisionDisable)) {
5929
+ container.divisionDisable = true;
5930
+ }
5928
5931
  if (LIST_OWNERS$1.indexOf(childNode.tagName) !== -1) {
5929
5932
  container.flags |= 8 /* FLAGS.IS_LIST_OWNER */;
5930
5933
  }
@@ -6004,11 +6007,12 @@ var parseTree$1 = function (context, element) { return __awaiter$1(void 0, void
6004
6007
  // 修改 parseNodeTree 调用,传入局部列表
6005
6008
  parseNodeTree$1(context, element, container, container, foreignObjectRendererList);
6006
6009
  uniqueList = foreignObjectRendererList.filter(function (item, index, self) {
6007
- return index === self.findIndex(function (t) { return t === item; });
6008
- });
6009
- screenshotPromises = uniqueList.map(function (item) {
6010
- return renderForeignObject(item);
6010
+ return index ===
6011
+ self.findIndex(function (t) {
6012
+ return t === item;
6013
+ });
6011
6014
  });
6015
+ screenshotPromises = uniqueList.map(function (item) { return renderForeignObject(item); });
6012
6016
  return [4 /*yield*/, Promise.all(screenshotPromises)];
6013
6017
  case 1:
6014
6018
  screenshotResults = _a.sent();
@@ -6091,7 +6095,7 @@ var renderForeignObject = function (element) { return __awaiter$1(void 0, void 0
6091
6095
  case 2:
6092
6096
  _a.trys.push([2, 4, , 5]);
6093
6097
  return [4 /*yield*/, capture.toPng({
6094
- quality: 0.1,
6098
+ quality: 0.1
6095
6099
  // width: Math.ceil(rect.width),
6096
6100
  // height: Math.ceil(rect.height)
6097
6101
  })];
@@ -8981,48 +8985,64 @@ var parseStackingContexts$1 = function (container) {
8981
8985
  return root;
8982
8986
  };
8983
8987
 
8984
- // 遮罩偏移常量
8985
- // const MASK_OFFSET = 10000;
8986
- // Canvas渲染器类,继承自Renderer
8987
8988
  var CanvasRenderer$1 = /** @class */ (function (_super) {
8988
8989
  __extends$1(CanvasRenderer, _super);
8989
- // 构造函数
8990
8990
  function CanvasRenderer(context, options) {
8991
- var _this = this;
8992
- console.log('options参数', options, context);
8993
- _this = _super.call(this, context, options) || this;
8994
- _this._activeEffects = []; // 活动效果数组
8991
+ var _this = _super.call(this, context, options) || this;
8992
+ _this._activeEffects = [];
8993
+ _this.totalPages = 1;
8995
8994
  _this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
8996
8995
  _this.ctx = _this.canvas.getContext('2d');
8997
- // 计算页面尺寸并转换为 pt 单位 (1pt = 1/72 inch, 1px = 1/96 inch)
8998
8996
  var pxToPt = function (px) { return px * (72 / 96); };
8999
- //
9000
8997
  var pageWidth = pxToPt(options.width);
9001
8998
  var pageHeight = pxToPt(options.height);
9002
- // 初始化 jsPDF
8999
+ // const enc =
9000
+ // this.options.encryption &&
9001
+ // (this.options.encryption.userPassword ||
9002
+ // this.options.encryption.ownerPassword ||
9003
+ // (this.options.encryption.userPermissions && this.options.encryption.userPermissions.length))
9004
+ // ? this.options.encryption
9005
+ // : [];
9006
+ var encOptions = _this.options.encryption
9007
+ ? {
9008
+ userPassword: _this.options.encryption.userPassword,
9009
+ ownerPassword: _this.options.encryption.ownerPassword,
9010
+ userPermissions: _this.options.encryption.userPermissions
9011
+ }
9012
+ : undefined;
9003
9013
  _this.jspdfCtx = new E$1({
9004
9014
  orientation: pageWidth > pageHeight ? 'landscape' : 'portrait',
9005
9015
  unit: 'pt',
9006
- format: [pageWidth, pageHeight],
9007
- hotfixes: ["px_scaling"]
9016
+ format: options.pagination && options.format ? options.format : [pageHeight, pageWidth],
9017
+ hotfixes: ['px_scaling'],
9018
+ putOnlyUsedFonts: options.putOnlyUsedFonts,
9019
+ compress: options.compress,
9020
+ precision: options.precision,
9021
+ floatPrecision: options.floatPrecision,
9022
+ encryption: encOptions
9008
9023
  });
9009
- // 设置PDF文件的保存方式
9024
+ // orientation: pageWidth > pageHeight ? 'landscape' : 'portrait',
9025
+ // unit: 'pt',
9026
+ // format: options.pagination && options.format ? options.format : [pageHeight, pageWidth],
9027
+ // hotfixes: ['px_scaling'],
9028
+ // putOnlyUsedFonts: options.putOnlyUsedFonts,
9029
+ // compress: options.compress,
9030
+ // precision: options.precision,
9031
+ // floatPrecision: options.floatPrecision,
9032
+ // encryption: enc
9033
+ // });
9010
9034
  _this.context2dCtx = _this.jspdfCtx.context2d;
9011
9035
  _this.context2dCtx.scale(0.75, 0.75);
9012
9036
  _this.context2dCtx.translate(-options.x, -options.y);
9013
- // 确保字体已加载并注册到 jsPDF
9014
9037
  if (options.fontConfig) {
9015
9038
  try {
9016
9039
  _this.loadFont();
9017
9040
  }
9018
9041
  catch (error) {
9019
9042
  console.warn('Failed to set font:', error);
9020
- // 如果设置失败,使用默认字体
9021
9043
  _this.jspdfCtx.setFont('Helvetica');
9022
9044
  }
9023
9045
  }
9024
- // this.jspdfCtx.setFont('SourceHanSansSC-Normal-Min');
9025
- // 将 pxToPt 保存为实例属性,以便其他方法使用
9026
9046
  _this.pxToPt = pxToPt;
9027
9047
  if (!options.canvas) {
9028
9048
  _this.canvas.width = 10;
@@ -9031,9 +9051,6 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9031
9051
  _this.canvas.style.height = "10px";
9032
9052
  }
9033
9053
  _this.fontMetrics = new FontMetrics$1(document);
9034
- // this.ctx.scale(this.options.scale, this.options.scale);
9035
- // this.ctx.translate(-options.x, -options.y);
9036
- // this.ctx.textBaseline = 'bottom';
9037
9054
  _this.context2dCtx.textBaseline = 'bottom';
9038
9055
  _this._activeEffects = [];
9039
9056
  _this.context.logger.debug("Canvas renderer initialized (".concat(options.width, "x").concat(options.height, ") with scale ").concat(options.scale));
@@ -9043,67 +9060,23 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9043
9060
  return __awaiter$1(this, void 0, void 0, function () {
9044
9061
  var fontData;
9045
9062
  return __generator$1(this, function (_a) {
9046
- switch (_a.label) {
9047
- case 0:
9048
- if (!this.options.fontConfig.fontBase64) return [3 /*break*/, 1];
9049
- // 直接使用 Base64 编码
9050
- fontData = this.options.fontConfig.fontBase64;
9051
- return [3 /*break*/, 3];
9052
- case 1:
9053
- if (!this.options.fontConfig.fontUrl) return [3 /*break*/, 3];
9054
- return [4 /*yield*/, this.loadFontFromURL(this.options.fontConfig.fontUrl)];
9055
- case 2:
9056
- fontData = _a.sent();
9057
- _a.label = 3;
9058
- case 3:
9059
- // console.log('fontData',fontData)
9060
- // 将字体添加到 jsPDF
9061
- this.addFontToJsPDF(fontData);
9062
- return [2 /*return*/];
9063
- }
9064
- });
9065
- });
9066
- };
9067
- CanvasRenderer.prototype.loadFontFromURL = function (url) {
9068
- return __awaiter$1(this, void 0, void 0, function () {
9069
- var response, blob;
9070
- return __generator$1(this, function (_a) {
9071
- switch (_a.label) {
9072
- case 0: return [4 /*yield*/, fetch(url, {
9073
- mode: 'no-cors',
9074
- headers: {
9075
- 'Content-Type': 'font/ttf'
9076
- }
9077
- })];
9078
- case 1:
9079
- response = _a.sent();
9080
- return [4 /*yield*/, response.blob()];
9081
- case 2:
9082
- blob = _a.sent();
9083
- // const fontUrl = URL.createObjectURL(blob);
9084
- // console.log('response', blob, fontUrl)
9085
- // 注意:no-cors 模式下无法读取响应内容!
9086
- // const blob = await response.blob();
9087
- return [2 /*return*/, new Promise(function (resolve, reject) {
9088
- var reader = new FileReader();
9089
- reader.onload = function () { return resolve(reader.result.split(',')[1]); }; // 提取 Base64 数据
9090
- reader.onerror = function () { return reject(new Error('字体文件读取失败')); };
9091
- reader.readAsDataURL(blob);
9092
- })];
9063
+ if (this.options.fontConfig.fontBase64) {
9064
+ fontData = this.options.fontConfig.fontBase64;
9093
9065
  }
9066
+ this.addFontToJsPDF(fontData);
9067
+ return [2 /*return*/];
9094
9068
  });
9095
9069
  });
9096
9070
  };
9097
9071
  CanvasRenderer.prototype.addFontToJsPDF = function (fontData) {
9098
- var _a = this.options.fontConfig, fontFamily = _a.fontFamily, fontWeight = _a.fontWeight, fontStyle = _a.fontStyle;
9072
+ var fontFamily = this.options.fontConfig.fontFamily;
9099
9073
  if (!fontFamily) {
9100
9074
  return;
9101
9075
  }
9102
- this.jspdfCtx.addFileToVFS("".concat(fontFamily, ".ttf"), fontData); // 将字体添加到虚拟文件系统
9103
- this.jspdfCtx.addFont("".concat(fontFamily, ".ttf"), fontFamily, fontStyle, fontWeight); // 注册字体
9104
- this.jspdfCtx.setFont(fontFamily); // 设置当前字体
9076
+ this.jspdfCtx.addFileToVFS("".concat(fontFamily, ".ttf"), fontData);
9077
+ this.jspdfCtx.addFont("".concat(fontFamily, ".ttf"), fontFamily, 'normal');
9078
+ this.jspdfCtx.setFont(fontFamily);
9105
9079
  };
9106
- // 应用效果数组
9107
9080
  CanvasRenderer.prototype.applyEffects = function (effects) {
9108
9081
  var _this = this;
9109
9082
  while (this._activeEffects.length) {
@@ -9111,46 +9084,29 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9111
9084
  }
9112
9085
  effects.forEach(function (effect) { return _this.applyEffect(effect); });
9113
9086
  };
9114
- // 应用单个效果
9115
9087
  CanvasRenderer.prototype.applyEffect = function (effect) {
9116
9088
  this.ctx.save();
9117
- // this.context2dCtx.save()
9118
9089
  if (isOpacityEffect$1(effect)) {
9119
9090
  this.ctx.globalAlpha = effect.opacity;
9120
- // this.context2dCtx.globalAlpha = effect.opacity
9121
9091
  }
9122
9092
  if (isTransformEffect$1(effect)) {
9123
9093
  this.ctx.translate(effect.offsetX, effect.offsetY);
9124
9094
  this.ctx.transform(effect.matrix[0], effect.matrix[1], effect.matrix[2], effect.matrix[3], effect.matrix[4], effect.matrix[5]);
9125
9095
  this.ctx.translate(-effect.offsetX, -effect.offsetY);
9126
- // this.context2dCtx.translate(effect.offsetX, effect.offsetY);
9127
- // this.context2dCtx.transform(
9128
- // effect.matrix[0],
9129
- // effect.matrix[1],
9130
- // effect.matrix[2],
9131
- // effect.matrix[3],
9132
- // effect.matrix[4],
9133
- // effect.matrix[5]
9134
- // );
9135
- // this.context2dCtx.translate(-effect.offsetX, -effect.offsetY);
9136
9096
  }
9137
9097
  if (isClipEffect$1(effect)) {
9138
9098
  this.path(effect.path);
9139
9099
  this.ctx.clip();
9140
- // this.context2dCtx.clip()
9141
9100
  }
9142
9101
  this._activeEffects.push(effect);
9143
9102
  };
9144
- // 移除最后应用的效果
9145
9103
  CanvasRenderer.prototype.popEffect = function () {
9146
9104
  this._activeEffects.pop();
9147
- // this.ctx.restore();
9148
9105
  this.context2dCtx.restore();
9149
9106
  if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
9150
9107
  this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
9151
9108
  }
9152
9109
  };
9153
- // 渲染堆叠上下文
9154
9110
  CanvasRenderer.prototype.renderStack = function (stack) {
9155
9111
  return __awaiter$1(this, void 0, void 0, function () {
9156
9112
  var styles;
@@ -9162,13 +9118,12 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9162
9118
  return [4 /*yield*/, this.renderStackContent(stack)];
9163
9119
  case 1:
9164
9120
  _a.sent();
9165
- return [3 /*break*/, 2];
9121
+ _a.label = 2;
9166
9122
  case 2: return [2 /*return*/];
9167
9123
  }
9168
9124
  });
9169
9125
  });
9170
9126
  };
9171
- // 渲染节点
9172
9127
  CanvasRenderer.prototype.renderNode = function (paint) {
9173
9128
  return __awaiter$1(this, void 0, void 0, function () {
9174
9129
  return __generator$1(this, function (_a) {
@@ -9190,27 +9145,19 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9190
9145
  });
9191
9146
  });
9192
9147
  };
9193
- // 渲染带有字母间距的文本
9194
9148
  CanvasRenderer.prototype.renderTextWithLetterSpacing = function (text, letterSpacing, baseline) {
9195
9149
  var _this = this;
9196
9150
  if (letterSpacing === 0) {
9197
- // console.log(text.text, text.bounds.left,'绘制文字-没有letterSpacing')
9198
- // this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
9199
9151
  this.context2dCtx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
9200
9152
  }
9201
9153
  else {
9202
9154
  var letters = segmentGraphemes$1(text.text);
9203
9155
  letters.reduce(function (left, letter) {
9204
- // console.log(left, letter,'绘制文字')
9205
- // this.ctx.fillText(letter, left, text.bounds.top + baseline);
9206
- // this.context2dCtx.fillText(letter, left - leftMargin, text.bounds.top + baseline - topMargin);
9207
- // 使用jspdf绘制文字
9208
9156
  _this.context2dCtx.fillText(letter, left, text.bounds.top + baseline);
9209
9157
  return left + _this.ctx.measureText(letter).width;
9210
9158
  }, text.bounds.left);
9211
9159
  }
9212
9160
  };
9213
- // 创建字体样式
9214
9161
  CanvasRenderer.prototype.createFontStyle = function (styles) {
9215
9162
  var fontVariant = styles.fontVariant
9216
9163
  .filter(function (variant) { return variant === 'normal' || variant === 'small-caps'; })
@@ -9225,18 +9172,16 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9225
9172
  fontSize
9226
9173
  ];
9227
9174
  };
9228
- // 添加一个新的颜色转换函数
9229
9175
  CanvasRenderer.prototype.convertColor = function (color) {
9230
- // 如果是透明色,返回白色
9231
9176
  if (isTransparent$1(color)) {
9232
9177
  return '#FFFFFF';
9233
9178
  }
9234
- // 将 rgba 转换为 rgb
9235
- // 从32位整数中提取RGB分量
9236
9179
  var r = 0xff & (color >> 24);
9237
9180
  var g = 0xff & (color >> 16);
9238
9181
  var b = 0xff & (color >> 8);
9239
- return "#".concat(r.toString(16).padStart(2, '0')).concat(g.toString(16).padStart(2, '0')).concat(b.toString(16).padStart(2, '0'));
9182
+ return "#".concat(r.toString(16).padStart(2, '0')).concat(g.toString(16).padStart(2, '0')).concat(b
9183
+ .toString(16)
9184
+ .padStart(2, '0'));
9240
9185
  };
9241
9186
  CanvasRenderer.prototype.renderTextNode = function (text, styles) {
9242
9187
  return __awaiter$1(this, void 0, void 0, function () {
@@ -9244,15 +9189,12 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9244
9189
  var _this = this;
9245
9190
  return __generator$1(this, function (_c) {
9246
9191
  _a = this.createFontStyle(styles), font = _a[0], fontFamily = _a[1], fontSize = _a[2];
9247
- // ,
9248
- // 设置 CanvasRenderingContext2D 的字体样式
9249
9192
  this.ctx.font = font;
9250
- // 设置 jsPDF context2d 的字体样式 (如果需要,jsPDF 通常会自动同步)
9251
- this.context2dCtx.font = this.options.fontConfig.fontFamily; // 通常不需要显式设置,jsPDF 会处理
9193
+ this.context2dCtx.font = this.options.fontConfig.fontFamily;
9252
9194
  this.ctx.direction = styles.direction === 1 /* DIRECTION.RTL */ ? 'rtl' : 'ltr';
9253
- this.context2dCtx.direction = styles.direction === 1 /* DIRECTION.RTL */ ? 'rtl' : 'ltr'; // 根据 jsPDF API 调整
9195
+ this.context2dCtx.direction = styles.direction === 1 /* DIRECTION.RTL */ ? 'rtl' : 'ltr';
9254
9196
  this.ctx.textAlign = 'left';
9255
- this.context2dCtx.textAlign = 'left'; // 根据 jsPDF API 调整
9197
+ this.context2dCtx.textAlign = 'left';
9256
9198
  fontSizePt = styles.fontSize.number;
9257
9199
  this.jspdfCtx.setFontSize(fontSizePt);
9258
9200
  _b = this.fontMetrics.getMetrics(fontFamily, fontSize), baseline = _b.baseline, middle = _b.middle;
@@ -9261,15 +9203,9 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9261
9203
  paintOrder.forEach(function (paintOrderLayer) {
9262
9204
  switch (paintOrderLayer) {
9263
9205
  case 0 /* PAINT_ORDER_LAYER.FILL */:
9264
- // 设置 CanvasRenderingContext2D 的填充样式
9265
- // this.ctx.fillStyle = asString(styles.color);
9266
- // 设置 jsPDF context2d 的填充样式
9267
9206
  _this.context2dCtx.fillStyle = asString$1(styles.color);
9268
9207
  _this.renderTextWithLetterSpacing(textItem, styles.letterSpacing, baseline);
9269
9208
  if (styles.textDecorationLine.length) {
9270
- // 设置 CanvasRenderingContext2D 的填充样式
9271
- // this.ctx.fillStyle = asString(styles.textDecorationColor || styles.color);
9272
- // 设置 jsPDF context2d 的填充样式
9273
9209
  _this.context2dCtx.fillStyle = asString$1(styles.textDecorationColor || styles.color);
9274
9210
  styles.textDecorationLine.forEach(function (textDecorationLine) {
9275
9211
  var x = textItem.bounds.left;
@@ -9277,18 +9213,15 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9277
9213
  var y_underline = Math.round(textItem.bounds.top + baseline);
9278
9214
  var y_overline = Math.round(textItem.bounds.top);
9279
9215
  var y_line_through = Math.ceil(textItem.bounds.top + middle);
9280
- var thickness = 1; // 装饰线的粗细,可以根据需要调整
9216
+ var thickness = 1;
9281
9217
  switch (textDecorationLine) {
9282
9218
  case 1 /* TEXT_DECORATION_LINE.UNDERLINE */:
9283
- // this.ctx.fillRect(x, y_underline, width, thickness);
9284
9219
  _this.context2dCtx.fillRect(x, y_underline, width, thickness);
9285
9220
  break;
9286
9221
  case 2 /* TEXT_DECORATION_LINE.OVERLINE */:
9287
- // this.ctx.fillRect(x, y_overline, width, thickness);
9288
9222
  _this.context2dCtx.fillRect(x, y_overline, width, thickness);
9289
9223
  break;
9290
9224
  case 3 /* TEXT_DECORATION_LINE.LINE_THROUGH */:
9291
- // this.ctx.fillRect(x, y_line_through, width, thickness);
9292
9225
  _this.context2dCtx.fillRect(x, y_line_through, width, thickness);
9293
9226
  break;
9294
9227
  }
@@ -9297,24 +9230,10 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9297
9230
  break;
9298
9231
  case 1 /* PAINT_ORDER_LAYER.STROKE */:
9299
9232
  if (styles.webkitTextStrokeWidth && textItem.text.trim().length) {
9300
- // 设置 CanvasRenderingContext2D 的描边样式
9301
- // this.ctx.strokeStyle = asString(styles.webkitTextStrokeColor);
9302
- // this.ctx.lineWidth = styles.webkitTextStrokeWidth;
9303
- // this.ctx.lineJoin = !!(window as any).chrome ? 'miter' : 'round';
9304
- // 设置 jsPDF context2d 的描边样式
9305
9233
  _this.context2dCtx.strokeStyle = asString$1(styles.webkitTextStrokeColor);
9306
9234
  _this.context2dCtx.lineWidth = styles.webkitTextStrokeWidth;
9307
- // this.context2dCtx.lineJoin = ...; // 根据 jsPDF API 调整
9308
- // CanvasRenderingContext2D 描边
9309
- // this.ctx.strokeText(textItem.text, textItem.bounds.left, textItem.bounds.top + baseline);
9310
- // jsPDF context2d 描边
9311
9235
  _this.context2dCtx.strokeText(textItem.text, textItem.bounds.left, textItem.bounds.top + baseline);
9312
9236
  }
9313
- // 清除 CanvasRenderingContext2D 的描边样式
9314
- // this.ctx.strokeStyle = '';
9315
- // this.ctx.lineWidth = 0;
9316
- // this.ctx.lineJoin = 'miter';
9317
- // 清除 jsPDF context2d 的描边样式
9318
9237
  _this.context2dCtx.strokeStyle = '';
9319
9238
  _this.context2dCtx.lineWidth = 0;
9320
9239
  _this.context2dCtx.lineJoin = 'miter';
@@ -9335,31 +9254,14 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9335
9254
  this.ctx.clip();
9336
9255
  this.ctx.drawImage(image, 0, 0, container.intrinsicWidth, container.intrinsicHeight, box.left, box.top, box.width, box.height);
9337
9256
  this.ctx.restore();
9338
- // this.context2dCtx.save();
9339
- // this.context2dCtx.clip();
9340
- // this.context2dCtx.drawImage(
9341
- // image,
9342
- // 0,
9343
- // 0,
9344
- // container.intrinsicWidth,
9345
- // container.intrinsicHeight,
9346
- // box.left,
9347
- // box.top,
9348
- // box.width,
9349
- // box.height
9350
- // );
9351
- // this.context2dCtx.restore();
9352
9257
  }
9353
9258
  };
9354
- // 渲染节点内容
9355
- // 渲染节点内容的异步方法
9356
9259
  CanvasRenderer.prototype.renderNodeContent = function (paint) {
9357
9260
  return __awaiter$1(this, void 0, void 0, function () {
9358
- var container, curves, styles, _i, _a, child, image, bounds, x, y, width, height, bounds, x, y, width, height, dataURL, image, bounds, x, y, width, height, canvas, ctx, dataURL, e_2, iframeRenderer, canvas, size, _b, fontFamily, fontSize, baseline, bounds, x, textBounds, img, image, url, fontFamily, bounds;
9261
+ var container, curves, styles, _i, _a, child, image, bounds, x, y, width, height, bounds, x, y, width, height, dataURL, image, bounds, x, y, width, height, canvas, ctx, dataURL, e_2, size, _b, fontFamily, fontSize, baseline, bounds, x, textBounds, img, image, url, fontFamily, bounds;
9359
9262
  return __generator$1(this, function (_c) {
9360
9263
  switch (_c.label) {
9361
9264
  case 0:
9362
- // 应用内容效果
9363
9265
  this.applyEffects(paint.getEffects(4 /* EffectTarget.CONTENT */));
9364
9266
  container = paint.container;
9365
9267
  curves = paint.curves;
@@ -9384,18 +9286,14 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9384
9286
  return [4 /*yield*/, this.context.cache.match(container.src)];
9385
9287
  case 6:
9386
9288
  image = _c.sent();
9387
- // 渲染到 Canvas
9388
9289
  this.renderReplacedElement(container, curves, image);
9389
- // 添加到 PDF
9390
9290
  try {
9391
9291
  bounds = contentBox$1(container);
9392
- x = this.pxToPt(bounds.left);
9393
- y = this.pxToPt(bounds.top);
9292
+ x = this.pxToPt(bounds.left - this.options.x);
9293
+ y = this.pxToPt(bounds.top - this.options.y);
9394
9294
  width = this.pxToPt(bounds.width);
9395
9295
  height = this.pxToPt(bounds.height);
9396
- // 将图片添加到 PDF
9397
- this.jspdfCtx.addImage(image, 'JPEG', // 默认使用 JPEG 格式
9398
- x, y, width, height);
9296
+ this.addImagePdf(image, 'JPEG', x, y, width, height);
9399
9297
  }
9400
9298
  catch (err) {
9401
9299
  this.context.logger.error("Error adding image to PDF: ".concat(err));
@@ -9407,18 +9305,15 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9407
9305
  return [3 /*break*/, 8];
9408
9306
  case 8:
9409
9307
  if (container instanceof CanvasElementContainer$1) {
9410
- // 渲染到 Canvas
9411
9308
  this.renderReplacedElement(container, curves, container.canvas);
9412
- // 添加到 PDF
9413
9309
  try {
9414
9310
  bounds = contentBox$1(container);
9415
- x = this.pxToPt(bounds.left);
9416
- y = this.pxToPt(bounds.top);
9311
+ x = this.pxToPt(bounds.left - this.options.x);
9312
+ y = this.pxToPt(bounds.top - this.options.y);
9417
9313
  width = this.pxToPt(bounds.width);
9418
9314
  height = this.pxToPt(bounds.height);
9419
9315
  dataURL = container.canvas.toDataURL('image/png', 0.95);
9420
- // Canvas 添加到 PDF
9421
- this.jspdfCtx.addImage(dataURL, 'PNG', x, y, width, height);
9316
+ this.addImagePdf(dataURL, 'PNG', x, y, width, height);
9422
9317
  }
9423
9318
  catch (err) {
9424
9319
  this.context.logger.error("Error adding canvas to PDF: ".concat(err));
@@ -9431,13 +9326,11 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9431
9326
  return [4 /*yield*/, this.context.cache.match(container.svg)];
9432
9327
  case 10:
9433
9328
  image = _c.sent();
9434
- // 渲染到 Canvas
9435
9329
  this.renderReplacedElement(container, curves, image);
9436
- // 添加到 PDF
9437
9330
  try {
9438
9331
  bounds = contentBox$1(container);
9439
- x = this.pxToPt(bounds.left);
9440
- y = this.pxToPt(bounds.top);
9332
+ x = this.pxToPt(bounds.left - this.options.x);
9333
+ y = this.pxToPt(bounds.top - this.options.y);
9441
9334
  width = this.pxToPt(bounds.width);
9442
9335
  height = this.pxToPt(bounds.height);
9443
9336
  canvas = document.createElement('canvas');
@@ -9445,13 +9338,10 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9445
9338
  canvas.height = container.intrinsicHeight || image.height;
9446
9339
  ctx = canvas.getContext('2d');
9447
9340
  if (ctx) {
9448
- // 设置白色背景或保持透明
9449
9341
  ctx.clearRect(0, 0, canvas.width, canvas.height);
9450
- // 绘制SVG图像
9451
9342
  ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
9452
9343
  dataURL = canvas.toDataURL('image/png');
9453
- // SVG 添加到 PDF
9454
- this.jspdfCtx.addImage(dataURL, 'PNG', x, y, width, height);
9344
+ this.addImagePdf(dataURL, 'PNG', x, y, width, height);
9455
9345
  }
9456
9346
  }
9457
9347
  catch (err) {
@@ -9463,42 +9353,11 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9463
9353
  this.context.logger.error("Error loading svg ".concat(e_2));
9464
9354
  return [3 /*break*/, 12];
9465
9355
  case 12:
9466
- if (!(container instanceof IFrameElementContainer$1 && container.tree)) return [3 /*break*/, 14];
9467
- iframeRenderer = new CanvasRenderer(this.context, {
9468
- scale: this.options.scale,
9469
- fontConfig: this.options.fontConfig,
9470
- backgroundColor: container.backgroundColor,
9471
- x: 0,
9472
- y: 0,
9473
- width: container.width,
9474
- height: container.height
9475
- });
9476
- return [4 /*yield*/, iframeRenderer.render(container.tree)];
9477
- case 13:
9478
- canvas = _c.sent();
9479
- if (container.width && container.height) {
9480
- // this.ctx.drawImage(
9481
- // canvas,
9482
- // 0,
9483
- // 0,
9484
- // container.width,
9485
- // container.height,
9486
- // container.bounds.left,
9487
- // container.bounds.top,
9488
- // container.bounds.width,
9489
- // container.bounds.height
9490
- // );
9491
- this.context2dCtx.drawImage(canvas, 0, 0, container.width, container.height, container.bounds.left, container.bounds.top, container.bounds.width, container.bounds.height);
9492
- }
9493
- _c.label = 14;
9494
- case 14:
9495
- // 处理Input元素
9356
+ if (container instanceof IFrameElementContainer$1 && container.tree) ;
9496
9357
  if (container instanceof InputElementContainer$1) {
9497
9358
  size = Math.min(container.bounds.width, container.bounds.height);
9498
- // 渲染复选框
9499
9359
  if (container.type === CHECKBOX$1) {
9500
9360
  if (container.checked) {
9501
- // this.ctx.save();
9502
9361
  this.context2dCtx.save();
9503
9362
  this.path([
9504
9363
  new Vector$1(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79),
@@ -9509,9 +9368,6 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9509
9368
  new Vector$1(container.bounds.left + size * 0.84, container.bounds.top + size * 0.34085),
9510
9369
  new Vector$1(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79)
9511
9370
  ]);
9512
- // this.ctx.fillStyle = this.convertColor(INPUT_COLOR);
9513
- // this.ctx.fill();
9514
- // this.ctx.restore();
9515
9371
  this.context2dCtx.fillStyle = this.convertColor(INPUT_COLOR$1);
9516
9372
  this.context2dCtx.fill();
9517
9373
  this.context2dCtx.restore();
@@ -9520,47 +9376,25 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9520
9376
  }
9521
9377
  }
9522
9378
  }
9523
- // 渲染单选框
9524
9379
  else if (container.type === RADIO$1) {
9525
9380
  if (container.checked) {
9526
- // this.ctx.save();
9527
- // this.ctx.beginPath();
9528
- // this.ctx.arc(
9529
- // container.bounds.left + size / 2,
9530
- // container.bounds.top + size / 2,
9531
- // size / 4,
9532
- // 0,
9533
- // Math.PI * 2,
9534
- // true
9535
- // );
9536
- // this.ctx.fillStyle = this.convertColor(INPUT_COLOR);
9537
- // this.ctx.fill();
9538
- // this.ctx.restore();
9539
9381
  this.context2dCtx.save();
9540
9382
  this.context2dCtx.beginPath();
9541
9383
  this.context2dCtx.arc(container.bounds.left + size / 2, container.bounds.top + size / 2, size / 4, 0, Math.PI * 2, true);
9542
9384
  this.context2dCtx.fillStyle = this.convertColor(INPUT_COLOR$1);
9543
9385
  this.context2dCtx.fill();
9544
9386
  this.context2dCtx.restore();
9545
- // 在 restore 之后重新设置字体
9546
9387
  }
9547
9388
  }
9548
9389
  }
9549
- // 处理文本输入元素
9550
9390
  if (isTextInputElement$1(container) && container.value.length) {
9551
9391
  _b = this.createFontStyle(styles), fontFamily = _b[0], fontSize = _b[1];
9552
9392
  baseline = this.fontMetrics.getMetrics(fontFamily, fontSize).baseline;
9553
- // this.ctx.font = fontFamily;
9554
- // this.ctx.fillStyle = this.convertColor(styles.color);
9555
- // this.context2dCtx.font = fontFamily;
9556
9393
  this.context2dCtx.fillStyle = this.convertColor(styles.color);
9557
- // this.ctx.textBaseline = 'alphabetic';
9558
- // this.ctx.textAlign = canvasTextAlign(container.styles.textAlign);
9559
9394
  this.context2dCtx.textBaseline = 'alphabetic';
9560
9395
  this.context2dCtx.textAlign = canvasTextAlign$1(container.styles.textAlign);
9561
9396
  bounds = contentBox$1(container);
9562
9397
  x = 0;
9563
- // 根据文本对齐方式调整x坐标
9564
9398
  switch (container.styles.textAlign) {
9565
9399
  case 1 /* TEXT_ALIGN.CENTER */:
9566
9400
  x += bounds.width / 2;
@@ -9570,7 +9404,6 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9570
9404
  break;
9571
9405
  }
9572
9406
  textBounds = bounds.add(x, 0, 0, -bounds.height / 2 + 1);
9573
- // this.ctx.save();
9574
9407
  this.context2dCtx.save();
9575
9408
  this.path([
9576
9409
  new Vector$1(bounds.left, bounds.top),
@@ -9578,56 +9411,45 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9578
9411
  new Vector$1(bounds.left + bounds.width, bounds.top + bounds.height),
9579
9412
  new Vector$1(bounds.left, bounds.top + bounds.height)
9580
9413
  ]);
9581
- // this.ctx.clip();
9582
9414
  this.context2dCtx.clip();
9583
9415
  this.renderTextWithLetterSpacing(new TextBounds$1(container.value, textBounds), styles.letterSpacing, baseline);
9584
- // this.ctx.restore();
9585
- // this.ctx.textBaseline = 'alphabetic';
9586
- // this.ctx.textAlign = 'left';
9587
9416
  this.context2dCtx.restore();
9588
9417
  this.context2dCtx.textBaseline = 'alphabetic';
9589
9418
  this.context2dCtx.textAlign = 'left';
9590
9419
  }
9591
- if (!contains$1(container.styles.display, 2048 /* DISPLAY.LIST_ITEM */)) return [3 /*break*/, 20];
9592
- if (!(container.styles.listStyleImage !== null)) return [3 /*break*/, 19];
9420
+ if (!contains$1(container.styles.display, 2048 /* DISPLAY.LIST_ITEM */)) return [3 /*break*/, 18];
9421
+ if (!(container.styles.listStyleImage !== null)) return [3 /*break*/, 17];
9593
9422
  img = container.styles.listStyleImage;
9594
- if (!(img.type === 0 /* CSSImageType.URL */)) return [3 /*break*/, 18];
9423
+ if (!(img.type === 0 /* CSSImageType.URL */)) return [3 /*break*/, 16];
9595
9424
  image = void 0;
9596
9425
  url = img.url;
9597
- _c.label = 15;
9598
- case 15:
9599
- _c.trys.push([15, 17, , 18]);
9426
+ _c.label = 13;
9427
+ case 13:
9428
+ _c.trys.push([13, 15, , 16]);
9600
9429
  return [4 /*yield*/, this.context.cache.match(url)];
9601
- case 16:
9430
+ case 14:
9602
9431
  image = _c.sent();
9603
- // this.ctx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top);
9604
9432
  this.context2dCtx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top);
9605
- return [3 /*break*/, 18];
9606
- case 17:
9433
+ return [3 /*break*/, 16];
9434
+ case 15:
9607
9435
  _c.sent();
9608
9436
  this.context.logger.error("Error loading list-style-image ".concat(url));
9609
- return [3 /*break*/, 18];
9610
- case 18: return [3 /*break*/, 20];
9611
- case 19:
9437
+ return [3 /*break*/, 16];
9438
+ case 16: return [3 /*break*/, 18];
9439
+ case 17:
9612
9440
  if (paint.listValue && container.styles.listStyleType !== -1 /* LIST_STYLE_TYPE.NONE */) {
9613
9441
  fontFamily = this.createFontStyle(styles)[0];
9614
- // this.ctx.font = fontFamily;
9615
- // this.ctx.fillStyle = this.convertColor(styles.color);
9616
9442
  this.context2dCtx.font = fontFamily;
9617
9443
  this.context2dCtx.fillStyle = this.convertColor(styles.color);
9618
- // this.ctx.textBaseline = 'middle';
9619
- // this.ctx.textAlign = 'right';
9620
9444
  this.context2dCtx.textBaseline = 'middle';
9621
9445
  this.context2dCtx.textAlign = 'right';
9622
9446
  bounds = new Bounds$1(container.bounds.left, container.bounds.top + getAbsoluteValue$1(container.styles.paddingTop, container.bounds.width), container.bounds.width, computeLineHeight$1(styles.lineHeight, styles.fontSize.number) / 2 + 1);
9623
9447
  this.renderTextWithLetterSpacing(new TextBounds$1(paint.listValue, bounds), styles.letterSpacing, computeLineHeight$1(styles.lineHeight, styles.fontSize.number) / 2 + 2);
9624
- // this.ctx.textBaseline = 'bottom';
9625
- // this.ctx.textAlign = 'left';
9626
9448
  this.context2dCtx.textBaseline = 'bottom';
9627
9449
  this.context2dCtx.textAlign = 'left';
9628
9450
  }
9629
- _c.label = 20;
9630
- case 20:
9451
+ _c.label = 18;
9452
+ case 18:
9631
9453
  if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
9632
9454
  this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
9633
9455
  }
@@ -9636,7 +9458,6 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9636
9458
  });
9637
9459
  });
9638
9460
  };
9639
- // 渲染堆叠上下文内容
9640
9461
  CanvasRenderer.prototype.renderStackContent = function (stack) {
9641
9462
  return __awaiter$1(this, void 0, void 0, function () {
9642
9463
  var _i, _a, child, _b, _c, child, _d, _e, child, _f, _g, child, _h, _j, child, _k, _l, child, _m, _o, child;
@@ -9646,12 +9467,8 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9646
9467
  if (contains$1(stack.element.container.flags, 16 /* FLAGS.DEBUG_RENDER */)) {
9647
9468
  debugger;
9648
9469
  }
9649
- // https://www.w3.org/TR/css-position-3/#painting-order
9650
- // 1. the background and borders of the element forming the stacking context.
9651
9470
  return [4 /*yield*/, this.renderNodeBackgroundAndBorders(stack.element)];
9652
9471
  case 1:
9653
- // https://www.w3.org/TR/css-position-3/#painting-order
9654
- // 1. the background and borders of the element forming the stacking context.
9655
9472
  _p.sent();
9656
9473
  _i = 0, _a = stack.negativeZIndex;
9657
9474
  _p.label = 2;
@@ -9665,11 +9482,8 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9665
9482
  case 4:
9666
9483
  _i++;
9667
9484
  return [3 /*break*/, 2];
9668
- case 5:
9669
- // 3. For all its in-flow, non-positioned, block-level descendants in tree order:
9670
- return [4 /*yield*/, this.renderNodeContent(stack.element)];
9485
+ case 5: return [4 /*yield*/, this.renderNodeContent(stack.element)];
9671
9486
  case 6:
9672
- // 3. For all its in-flow, non-positioned, block-level descendants in tree order:
9673
9487
  _p.sent();
9674
9488
  _b = 0, _c = stack.nonInlineLevel;
9675
9489
  _p.label = 7;
@@ -9753,16 +9567,7 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9753
9567
  });
9754
9568
  });
9755
9569
  };
9756
- // 创建遮罩
9757
9570
  CanvasRenderer.prototype.mask = function (paths) {
9758
- // this.ctx.beginPath();
9759
- // this.ctx.moveTo(0, 0);
9760
- // this.ctx.lineTo(this.canvas.width, 0);
9761
- // this.ctx.lineTo(this.canvas.width, this.canvas.height);
9762
- // this.ctx.lineTo(0, this.canvas.height);
9763
- // this.ctx.lineTo(0, 0);
9764
- // this.formatPath(paths.slice(0).reverse());
9765
- // this.ctx.closePath();
9766
9571
  this.context2dCtx.beginPath();
9767
9572
  this.context2dCtx.moveTo(0, 0);
9768
9573
  this.context2dCtx.lineTo(this.options.width, 0);
@@ -9772,54 +9577,33 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9772
9577
  this.formatPath(paths.slice(0).reverse());
9773
9578
  this.context2dCtx.closePath();
9774
9579
  };
9775
- // 创建路径
9776
9580
  CanvasRenderer.prototype.path = function (paths) {
9777
- // this.ctx.beginPath();
9778
- // this.formatPath(paths);
9779
- // this.ctx.closePath();
9780
9581
  this.context2dCtx.beginPath();
9781
9582
  this.formatPath(paths);
9782
9583
  this.context2dCtx.closePath();
9783
9584
  };
9784
- // 格式化路径
9785
9585
  CanvasRenderer.prototype.formatPath = function (paths) {
9786
9586
  var _this = this;
9787
9587
  paths.forEach(function (point, index) {
9788
9588
  var start = isBezierCurve$1(point) ? point.start : point;
9789
9589
  if (index === 0) {
9790
- // this.ctx.moveTo(start.x, start.y);
9791
9590
  _this.context2dCtx.moveTo(start.x, start.y);
9792
9591
  }
9793
9592
  else {
9794
- // this.ctx.lineTo(start.x, start.y);
9795
9593
  _this.context2dCtx.lineTo(start.x, start.y);
9796
9594
  }
9797
9595
  if (isBezierCurve$1(point)) {
9798
- // this.ctx.bezierCurveTo(
9799
- // point.startControl.x,
9800
- // point.startControl.y,
9801
- // point.endControl.x,
9802
- // point.endControl.y,
9803
- // point.end.x,
9804
- // point.end.y
9805
- // );
9806
9596
  _this.context2dCtx.bezierCurveTo(point.startControl.x, point.startControl.y, point.endControl.x, point.endControl.y, point.end.x, point.end.y);
9807
9597
  }
9808
9598
  });
9809
9599
  };
9810
- // 渲染重复图案
9811
9600
  CanvasRenderer.prototype.renderRepeat = function (path, pattern, offsetX, offsetY) {
9812
9601
  this.path(path);
9813
9602
  this.ctx.fillStyle = pattern;
9814
- // this.ctx.translate(offsetX, offsetY);
9815
- // this.ctx.fill();
9816
- // this.ctx.translate(-offsetX, -offsetY);
9817
- // this.context2dCtx.fillStyle =this.convertColor(pattern) ;
9818
9603
  this.context2dCtx.translate(offsetX, offsetY);
9819
9604
  this.context2dCtx.fill();
9820
9605
  this.context2dCtx.translate(-offsetX, -offsetY);
9821
9606
  };
9822
- // 调整图片大小
9823
9607
  CanvasRenderer.prototype.resizeImage = function (image, width, height) {
9824
9608
  var _a;
9825
9609
  if (image.width === width && image.height === height) {
@@ -9833,7 +9617,6 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9833
9617
  ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
9834
9618
  return canvas;
9835
9619
  };
9836
- // 渲染背景图片
9837
9620
  CanvasRenderer.prototype.renderBackgroundImage = function (container) {
9838
9621
  return __awaiter$1(this, void 0, void 0, function () {
9839
9622
  var index, _i, _a, backgroundImage, image, url, _b, path, x, y, width, height, pattern, xPt, yPt, widthPt, heightPt;
@@ -9844,7 +9627,7 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9844
9627
  _i = 0, _a = container.styles.backgroundImage.slice(0).reverse();
9845
9628
  _c.label = 1;
9846
9629
  case 1:
9847
- if (!(_i < _a.length)) return [3 /*break*/, 9];
9630
+ if (!(_i < _a.length)) return [3 /*break*/, 8];
9848
9631
  backgroundImage = _a[_i];
9849
9632
  if (!(backgroundImage.type === 0 /* CSSImageType.URL */)) return [3 /*break*/, 6];
9850
9633
  image = void 0;
@@ -9869,55 +9652,35 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9869
9652
  ]), path = _b[0], x = _b[1], y = _b[2], width = _b[3], height = _b[4];
9870
9653
  pattern = this.ctx.createPattern(this.resizeImage(image, width, height), 'repeat');
9871
9654
  this.renderRepeat(path, pattern, x, y);
9872
- xPt = this.pxToPt(x);
9873
- yPt = this.pxToPt(y);
9655
+ xPt = this.pxToPt(x - this.options.x);
9656
+ yPt = this.pxToPt(y - this.options.y);
9874
9657
  widthPt = this.pxToPt(width);
9875
9658
  heightPt = this.pxToPt(height);
9876
- // console.log('绘制背景图片', xPt, yPt, image)
9877
- this.jspdfCtx.addImage(image, 'JPEG', xPt, yPt, widthPt, heightPt);
9659
+ this.addImagePdf(image, 'JPEG', xPt, yPt, widthPt, heightPt);
9878
9660
  }
9879
- return [3 /*break*/, 7];
9661
+ _c.label = 6;
9880
9662
  case 6:
9881
- if (isLinearGradient$1(backgroundImage)) ;
9882
- else if (isRadialGradient$1(backgroundImage)) ;
9663
+ index--;
9883
9664
  _c.label = 7;
9884
9665
  case 7:
9885
- index--;
9886
- _c.label = 8;
9887
- case 8:
9888
9666
  _i++;
9889
9667
  return [3 /*break*/, 1];
9890
- case 9: return [2 /*return*/];
9668
+ case 8: return [2 /*return*/];
9891
9669
  }
9892
9670
  });
9893
9671
  });
9894
9672
  };
9895
- /**
9896
- * 渲染实线边框
9897
- * @param color - 边框颜色
9898
- * @param side - 边的位置(0-3,分别代表上右下左)
9899
- * @param curvePoints - 边框曲线点
9900
- */
9901
9673
  CanvasRenderer.prototype.renderSolidBorder = function (color, side, curvePoints) {
9902
9674
  return __awaiter$1(this, void 0, void 0, function () {
9903
9675
  return __generator$1(this, function (_a) {
9904
- // console.log('绘制边框')
9905
- // 解析边框路径
9906
- // console.log('Border curve points:', JSON.stringify(curvePoints));
9907
- // console.log('Page height:', this.jspdf.internal.pageSize.height);
9908
9676
  this.path(parsePathForBorder$1(curvePoints, side));
9909
- // 设置填充颜色
9910
- // this.ctx.fillStyle = this.convertColor(color);
9911
9677
  this.context2dCtx.fillStyle = this.convertColor(color);
9912
- // 填充路径
9913
- // this.ctx.fill();
9914
9678
  this.jspdfCtx.fill();
9915
9679
  this.context2dCtx.fill();
9916
9680
  return [2 /*return*/];
9917
9681
  });
9918
9682
  });
9919
9683
  };
9920
- // 渲染双线边框
9921
9684
  CanvasRenderer.prototype.renderDoubleBorder = function (color, width, side, curvePoints) {
9922
9685
  return __awaiter$1(this, void 0, void 0, function () {
9923
9686
  var outerPaths, innerPaths;
@@ -9932,27 +9695,22 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9932
9695
  case 2:
9933
9696
  outerPaths = parsePathForBorderDoubleOuter$1(curvePoints, side);
9934
9697
  this.path(outerPaths);
9935
- // this.ctx.fillStyle = this.convertColor(color);
9936
- // this.ctx.fill();
9937
9698
  this.context2dCtx.fillStyle = this.convertColor(color);
9938
9699
  this.context2dCtx.fill();
9939
9700
  innerPaths = parsePathForBorderDoubleInner$1(curvePoints, side);
9940
9701
  this.path(innerPaths);
9941
- // this.ctx.fill();
9942
9702
  this.context2dCtx.fill();
9943
9703
  return [2 /*return*/];
9944
9704
  }
9945
9705
  });
9946
9706
  });
9947
9707
  };
9948
- // 渲染节点的背景和边框
9949
9708
  CanvasRenderer.prototype.renderNodeBackgroundAndBorders = function (paint) {
9950
9709
  return __awaiter$1(this, void 0, void 0, function () {
9951
9710
  var styles, hasBackground, borders, backgroundPaintingArea, foreignobjectrendering, side, _i, borders_1, border;
9952
9711
  return __generator$1(this, function (_a) {
9953
9712
  switch (_a.label) {
9954
9713
  case 0:
9955
- // 应用背景和边框的效果
9956
9714
  this.applyEffects(paint.getEffects(2 /* EffectTarget.BACKGROUND_BORDERS */));
9957
9715
  styles = paint.container.styles;
9958
9716
  hasBackground = !isTransparent$1(styles.backgroundColor) || styles.backgroundImage.length;
@@ -9965,8 +9723,6 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9965
9723
  backgroundPaintingArea = calculateBackgroundCurvedPaintingArea$1(getBackgroundValueForIndex$1(styles.backgroundClip, 0), paint.curves);
9966
9724
  foreignobjectrendering = paint.container.foreignobjectrendering;
9967
9725
  if (!(hasBackground || styles.boxShadow.length)) return [3 /*break*/, 2];
9968
- // console.log(paint,foreignobjectrendering, 'paint边框')
9969
- // 在 save 之前确保字体设置正确
9970
9726
  if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
9971
9727
  this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
9972
9728
  }
@@ -9974,12 +9730,7 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9974
9730
  this.context2dCtx.save();
9975
9731
  this.path(backgroundPaintingArea);
9976
9732
  this.context2dCtx.clip();
9977
- // this.ctx.save();
9978
- // this.path(backgroundPaintingArea);
9979
- // this.ctx.clip();
9980
9733
  if (!isTransparent$1(styles.backgroundColor)) {
9981
- // this.ctx.fillStyle = asString(styles.backgroundColor);
9982
- // this.ctx.fill();
9983
9734
  this.context2dCtx.fillStyle = this.convertColor(styles.backgroundColor);
9984
9735
  this.context2dCtx.fill();
9985
9736
  }
@@ -9987,9 +9738,7 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
9987
9738
  return [4 /*yield*/, this.renderBackgroundImage(paint.container)];
9988
9739
  case 1:
9989
9740
  _a.sent();
9990
- // this.ctx.restore();
9991
9741
  this.context2dCtx.restore();
9992
- // 在 restore 之后重新设置字体
9993
9742
  if (this.options.fontConfig && this.options.fontConfig.fontFamily) {
9994
9743
  this.jspdfCtx.setFont(this.options.fontConfig.fontFamily);
9995
9744
  }
@@ -10036,27 +9785,15 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
10036
9785
  });
10037
9786
  });
10038
9787
  };
10039
- // 这个方法用于渲染虚线和点线边框
10040
- CanvasRenderer.prototype.renderDashedDottedBorder = function (color, // 边框颜色
10041
- width, // 边框宽度
10042
- side, // 边的位置(0-3,分别代表上右下左)
10043
- curvePoints, // 边框曲线点
10044
- style // 边框样式(DASHED或DOTTED)
10045
- ) {
9788
+ CanvasRenderer.prototype.renderDashedDottedBorder = function (color, width, side, curvePoints, style) {
10046
9789
  return __awaiter$1(this, void 0, void 0, function () {
10047
9790
  var strokePaths, boxPaths, startX, startY, endX, endY, length, dashLength, spaceLength, useLineDash, multiplier, numberOfDashes, minSpace, maxSpace, path1, path2, x1, y1, x2, y2, path1, path2;
10048
9791
  return __generator$1(this, function (_a) {
10049
- // this.ctx.save(); // 保存当前画布状态
10050
- // this.jspdfCtx.saveGraphicsState(); // 保存PDF绘图状态
10051
9792
  this.context2dCtx.save();
10052
9793
  strokePaths = parsePathForBorderStroke$1(curvePoints, side);
10053
9794
  boxPaths = parsePathForBorder$1(curvePoints, side);
10054
- // 如果是虚线边框,需要先裁剪路径
10055
9795
  if (style === 2 /* BORDER_STYLE.DASHED */) {
10056
9796
  this.path(boxPaths);
10057
- // this.ctx.clip();
10058
- // // PDF裁剪路径
10059
- // this.jspdfCtx.clip();
10060
9797
  this.context2dCtx.clip();
10061
9798
  }
10062
9799
  if (isBezierCurve$1(boxPaths[0])) {
@@ -10081,10 +9818,8 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
10081
9818
  else {
10082
9819
  length = Math.abs(startY - endY);
10083
9820
  }
10084
- // 开始绘制路径
10085
- // this.ctx.beginPath();
10086
9821
  this.context2dCtx.beginPath();
10087
- this.jspdfCtx.setDrawColor(this.convertColor(color)); // 设置PDF绘制颜色
9822
+ this.jspdfCtx.setDrawColor(this.convertColor(color));
10088
9823
  if (style === 3 /* BORDER_STYLE.DOTTED */) {
10089
9824
  this.formatPath(strokePaths);
10090
9825
  }
@@ -10115,34 +9850,23 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
10115
9850
  ? minSpace
10116
9851
  : maxSpace;
10117
9852
  }
10118
- // 设置虚线样式
10119
9853
  if (useLineDash) {
10120
9854
  if (style === 3 /* BORDER_STYLE.DOTTED */) {
10121
- // this.ctx.setLineDash([0, dashLength + spaceLength]);
10122
- this.jspdfCtx.setLineDashPattern([0, dashLength + spaceLength], 0); // PDF虚线样式
9855
+ this.jspdfCtx.setLineDashPattern([0, dashLength + spaceLength], 0);
10123
9856
  }
10124
9857
  else {
10125
- // this.ctx.setLineDash([dashLength, spaceLength]);
10126
- this.jspdfCtx.setLineDashPattern([dashLength, spaceLength], 0); // PDF虚线样式
9858
+ this.jspdfCtx.setLineDashPattern([dashLength, spaceLength], 0);
10127
9859
  }
10128
9860
  }
10129
- // 设置线条样式并绘制
10130
9861
  if (style === 3 /* BORDER_STYLE.DOTTED */) {
10131
- // this.ctx.lineCap = 'round';
10132
- // this.ctx.lineWidth = width;
10133
- this.jspdfCtx.setLineCap('round'); // PDF线帽样式
9862
+ this.jspdfCtx.setLineCap('round');
10134
9863
  this.jspdfCtx.setLineWidth(width);
10135
9864
  }
10136
9865
  else {
10137
- // this.ctx.lineWidth = width * 2 + 1.1;
10138
9866
  this.jspdfCtx.setLineWidth(width * 2 + 1.1);
10139
9867
  }
10140
- // this.ctx.strokeStyle = this.convertColor(color);
10141
- // this.ctx.stroke();
10142
- this.jspdfCtx.stroke(); // PDF绘制线条
10143
- // this.ctx.setLineDash([]);
10144
- this.jspdfCtx.setLineDashPattern([], 0); // 重置PDF虚线样式
10145
- // 处理虚线边框的圆角连接处
9868
+ this.jspdfCtx.stroke();
9869
+ this.jspdfCtx.setLineDashPattern([], 0);
10146
9870
  if (style === 2 /* BORDER_STYLE.DASHED */) {
10147
9871
  if (isBezierCurve$1(boxPaths[0])) {
10148
9872
  path1 = boxPaths[3];
@@ -10162,42 +9886,189 @@ var CanvasRenderer$1 = /** @class */ (function (_super) {
10162
9886
  if (isBezierCurve$1(boxPaths[1])) {
10163
9887
  path1 = boxPaths[1];
10164
9888
  path2 = boxPaths[2];
10165
- // this.ctx.beginPath();
10166
- // this.formatPath([new Vector(path1.end.x, path1.end.y), new Vector(path2.start.x, path2.start.y)]);
10167
- // this.ctx.stroke();
10168
- this.jspdfCtx.lines([[path1.end.x, path1.end.y, path2.start.x, path2.start.y]], path1.end.x, path1.end.y); // PDF绘制连接线
9889
+ this.jspdfCtx.lines([[path1.end.x, path1.end.y, path2.start.x, path2.start.y]], path1.end.x, path1.end.y);
10169
9890
  this.jspdfCtx.stroke();
10170
9891
  }
10171
9892
  }
10172
- // this.ctx.restore(); // 恢复画布状态
10173
- this.jspdfCtx.restoreGraphicsState(); // 恢复PDF绘图状态
9893
+ this.jspdfCtx.restoreGraphicsState();
9894
+ return [2 /*return*/];
9895
+ });
9896
+ });
9897
+ };
9898
+ CanvasRenderer.prototype.addPage = function (offsetY) {
9899
+ return __awaiter$1(this, void 0, void 0, function () {
9900
+ return __generator$1(this, function (_a) {
9901
+ this.context2dCtx.translate(0, -offsetY);
9902
+ this.jspdfCtx.addPage();
10174
9903
  return [2 /*return*/];
10175
9904
  });
10176
9905
  });
10177
9906
  };
10178
- CanvasRenderer.prototype.render = function (element) {
9907
+ CanvasRenderer.prototype.renderPage = function (element, pageNum) {
10179
9908
  return __awaiter$1(this, void 0, void 0, function () {
10180
- var stack, pdfBlob;
9909
+ var cfg, pageW, pageH, mt, mb, bx, by, bw, bh, stack, headerText, headerPos, footerText, footerPos;
10181
9910
  return __generator$1(this, function (_a) {
10182
9911
  switch (_a.label) {
10183
9912
  case 0:
9913
+ cfg = this.options.pageConfig;
9914
+ pageW = this.jspdfCtx.internal.pageSize.getWidth();
9915
+ pageH = this.jspdfCtx.internal.pageSize.getHeight();
9916
+ mt = 0;
9917
+ mb = 0;
10184
9918
  if (this.options.backgroundColor) {
10185
- // this.ctx.fillStyle = this.convertColor(this.options.backgroundColor);
10186
- // this.ctx.fillRect(this.options.x, this.options.y, this.options.width, this.options.height);
10187
- this.jspdfCtx.setFillColor(this.convertColor(this.options.backgroundColor)); // PDF填充背景颜色
10188
- this.jspdfCtx.rect(this.options.x, this.options.y, this.options.width, this.options.height, 'F'); // PDF绘制矩形
9919
+ this.jspdfCtx.setFillColor(this.convertColor(this.options.backgroundColor));
9920
+ bx = this.safe(this.options.x);
9921
+ by = this.safe(this.options.y);
9922
+ bw = Math.max(1, this.safe(this.options.width, 1));
9923
+ bh = Math.max(1, this.safe(this.options.height, 1));
9924
+ this.jspdfCtx.rect(bx, by, bw, bh, 'F');
10189
9925
  }
10190
9926
  stack = parseStackingContexts$1(element);
10191
9927
  return [4 /*yield*/, this.renderStack(stack)];
10192
9928
  case 1:
10193
9929
  _a.sent();
10194
9930
  this.applyEffects([]);
10195
- pdfBlob = this.jspdfCtx.output('blob');
10196
- return [2 /*return*/, pdfBlob];
9931
+ if (cfg === null || cfg === void 0 ? void 0 : cfg.header) {
9932
+ headerText = String(cfg.header.content)
9933
+ .replace('${currentPage}', String(pageNum))
9934
+ .replace('${totalPages}', String(this.totalPages));
9935
+ this.jspdfCtx.setFontSize(this.safe(this.pxToPt(cfg.header.contentFontSize), 1));
9936
+ this.setTextColorFromString(cfg.header.contentColor);
9937
+ headerPos = this.computeContentPosition(cfg.header.contentPosition, pageW, pageH, cfg.header.height, mt, mb, 'header', cfg.header.padding);
9938
+ this.textPdf(headerText, headerPos.x, headerPos.y, headerPos.align);
9939
+ }
9940
+ if (cfg === null || cfg === void 0 ? void 0 : cfg.footer) {
9941
+ footerText = String(cfg.footer.content)
9942
+ .replace('${currentPage}', String(pageNum))
9943
+ .replace('${totalPages}', String(this.totalPages));
9944
+ this.jspdfCtx.setFontSize(this.safe(this.pxToPt(cfg.footer.contentFontSize), 1));
9945
+ this.setTextColorFromString(cfg.footer.contentColor);
9946
+ footerPos = this.computeContentPosition(cfg.footer.contentPosition, pageW, pageH, cfg.footer.height, mt, mb, 'footer', cfg.footer.padding);
9947
+ this.textPdf(footerText, footerPos.x, footerPos.y, footerPos.align);
9948
+ }
9949
+ return [2 /*return*/];
10197
9950
  }
10198
9951
  });
10199
9952
  });
10200
9953
  };
9954
+ CanvasRenderer.prototype.setTotalPages = function (total) {
9955
+ this.totalPages = total;
9956
+ };
9957
+ CanvasRenderer.prototype.setTextColorFromString = function (color) {
9958
+ var _a;
9959
+ var named = {
9960
+ black: [0, 0, 0],
9961
+ white: [255, 255, 255],
9962
+ red: [255, 0, 0],
9963
+ green: [0, 128, 0],
9964
+ blue: [0, 0, 255],
9965
+ gray: [128, 128, 128]
9966
+ };
9967
+ var r = 0, g = 0, b = 0;
9968
+ var c = (color === null || color === void 0 ? void 0 : color.toLowerCase()) || 'black';
9969
+ if (c in named) {
9970
+ _a = named[c], r = _a[0], g = _a[1], b = _a[2];
9971
+ }
9972
+ else if (c.startsWith('#') && (c.length === 7 || c.length === 4)) {
9973
+ var hex = c.length === 4 ? "#".concat(c[1]).concat(c[1]).concat(c[2]).concat(c[2]).concat(c[3]).concat(c[3]) : c;
9974
+ r = parseInt(hex.slice(1, 3), 16);
9975
+ g = parseInt(hex.slice(3, 5), 16);
9976
+ b = parseInt(hex.slice(5, 7), 16);
9977
+ }
9978
+ this.jspdfCtx.setTextColor(r, g, b);
9979
+ };
9980
+ CanvasRenderer.prototype.safe = function (n, min) {
9981
+ if (min === void 0) { min = 0; }
9982
+ var v = Number(n);
9983
+ return Number.isFinite(v) ? v : min;
9984
+ };
9985
+ CanvasRenderer.prototype.textPdf = function (text, x, y, align) {
9986
+ var sx = this.safe(x);
9987
+ var sy = this.safe(y);
9988
+ this.jspdfCtx.text(String(text), sx, sy, { align: align });
9989
+ };
9990
+ CanvasRenderer.prototype.computeContentPosition = function (pos, pageW, pageH, areaH, mt, mb, area, paddingPx) {
9991
+ var _this = this;
9992
+ var _a = (paddingPx !== null && paddingPx !== void 0 ? paddingPx : [24, 24, 24, 24]).map(function (v) { return _this.pxToPt(v); }), pt = _a[0], pr = _a[1], pb = _a[2], pl = _a[3];
9993
+ var areaHPt = this.pxToPt(areaH);
9994
+ var mtPt = this.pxToPt(mt);
9995
+ var mbPt = this.pxToPt(mb);
9996
+ if (Array.isArray(pos) && pos.length >= 2) {
9997
+ return { x: this.pxToPt(pos[0]), y: this.pxToPt(pos[1]), align: 'left' };
9998
+ }
9999
+ if (area === 'header') {
10000
+ switch (pos) {
10001
+ case 'center':
10002
+ return {
10003
+ x: pageW / 2,
10004
+ y: mtPt + pt + (areaHPt - pt - pb) / 2,
10005
+ align: 'center'
10006
+ };
10007
+ case 'centerLeft':
10008
+ return { x: pl, y: mtPt + pt + (areaHPt - pt - pb) / 2, align: 'left' };
10009
+ case 'centerRight':
10010
+ return { x: pageW - pr, y: mtPt + pt + (areaHPt - pt - pb) / 2, align: 'right' };
10011
+ case 'centerTop':
10012
+ return { x: pageW / 2, y: mtPt + pt, align: 'center' };
10013
+ case 'centerBottom':
10014
+ return { x: pageW / 2, y: mtPt + areaHPt - pb, align: 'center' };
10015
+ case 'leftTop':
10016
+ return { x: pl, y: mtPt + pt, align: 'left' };
10017
+ case 'leftBottom':
10018
+ return { x: pl, y: mtPt + areaHPt - pb, align: 'left' };
10019
+ case 'rightTop':
10020
+ return { x: pageW - pr, y: mtPt + pt, align: 'right' };
10021
+ case 'rightBottom':
10022
+ return { x: pageW - pr, y: mtPt + areaHPt - pb, align: 'right' };
10023
+ default:
10024
+ return { x: pl, y: mtPt + pt, align: 'left' };
10025
+ }
10026
+ }
10027
+ else {
10028
+ switch (pos) {
10029
+ case 'center':
10030
+ return {
10031
+ x: pageW / 2,
10032
+ y: pageH - mbPt - areaHPt + pt + (areaHPt - pt - pb) / 2,
10033
+ align: 'center'
10034
+ };
10035
+ case 'centerLeft':
10036
+ return { x: pl, y: pageH - mbPt - areaHPt + pt + (areaHPt - pt - pb) / 2, align: 'left' };
10037
+ case 'centerRight':
10038
+ return { x: pageW - pr, y: pageH - mbPt - areaHPt + pt + (areaHPt - pt - pb) / 2, align: 'right' };
10039
+ case 'centerTop':
10040
+ return { x: pageW / 2, y: pageH - mbPt - areaHPt + pt, align: 'center' };
10041
+ case 'centerBottom':
10042
+ return { x: pageW / 2, y: pageH - mbPt - pb, align: 'center' };
10043
+ case 'leftTop':
10044
+ return { x: pl, y: pageH - mbPt - areaHPt + pt, align: 'left' };
10045
+ case 'leftBottom':
10046
+ return { x: pl, y: pageH - mbPt - pb, align: 'left' };
10047
+ case 'rightTop':
10048
+ return { x: pageW - pr, y: pageH - mbPt - areaHPt + pt, align: 'right' };
10049
+ case 'rightBottom':
10050
+ return { x: pageW - pr, y: pageH - mbPt - pb, align: 'right' };
10051
+ default:
10052
+ return { x: pl, y: pageH - mbPt - pb, align: 'left' };
10053
+ }
10054
+ }
10055
+ };
10056
+ CanvasRenderer.prototype.addImagePdf = function (img, format, x, y, w, h) {
10057
+ var sx = this.safe(x);
10058
+ var sy = this.safe(y);
10059
+ var sw = Math.max(1, this.safe(w, 1));
10060
+ var sh = Math.max(1, this.safe(h, 1));
10061
+ this.jspdfCtx.addImage(img, format, sx, sy, sw, sh);
10062
+ };
10063
+ CanvasRenderer.prototype.output = function () {
10064
+ return __awaiter$1(this, void 0, void 0, function () {
10065
+ var pdfBlob;
10066
+ return __generator$1(this, function (_a) {
10067
+ pdfBlob = this.jspdfCtx.output('blob');
10068
+ return [2 /*return*/, pdfBlob];
10069
+ });
10070
+ });
10071
+ };
10201
10072
  return CanvasRenderer;
10202
10073
  }(Renderer$1));
10203
10074
  var isTextInputElement$1 = function (container) {
@@ -10242,19 +10113,258 @@ var fixIOSSystemFonts$1 = function (fontFamilies) {
10242
10113
  : fontFamilies;
10243
10114
  };
10244
10115
 
10116
+ // 96 DPI pixel values
10117
+ var PAGE_FORMAT_MAP = {
10118
+ // A Series
10119
+ a0: { width: 3179, height: 4494 },
10120
+ a1: { width: 2245, height: 3179 },
10121
+ a2: { width: 1587, height: 2245 },
10122
+ a3: { width: 1123, height: 1587 },
10123
+ a4: { width: 794, height: 1123 },
10124
+ a5: { width: 559, height: 794 },
10125
+ a6: { width: 397, height: 559 },
10126
+ a7: { width: 280, height: 397 },
10127
+ a8: { width: 197, height: 280 },
10128
+ a9: { width: 140, height: 197 },
10129
+ a10: { width: 98, height: 140 },
10130
+ // B Series
10131
+ b0: { width: 3780, height: 5344 },
10132
+ b1: { width: 2672, height: 3780 },
10133
+ b2: { width: 1890, height: 2672 },
10134
+ b3: { width: 1334, height: 1890 },
10135
+ b4: { width: 945, height: 1334 },
10136
+ b5: { width: 665, height: 945 },
10137
+ b6: { width: 472, height: 665 },
10138
+ b7: { width: 333, height: 472 },
10139
+ b8: { width: 234, height: 333 },
10140
+ b9: { width: 166, height: 234 },
10141
+ b10: { width: 117, height: 166 },
10142
+ // C Series
10143
+ c0: { width: 3466, height: 4902 },
10144
+ c1: { width: 2449, height: 3466 },
10145
+ c2: { width: 1731, height: 2449 },
10146
+ c3: { width: 1225, height: 1731 },
10147
+ c4: { width: 865, height: 1225 },
10148
+ c5: { width: 612, height: 865 },
10149
+ c6: { width: 431, height: 612 },
10150
+ c7: { width: 306, height: 431 },
10151
+ c8: { width: 215, height: 306 },
10152
+ c9: { width: 151, height: 215 },
10153
+ c10: { width: 106, height: 151 },
10154
+ // Others
10155
+ dl: { width: 416, height: 832 },
10156
+ letter: { width: 816, height: 1056 },
10157
+ 'government-letter': { width: 768, height: 1008 },
10158
+ legal: { width: 816, height: 1344 },
10159
+ 'junior-legal': { width: 480, height: 768 },
10160
+ ledger: { width: 1632, height: 1056 },
10161
+ tabloid: { width: 1056, height: 1632 },
10162
+ 'credit-card': { width: 204, height: 324 },
10163
+ // Aliases / Compatibility
10164
+ A4: { width: 794, height: 1123 }
10165
+ };
10166
+
10167
+ var offSetPageObj = {};
10168
+ var offSetTotal = 0;
10169
+ var activePageHeight = 1123;
10170
+ var pageMarginTop = 0;
10171
+ var pageMarginBottom = 0;
10172
+ var cloneContainerShallow = function (src) {
10173
+ var c = Object.create(Object.getPrototypeOf(src));
10174
+ var srcObj = src;
10175
+ for (var _i = 0, _a = Object.keys(srcObj); _i < _a.length; _i++) {
10176
+ var key = _a[_i];
10177
+ if (key === 'elements' || key === 'bounds' || key === 'styles' || key === 'textNodes')
10178
+ continue;
10179
+ c[key] = srcObj[key];
10180
+ }
10181
+ c.context = src.context;
10182
+ c.styles = Object.assign(Object.create(Object.getPrototypeOf(src.styles)), src.styles);
10183
+ c.textNodes = src.textNodes;
10184
+ c.flags = src.flags;
10185
+ c.bounds = new Bounds$1(src.bounds.left, src.bounds.top, src.bounds.width, src.bounds.height);
10186
+ c.elements = [];
10187
+ return c;
10188
+ };
10189
+ var cloneTextContainerShallow = function (src) {
10190
+ var c = Object.create(Object.getPrototypeOf(src));
10191
+ c.text = src.text;
10192
+ c.textBounds = [];
10193
+ return c;
10194
+ };
10195
+ var computeMaxBottom = function (node) {
10196
+ var maxBottom = node.bounds.top + node.bounds.height;
10197
+ for (var _i = 0, _a = node.textNodes; _i < _a.length; _i++) {
10198
+ var tn = _a[_i];
10199
+ for (var _b = 0, _c = tn.textBounds; _b < _c.length; _b++) {
10200
+ var tb = _c[_b];
10201
+ var b = tb.bounds.top + tb.bounds.height;
10202
+ if (b > maxBottom)
10203
+ maxBottom = b;
10204
+ }
10205
+ }
10206
+ for (var _d = 0, _e = node.elements; _d < _e.length; _d++) {
10207
+ var el = _e[_d];
10208
+ var b = computeMaxBottom(el);
10209
+ if (b > maxBottom)
10210
+ maxBottom = b;
10211
+ }
10212
+ return maxBottom;
10213
+ };
10214
+ var filterTextNodesForPage = function (container, pageStart, pageEnd) {
10215
+ var result = [];
10216
+ for (var _i = 0, _a = container.textNodes; _i < _a.length; _i++) {
10217
+ var tc = _a[_i];
10218
+ var filtered = [];
10219
+ for (var _b = 0, _c = tc.textBounds; _b < _c.length; _b++) {
10220
+ var tb = _c[_b];
10221
+ var pageIndex = Math.floor(pageEnd / activePageHeight);
10222
+ var maxKey = Math.max.apply(Math, Object.keys(offSetPageObj).map(function (k) { return +k; }));
10223
+ var activePageOffset = offSetPageObj[maxKey] || 0;
10224
+ var top_1 = tb.bounds.top + activePageOffset;
10225
+ var bottom = tb.bounds.top + tb.bounds.height + activePageOffset;
10226
+ var intersects = bottom > pageStart && top_1 < pageEnd;
10227
+ var crossesToNextPage = bottom > pageEnd;
10228
+ if (intersects && !crossesToNextPage) {
10229
+ var offsetNum = 0;
10230
+ if (top_1 < pageStart) {
10231
+ offsetNum = pageStart - top_1;
10232
+ if (!offSetPageObj[pageIndex] ||
10233
+ (offSetPageObj[pageIndex] && offSetPageObj[pageIndex] < offsetNum)) {
10234
+ if (offSetPageObj[pageIndex] && offSetPageObj[pageIndex] < offsetNum) {
10235
+ offSetTotal = offSetTotal - offSetPageObj[pageIndex] + offsetNum;
10236
+ }
10237
+ else {
10238
+ offSetTotal += offsetNum;
10239
+ }
10240
+ offSetPageObj[pageIndex] = offSetTotal;
10241
+ }
10242
+ }
10243
+ var visibleTop = Math.max(top_1, pageStart);
10244
+ var visibleBottom = Math.min(bottom, pageEnd);
10245
+ var newTop = visibleTop - pageStart;
10246
+ var newHeight = Math.max(0, visibleBottom - visibleTop);
10247
+ // 根据可见区域生成新的 Bounds
10248
+ var nb = new Bounds$1(tb.bounds.left, newTop + pageMarginTop, tb.bounds.width, newHeight);
10249
+ // if (pageIndex == 3) {
10250
+ // console.log(
10251
+ // 'nb',
10252
+ // nb,
10253
+ // 'pageStart',
10254
+ // pageStart,
10255
+ // 'tb.bounds.top',
10256
+ // tb.bounds.top,
10257
+ // 'activePageOffset',
10258
+ // activePageOffset,
10259
+ // (tb as any).text
10260
+ // );
10261
+ // }
10262
+ // 把文字内容和新的 bounds 一起放进 filtered
10263
+ filtered.push({ text: tb.text, bounds: nb });
10264
+ }
10265
+ }
10266
+ if (filtered.length > 0) {
10267
+ var clone = cloneTextContainerShallow(tc);
10268
+ clone.textBounds = filtered;
10269
+ result.push(clone);
10270
+ }
10271
+ }
10272
+ return result;
10273
+ };
10274
+ var filterElementForPage = function (container, pageStart, pageEnd) {
10275
+ var pageIndex = Math.floor(pageEnd / activePageHeight);
10276
+ var maxKey = Math.max.apply(Math, Object.keys(offSetPageObj).map(function (k) { return +k; }));
10277
+ var activePageOffset = offSetPageObj[maxKey] || 0;
10278
+ var top = container.bounds.top + activePageOffset;
10279
+ var bottom = container.bounds.top + container.bounds.height + activePageOffset;
10280
+ if (container.divisionDisable && bottom > pageEnd && top < pageEnd) {
10281
+ var offsetNum = pageEnd - top;
10282
+ var prev = offSetPageObj[pageIndex] || 0;
10283
+ if (!offSetPageObj[pageIndex] || prev < offsetNum) {
10284
+ offSetTotal += offsetNum - prev;
10285
+ offSetPageObj[pageIndex] = offSetTotal;
10286
+ }
10287
+ return null;
10288
+ }
10289
+ var children = [];
10290
+ for (var _i = 0, _a = container.elements; _i < _a.length; _i++) {
10291
+ var child = _a[_i];
10292
+ var part = filterElementForPage(child, pageStart, pageEnd);
10293
+ if (part)
10294
+ children.push(part);
10295
+ }
10296
+ var textNodes = filterTextNodesForPage(container, pageStart, pageEnd);
10297
+ var visibleTop = Math.max(top, pageStart);
10298
+ var visibleBottom = Math.min(bottom, pageEnd);
10299
+ var newHeight = Math.max(0, visibleBottom - visibleTop);
10300
+ var hasContent = children.length > 0 || textNodes.length > 0 || newHeight > 0;
10301
+ if (!hasContent)
10302
+ return null;
10303
+ var clone = cloneContainerShallow(container);
10304
+ clone.elements = children;
10305
+ clone.textNodes = textNodes;
10306
+ var newTop = visibleTop >= pageStart ? visibleTop - pageStart : 0;
10307
+ clone.bounds = new Bounds$1(container.bounds.left, newTop + pageMarginTop, container.bounds.width, newHeight);
10308
+ return clone;
10309
+ };
10310
+ var paginateNode = function (root, pageHeight, initialOffset, pageConfig) {
10311
+ var _a, _b;
10312
+ if (initialOffset === void 0) { initialOffset = 0; }
10313
+ if (initialOffset < 0)
10314
+ initialOffset = 0;
10315
+ offSetTotal = 0;
10316
+ Object.keys(offSetPageObj).forEach(function (key) { return delete offSetPageObj[key]; });
10317
+ var maxBottom = computeMaxBottom(root);
10318
+ pageMarginTop = ((_a = pageConfig === null || pageConfig === void 0 ? void 0 : pageConfig.header) === null || _a === void 0 ? void 0 : _a.height) || 0;
10319
+ pageMarginBottom = ((_b = pageConfig === null || pageConfig === void 0 ? void 0 : pageConfig.footer) === null || _b === void 0 ? void 0 : _b.height) || 0;
10320
+ activePageHeight = pageHeight - pageMarginTop - pageMarginBottom;
10321
+ var totalPages = Math.max(1, Math.ceil((maxBottom - initialOffset) / activePageHeight));
10322
+ var pages = [];
10323
+ for (var i = 0; i < totalPages; i++) {
10324
+ var pageStart = initialOffset + i * activePageHeight;
10325
+ var pageEnd = pageStart + activePageHeight;
10326
+ var pageRoot = filterElementForPage(root, pageStart, pageEnd);
10327
+ if (pageRoot)
10328
+ pages.push(pageRoot);
10329
+ }
10330
+ // console.log(offSetPageObj, '偏移量');
10331
+ return pages;
10332
+ };
10333
+
10245
10334
  var dompdf = function (element, options) {
10246
- // 移除元素的边框和阴影样式
10247
10335
  if (options === void 0) { options = {}; }
10248
10336
  return renderElement$1(element, options);
10249
10337
  };
10250
10338
  if (typeof window !== 'undefined') {
10251
10339
  CacheStorage$1.setContext(window);
10252
10340
  }
10341
+ var parseBackgroundColor$1 = function (context, element, backgroundColorOverride) {
10342
+ var ownerDocument = element.ownerDocument;
10343
+ // http://www.w3.org/TR/css3-background/#special-backgrounds
10344
+ var documentBackgroundColor = ownerDocument.documentElement
10345
+ ? parseColor$1(context, getComputedStyle(ownerDocument.documentElement).backgroundColor)
10346
+ : COLORS$1.TRANSPARENT;
10347
+ var bodyBackgroundColor = ownerDocument.body
10348
+ ? parseColor$1(context, getComputedStyle(ownerDocument.body).backgroundColor)
10349
+ : COLORS$1.TRANSPARENT;
10350
+ var defaultBackgroundColor = typeof backgroundColorOverride === 'string'
10351
+ ? parseColor$1(context, backgroundColorOverride)
10352
+ : backgroundColorOverride === null
10353
+ ? COLORS$1.TRANSPARENT
10354
+ : 0xffffffff;
10355
+ return element === ownerDocument.documentElement
10356
+ ? isTransparent$1(documentBackgroundColor)
10357
+ ? isTransparent$1(bodyBackgroundColor)
10358
+ ? defaultBackgroundColor
10359
+ : bodyBackgroundColor
10360
+ : documentBackgroundColor
10361
+ : defaultBackgroundColor;
10362
+ };
10253
10363
  var renderElement$1 = function (element, opts) { return __awaiter$1(void 0, void 0, void 0, function () {
10254
- var ownerDocument, defaultView, resourceOptions, contextOptions, windowOptions, windowBounds, context, foreignObjectRendering, cloneOptions, documentCloner, clonedElement, container, _a, width, height, left, top, backgroundColor, renderOptions, canvas, renderer, root, renderer;
10255
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
10256
- return __generator$1(this, function (_v) {
10257
- switch (_v.label) {
10364
+ var ownerDocument, defaultView, resourceOptions, contextOptions, windowOptions, windowBounds, context, foreignObjectRendering, cloneOptions, documentCloner, clonedElement, container, _a, width, height, left, top, backgroundColor, renderOptions, canvas, renderer, root, pageHeight, offsetY, adjustTop_1, pageRoots, renderer, i;
10365
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
10366
+ return __generator$1(this, function (_2) {
10367
+ switch (_2.label) {
10258
10368
  case 0:
10259
10369
  if (!element || typeof element !== 'object') {
10260
10370
  return [2 /*return*/, Promise.reject('Invalid element provided as first argument')];
@@ -10293,7 +10403,6 @@ var renderElement$1 = function (element, opts) { return __awaiter$1(void 0, void
10293
10403
  context.logger.debug("Starting document clone with size ".concat(windowBounds.width, "x").concat(windowBounds.height, " scrolled to ").concat(-windowBounds.left, ",").concat(-windowBounds.top));
10294
10404
  documentCloner = new DocumentCloner$1(context, element, cloneOptions);
10295
10405
  clonedElement = documentCloner.clonedReferenceElement;
10296
- // console.log('设置自定义字体',opts.fontConfig,clonedElement,clonedElement.style)
10297
10406
  if (clonedElement && clonedElement.style) {
10298
10407
  clonedElement.style.border = 'none';
10299
10408
  clonedElement.style.boxShadow = 'none';
@@ -10306,7 +10415,7 @@ var renderElement$1 = function (element, opts) { return __awaiter$1(void 0, void
10306
10415
  }
10307
10416
  return [4 /*yield*/, documentCloner.toIFrame(ownerDocument, windowBounds)];
10308
10417
  case 1:
10309
- container = _v.sent();
10418
+ container = _2.sent();
10310
10419
  _a = isBodyElement$1(clonedElement) || isHTMLElement$1(clonedElement)
10311
10420
  ? parseDocumentSize$1(clonedElement.ownerDocument)
10312
10421
  : parseBounds$1(context, clonedElement), width = _a.width, height = _a.height, left = _a.left, top = _a.top;
@@ -10321,10 +10430,36 @@ var renderElement$1 = function (element, opts) { return __awaiter$1(void 0, void
10321
10430
  height: (_s = opts.height) !== null && _s !== void 0 ? _s : Math.ceil(height),
10322
10431
  fontConfig: (_t = opts.fontConfig) !== null && _t !== void 0 ? _t : {
10323
10432
  fontFamily: '',
10324
- fontBase64: '',
10325
- fontUrl: '',
10326
- fontWeight: 400,
10327
- fontStyle: ''
10433
+ fontBase64: ''
10434
+ },
10435
+ encryption: {
10436
+ userPassword: '',
10437
+ ownerPassword: '',
10438
+ userPermissions: []
10439
+ },
10440
+ precision: (_u = opts.precision) !== null && _u !== void 0 ? _u : 16,
10441
+ floatPrecision: (_v = opts.floatPrecision) !== null && _v !== void 0 ? _v : 16,
10442
+ compress: (_w = opts.compress) !== null && _w !== void 0 ? _w : false,
10443
+ putOnlyUsedFonts: (_x = opts.putOnlyUsedFonts) !== null && _x !== void 0 ? _x : false,
10444
+ pagination: (_y = opts.pagination) !== null && _y !== void 0 ? _y : false,
10445
+ format: (_z = opts.format) !== null && _z !== void 0 ? _z : 'a4',
10446
+ pageConfig: (_0 = opts.pageConfig) !== null && _0 !== void 0 ? _0 : {
10447
+ header: {
10448
+ content: '',
10449
+ height: 50,
10450
+ contentPosition: 'centerRight',
10451
+ contentColor: '#333333',
10452
+ contentFontSize: 16,
10453
+ padding: [0, 24, 0, 24]
10454
+ },
10455
+ footer: {
10456
+ content: '${currentPage}/${totalPages}',
10457
+ height: 50,
10458
+ contentPosition: 'center',
10459
+ contentColor: '#333333',
10460
+ contentFontSize: 16,
10461
+ padding: [0, 24, 0, 24]
10462
+ }
10328
10463
  }
10329
10464
  };
10330
10465
  if (!foreignObjectRendering) return [3 /*break*/, 3];
@@ -10332,28 +10467,67 @@ var renderElement$1 = function (element, opts) { return __awaiter$1(void 0, void
10332
10467
  renderer = new ForeignObjectRenderer$1(context, renderOptions);
10333
10468
  return [4 /*yield*/, renderer.render(clonedElement)];
10334
10469
  case 2:
10335
- canvas = _v.sent();
10336
- return [3 /*break*/, 6];
10470
+ canvas = _2.sent();
10471
+ return [3 /*break*/, 11];
10337
10472
  case 3:
10338
10473
  context.logger.debug("Document cloned, element located at ".concat(left, ",").concat(top, " with size ").concat(width, "x").concat(height, " using computed rendering"));
10339
10474
  context.logger.debug("Starting DOM parsing", context, clonedElement);
10340
10475
  return [4 /*yield*/, parseTree$1(context, clonedElement)];
10341
10476
  case 4:
10342
- root = _v.sent();
10477
+ root = _2.sent();
10478
+ pageHeight = PAGE_FORMAT_MAP[renderOptions.format || 'a4'].height;
10479
+ if (renderOptions.y !== 0) {
10480
+ offsetY = renderOptions.y;
10481
+ renderOptions.y = 0;
10482
+ adjustTop_1 = function (node, delta) {
10483
+ node.bounds.top = node.bounds.top - delta;
10484
+ for (var _i = 0, _a = node.textNodes; _i < _a.length; _i++) {
10485
+ var tn = _a[_i];
10486
+ for (var _b = 0, _c = tn.textBounds; _b < _c.length; _b++) {
10487
+ var tb = _c[_b];
10488
+ tb.bounds.top = tb.bounds.top - delta;
10489
+ }
10490
+ }
10491
+ for (var _d = 0, _e = node.elements; _d < _e.length; _d++) {
10492
+ var el = _e[_d];
10493
+ adjustTop_1(el, delta);
10494
+ }
10495
+ };
10496
+ adjustTop_1(root, offsetY);
10497
+ }
10498
+ pageRoots = paginateNode(root, pageHeight, renderOptions.y, renderOptions.pageConfig);
10343
10499
  Reflect.deleteProperty(root, 'context');
10344
- // Reflect.deleteProperty(root, 'elements')
10345
- // =[];
10346
10500
  if (backgroundColor === root.styles.backgroundColor) {
10347
10501
  root.styles.backgroundColor = COLORS$1.TRANSPARENT;
10348
10502
  }
10349
10503
  context.logger.debug("Starting renderer for element at ".concat(renderOptions.x, ",").concat(renderOptions.y, " with size ").concat(renderOptions.width, "x").concat(renderOptions.height));
10504
+ // console.log('pageRootrenderOptions', root, renderOptions, pageRoots);
10505
+ // , pageRoots, paginationState
10506
+ renderOptions.y = 0;
10350
10507
  renderer = new CanvasRenderer$1(context, renderOptions);
10351
- return [4 /*yield*/, renderer.render(root)];
10508
+ renderer.setTotalPages(pageRoots.length);
10509
+ if (!(pageRoots.length > 0)) return [3 /*break*/, 9];
10510
+ return [4 /*yield*/, renderer.renderPage(pageRoots[0], 1)];
10352
10511
  case 5:
10353
- canvas = _v.sent();
10354
- _v.label = 6;
10512
+ _2.sent();
10513
+ i = 1;
10514
+ _2.label = 6;
10355
10515
  case 6:
10356
- if ((_u = opts.removeContainer) !== null && _u !== void 0 ? _u : true) {
10516
+ if (!(i < pageRoots.length)) return [3 /*break*/, 9];
10517
+ renderer.addPage(0);
10518
+ return [4 /*yield*/, renderer.renderPage(pageRoots[i], i + 1)];
10519
+ case 7:
10520
+ _2.sent();
10521
+ _2.label = 8;
10522
+ case 8:
10523
+ i++;
10524
+ return [3 /*break*/, 6];
10525
+ case 9: return [4 /*yield*/, renderer.output()];
10526
+ case 10:
10527
+ canvas = _2.sent();
10528
+ _2.label = 11;
10529
+ case 11:
10530
+ if ((_1 = opts.removeContainer) !== null && _1 !== void 0 ? _1 : true) {
10357
10531
  if (!DocumentCloner$1.destroy(container)) {
10358
10532
  context.logger.error("Cannot detach cloned iframe as it is not in the DOM anymore");
10359
10533
  }
@@ -10362,29 +10536,7 @@ var renderElement$1 = function (element, opts) { return __awaiter$1(void 0, void
10362
10536
  return [2 /*return*/, canvas];
10363
10537
  }
10364
10538
  });
10365
- }); };
10366
- var parseBackgroundColor$1 = function (context, element, backgroundColorOverride) {
10367
- var ownerDocument = element.ownerDocument;
10368
- // http://www.w3.org/TR/css3-background/#special-backgrounds
10369
- var documentBackgroundColor = ownerDocument.documentElement
10370
- ? parseColor$1(context, getComputedStyle(ownerDocument.documentElement).backgroundColor)
10371
- : COLORS$1.TRANSPARENT;
10372
- var bodyBackgroundColor = ownerDocument.body
10373
- ? parseColor$1(context, getComputedStyle(ownerDocument.body).backgroundColor)
10374
- : COLORS$1.TRANSPARENT;
10375
- var defaultBackgroundColor = typeof backgroundColorOverride === 'string'
10376
- ? parseColor$1(context, backgroundColorOverride)
10377
- : backgroundColorOverride === null
10378
- ? COLORS$1.TRANSPARENT
10379
- : 0xffffffff;
10380
- return element === ownerDocument.documentElement
10381
- ? isTransparent$1(documentBackgroundColor)
10382
- ? isTransparent$1(bodyBackgroundColor)
10383
- ? defaultBackgroundColor
10384
- : bodyBackgroundColor
10385
- : documentBackgroundColor
10386
- : defaultBackgroundColor;
10387
- };
10539
+ }); };
10388
10540
 
10389
10541
  /*!
10390
10542
  * html2canvas 1.4.1 <https://html2canvas.hertzen.com>