jspdf-autotable
Version:
Generate pdf tables with javascript (jsPDF plugin)
1,349 lines (1,296 loc) • 98.9 kB
JavaScript
/*!
*
* jsPDF AutoTable plugin v3.8.4
*
* Copyright (c) 2024 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory((function webpackLoadOptionalExternalModule() { try { return require("jspdf"); } catch(e) {} }()));
else if(typeof define === 'function' && define.amd)
define(["jspdf"], factory);
else {
var a = typeof exports === 'object' ? factory((function webpackLoadOptionalExternalModule() { try { return require("jspdf"); } catch(e) {} }())) : factory(root["jspdf"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(typeof globalThis !== 'undefined' ? globalThis : typeof this !== 'undefined' ? this : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : global , function(__WEBPACK_EXTERNAL_MODULE__964__) {
return /******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 172:
/***/ (function(__unused_webpack_module, exports) {
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CellHookData = exports.HookData = void 0;
var HookData = /** @class */ (function () {
function HookData(doc, table, cursor) {
this.table = table;
this.pageNumber = table.pageNumber;
this.pageCount = this.pageNumber;
this.settings = table.settings;
this.cursor = cursor;
this.doc = doc.getDocument();
}
return HookData;
}());
exports.HookData = HookData;
var CellHookData = /** @class */ (function (_super) {
__extends(CellHookData, _super);
function CellHookData(doc, table, cell, row, column, cursor) {
var _this = _super.call(this, doc, table, cursor) || this;
_this.cell = cell;
_this.row = row;
_this.column = column;
_this.section = row.section;
return _this;
}
return CellHookData;
}(HookData));
exports.CellHookData = CellHookData;
/***/ }),
/***/ 340:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
var htmlParser_1 = __webpack_require__(4);
var autoTableText_1 = __webpack_require__(136);
var documentHandler_1 = __webpack_require__(744);
var inputParser_1 = __webpack_require__(776);
var tableDrawer_1 = __webpack_require__(664);
var tableCalculator_1 = __webpack_require__(972);
function default_1(jsPDF) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jsPDF.API.autoTable = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var options;
if (args.length === 1) {
options = args[0];
}
else {
console.error('Use of deprecated autoTable initiation');
options = args[2] || {};
options.columns = args[0];
options.body = args[1];
}
var input = (0, inputParser_1.parseInput)(this, options);
var table = (0, tableCalculator_1.createTable)(this, input);
(0, tableDrawer_1.drawTable)(this, table);
return this;
};
// Assign false to enable `doc.lastAutoTable.finalY || 40` sugar
jsPDF.API.lastAutoTable = false;
jsPDF.API.previousAutoTable = false; // deprecated in v3
jsPDF.API.autoTable.previous = false; // deprecated in v3
jsPDF.API.autoTableText = function (text, x, y, styles) {
(0, autoTableText_1.default)(text, x, y, styles, this);
};
jsPDF.API.autoTableSetDefaults = function (defaults) {
documentHandler_1.DocHandler.setDefaults(defaults, this);
return this;
};
jsPDF.autoTableSetDefaults = function (defaults, doc) {
documentHandler_1.DocHandler.setDefaults(defaults, doc);
};
jsPDF.API.autoTableHtmlToJson = function (tableElem, includeHiddenElements) {
var _a;
if (includeHiddenElements === void 0) { includeHiddenElements = false; }
if (typeof window === 'undefined') {
console.error('Cannot run autoTableHtmlToJson in non browser environment');
return null;
}
var doc = new documentHandler_1.DocHandler(this);
var _b = (0, htmlParser_1.parseHtml)(doc, tableElem, window, includeHiddenElements, false), head = _b.head, body = _b.body;
var columns = ((_a = head[0]) === null || _a === void 0 ? void 0 : _a.map(function (c) { return c.content; })) || [];
return { columns: columns, rows: body, data: body };
};
/**
* @deprecated
*/
jsPDF.API.autoTableEndPosY = function () {
console.error('Use of deprecated function: autoTableEndPosY. Use doc.lastAutoTable.finalY instead.');
var prev = this.lastAutoTable;
if (prev && prev.finalY) {
return prev.finalY;
}
else {
return 0;
}
};
/**
* @deprecated
*/
jsPDF.API.autoTableAddPageContent = function (hook) {
console.error('Use of deprecated function: autoTableAddPageContent. Use jsPDF.autoTableSetDefaults({didDrawPage: () => {}}) instead.');
if (!jsPDF.API.autoTable.globalDefaults) {
jsPDF.API.autoTable.globalDefaults = {};
}
jsPDF.API.autoTable.globalDefaults.addPageContent = hook;
return this;
};
/**
* @deprecated
*/
jsPDF.API.autoTableAddPage = function () {
console.error('Use of deprecated function: autoTableAddPage. Use doc.addPage()');
this.addPage();
return this;
};
}
exports["default"] = default_1;
/***/ }),
/***/ 136:
/***/ (function(__unused_webpack_module, exports) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
/**
* Improved text function with halign and valign support
* Inspiration from: http://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113#28433113
*/
function default_1(text, x, y, styles, doc) {
styles = styles || {};
var PHYSICAL_LINE_HEIGHT = 1.15;
var k = doc.internal.scaleFactor;
var fontSize = doc.internal.getFontSize() / k;
var lineHeightFactor = doc.getLineHeightFactor
? doc.getLineHeightFactor()
: PHYSICAL_LINE_HEIGHT;
var lineHeight = fontSize * lineHeightFactor;
var splitRegex = /\r\n|\r|\n/g;
var splitText = '';
var lineCount = 1;
if (styles.valign === 'middle' ||
styles.valign === 'bottom' ||
styles.halign === 'center' ||
styles.halign === 'right') {
splitText = typeof text === 'string' ? text.split(splitRegex) : text;
lineCount = splitText.length || 1;
}
// Align the top
y += fontSize * (2 - PHYSICAL_LINE_HEIGHT);
if (styles.valign === 'middle')
y -= (lineCount / 2) * lineHeight;
else if (styles.valign === 'bottom')
y -= lineCount * lineHeight;
if (styles.halign === 'center' || styles.halign === 'right') {
var alignSize = fontSize;
if (styles.halign === 'center')
alignSize *= 0.5;
if (splitText && lineCount >= 1) {
for (var iLine = 0; iLine < splitText.length; iLine++) {
doc.text(splitText[iLine], x - doc.getStringUnitWidth(splitText[iLine]) * alignSize, y);
y += lineHeight;
}
return doc;
}
x -= doc.getStringUnitWidth(text) * alignSize;
}
if (styles.halign === 'justify') {
doc.text(text, x, y, {
maxWidth: styles.maxWidth || 100,
align: 'justify',
});
}
else {
doc.text(text, x, y);
}
return doc;
}
exports["default"] = default_1;
/***/ }),
/***/ 420:
/***/ (function(__unused_webpack_module, exports) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getPageAvailableWidth = exports.parseSpacing = exports.getFillStyle = exports.addTableBorder = exports.getStringWidth = void 0;
function getStringWidth(text, styles, doc) {
doc.applyStyles(styles, true);
var textArr = Array.isArray(text) ? text : [text];
var widestLineWidth = textArr
.map(function (text) { return doc.getTextWidth(text); })
.reduce(function (a, b) { return Math.max(a, b); }, 0);
return widestLineWidth;
}
exports.getStringWidth = getStringWidth;
function addTableBorder(doc, table, startPos, cursor) {
var lineWidth = table.settings.tableLineWidth;
var lineColor = table.settings.tableLineColor;
doc.applyStyles({ lineWidth: lineWidth, lineColor: lineColor });
var fillStyle = getFillStyle(lineWidth, false);
if (fillStyle) {
doc.rect(startPos.x, startPos.y, table.getWidth(doc.pageSize().width), cursor.y - startPos.y, fillStyle);
}
}
exports.addTableBorder = addTableBorder;
function getFillStyle(lineWidth, fillColor) {
var drawLine = lineWidth > 0;
var drawBackground = fillColor || fillColor === 0;
if (drawLine && drawBackground) {
return 'DF'; // Fill then stroke
}
else if (drawLine) {
return 'S'; // Only stroke (transparent background)
}
else if (drawBackground) {
return 'F'; // Only fill, no stroke
}
else {
return null;
}
}
exports.getFillStyle = getFillStyle;
function parseSpacing(value, defaultValue) {
var _a, _b, _c, _d;
value = value || defaultValue;
if (Array.isArray(value)) {
if (value.length >= 4) {
return {
top: value[0],
right: value[1],
bottom: value[2],
left: value[3],
};
}
else if (value.length === 3) {
return {
top: value[0],
right: value[1],
bottom: value[2],
left: value[1],
};
}
else if (value.length === 2) {
return {
top: value[0],
right: value[1],
bottom: value[0],
left: value[1],
};
}
else if (value.length === 1) {
value = value[0];
}
else {
value = defaultValue;
}
}
if (typeof value === 'object') {
if (typeof value.vertical === 'number') {
value.top = value.vertical;
value.bottom = value.vertical;
}
if (typeof value.horizontal === 'number') {
value.right = value.horizontal;
value.left = value.horizontal;
}
return {
left: (_a = value.left) !== null && _a !== void 0 ? _a : defaultValue,
top: (_b = value.top) !== null && _b !== void 0 ? _b : defaultValue,
right: (_c = value.right) !== null && _c !== void 0 ? _c : defaultValue,
bottom: (_d = value.bottom) !== null && _d !== void 0 ? _d : defaultValue,
};
}
if (typeof value !== 'number') {
value = defaultValue;
}
return { top: value, right: value, bottom: value, left: value };
}
exports.parseSpacing = parseSpacing;
function getPageAvailableWidth(doc, table) {
var margins = parseSpacing(table.settings.margin, 0);
return doc.pageSize().width - (margins.left + margins.right);
}
exports.getPageAvailableWidth = getPageAvailableWidth;
/***/ }),
/***/ 796:
/***/ (function(__unused_webpack_module, exports) {
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getTheme = exports.defaultStyles = exports.HtmlRowInput = void 0;
var HtmlRowInput = /** @class */ (function (_super) {
__extends(HtmlRowInput, _super);
function HtmlRowInput(element) {
var _this = _super.call(this) || this;
_this._element = element;
return _this;
}
return HtmlRowInput;
}(Array));
exports.HtmlRowInput = HtmlRowInput;
// Base style for all themes
function defaultStyles(scaleFactor) {
return {
font: 'helvetica', // helvetica, times, courier
fontStyle: 'normal', // normal, bold, italic, bolditalic
overflow: 'linebreak', // linebreak, ellipsize, visible or hidden
fillColor: false, // Either false for transparent, rbg array e.g. [255, 255, 255] or gray level e.g 200
textColor: 20,
halign: 'left', // left, center, right, justify
valign: 'top', // top, middle, bottom
fontSize: 10,
cellPadding: 5 / scaleFactor, // number or {top,left,right,left,vertical,horizontal}
lineColor: 200,
lineWidth: 0,
cellWidth: 'auto', // 'auto'|'wrap'|number
minCellHeight: 0,
minCellWidth: 0,
};
}
exports.defaultStyles = defaultStyles;
function getTheme(name) {
var themes = {
striped: {
table: { fillColor: 255, textColor: 80, fontStyle: 'normal' },
head: { textColor: 255, fillColor: [41, 128, 185], fontStyle: 'bold' },
body: {},
foot: { textColor: 255, fillColor: [41, 128, 185], fontStyle: 'bold' },
alternateRow: { fillColor: 245 },
},
grid: {
table: {
fillColor: 255,
textColor: 80,
fontStyle: 'normal',
lineWidth: 0.1,
},
head: {
textColor: 255,
fillColor: [26, 188, 156],
fontStyle: 'bold',
lineWidth: 0,
},
body: {},
foot: {
textColor: 255,
fillColor: [26, 188, 156],
fontStyle: 'bold',
lineWidth: 0,
},
alternateRow: {},
},
plain: {
head: { fontStyle: 'bold' },
foot: { fontStyle: 'bold' },
},
};
return themes[name];
}
exports.getTheme = getTheme;
/***/ }),
/***/ 903:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseCss = void 0;
// Limitations
// - No support for border spacing
// - No support for transparency
var common_1 = __webpack_require__(420);
function parseCss(supportedFonts, element, scaleFactor, style, window) {
var result = {};
var pxScaleFactor = 96 / 72;
var backgroundColor = parseColor(element, function (elem) {
return window.getComputedStyle(elem)['backgroundColor'];
});
if (backgroundColor != null)
result.fillColor = backgroundColor;
var textColor = parseColor(element, function (elem) {
return window.getComputedStyle(elem)['color'];
});
if (textColor != null)
result.textColor = textColor;
var padding = parsePadding(style, scaleFactor);
if (padding)
result.cellPadding = padding;
var borderColorSide = 'borderTopColor';
var finalScaleFactor = pxScaleFactor * scaleFactor;
var btw = style.borderTopWidth;
if (style.borderBottomWidth === btw &&
style.borderRightWidth === btw &&
style.borderLeftWidth === btw) {
var borderWidth = (parseFloat(btw) || 0) / finalScaleFactor;
if (borderWidth)
result.lineWidth = borderWidth;
}
else {
result.lineWidth = {
top: (parseFloat(style.borderTopWidth) || 0) / finalScaleFactor,
right: (parseFloat(style.borderRightWidth) || 0) / finalScaleFactor,
bottom: (parseFloat(style.borderBottomWidth) || 0) / finalScaleFactor,
left: (parseFloat(style.borderLeftWidth) || 0) / finalScaleFactor,
};
// Choose border color of first available side
// could be improved by supporting object as lineColor
if (!result.lineWidth.top) {
if (result.lineWidth.right) {
borderColorSide = 'borderRightColor';
}
else if (result.lineWidth.bottom) {
borderColorSide = 'borderBottomColor';
}
else if (result.lineWidth.left) {
borderColorSide = 'borderLeftColor';
}
}
}
var borderColor = parseColor(element, function (elem) {
return window.getComputedStyle(elem)[borderColorSide];
});
if (borderColor != null)
result.lineColor = borderColor;
var accepted = ['left', 'right', 'center', 'justify'];
if (accepted.indexOf(style.textAlign) !== -1) {
result.halign = style.textAlign;
}
accepted = ['middle', 'bottom', 'top'];
if (accepted.indexOf(style.verticalAlign) !== -1) {
result.valign = style.verticalAlign;
}
var res = parseInt(style.fontSize || '');
if (!isNaN(res))
result.fontSize = res / pxScaleFactor;
var fontStyle = parseFontStyle(style);
if (fontStyle)
result.fontStyle = fontStyle;
var font = (style.fontFamily || '').toLowerCase();
if (supportedFonts.indexOf(font) !== -1) {
result.font = font;
}
return result;
}
exports.parseCss = parseCss;
function parseFontStyle(style) {
var res = '';
if (style.fontWeight === 'bold' ||
style.fontWeight === 'bolder' ||
parseInt(style.fontWeight) >= 700) {
res = 'bold';
}
if (style.fontStyle === 'italic' || style.fontStyle === 'oblique') {
res += 'italic';
}
return res;
}
function parseColor(element, styleGetter) {
var cssColor = realColor(element, styleGetter);
if (!cssColor)
return null;
var rgba = cssColor.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/);
if (!rgba || !Array.isArray(rgba)) {
return null;
}
var color = [
parseInt(rgba[1]),
parseInt(rgba[2]),
parseInt(rgba[3]),
];
var alpha = parseInt(rgba[4]);
if (alpha === 0 || isNaN(color[0]) || isNaN(color[1]) || isNaN(color[2])) {
return null;
}
return color;
}
function realColor(elem, styleGetter) {
var bg = styleGetter(elem);
if (bg === 'rgba(0, 0, 0, 0)' ||
bg === 'transparent' ||
bg === 'initial' ||
bg === 'inherit') {
if (elem.parentElement == null) {
return null;
}
return realColor(elem.parentElement, styleGetter);
}
else {
return bg;
}
}
function parsePadding(style, scaleFactor) {
var val = [
style.paddingTop,
style.paddingRight,
style.paddingBottom,
style.paddingLeft,
];
var pxScaleFactor = 96 / (72 / scaleFactor);
var linePadding = (parseInt(style.lineHeight) - parseInt(style.fontSize)) / scaleFactor / 2;
var inputPadding = val.map(function (n) {
return parseInt(n || '0') / pxScaleFactor;
});
var padding = (0, common_1.parseSpacing)(inputPadding, 0);
if (linePadding > padding.top) {
padding.top = linePadding;
}
if (linePadding > padding.bottom) {
padding.bottom = linePadding;
}
return padding;
}
/***/ }),
/***/ 744:
/***/ (function(__unused_webpack_module, exports) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DocHandler = void 0;
var globalDefaults = {};
var DocHandler = /** @class */ (function () {
function DocHandler(jsPDFDocument) {
this.jsPDFDocument = jsPDFDocument;
this.userStyles = {
// Black for versions of jspdf without getTextColor
textColor: jsPDFDocument.getTextColor
? this.jsPDFDocument.getTextColor()
: 0,
fontSize: jsPDFDocument.internal.getFontSize(),
fontStyle: jsPDFDocument.internal.getFont().fontStyle,
font: jsPDFDocument.internal.getFont().fontName,
// 0 for versions of jspdf without getLineWidth
lineWidth: jsPDFDocument.getLineWidth
? this.jsPDFDocument.getLineWidth()
: 0,
// Black for versions of jspdf without getDrawColor
lineColor: jsPDFDocument.getDrawColor
? this.jsPDFDocument.getDrawColor()
: 0,
};
}
DocHandler.setDefaults = function (defaults, doc) {
if (doc === void 0) { doc = null; }
if (doc) {
doc.__autoTableDocumentDefaults = defaults;
}
else {
globalDefaults = defaults;
}
};
DocHandler.unifyColor = function (c) {
if (Array.isArray(c)) {
return c;
}
else if (typeof c === 'number') {
return [c, c, c];
}
else if (typeof c === 'string') {
return [c];
}
else {
return null;
}
};
DocHandler.prototype.applyStyles = function (styles, fontOnly) {
// Font style needs to be applied before font
// https://github.com/simonbengtsson/jsPDF-AutoTable/issues/632
var _a, _b, _c;
if (fontOnly === void 0) { fontOnly = false; }
if (styles.fontStyle)
this.jsPDFDocument.setFontStyle &&
this.jsPDFDocument.setFontStyle(styles.fontStyle);
var _d = this.jsPDFDocument.internal.getFont(), fontStyle = _d.fontStyle, fontName = _d.fontName;
if (styles.font)
fontName = styles.font;
if (styles.fontStyle) {
fontStyle = styles.fontStyle;
var availableFontStyles = this.getFontList()[fontName];
if (availableFontStyles &&
availableFontStyles.indexOf(fontStyle) === -1) {
// Common issue was that the default bold in headers
// made custom fonts not work. For example:
// https://github.com/simonbengtsson/jsPDF-AutoTable/issues/653
this.jsPDFDocument.setFontStyle &&
this.jsPDFDocument.setFontStyle(availableFontStyles[0]);
fontStyle = availableFontStyles[0];
}
}
this.jsPDFDocument.setFont(fontName, fontStyle);
if (styles.fontSize)
this.jsPDFDocument.setFontSize(styles.fontSize);
if (fontOnly) {
return; // Performance improvement
}
var color = DocHandler.unifyColor(styles.fillColor);
if (color)
(_a = this.jsPDFDocument).setFillColor.apply(_a, color);
color = DocHandler.unifyColor(styles.textColor);
if (color)
(_b = this.jsPDFDocument).setTextColor.apply(_b, color);
color = DocHandler.unifyColor(styles.lineColor);
if (color)
(_c = this.jsPDFDocument).setDrawColor.apply(_c, color);
if (typeof styles.lineWidth === 'number') {
this.jsPDFDocument.setLineWidth(styles.lineWidth);
}
};
DocHandler.prototype.splitTextToSize = function (text, size, opts) {
return this.jsPDFDocument.splitTextToSize(text, size, opts);
};
/**
* Adds a rectangle to the PDF
* @param x Coordinate (in units declared at inception of PDF document) against left edge of the page
* @param y Coordinate (in units declared at inception of PDF document) against upper edge of the page
* @param width Width (in units declared at inception of PDF document)
* @param height Height (in units declared at inception of PDF document)
* @param fillStyle A string specifying the painting style or null. Valid styles include: 'S' [default] - stroke, 'F' - fill, and 'DF' (or 'FD') - fill then stroke.
*/
DocHandler.prototype.rect = function (x, y, width, height, fillStyle) {
// null is excluded from fillStyle possible values because it isn't needed
// and is prone to bugs as it's used to postpone setting the style
// https://rawgit.com/MrRio/jsPDF/master/docs/jsPDF.html#rect
return this.jsPDFDocument.rect(x, y, width, height, fillStyle);
};
DocHandler.prototype.getLastAutoTable = function () {
return this.jsPDFDocument.lastAutoTable || null;
};
DocHandler.prototype.getTextWidth = function (text) {
return this.jsPDFDocument.getTextWidth(text);
};
DocHandler.prototype.getDocument = function () {
return this.jsPDFDocument;
};
DocHandler.prototype.setPage = function (page) {
this.jsPDFDocument.setPage(page);
};
DocHandler.prototype.addPage = function () {
return this.jsPDFDocument.addPage();
};
DocHandler.prototype.getFontList = function () {
return this.jsPDFDocument.getFontList();
};
DocHandler.prototype.getGlobalOptions = function () {
return globalDefaults || {};
};
DocHandler.prototype.getDocumentOptions = function () {
return this.jsPDFDocument.__autoTableDocumentDefaults || {};
};
DocHandler.prototype.pageSize = function () {
var pageSize = this.jsPDFDocument.internal.pageSize;
// JSPDF 1.4 uses get functions instead of properties on pageSize
if (pageSize.width == null) {
pageSize = {
width: pageSize.getWidth(),
height: pageSize.getHeight(),
};
}
return pageSize;
};
DocHandler.prototype.scaleFactor = function () {
return this.jsPDFDocument.internal.scaleFactor;
};
DocHandler.prototype.getLineHeightFactor = function () {
var doc = this.jsPDFDocument;
return doc.getLineHeightFactor ? doc.getLineHeightFactor() : 1.15;
};
DocHandler.prototype.getLineHeight = function (fontSize) {
return (fontSize / this.scaleFactor()) * this.getLineHeightFactor();
};
DocHandler.prototype.pageNumber = function () {
var pageInfo = this.jsPDFDocument.internal.getCurrentPageInfo();
if (!pageInfo) {
// Only recent versions of jspdf has pageInfo
return this.jsPDFDocument.internal.getNumberOfPages();
}
return pageInfo.pageNumber;
};
return DocHandler;
}());
exports.DocHandler = DocHandler;
/***/ }),
/***/ 4:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseHtml = void 0;
var cssParser_1 = __webpack_require__(903);
var config_1 = __webpack_require__(796);
function parseHtml(doc, input, window, includeHiddenHtml, useCss) {
var _a, _b;
if (includeHiddenHtml === void 0) { includeHiddenHtml = false; }
if (useCss === void 0) { useCss = false; }
var tableElement;
if (typeof input === 'string') {
tableElement = window.document.querySelector(input);
}
else {
tableElement = input;
}
var supportedFonts = Object.keys(doc.getFontList());
var scaleFactor = doc.scaleFactor();
var head = [], body = [], foot = [];
if (!tableElement) {
console.error('Html table could not be found with input: ', input);
return { head: head, body: body, foot: foot };
}
for (var i = 0; i < tableElement.rows.length; i++) {
var element = tableElement.rows[i];
var tagName = (_b = (_a = element === null || element === void 0 ? void 0 : element.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase();
var row = parseRowContent(supportedFonts, scaleFactor, window, element, includeHiddenHtml, useCss);
if (!row)
continue;
if (tagName === 'thead') {
head.push(row);
}
else if (tagName === 'tfoot') {
foot.push(row);
}
else {
// Add to body both if parent is tbody or table
body.push(row);
}
}
return { head: head, body: body, foot: foot };
}
exports.parseHtml = parseHtml;
function parseRowContent(supportedFonts, scaleFactor, window, row, includeHidden, useCss) {
var resultRow = new config_1.HtmlRowInput(row);
for (var i = 0; i < row.cells.length; i++) {
var cell = row.cells[i];
var style_1 = window.getComputedStyle(cell);
if (includeHidden || style_1.display !== 'none') {
var cellStyles = void 0;
if (useCss) {
cellStyles = (0, cssParser_1.parseCss)(supportedFonts, cell, scaleFactor, style_1, window);
}
resultRow.push({
rowSpan: cell.rowSpan,
colSpan: cell.colSpan,
styles: cellStyles,
_element: cell,
content: parseCellContent(cell),
});
}
}
var style = window.getComputedStyle(row);
if (resultRow.length > 0 && (includeHidden || style.display !== 'none')) {
return resultRow;
}
}
function parseCellContent(orgCell) {
// Work on cloned node to make sure no changes are applied to html table
var cell = orgCell.cloneNode(true);
// Remove extra space and line breaks in markup to make it more similar to
// what would be shown in html
cell.innerHTML = cell.innerHTML.replace(/\n/g, '').replace(/ +/g, ' ');
// Preserve <br> tags as line breaks in the pdf
cell.innerHTML = cell.innerHTML
.split(/<br.*?>/) //start with '<br' and ends with '>'.
.map(function (part) { return part.trim(); })
.join('\n');
// innerText for ie
return cell.innerText || cell.textContent || '';
}
/***/ }),
/***/ 776:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.parseInput = void 0;
var htmlParser_1 = __webpack_require__(4);
var polyfills_1 = __webpack_require__(356);
var common_1 = __webpack_require__(420);
var documentHandler_1 = __webpack_require__(744);
var inputValidator_1 = __webpack_require__(792);
function parseInput(d, current) {
var doc = new documentHandler_1.DocHandler(d);
var document = doc.getDocumentOptions();
var global = doc.getGlobalOptions();
(0, inputValidator_1.default)(doc, global, document, current);
var options = (0, polyfills_1.assign)({}, global, document, current);
var win;
if (typeof window !== 'undefined') {
win = window;
}
var styles = parseStyles(global, document, current);
var hooks = parseHooks(global, document, current);
var settings = parseSettings(doc, options);
var content = parseContent(doc, options, win);
return {
id: current.tableId,
content: content,
hooks: hooks,
styles: styles,
settings: settings,
};
}
exports.parseInput = parseInput;
function parseStyles(gInput, dInput, cInput) {
var styleOptions = {
styles: {},
headStyles: {},
bodyStyles: {},
footStyles: {},
alternateRowStyles: {},
columnStyles: {},
};
var _loop_1 = function (prop) {
if (prop === 'columnStyles') {
var global_1 = gInput[prop];
var document_1 = dInput[prop];
var current = cInput[prop];
styleOptions.columnStyles = (0, polyfills_1.assign)({}, global_1, document_1, current);
}
else {
var allOptions = [gInput, dInput, cInput];
var styles = allOptions.map(function (opts) { return opts[prop] || {}; });
styleOptions[prop] = (0, polyfills_1.assign)({}, styles[0], styles[1], styles[2]);
}
};
for (var _i = 0, _a = Object.keys(styleOptions); _i < _a.length; _i++) {
var prop = _a[_i];
_loop_1(prop);
}
return styleOptions;
}
function parseHooks(global, document, current) {
var allOptions = [global, document, current];
var result = {
didParseCell: [],
willDrawCell: [],
didDrawCell: [],
willDrawPage: [],
didDrawPage: [],
};
for (var _i = 0, allOptions_1 = allOptions; _i < allOptions_1.length; _i++) {
var options = allOptions_1[_i];
if (options.didParseCell)
result.didParseCell.push(options.didParseCell);
if (options.willDrawCell)
result.willDrawCell.push(options.willDrawCell);
if (options.didDrawCell)
result.didDrawCell.push(options.didDrawCell);
if (options.willDrawPage)
result.willDrawPage.push(options.willDrawPage);
if (options.didDrawPage)
result.didDrawPage.push(options.didDrawPage);
}
return result;
}
function parseSettings(doc, options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
var margin = (0, common_1.parseSpacing)(options.margin, 40 / doc.scaleFactor());
var startY = (_a = getStartY(doc, options.startY)) !== null && _a !== void 0 ? _a : margin.top;
var showFoot;
if (options.showFoot === true) {
showFoot = 'everyPage';
}
else if (options.showFoot === false) {
showFoot = 'never';
}
else {
showFoot = (_b = options.showFoot) !== null && _b !== void 0 ? _b : 'everyPage';
}
var showHead;
if (options.showHead === true) {
showHead = 'everyPage';
}
else if (options.showHead === false) {
showHead = 'never';
}
else {
showHead = (_c = options.showHead) !== null && _c !== void 0 ? _c : 'everyPage';
}
var useCss = (_d = options.useCss) !== null && _d !== void 0 ? _d : false;
var theme = options.theme || (useCss ? 'plain' : 'striped');
var horizontalPageBreak = !!options.horizontalPageBreak;
var horizontalPageBreakRepeat = (_e = options.horizontalPageBreakRepeat) !== null && _e !== void 0 ? _e : null;
return {
includeHiddenHtml: (_f = options.includeHiddenHtml) !== null && _f !== void 0 ? _f : false,
useCss: useCss,
theme: theme,
startY: startY,
margin: margin,
pageBreak: (_g = options.pageBreak) !== null && _g !== void 0 ? _g : 'auto',
rowPageBreak: (_h = options.rowPageBreak) !== null && _h !== void 0 ? _h : 'auto',
tableWidth: (_j = options.tableWidth) !== null && _j !== void 0 ? _j : 'auto',
showHead: showHead,
showFoot: showFoot,
tableLineWidth: (_k = options.tableLineWidth) !== null && _k !== void 0 ? _k : 0,
tableLineColor: (_l = options.tableLineColor) !== null && _l !== void 0 ? _l : 200,
horizontalPageBreak: horizontalPageBreak,
horizontalPageBreakRepeat: horizontalPageBreakRepeat,
horizontalPageBreakBehaviour: (_m = options.horizontalPageBreakBehaviour) !== null && _m !== void 0 ? _m : 'afterAllRows',
};
}
function getStartY(doc, userStartY) {
var previous = doc.getLastAutoTable();
var sf = doc.scaleFactor();
var currentPage = doc.pageNumber();
var isSamePageAsPreviousTable = false;
if (previous && previous.startPageNumber) {
var endingPage = previous.startPageNumber + previous.pageNumber - 1;
isSamePageAsPreviousTable = endingPage === currentPage;
}
if (typeof userStartY === 'number') {
return userStartY;
}
else if (userStartY == null || userStartY === false) {
if (isSamePageAsPreviousTable && (previous === null || previous === void 0 ? void 0 : previous.finalY) != null) {
// Some users had issues with overlapping tables when they used multiple
// tables without setting startY so setting it here to a sensible default.
return previous.finalY + 20 / sf;
}
}
return null;
}
function parseContent(doc, options, window) {
var head = options.head || [];
var body = options.body || [];
var foot = options.foot || [];
if (options.html) {
var hidden = options.includeHiddenHtml;
if (window) {
var htmlContent = (0, htmlParser_1.parseHtml)(doc, options.html, window, hidden, options.useCss) || {};
head = htmlContent.head || head;
body = htmlContent.body || head;
foot = htmlContent.foot || head;
}
else {
console.error('Cannot parse html in non browser environment');
}
}
var columns = options.columns || parseColumns(head, body, foot);
return {
columns: columns,
head: head,
body: body,
foot: foot,
};
}
function parseColumns(head, body, foot) {
var firstRow = head[0] || body[0] || foot[0] || [];
var result = [];
Object.keys(firstRow)
.filter(function (key) { return key !== '_element'; })
.forEach(function (key) {
var colSpan = 1;
var input;
if (Array.isArray(firstRow)) {
input = firstRow[parseInt(key)];
}
else {
input = firstRow[key];
}
if (typeof input === 'object' && !Array.isArray(input)) {
colSpan = (input === null || input === void 0 ? void 0 : input.colSpan) || 1;
}
for (var i = 0; i < colSpan; i++) {
var id = void 0;
if (Array.isArray(firstRow)) {
id = result.length;
}
else {
id = key + (i > 0 ? "_".concat(i) : '');
}
var rowResult = { dataKey: id };
result.push(rowResult);
}
});
return result;
}
/***/ }),
/***/ 792:
/***/ (function(__unused_webpack_module, exports) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
function default_1(doc, global, document, current) {
var _loop_1 = function (options) {
if (options && typeof options !== 'object') {
console.error('The options parameter should be of type object, is: ' + typeof options);
}
if (typeof options.extendWidth !== 'undefined') {
options.tableWidth = options.extendWidth ? 'auto' : 'wrap';
console.error('Use of deprecated option: extendWidth, use tableWidth instead.');
}
if (typeof options.margins !== 'undefined') {
if (typeof options.margin === 'undefined')
options.margin = options.margins;
console.error('Use of deprecated option: margins, use margin instead.');
}
if (options.startY && typeof options.startY !== 'number') {
console.error('Invalid value for startY option', options.startY);
delete options.startY;
}
if (!options.didDrawPage &&
(options.afterPageContent ||
options.beforePageContent ||
options.afterPageAdd)) {
console.error('The afterPageContent, beforePageContent and afterPageAdd hooks are deprecated. Use didDrawPage instead');
options.didDrawPage = function (data) {
doc.applyStyles(doc.userStyles);
if (options.beforePageContent)
options.beforePageContent(data);
doc.applyStyles(doc.userStyles);
if (options.afterPageContent)
options.afterPageContent(data);
doc.applyStyles(doc.userStyles);
if (options.afterPageAdd && data.pageNumber > 1) {
;
data.afterPageAdd(data);
}
doc.applyStyles(doc.userStyles);
};
}
;
[
'createdHeaderCell',
'drawHeaderRow',
'drawRow',
'drawHeaderCell',
].forEach(function (name) {
if (options[name]) {
console.error("The \"".concat(name, "\" hook has changed in version 3.0, check the changelog for how to migrate."));
}
});
[
['showFoot', 'showFooter'],
['showHead', 'showHeader'],
['didDrawPage', 'addPageContent'],
['didParseCell', 'createdCell'],
['headStyles', 'headerStyles'],
].forEach(function (_a) {
var current = _a[0], deprecated = _a[1];
if (options[deprecated]) {
console.error("Use of deprecated option ".concat(deprecated, ". Use ").concat(current, " instead"));
options[current] = options[deprecated];
}
});
[
['padding', 'cellPadding'],
['lineHeight', 'rowHeight'],
'fontSize',
'overflow',
].forEach(function (o) {
var deprecatedOption = typeof o === 'string' ? o : o[0];
var style = typeof o === 'string' ? o : o[1];
if (typeof options[deprecatedOption] !== 'undefined') {
if (typeof options.styles[style] === 'undefined') {
options.styles[style] = options[deprecatedOption];
}
console.error('Use of deprecated option: ' +
deprecatedOption +
', use the style ' +
style +
' instead.');
}
});
for (var _b = 0, _c = [
'styles',
'bodyStyles',
'headStyles',
'footStyles',
]; _b < _c.length; _b++) {
var styleProp = _c[_b];
checkStyles(options[styleProp] || {});
}
var columnStyles = options['columnStyles'] || {};
for (var _d = 0, _e = Object.keys(columnStyles); _d < _e.length; _d++) {
var key = _e[_d];
checkStyles(columnStyles[key] || {});
}
};
for (var _i = 0, _a = [global, document, current]; _i < _a.length; _i++) {
var options = _a[_i];
_loop_1(options);
}
}
exports["default"] = default_1;
function checkStyles(styles) {
if (styles.rowHeight) {
console.error('Use of deprecated style rowHeight. It is renamed to minCellHeight.');
if (!styles.minCellHeight) {
styles.minCellHeight = styles.rowHeight;
}
}
else if (styles.columnWidth) {
console.error('Use of deprecated style columnWidth. It is renamed to cellWidth.');
if (!styles.cellWidth) {
styles.cellWidth = styles.columnWidth;
}
}
}
/***/ }),
/***/ 260:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Column = exports.Cell = exports.Row = exports.Table = void 0;
var config_1 = __webpack_require__(796);
var HookData_1 = __webpack_require__(172);
var common_1 = __webpack_require__(420);
var Table = /** @class */ (function () {
function Table(input, content) {
this.pageNumber = 1;
// Deprecated, use pageNumber instead
// Not using getter since:
// https://github.com/simonbengtsson/jsPDF-AutoTable/issues/596
this.pageCount = 1;
this.id = input.id;
this.settings = input.settings;
this.styles = input.styles;
this.hooks = input.hooks;
this.columns = content.columns;
this.head = content.head;
this.body = content.body;
this.foot = content.foot;
}
Table.prototype.getHeadHeight = function (columns) {
return this.head.reduce(function (acc, row) { return acc + row.getMaxCellHeight(columns); }, 0);
};
Table.prototype.getFootHeight = function (columns) {
return this.foot.reduce(function (acc, row) { return acc + row.getMaxCellHeight(columns); }, 0);
};
Table.prototype.allRows = function () {
return this.head.concat(this.body).concat(this.foot);
};
Table.prototype.callCellHooks = function (doc, handlers, cell, row, column, cursor) {
for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) {
var handler = handlers_1[_i];
var data = new HookData_1.CellHookData(doc, this, cell, row, column, cursor);
var result = handler(data) === false;
// Make sure text is always string[] since user can assign string
cell.text = Array.isArray(cell.text) ? cell.text : [cell.text];
if (result) {
return false;
}
}
return true;
};
Table.prototype.callEndPageHooks = function (doc, cursor) {
doc.applyStyles(doc.userStyles);
for (var _i = 0, _a = this.hooks.didDrawPage; _i < _a.length; _i++) {
var handler = _a[_i];
handler(new HookData_1.HookData(doc, this, cursor));
}
};
Table.prototype.callWillDrawPageHooks = function (doc, cursor) {
for (var _i = 0, _a = this.hooks.willDrawPage; _i < _a.length; _i++) {
var handler = _a[_i];
handler(new HookData_1.HookData(doc, this, cursor));
}
};
Table.prototype.getWidth = function (pageWidth) {
if (typeof this.settings.tableWidth === 'number') {
return this.settings.tableWidth;
}
else if (this.settings.tableWidth === 'wrap') {
var wrappedWidth = this.columns.reduce(function (total, col) { return total + col.wrappedWidth; }, 0);
return wrappedWidth;
}
else {
var margin = this.settings.margin;
return pageWidth - margin.left - margin.right;
}
};
return Table;
}());
exports.Table = Table;
var Row = /** @class */ (function () {
function Row(raw, index, section, cells, spansMultiplePages) {
if (spansMultiplePages === void 0) { spansMultiplePages = false; }
this.height = 0;
this.raw = raw;
if (raw instanceof config_1.HtmlRowInput) {
this.raw = raw._element;
this.element = raw._element;
}
this.index = index;
this.section = section;
this.cells = cells;
this.spansMultiplePages = spansMultiplePages;
}
Row.prototype.getMaxCellHeight = function (columns) {
var _this = this;
return columns.reduce(function (acc, column) { var _a; return Math.max(acc, ((_a = _this.cells[column.index]) === null || _a === void 0 ? void 0 : _a.height) || 0); }, 0);
};
Row.prototype.hasRowSpan = function (columns) {
var _this = this;
return (columns.filter(function (column) {
var cell = _this.cells[column.index];
if (!cell)
return false;
return cell.rowSpan > 1;
}).length > 0);
};
Row.prototype.canEntireRowFit = function (height, columns) {
return this.getMaxCellHeight(columns) <= height;
};
Row.prototype.getMinimumRowHeight = function (columns, doc) {
var _this = this;
return columns.reduce(function (acc, column) {
var cell = _this.cells[column.index];
if (!cell)
return 0;
var lineHeight = doc.getLineHeight(cell.styles.fontSize);
var vPadding = cell.padding('vertical');
var oneRowHeight = vPadding + lineHeight;
return oneRowHeight > acc ? oneRowHeight : acc;
}, 0);
};
return Row;
}());
exports.Row = Row;
var Cell = /** @class */ (function () {
function Cell(raw, styles, section) {
var _a, _b;
this.contentHeight = 0;
this.contentWidth = 0;
this.wrappedWidth = 0;
this.minReadableWidth = 0;
this.minWidth = 0;
this.width = 0;
this.height = 0;
this.x = 0;
this.y = 0;
this.styles = styles;
this.section = section;
this.raw = raw;
var content = raw;
if (raw != null && typeof raw === 'object' && !Array.isArray(raw)) {
this.rowSpan = raw.rowSpan || 1;
this.colSpan = raw.colSpan || 1;
content = (_b = (_a = raw.content) !== null && _a !== void 0 ? _a : raw.title) !== null && _b !== void 0 ? _b : raw;
if (raw._element) {
this.raw = raw._element;
}
}
else {
this.rowSpan = 1;
this.colSpan = 1;
}
// Stringify 0 and false, but not undefined or null
var text = content != null ? '' + content : '';
var splitRegex = /\r\n|\r|\n/g;
this.text = text.split(splitRegex);
}
Cell.prototype.getTextPos = function () {
var y;
if (this.styles.valign === 'top') {
y = this.y + this.padding('top');
}
else if (this.styles.valign === 'bottom') {
y = this.y + this.height - this.padding('bottom');
}
else {
var netHeight = t