From 1dc9427d3472414c7fd1c8759e9e13d3670a9b5f Mon Sep 17 00:00:00 2001 From: Release Bot Date: Tue, 10 Oct 2023 16:20:54 +0000 Subject: [PATCH] 3.7.0 --- dist/index.d.ts | 8 +- dist/jspdf.plugin.autotable.js | 298 ++++++++++++++--------------- dist/jspdf.plugin.autotable.min.js | 4 +- dist/jspdf.plugin.autotable.mjs | 288 ++++++++++++++-------------- package-lock.json | 4 +- package.json | 2 +- 6 files changed, 298 insertions(+), 306 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 4f4a7666..389175da 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -19,9 +19,9 @@ declare class DocHandler { * @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. In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument. **In "advanced" API mode this parameter is deprecated.** + * @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. */ - rect(x: number, y: number, width: number, height: number, fillStyle: "S" | "F" | "DF" | "FD" | null): any; + rect(x: number, y: number, width: number, height: number, fillStyle: "S" | "F" | "DF" | "FD"): any; getLastAutoTable(): Table | null; getTextWidth(text: string | string[]): number; getDocument(): any; @@ -37,6 +37,8 @@ declare class DocHandler { height: number; }; scaleFactor(): number; + get lineHeightFactor(): number; + getLineHeight(fontSize: number): number; pageNumber(): number; } declare class HookData { @@ -187,7 +189,7 @@ export declare class Cell { y: number; constructor(raw: CellInput, styles: Styles, section: Section); getTextPos(): Pos; - getContentHeight(scaleFactor: number): number; + getContentHeight(scaleFactor: number, lineHeightFactor?: number): number; padding(name: "vertical" | "horizontal" | "top" | "bottom" | "left" | "right"): number; } export declare class Column { diff --git a/dist/jspdf.plugin.autotable.js b/dist/jspdf.plugin.autotable.js index 82dfdc93..099b5a60 100644 --- a/dist/jspdf.plugin.autotable.js +++ b/dist/jspdf.plugin.autotable.js @@ -1,6 +1,6 @@ /*! * - * jsPDF AutoTable plugin v3.6.0 + * jsPDF AutoTable plugin v3.7.0 * * Copyright (c) 2023 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable * Licensed under the MIT License. @@ -178,9 +178,13 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); */ function default_1(text, x, y, styles, doc) { styles = styles || {}; - var FONT_ROW_RATIO = 1.15; + 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; @@ -192,11 +196,11 @@ function default_1(text, x, y, styles, doc) { lineCount = splitText.length || 1; } // Align the top - y += fontSize * (2 - FONT_ROW_RATIO); + y += fontSize * (2 - PHYSICAL_LINE_HEIGHT); if (styles.valign === 'middle') - y -= (lineCount / 2) * fontSize * FONT_ROW_RATIO; + y -= (lineCount / 2) * lineHeight; else if (styles.valign === 'bottom') - y -= lineCount * fontSize * FONT_ROW_RATIO; + y -= lineCount * lineHeight; if (styles.halign === 'center' || styles.halign === 'right') { var alignSize = fontSize; if (styles.halign === 'center') @@ -204,7 +208,7 @@ function default_1(text, x, y, styles, doc) { if (splitText && lineCount >= 1) { for (var iLine = 0; iLine < splitText.length; iLine++) { doc.text(splitText[iLine], x - doc.getStringUnitWidth(splitText[iLine]) * alignSize, y); - y += fontSize * FONT_ROW_RATIO; + y += lineHeight; } return doc; } @@ -231,7 +235,7 @@ exports["default"] = default_1; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.parseSpacing = exports.getFillStyle = exports.addTableBorder = exports.getStringWidth = void 0; +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]; @@ -325,6 +329,11 @@ function parseSpacing(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; /***/ }), @@ -349,11 +358,7 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getTheme = exports.defaultStyles = exports.HtmlRowInput = exports.FONT_ROW_RATIO = void 0; -/** - * Ratio between font size and font height. The number comes from jspdf's source code - */ -exports.FONT_ROW_RATIO = 1.15; +exports.getTheme = exports.defaultStyles = exports.HtmlRowInput = void 0; var HtmlRowInput = /** @class */ (function (_super) { __extends(HtmlRowInput, _super); function HtmlRowInput(element) { @@ -450,19 +455,46 @@ function parseCss(supportedFonts, element, scaleFactor, style, window) { }); 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'; + } + } + } + console.log(result.lineWidth); var borderColor = parseColor(element, function (elem) { - return window.getComputedStyle(elem)['borderTopColor']; + return window.getComputedStyle(elem)[borderColorSide]; }); if (borderColor != null) result.lineColor = borderColor; - var padding = parsePadding(style, scaleFactor); - if (padding) - result.cellPadding = padding; - // style.borderWidth only works in chrome (borderTopWidth etc works in firefox and ie as well) - var bw = parseInt(style.borderTopWidth || ''); - bw = bw / pxScaleFactor / scaleFactor; - if (bw) - result.lineWidth = bw; var accepted = ['left', 'right', 'center', 'justify']; if (accepted.indexOf(style.textAlign) !== -1) { result.halign = style.textAlign; @@ -658,12 +690,12 @@ var DocHandler = /** @class */ (function () { * @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. In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument. **In "advanced" API mode this parameter is deprecated.** + * @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) { - if (!['S', 'F', 'DF', 'FD', null].some(function (v) { return v === fillStyle; })) { - throw new TypeError("Invalid value '".concat(fillStyle, "' passed to rect. Allowed values are: 'S', 'F', 'DF', 'FD', null")); - } + // 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 () { @@ -704,6 +736,17 @@ var DocHandler = /** @class */ (function () { DocHandler.prototype.scaleFactor = function () { return this.jsPDFDocument.internal.scaleFactor; }; + Object.defineProperty(DocHandler.prototype, "lineHeightFactor", { + get: function () { + var doc = this.jsPDFDocument; + return doc.getLineHeightFactor ? doc.getLineHeightFactor() : 1.15; + }, + enumerable: false, + configurable: true + }); + DocHandler.prototype.getLineHeight = function (fontSize) { + return (fontSize / this.scaleFactor()) * this.lineHeightFactor; + }; DocHandler.prototype.pageNumber = function () { var pageInfo = this.jsPDFDocument.internal.getCurrentPageInfo(); if (!pageInfo) { @@ -797,7 +840,7 @@ function parseCellContent(orgCell) { cell.innerHTML = cell.innerHTML.replace(/\n/g, '').replace(/ +/g, ' '); // Preserve
tags as line breaks in the pdf cell.innerHTML = cell.innerHTML - .split(/\/) //start with ''. + .split(//) //start with ''. .map(function (part) { return part.trim(); }) .join('\n'); // innerText for ie @@ -1257,9 +1300,9 @@ var Row = /** @class */ (function () { var cell = _this.cells[column.index]; if (!cell) return 0; - var fontHeight = (cell.styles.fontSize / doc.scaleFactor()) * config_1.FONT_ROW_RATIO; + var lineHeight = doc.getLineHeight(cell.styles.fontSize); var vPadding = cell.padding('vertical'); - var oneRowHeight = vPadding + fontHeight; + var oneRowHeight = vPadding + lineHeight; return oneRowHeight > acc ? oneRowHeight : acc; }, 0); }; @@ -1324,10 +1367,12 @@ var Cell = /** @class */ (function () { } return { x: x, y: y }; }; - Cell.prototype.getContentHeight = function (scaleFactor) { + // TODO (v4): replace parameters with only (lineHeight) + Cell.prototype.getContentHeight = function (scaleFactor, lineHeightFactor) { + if (lineHeightFactor === void 0) { lineHeightFactor = 1.15; } var lineCount = Array.isArray(this.text) ? this.text.length : 1; - var fontHeight = (this.styles.fontSize / scaleFactor) * config_1.FONT_ROW_RATIO; - var height = lineCount * fontHeight + this.padding('vertical'); + var lineHeight = (this.styles.fontSize / scaleFactor) * lineHeightFactor; + var height = lineCount * lineHeight + this.padding('vertical'); return Math.max(height, this.styles.minCellHeight); }; Cell.prototype.padding = function (name) { @@ -1570,18 +1615,8 @@ function cellStyles(sectionName, column, rowIndex, themeName, styles, scaleFacto /***/ (function(__unused_webpack_module, exports, __webpack_require__) { -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.addPage = exports.drawTable = void 0; -var config_1 = __webpack_require__(913); var common_1 = __webpack_require__(200); var models_1 = __webpack_require__(287); var documentHandler_1 = __webpack_require__(323); @@ -1612,7 +1647,7 @@ function drawTable(jsPDFDoc, table) { table.callWillDrawPageHooks(doc, cursor); var startPos = (0, polyfills_1.assign)({}, cursor); table.startPageNumber = doc.pageNumber(); - if (settings.horizontalPageBreak === true) { + if (settings.horizontalPageBreak) { // managed flow for split columns printTableWithHorizontalPageBreak(doc, table, startPos, cursor); } @@ -1649,7 +1684,7 @@ function drawTable(jsPDFDoc, table) { exports.drawTable = drawTable; function printTableWithHorizontalPageBreak(doc, table, startPos, cursor) { // calculate width of columns and render only those which can fit into page - var allColumnsCanFitResult = tablePrinter_1.default.calculateAllColumnsCanFitInPage(doc, table); + var allColumnsCanFitResult = (0, tablePrinter_1.calculateAllColumnsCanFitInPage)(doc, table); allColumnsCanFitResult.map(function (colsAndIndexes, index) { doc.applyStyles(doc.userStyles); // add page to print next columns in new page @@ -1660,9 +1695,8 @@ function printTableWithHorizontalPageBreak(doc, table, startPos, cursor) { // print head for selected columns printHead(doc, table, cursor, colsAndIndexes.columns); } - // print body for selected columns + // print body & footer for selected columns printBody(doc, table, startPos, cursor, colsAndIndexes.columns); - // print foot for selected columns printFoot(doc, table, cursor, colsAndIndexes.columns); }); } @@ -1688,9 +1722,9 @@ function printFoot(doc, table, cursor, columns) { } } function getRemainingLineCount(cell, remainingPageSpace, doc) { - var fontHeight = (cell.styles.fontSize / doc.scaleFactor()) * config_1.FONT_ROW_RATIO; + var lineHeight = doc.getLineHeight(cell.styles.fontSize); var vPadding = cell.padding('vertical'); - var remainingLines = Math.floor((remainingPageSpace - vPadding) / fontHeight); + var remainingLines = Math.floor((remainingPageSpace - vPadding) / lineHeight); return Math.max(0, remainingLines); } function modifyRowToFit(row, remainingPageSpace, table, doc) { @@ -1714,7 +1748,8 @@ function modifyRowToFit(row, remainingPageSpace, table, doc) { remainderCell.text = cell.text.splice(remainingLineCount, cell.text.length); } var scaleFactor = doc.scaleFactor(); - cell.contentHeight = cell.getContentHeight(scaleFactor); + var lineHeightFactor = doc.lineHeightFactor; + cell.contentHeight = cell.getContentHeight(scaleFactor, lineHeightFactor); if (cell.contentHeight >= remainingPageSpace) { cell.contentHeight = remainingPageSpace; remainderCell.styles.minCellHeight -= remainingPageSpace; @@ -1722,7 +1757,7 @@ function modifyRowToFit(row, remainingPageSpace, table, doc) { if (cell.contentHeight > row.height) { row.height = cell.contentHeight; } - remainderCell.contentHeight = remainderCell.getContentHeight(scaleFactor); + remainderCell.contentHeight = remainderCell.getContentHeight(scaleFactor, lineHeightFactor); if (remainderCell.contentHeight > rowHeight) { rowHeight = remainderCell.contentHeight; } @@ -1816,7 +1851,7 @@ function printRow(doc, table, row, cursor, columns) { cursor.x += column.width; continue; } - drawCellBorders(doc, cell, cursor); + drawCellRect(doc, cell, cursor); var textPos = cell.getTextPos(); (0, autoTableText_1.default)(cell.text, textPos.x, textPos.y, { halign: cell.styles.halign, @@ -1828,32 +1863,27 @@ function printRow(doc, table, row, cursor, columns) { } cursor.y += row.height; } -function drawCellBorders(doc, cell, cursor) { +function drawCellRect(doc, cell, cursor) { var cellStyles = cell.styles; + // https://github.com/simonbengtsson/jsPDF-AutoTable/issues/774 + // TODO (v4): better solution? doc.getDocument().setFillColor(doc.getDocument().getFillColor()); if (typeof cellStyles.lineWidth === 'number') { - // prints normal cell border using rect's stroke + // Draw cell background with normal borders var fillStyle = (0, common_1.getFillStyle)(cellStyles.lineWidth, cellStyles.fillColor); if (fillStyle) { doc.rect(cell.x, cursor.y, cell.width, cell.height, fillStyle); } } else if (typeof cellStyles.lineWidth === 'object') { - drawCellBackground(doc, cell, cursor, cellStyles.fillColor); - drawBorders(doc, cell, cursor, cellStyles.fillColor, cellStyles.lineWidth); + // Draw cell background + if (cellStyles.fillColor) { + doc.rect(cell.x, cursor.y, cell.width, cell.height, 'F'); + } + // Draw cell individual borders + drawCellBorders(doc, cell, cursor, cellStyles.lineWidth); } } -/** - * Prints cell background without borders and allows transparent color. - * @param doc - * @param cell - * @param cursor - * @param fillColor - passed to getFillStyle; `false` will map to transparent, `truthy` values to 'F' from jsPDF.rect - */ -function drawCellBackground(doc, cell, cursor, fillColor) { - var fillStyle = (0, common_1.getFillStyle)(0, fillColor); - doc.rect(cell.x, cursor.y, cell.width, cell.height, fillStyle); -} /** * Draw all specified borders. Borders are centered on cell's edge and lengthened * to overlap with neighbours to create sharp corners. @@ -1863,7 +1893,7 @@ function drawCellBackground(doc, cell, cursor, fillColor) { * @param fillColor * @param lineWidth */ -function drawBorders(doc, cell, cursor, fillColor, lineWidth) { +function drawCellBorders(doc, cell, cursor, lineWidth) { var x1, y1, x2, y2; if (lineWidth.top) { x1 = cursor.x; @@ -1876,7 +1906,7 @@ function drawBorders(doc, cell, cursor, fillColor, lineWidth) { if (lineWidth.left) { x1 -= 0.5 * lineWidth.left; } - drawLine([x1, y1, x2, y2], lineWidth.top, fillColor); + drawLine(lineWidth.top, x1, y1, x2, y2); } if (lineWidth.bottom) { x1 = cursor.x; @@ -1889,7 +1919,7 @@ function drawBorders(doc, cell, cursor, fillColor, lineWidth) { if (lineWidth.left) { x1 -= 0.5 * lineWidth.left; } - drawLine([x1, y1, x2, y2], lineWidth.bottom, fillColor); + drawLine(lineWidth.bottom, x1, y1, x2, y2); } if (lineWidth.left) { x1 = cursor.x; @@ -1902,7 +1932,7 @@ function drawBorders(doc, cell, cursor, fillColor, lineWidth) { if (lineWidth.bottom) { y2 += 0.5 * lineWidth.bottom; } - drawLine([x1, y1, x2, y2], lineWidth.left, fillColor); + drawLine(lineWidth.left, x1, y1, x2, y2); } if (lineWidth.right) { x1 = cursor.x + cell.width; @@ -1915,12 +1945,11 @@ function drawBorders(doc, cell, cursor, fillColor, lineWidth) { if (lineWidth.bottom) { y2 += 0.5 * lineWidth.bottom; } - drawLine([x1, y1, x2, y2], lineWidth.right, fillColor); + drawLine(lineWidth.right, x1, y1, x2, y2); } - function drawLine(coords, width, color) { - var _a; + function drawLine(width, x1, y1, x2, y2) { doc.getDocument().setLineWidth(width); - (_a = doc.getDocument()).line.apply(_a, __spreadArray(__spreadArray([], coords, false), [(0, common_1.getFillStyle)(width, color)], false)); + doc.getDocument().line(x1, y1, x2, y2, 'S'); } } function getRemainingPageSpace(doc, table, isLastRow, cursor) { @@ -1975,105 +2004,73 @@ function nextPage(doc) { Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.calculateAllColumnsCanFitInPage = void 0; var common_1 = __webpack_require__(200); -var getPageAvailableWidth = function (doc, table) { - var margins = (0, common_1.parseSpacing)(table.settings.margin, 0); - var availablePageWidth = doc.pageSize().width - (margins.left + margins.right); - return availablePageWidth; -}; // get columns can be fit into page -var getColumnsCanFitInPage = function (doc, table, config) { +function getColumnsCanFitInPage(doc, table, config) { var _a; if (config === void 0) { config = {}; } // Get page width - var availablePageWidth = getPageAvailableWidth(doc, table); - var remainingWidth = availablePageWidth; + var remainingWidth = (0, common_1.getPageAvailableWidth)(doc, table); // Get column data key to repeat var repeatColumnsMap = new Map(); - var repeatColumn = null; - var cols = []; + var colIndexes = []; var columns = []; - var len = table.columns.length; - var i = (_a = config === null || config === void 0 ? void 0 : config.start) !== null && _a !== void 0 ? _a : 0; - var horizontalPageBreakRepeat = table.settings.horizontalPageBreakRepeat; - // Code to repeat the given column in split pages - if (horizontalPageBreakRepeat !== null && horizontalPageBreakRepeat !== undefined && Array.isArray(horizontalPageBreakRepeat)) { - var _loop_1 = function (field) { - var col = table.columns.find(function (item) { - return item.dataKey === field || - item.index === field; - }); - if (col) { - repeatColumnsMap.set(col.index, col); - cols.push(col.index); - columns.push(table.columns[col.index]); - remainingWidth = remainingWidth - col.wrappedWidth; - } - }; - for (var _i = 0, horizontalPageBreakRepeat_1 = horizontalPageBreakRepeat; _i < horizontalPageBreakRepeat_1.length; _i++) { - var field = horizontalPageBreakRepeat_1[_i]; - _loop_1(field); - } + var horizontalPageBreakRepeat = []; + table.settings.horizontalPageBreakRepeat; + if (Array.isArray(table.settings.horizontalPageBreakRepeat)) { + horizontalPageBreakRepeat = table.settings.horizontalPageBreakRepeat; // It can be a single value of type string or number (even number: 0) } - else if (horizontalPageBreakRepeat !== null && horizontalPageBreakRepeat !== undefined) { - repeatColumn = table.columns.find(function (item) { - return item.dataKey === horizontalPageBreakRepeat || - item.index === horizontalPageBreakRepeat; - }); - if (repeatColumn) { - cols.push(repeatColumn.index); - columns.push(table.columns[repeatColumn.index]); - remainingWidth = remainingWidth - repeatColumn.wrappedWidth; - } + else if (typeof table.settings.horizontalPageBreakRepeat === 'string' || + typeof table.settings.horizontalPageBreakRepeat === 'number') { + horizontalPageBreakRepeat = [table.settings.horizontalPageBreakRepeat]; } - while (i < len) { - // Prevent columnDataKeyToRepeat from being pushed twice on a page - if ((Array.isArray(horizontalPageBreakRepeat) && repeatColumnsMap.get(i)) - || (repeatColumn === null || repeatColumn === void 0 ? void 0 : repeatColumn.index) === i) { + // Code to repeat the given column in split pages + horizontalPageBreakRepeat.forEach(function (field) { + var col = table.columns.find(function (item) { return item.dataKey === field || item.index === field; }); + if (col && !repeatColumnsMap.has(col.index)) { + repeatColumnsMap.set(col.index, true); + colIndexes.push(col.index); + columns.push(table.columns[col.index]); + remainingWidth -= col.wrappedWidth; + } + }); + var first = true; + var i = (_a = config === null || config === void 0 ? void 0 : config.start) !== null && _a !== void 0 ? _a : 0; // make sure couter is initiated outside the loop + while (i < table.columns.length) { + // Prevent duplicates + if (repeatColumnsMap.has(i)) { i++; continue; } var colWidth = table.columns[i].wrappedWidth; - if (remainingWidth < colWidth) { - if (i === 0 || i === config.start) { - cols.push(i); - columns.push(table.columns[i]); - } + // Take at least one column even if it doesn't fit + if (first || remainingWidth >= colWidth) { + first = false; + colIndexes.push(i); + columns.push(table.columns[i]); + remainingWidth -= colWidth; + } + else { break; } - cols.push(i); - columns.push(table.columns[i]); - remainingWidth -= colWidth; i++; } - return { colIndexes: cols, columns: columns, lastIndex: i }; -}; -var calculateAllColumnsCanFitInPage = function (doc, table) { - // const margins = table.settings.margin; - // const availablePageWidth = doc.pageSize().width - (margins.left + margins.right); + return { colIndexes: colIndexes, columns: columns, lastIndex: i - 1 }; +} +function calculateAllColumnsCanFitInPage(doc, table) { var allResults = []; - var index = 0; - var len = table.columns.length; - while (index < len) { - var result = getColumnsCanFitInPage(doc, table, { - start: index === 0 ? 0 : index, - }); - if (result && result.columns && result.columns.length) { - index = result.lastIndex; + for (var i = 0; i < table.columns.length; i++) { + var result = getColumnsCanFitInPage(doc, table, { start: i }); + if (result.columns.length) { allResults.push(result); - } - else { - index++; + i = result.lastIndex; } } return allResults; -}; -exports["default"] = { - getColumnsCanFitInPage: getColumnsCanFitInPage, - calculateAllColumnsCanFitInPage: calculateAllColumnsCanFitInPage, - getPageAvailableWidth: getPageAvailableWidth, -}; +} +exports.calculateAllColumnsCanFitInPage = calculateAllColumnsCanFitInPage; /***/ }), @@ -2085,7 +2082,6 @@ exports["default"] = { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.ellipsize = exports.resizeColumns = exports.calculateWidths = void 0; var common_1 = __webpack_require__(200); -var tablePrinter_1 = __webpack_require__(435); /** * Calculate the column widths */ @@ -2136,7 +2132,7 @@ exports.calculateWidths = calculateWidths; function calculate(doc, table) { var sf = doc.scaleFactor(); var horizontalPageBreak = table.settings.horizontalPageBreak; - var availablePageWidth = tablePrinter_1.default.getPageAvailableWidth(doc, table); + var availablePageWidth = (0, common_1.getPageAvailableWidth)(doc, table); table.allRows().forEach(function (row) { for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { var column = _a[_i]; @@ -2351,7 +2347,7 @@ function fitContent(table, doc) { cell.text = result; } } - cell.contentHeight = cell.getContentHeight(doc.scaleFactor()); + cell.contentHeight = cell.getContentHeight(doc.scaleFactor(), doc.lineHeightFactor); var realContentHeight = cell.contentHeight / cell.rowSpan; if (cell.rowSpan > 1 && rowSpanHeight.count * rowSpanHeight.height < diff --git a/dist/jspdf.plugin.autotable.min.js b/dist/jspdf.plugin.autotable.min.js index 789670a9..b6d03265 100644 --- a/dist/jspdf.plugin.autotable.min.js +++ b/dist/jspdf.plugin.autotable.min.js @@ -1,10 +1,10 @@ /*! * - * jsPDF AutoTable plugin v3.6.0 + * jsPDF AutoTable plugin v3.7.0 * * Copyright (c) 2023 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable * Licensed under the MIT License. * http://opensource.org/licenses/mit-license * */ -!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(function(){try{return require("jspdf")}catch(t){}}());else if("function"==typeof define&&define.amd)define(["jspdf"],e);else{var n="object"==typeof exports?e(function(){try{return require("jspdf")}catch(t){}}()):e(t.jspdf);for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}("undefined"!=typeof globalThis?globalThis:void 0!==this?this:"undefined"!=typeof window?window:"undefined"!=typeof self?self:global,(function(t){return function(){"use strict";var e={662:function(t,e){var n,o=this&&this.__extends||(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)});Object.defineProperty(e,"__esModule",{value:!0}),e.CellHookData=e.HookData=void 0;var r=function(t,e,n){this.table=e,this.pageNumber=e.pageNumber,this.pageCount=this.pageNumber,this.settings=e.settings,this.cursor=n,this.doc=t.getDocument()};e.HookData=r;var i=function(t){function e(e,n,o,r,i,l){var a=t.call(this,e,n,l)||this;return a.cell=o,a.row=r,a.column=i,a.section=r.section,a}return o(e,t),e}(r);e.CellHookData=i},790:function(t,e,n){Object.defineProperty(e,"__esModule",{value:!0});var o=n(148),r=n(938),i=n(323),l=n(587),a=n(49),s=n(858);e.default=function(t){t.API.autoTable=function(){for(var t,e=[],n=0;n {}}) instead."),t.API.autoTable.globalDefaults||(t.API.autoTable.globalDefaults={}),t.API.autoTable.globalDefaults.addPageContent=e,this},t.API.autoTableAddPage=function(){return console.error("Use of deprecated function: autoTableAddPage. Use doc.addPage()"),this.addPage(),this}}},938:function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e,n,o,r){o=o||{};var i=1.15,l=r.internal.scaleFactor,a=r.internal.getFontSize()/l,s="",u=1;if("middle"!==o.valign&&"bottom"!==o.valign&&"center"!==o.halign&&"right"!==o.halign||(u=(s="string"==typeof t?t.split(/\r\n|\r|\n/g):t).length||1),n+=a*(2-i),"middle"===o.valign?n-=u/2*a*i:"bottom"===o.valign&&(n-=u*a*i),"center"===o.halign||"right"===o.halign){var d=a;if("center"===o.halign&&(d*=.5),s&&u>=1){for(var h=0;h0,o=e||0===e;return n&&o?"DF":n?"S":o?"F":null}Object.defineProperty(e,"__esModule",{value:!0}),e.parseSpacing=e.getFillStyle=e.addTableBorder=e.getStringWidth=void 0,e.getStringWidth=function(t,e,n){return n.applyStyles(e,!0),(Array.isArray(t)?t:[t]).map((function(t){return n.getTextWidth(t)})).reduce((function(t,e){return Math.max(t,e)}),0)},e.addTableBorder=function(t,e,o,r){var i=e.settings.tableLineWidth,l=e.settings.tableLineColor;t.applyStyles({lineWidth:i,lineColor:l});var a=n(i,!1);a&&t.rect(o.x,o.y,e.getWidth(t.pageSize().width),r.y-o.y,a)},e.getFillStyle=n,e.parseSpacing=function(t,e){var n,o,r,i;if(t=t||e,Array.isArray(t)){if(t.length>=4)return{top:t[0],right:t[1],bottom:t[2],left:t[3]};if(3===t.length)return{top:t[0],right:t[1],bottom:t[2],left:t[1]};if(2===t.length)return{top:t[0],right:t[1],bottom:t[0],left:t[1]};t=1===t.length?t[0]:e}return"object"==typeof t?("number"==typeof t.vertical&&(t.top=t.vertical,t.bottom=t.vertical),"number"==typeof t.horizontal&&(t.right=t.horizontal,t.left=t.horizontal),{left:null!==(n=t.left)&&void 0!==n?n:e,top:null!==(o=t.top)&&void 0!==o?o:e,right:null!==(r=t.right)&&void 0!==r?r:e,bottom:null!==(i=t.bottom)&&void 0!==i?i:e}):("number"!=typeof t&&(t=e),{top:t,right:t,bottom:t,left:t})}},913:function(t,e){var n,o=this&&this.__extends||(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)});Object.defineProperty(e,"__esModule",{value:!0}),e.getTheme=e.defaultStyles=e.HtmlRowInput=e.FONT_ROW_RATIO=void 0,e.FONT_ROW_RATIO=1.15;var r=function(t){function e(e){var n=t.call(this)||this;return n._element=e,n}return o(e,t),e}(Array);e.HtmlRowInput=r,e.defaultStyles=function(t){return{font:"helvetica",fontStyle:"normal",overflow:"linebreak",fillColor:!1,textColor:20,halign:"left",valign:"top",fontSize:10,cellPadding:5/t,lineColor:200,lineWidth:0,cellWidth:"auto",minCellHeight:0,minCellWidth:0}},e.getTheme=function(t){return{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:.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"}}}[t]}},259:function(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.parseCss=void 0;var o=n(200);function r(t,e){var n=i(t,e);if(!n)return null;var o=n.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/);if(!o||!Array.isArray(o))return null;var r=[parseInt(o[1]),parseInt(o[2]),parseInt(o[3])];return 0===parseInt(o[4])||isNaN(r[0])||isNaN(r[1])||isNaN(r[2])?null:r}function i(t,e){var n=e(t);return"rgba(0, 0, 0, 0)"===n||"transparent"===n||"initial"===n||"inherit"===n?null==t.parentElement?null:i(t.parentElement,e):n}e.parseCss=function(t,e,n,i,l){var a={},s=96/72,u=r(e,(function(t){return l.getComputedStyle(t).backgroundColor}));null!=u&&(a.fillColor=u);var d=r(e,(function(t){return l.getComputedStyle(t).color}));null!=d&&(a.textColor=d);var h=r(e,(function(t){return l.getComputedStyle(t).borderTopColor}));null!=h&&(a.lineColor=h);var c=function(t,e){var n=[t.paddingTop,t.paddingRight,t.paddingBottom,t.paddingLeft],r=96/(72/e),i=(parseInt(t.lineHeight)-parseInt(t.fontSize))/e/2,l=n.map((function(t){return parseInt(t||"0")/r})),a=(0,o.parseSpacing)(l,0);i>a.top&&(a.top=i);i>a.bottom&&(a.bottom=i);return a}(i,n);c&&(a.cellPadding=c);var f=parseInt(i.borderTopWidth||"");(f=f/s/n)&&(a.lineWidth=f);var p=["left","right","center","justify"];-1!==p.indexOf(i.textAlign)&&(a.halign=i.textAlign),-1!==(p=["middle","bottom","top"]).indexOf(i.verticalAlign)&&(a.valign=i.verticalAlign);var g=parseInt(i.fontSize||"");isNaN(g)||(a.fontSize=g/s);var y=function(t){var e="";("bold"===t.fontWeight||"bolder"===t.fontWeight||parseInt(t.fontWeight)>=700)&&(e="bold");"italic"!==t.fontStyle&&"oblique"!==t.fontStyle||(e+="italic");return e}(i);y&&(a.fontStyle=y);var v=(i.fontFamily||"").toLowerCase();return-1!==t.indexOf(v)&&(a.font=v),a}},323:function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.DocHandler=void 0;var n={},o=function(){function t(t){this.jsPDFDocument=t,this.userStyles={textColor:t.getTextColor?this.jsPDFDocument.getTextColor():0,fontSize:t.internal.getFontSize(),fontStyle:t.internal.getFont().fontStyle,font:t.internal.getFont().fontName,lineWidth:t.getLineWidth?this.jsPDFDocument.getLineWidth():0,lineColor:t.getDrawColor?this.jsPDFDocument.getDrawColor():0}}return t.setDefaults=function(t,e){void 0===e&&(e=null),e?e.__autoTableDocumentDefaults=t:n=t},t.unifyColor=function(t){return Array.isArray(t)?t:"number"==typeof t?[t,t,t]:"string"==typeof t?[t]:null},t.prototype.applyStyles=function(e,n){var o,r,i;void 0===n&&(n=!1),e.fontStyle&&this.jsPDFDocument.setFontStyle&&this.jsPDFDocument.setFontStyle(e.fontStyle);var l=this.jsPDFDocument.internal.getFont(),a=l.fontStyle,s=l.fontName;if(e.font&&(s=e.font),e.fontStyle){a=e.fontStyle;var u=this.getFontList()[s];u&&-1===u.indexOf(a)&&(this.jsPDFDocument.setFontStyle&&this.jsPDFDocument.setFontStyle(u[0]),a=u[0])}if(this.jsPDFDocument.setFont(s,a),e.fontSize&&this.jsPDFDocument.setFontSize(e.fontSize),!n){var d=t.unifyColor(e.fillColor);d&&(o=this.jsPDFDocument).setFillColor.apply(o,d),(d=t.unifyColor(e.textColor))&&(r=this.jsPDFDocument).setTextColor.apply(r,d),(d=t.unifyColor(e.lineColor))&&(i=this.jsPDFDocument).setDrawColor.apply(i,d),"number"==typeof e.lineWidth&&this.jsPDFDocument.setLineWidth(e.lineWidth)}},t.prototype.splitTextToSize=function(t,e,n){return this.jsPDFDocument.splitTextToSize(t,e,n)},t.prototype.rect=function(t,e,n,o,r){if(!["S","F","DF","FD",null].some((function(t){return t===r})))throw new TypeError("Invalid value '".concat(r,"' passed to rect. Allowed values are: 'S', 'F', 'DF', 'FD', null"));return this.jsPDFDocument.rect(t,e,n,o,r)},t.prototype.getLastAutoTable=function(){return this.jsPDFDocument.lastAutoTable||null},t.prototype.getTextWidth=function(t){return this.jsPDFDocument.getTextWidth(t)},t.prototype.getDocument=function(){return this.jsPDFDocument},t.prototype.setPage=function(t){this.jsPDFDocument.setPage(t)},t.prototype.addPage=function(){return this.jsPDFDocument.addPage()},t.prototype.getFontList=function(){return this.jsPDFDocument.getFontList()},t.prototype.getGlobalOptions=function(){return n||{}},t.prototype.getDocumentOptions=function(){return this.jsPDFDocument.__autoTableDocumentDefaults||{}},t.prototype.pageSize=function(){var t=this.jsPDFDocument.internal.pageSize;return null==t.width&&(t={width:t.getWidth(),height:t.getHeight()}),t},t.prototype.scaleFactor=function(){return this.jsPDFDocument.internal.scaleFactor},t.prototype.pageNumber=function(){var t=this.jsPDFDocument.internal.getCurrentPageInfo();return t?t.pageNumber:this.jsPDFDocument.internal.getNumberOfPages()},t}();e.DocHandler=o},148:function(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.parseHtml=void 0;var o=n(259),r=n(913);function i(t,e,n,i,a,s){for(var u=new r.HtmlRowInput(i),d=0;d0&&(a||"none"!==p.display))return u}function l(t){var e=t.cloneNode(!0);return e.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/ +/g," "),e.innerHTML=e.innerHTML.split(/\/).map((function(t){return t.trim()})).join("\n"),e.innerText||e.textContent||""}e.parseHtml=function(t,e,n,o,r){var l,a,s;void 0===o&&(o=!1),void 0===r&&(r=!1),s="string"==typeof e?n.document.querySelector(e):e;var u=Object.keys(t.getFontList()),d=t.scaleFactor(),h=[],c=[],f=[];if(!s)return console.error("Html table could not be found with input: ",e),{head:h,body:c,foot:f};for(var p=0;p0?"_".concat(i):"")};r.push(l)}})),r}(r,i,l);return{columns:u,head:r,body:i,foot:l}}(n,h,d);return{id:e.tableId,content:g,hooks:f,styles:c,settings:p}}},291:function(t,e){function n(t){t.rowHeight?(console.error("Use of deprecated style rowHeight. It is renamed to minCellHeight."),t.minCellHeight||(t.minCellHeight=t.rowHeight)):t.columnWidth&&(console.error("Use of deprecated style columnWidth. It is renamed to cellWidth."),t.cellWidth||(t.cellWidth=t.columnWidth))}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e,o,r){for(var i=function(e){e&&"object"!=typeof e&&console.error("The options parameter should be of type object, is: "+typeof e),void 0!==e.extendWidth&&(e.tableWidth=e.extendWidth?"auto":"wrap",console.error("Use of deprecated option: extendWidth, use tableWidth instead.")),void 0!==e.margins&&(void 0===e.margin&&(e.margin=e.margins),console.error("Use of deprecated option: margins, use margin instead.")),e.startY&&"number"!=typeof e.startY&&(console.error("Invalid value for startY option",e.startY),delete e.startY),!e.didDrawPage&&(e.afterPageContent||e.beforePageContent||e.afterPageAdd)&&(console.error("The afterPageContent, beforePageContent and afterPageAdd hooks are deprecated. Use didDrawPage instead"),e.didDrawPage=function(n){t.applyStyles(t.userStyles),e.beforePageContent&&e.beforePageContent(n),t.applyStyles(t.userStyles),e.afterPageContent&&e.afterPageContent(n),t.applyStyles(t.userStyles),e.afterPageAdd&&n.pageNumber>1&&n.afterPageAdd(n),t.applyStyles(t.userStyles)}),["createdHeaderCell","drawHeaderRow","drawRow","drawHeaderCell"].forEach((function(t){e[t]&&console.error('The "'.concat(t,'" 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(t){var n=t[0],o=t[1];e[o]&&(console.error("Use of deprecated option ".concat(o,". Use ").concat(n," instead")),e[n]=e[o])})),[["padding","cellPadding"],["lineHeight","rowHeight"],"fontSize","overflow"].forEach((function(t){var n="string"==typeof t?t:t[0],o="string"==typeof t?t:t[1];void 0!==e[n]&&(void 0===e.styles[o]&&(e.styles[o]=e[n]),console.error("Use of deprecated option: "+n+", use the style "+o+" instead."))}));for(var o=0,r=["styles","bodyStyles","headStyles","footStyles"];o1})).length>0},t.prototype.canEntireRowFit=function(t,e){return this.getMaxCellHeight(e)<=t},t.prototype.getMinimumRowHeight=function(t,e){var n=this;return t.reduce((function(t,r){var i=n.cells[r.index];if(!i)return 0;var l=i.styles.fontSize/e.scaleFactor()*o.FONT_ROW_RATIO,a=i.padding("vertical")+l;return a>t?a:t}),0)},t}();e.Row=a;var s=function(){function t(t,e,n){var o,r;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=e,this.section=n,this.raw=t;var i=t;null==t||"object"!=typeof t||Array.isArray(t)?(this.rowSpan=1,this.colSpan=1):(this.rowSpan=t.rowSpan||1,this.colSpan=t.colSpan||1,i=null!==(r=null!==(o=t.content)&&void 0!==o?o:t.title)&&void 0!==r?r:t,t._element&&(this.raw=t._element));var l=null!=i?""+i:"";this.text=l.split(/\r\n|\r|\n/g)}return t.prototype.getTextPos=function(){var t,e;if("top"===this.styles.valign)t=this.y+this.padding("top");else if("bottom"===this.styles.valign)t=this.y+this.height-this.padding("bottom");else{var n=this.height-this.padding("vertical");t=this.y+n/2+this.padding("top")}if("right"===this.styles.halign)e=this.x+this.width-this.padding("right");else if("center"===this.styles.halign){var o=this.width-this.padding("horizontal");e=this.x+o/2+this.padding("left")}else e=this.x+this.padding("left");return{x:e,y:t}},t.prototype.getContentHeight=function(t){var e=(Array.isArray(this.text)?this.text.length:1)*(this.styles.fontSize/t*o.FONT_ROW_RATIO)+this.padding("vertical");return Math.max(e,this.styles.minCellHeight)},t.prototype.padding=function(t){var e=(0,i.parseSpacing)(this.styles.cellPadding,0);return"vertical"===t?e.top+e.bottom:"horizontal"===t?e.left+e.right:e[t]},t}();e.Cell=s;var u=function(){function t(t,e,n){this.wrappedWidth=0,this.minReadableWidth=0,this.minWidth=0,this.width=0,this.dataKey=t,this.raw=e,this.index=n}return t.prototype.getMaxCustomCellWidth=function(t){for(var e=0,n=0,o=t.allRows();n0?n:null}function d(t,e,n,o,r,i,s){var u,d=(0,l.getTheme)(o);"head"===t?u=r.headStyles:"body"===t?u=r.bodyStyles:"foot"===t&&(u=r.footStyles);var h=(0,a.assign)({},d.table,d[t],r.styles,u),c=r.columnStyles[e.dataKey]||r.columnStyles[e.index]||{},f="body"===t?c:{},p="body"===t&&n%2==0?(0,a.assign)({},d.alternateRow,r.alternateRowStyles):{},g=(0,l.defaultStyles)(i),y=(0,a.assign)({},g,h,p,f);return(0,a.assign)(y,s)}e.createTable=function(t,e){var n=new o.DocHandler(t),l=function(t,e){var n=t.content,o=function(t){return t.map((function(t,e){var n,o,i;return i="object"==typeof t&&null!==(o=null!==(n=t.dataKey)&&void 0!==n?n:t.key)&&void 0!==o?o:e,new r.Column(i,t,e)}))}(n.columns);if(0===n.head.length){(i=u(o,"head"))&&n.head.push(i)}if(0===n.foot.length){var i;(i=u(o,"foot"))&&n.foot.push(i)}var l=t.settings.theme,a=t.styles;return{columns:o,head:s("head",n.head,o,a,l,e),body:s("body",n.body,o,a,l,e),foot:s("foot",n.foot,o,a,l,e)}}(e,n.scaleFactor()),a=new r.Table(e,l);return(0,i.calculateWidths)(n,a),n.applyStyles(n.userStyles),a}},49:function(t,e,n){var o=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;rl)return console.error("Will not be able to print row ".concat(e.index," correctly since it's minimum height is larger than page height")),!0;if(!s)return!1;var u=e.hasRowSpan(o.columns);return e.getMaxCellHeight(o.columns)>l?(u&&console.error("The content of row ".concat(e.index," will not be drawn correctly since drawing rows with a height larger than the page height and has cells with rowspans is not supported.")),!0):!u&&"avoid"!==o.settings.rowPageBreak}(t,n,u,e)){var d=function(t,e,n,o){var r={};t.spansMultiplePages=!0,t.height=0;for(var i=0,a=0,u=n.columns;af&&(c.text=m.text.splice(f,m.text.length));var p=o.scaleFactor();m.contentHeight=m.getContentHeight(p),m.contentHeight>=e&&(m.contentHeight=e,c.styles.minCellHeight-=e),m.contentHeight>t.height&&(t.height=m.contentHeight),c.contentHeight=c.getContentHeight(p),c.contentHeight>i&&(i=c.contentHeight),r[d.index]=c}}var g=new l.Row(t.raw,-1,t.section,r,!0);g.height=i;for(var y=0,v=n.columns;yp.pageSize().height)&&(y(p),l.y=r.top),e.callWillDrawPageHooks(p,l);var v=(0,s.assign)({},l);e.startPageNumber=p.pageNumber(),!0===n.horizontalPageBreak?function(t,e,n,o){var r=d.default.calculateAllColumnsCanFitInPage(t,e);r.map((function(r,i){t.applyStyles(t.userStyles),i>0?g(t,e,n,o,r.columns):function(t,e,n,o){var r=e.settings;t.applyStyles(t.userStyles),("firstPage"===r.showHead||"everyPage"===r.showHead)&&e.head.forEach((function(r){return f(t,e,r,n,o)}))}(t,e,o,r.columns),function(t,e,n,o,r){t.applyStyles(t.userStyles),e.body.forEach((function(i,l){var a=l===e.body.length-1;c(t,e,i,a,n,o,r)}))}(t,e,n,o,r.columns),function(t,e,n,o){var r=e.settings;t.applyStyles(t.userStyles),("lastPage"===r.showFoot||"everyPage"===r.showFoot)&&e.foot.forEach((function(r){return f(t,e,r,n,o)}))}(t,e,o,r.columns)}))}(p,e,v,l):(p.applyStyles(p.userStyles),"firstPage"!==n.showHead&&"everyPage"!==n.showHead||e.head.forEach((function(t){return f(p,e,t,l,e.columns)})),p.applyStyles(p.userStyles),e.body.forEach((function(t,n){var o=n===e.body.length-1;c(p,e,t,o,v,l,e.columns)})),p.applyStyles(p.userStyles),"lastPage"!==n.showFoot&&"everyPage"!==n.showFoot||e.foot.forEach((function(t){return f(p,e,t,l,e.columns)}))),(0,i.addTableBorder)(p,e,v,l),e.callEndPageHooks(p,l),e.finalY=l.y,t.lastAutoTable=e,t.previousAutoTable=e,t.autoTable&&(t.autoTable.previous=e),p.applyStyles(p.userStyles)},e.addPage=g},435:function(t,e,n){Object.defineProperty(e,"__esModule",{value:!0});var o=n(200),r=function(t,e){var n=(0,o.parseSpacing)(e.settings.margin,0);return t.pageSize().width-(n.left+n.right)},i=function(t,e,n){var o;void 0===n&&(n={});var i=r(t,e),l=new Map,a=null,s=[],u=[],d=e.columns.length,h=null!==(o=null==n?void 0:n.start)&&void 0!==o?o:0,c=e.settings.horizontalPageBreakRepeat;if(null!=c&&Array.isArray(c))for(var f=function(t){var n=e.columns.find((function(e){return e.dataKey===t||e.index===t}));n&&(l.set(n.index,n),s.push(n.index),u.push(e.columns[n.index]),i-=n.wrappedWidth)},p=0,g=c;pn(t)}));c.length&&(e=i(c,e,n))}return e}function l(t,e,n,r,i){return t.map((function(t){return function(t,e,n,r,i){var l=1e4*r.scaleFactor();if(e=Math.ceil(e*l)/l,e>=(0,o.getStringWidth)(t,n,r))return t;for(;e<(0,o.getStringWidth)(t+i,n,r)&&!(t.length<=1);)t=t.substring(0,t.length-1);return t.trim()+i}(t,e,n,r,i)}))}e.calculateWidths=function(t,e){!function(t,e){var n=t.scaleFactor(),i=e.settings.horizontalPageBreak,l=r.default.getPageAvailableWidth(t,e);e.allRows().forEach((function(r){for(var a=0,s=e.columns;al?(d.minWidth=l,d.wrappedWidth=l):(d.minWidth=d.contentWidth,d.wrappedWidth=d.contentWidth);else{var p=10/n;d.minWidth=d.styles.minCellWidth||p,d.wrappedWidth=d.contentWidth,d.minWidth>d.wrappedWidth&&(d.wrappedWidth=d.minWidth)}}}})),e.allRows().forEach((function(t){for(var n=0,o=e.columns;n1&&!r.minWidth&&(r.minWidth=i.minWidth),i.colSpan>1&&!r.wrappedWidth&&(r.wrappedWidth=i.minWidth))}}))}(t,e);var n=[],a=0;e.columns.forEach((function(t){var o=t.getMaxCustomCellWidth(e);o?t.width=o:(t.width=t.wrappedWidth,n.push(t)),a+=t.width}));var s=e.getWidth(t.pageSize().width)-a;s&&(s=i(n,s,(function(t){return Math.max(t.minReadableWidth,t.minWidth)}))),s&&(s=i(n,s,(function(t){return t.minWidth}))),s=Math.abs(s),!e.settings.horizontalPageBreak&&s>.1/t.scaleFactor()&&(s=s<1?s:Math.round(s),console.warn("Of the table content, ".concat(s," units width could not fit page"))),function(t){for(var e=t.allRows(),n=0;n1&&t.columns[a+1])i+=s.width,delete o.cells[s.index];else if(r){var u=r;delete o.cells[s.index],r=null,u.width=s.width+i}else{if(!(u=o.cells[s.index]))continue;if(l=u.colSpan,i=0,u.colSpan>1){r=u,i+=s.width;continue}u.width=s.width+i}}}(e),function(t,e){for(var n={count:0,height:0},o=0,r=t.allRows();o1&&n.count*n.height0&&n.height>f&&(f=n.height),f>i.height&&(i.height=f)}}n.count--}}(e,t),function(t){for(var e={},n=1,o=t.allRows(),r=0;r1)n--,delete i.cells[s.index];else if(u)u.cell.height+=i.height,n=u.cell.colSpan,delete i.cells[s.index],u.left--,u.left<=1&&delete e[s.index];else{var d=i.cells[s.index];if(!d)continue;if(d.height=i.height,d.rowSpan>1){var h=o.length-r,c=d.rowSpan>h?h:d.rowSpan;e[s.index]={cell:d,left:c,row:i}}}}}(e)},e.resizeColumns=i,e.ellipsize=l},84:function(e){if(void 0===t){var n=new Error("Cannot find module 'undefined'");throw n.code="MODULE_NOT_FOUND",n}e.exports=t}},n={};function o(t){var r=n[t];if(void 0!==r)return r.exports;var i=n[t]={exports:{}};return e[t].call(i.exports,i,i.exports,o),i.exports}var r={};return function(){var t=r;Object.defineProperty(t,"__esModule",{value:!0}),t.Cell=t.Column=t.Row=t.Table=t.CellHookData=t.__drawTable=t.__createTable=t.applyPlugin=void 0;var e=o(790),n=o(587),i=o(49),l=o(858),a=o(287);Object.defineProperty(t,"Table",{enumerable:!0,get:function(){return a.Table}});var s=o(662);Object.defineProperty(t,"CellHookData",{enumerable:!0,get:function(){return s.CellHookData}});var u=o(287);function d(t){(0,e.default)(t)}Object.defineProperty(t,"Cell",{enumerable:!0,get:function(){return u.Cell}}),Object.defineProperty(t,"Column",{enumerable:!0,get:function(){return u.Column}}),Object.defineProperty(t,"Row",{enumerable:!0,get:function(){return u.Row}}),t.applyPlugin=d,t.__createTable=function(t,e){var o=(0,n.parseInput)(t,e);return(0,l.createTable)(t,o)},t.__drawTable=function(t,e){(0,i.drawTable)(t,e)};try{var h=o(84);h.jsPDF&&(h=h.jsPDF),d(h)}catch(t){}t.default=function(t,e){var o=(0,n.parseInput)(t,e),r=(0,l.createTable)(t,o);(0,i.drawTable)(t,r)}}(),r}()})); \ No newline at end of file +!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(function(){try{return require("jspdf")}catch(t){}}());else if("function"==typeof define&&define.amd)define(["jspdf"],e);else{var n="object"==typeof exports?e(function(){try{return require("jspdf")}catch(t){}}()):e(t.jspdf);for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}("undefined"!=typeof globalThis?globalThis:void 0!==this?this:"undefined"!=typeof window?window:"undefined"!=typeof self?self:global,(function(t){return function(){"use strict";var e={662:function(t,e){var n,o=this&&this.__extends||(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)});Object.defineProperty(e,"__esModule",{value:!0}),e.CellHookData=e.HookData=void 0;var r=function(t,e,n){this.table=e,this.pageNumber=e.pageNumber,this.pageCount=this.pageNumber,this.settings=e.settings,this.cursor=n,this.doc=t.getDocument()};e.HookData=r;var i=function(t){function e(e,n,o,r,i,l){var a=t.call(this,e,n,l)||this;return a.cell=o,a.row=r,a.column=i,a.section=r.section,a}return o(e,t),e}(r);e.CellHookData=i},790:function(t,e,n){Object.defineProperty(e,"__esModule",{value:!0});var o=n(148),r=n(938),i=n(323),l=n(587),a=n(49),s=n(858);e.default=function(t){t.API.autoTable=function(){for(var t,e=[],n=0;n {}}) instead."),t.API.autoTable.globalDefaults||(t.API.autoTable.globalDefaults={}),t.API.autoTable.globalDefaults.addPageContent=e,this},t.API.autoTableAddPage=function(){return console.error("Use of deprecated function: autoTableAddPage. Use doc.addPage()"),this.addPage(),this}}},938:function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e,n,o,r){o=o||{};var i=r.internal.scaleFactor,l=r.internal.getFontSize()/i,a=l*(r.getLineHeightFactor?r.getLineHeightFactor():1.15),s="",u=1;if("middle"!==o.valign&&"bottom"!==o.valign&&"center"!==o.halign&&"right"!==o.halign||(u=(s="string"==typeof t?t.split(/\r\n|\r|\n/g):t).length||1),n+=l*(2-1.15),"middle"===o.valign?n-=u/2*a:"bottom"===o.valign&&(n-=u*a),"center"===o.halign||"right"===o.halign){var d=l;if("center"===o.halign&&(d*=.5),s&&u>=1){for(var h=0;h0,o=e||0===e;return n&&o?"DF":n?"S":o?"F":null}function o(t,e){var n,o,r,i;if(t=t||e,Array.isArray(t)){if(t.length>=4)return{top:t[0],right:t[1],bottom:t[2],left:t[3]};if(3===t.length)return{top:t[0],right:t[1],bottom:t[2],left:t[1]};if(2===t.length)return{top:t[0],right:t[1],bottom:t[0],left:t[1]};t=1===t.length?t[0]:e}return"object"==typeof t?("number"==typeof t.vertical&&(t.top=t.vertical,t.bottom=t.vertical),"number"==typeof t.horizontal&&(t.right=t.horizontal,t.left=t.horizontal),{left:null!==(n=t.left)&&void 0!==n?n:e,top:null!==(o=t.top)&&void 0!==o?o:e,right:null!==(r=t.right)&&void 0!==r?r:e,bottom:null!==(i=t.bottom)&&void 0!==i?i:e}):("number"!=typeof t&&(t=e),{top:t,right:t,bottom:t,left:t})}Object.defineProperty(e,"__esModule",{value:!0}),e.getPageAvailableWidth=e.parseSpacing=e.getFillStyle=e.addTableBorder=e.getStringWidth=void 0,e.getStringWidth=function(t,e,n){return n.applyStyles(e,!0),(Array.isArray(t)?t:[t]).map((function(t){return n.getTextWidth(t)})).reduce((function(t,e){return Math.max(t,e)}),0)},e.addTableBorder=function(t,e,o,r){var i=e.settings.tableLineWidth,l=e.settings.tableLineColor;t.applyStyles({lineWidth:i,lineColor:l});var a=n(i,!1);a&&t.rect(o.x,o.y,e.getWidth(t.pageSize().width),r.y-o.y,a)},e.getFillStyle=n,e.parseSpacing=o,e.getPageAvailableWidth=function(t,e){var n=o(e.settings.margin,0);return t.pageSize().width-(n.left+n.right)}},913:function(t,e){var n,o=this&&this.__extends||(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)});Object.defineProperty(e,"__esModule",{value:!0}),e.getTheme=e.defaultStyles=e.HtmlRowInput=void 0;var r=function(t){function e(e){var n=t.call(this)||this;return n._element=e,n}return o(e,t),e}(Array);e.HtmlRowInput=r,e.defaultStyles=function(t){return{font:"helvetica",fontStyle:"normal",overflow:"linebreak",fillColor:!1,textColor:20,halign:"left",valign:"top",fontSize:10,cellPadding:5/t,lineColor:200,lineWidth:0,cellWidth:"auto",minCellHeight:0,minCellWidth:0}},e.getTheme=function(t){return{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:.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"}}}[t]}},259:function(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.parseCss=void 0;var o=n(200);function r(t,e){var n=i(t,e);if(!n)return null;var o=n.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/);if(!o||!Array.isArray(o))return null;var r=[parseInt(o[1]),parseInt(o[2]),parseInt(o[3])];return 0===parseInt(o[4])||isNaN(r[0])||isNaN(r[1])||isNaN(r[2])?null:r}function i(t,e){var n=e(t);return"rgba(0, 0, 0, 0)"===n||"transparent"===n||"initial"===n||"inherit"===n?null==t.parentElement?null:i(t.parentElement,e):n}e.parseCss=function(t,e,n,i,l){var a={},s=96/72,u=r(e,(function(t){return l.getComputedStyle(t).backgroundColor}));null!=u&&(a.fillColor=u);var d=r(e,(function(t){return l.getComputedStyle(t).color}));null!=d&&(a.textColor=d);var h=function(t,e){var n=[t.paddingTop,t.paddingRight,t.paddingBottom,t.paddingLeft],r=96/(72/e),i=(parseInt(t.lineHeight)-parseInt(t.fontSize))/e/2,l=n.map((function(t){return parseInt(t||"0")/r})),a=(0,o.parseSpacing)(l,0);i>a.top&&(a.top=i);i>a.bottom&&(a.bottom=i);return a}(i,n);h&&(a.cellPadding=h);var c="borderTopColor",f=s*n,g=i.borderTopWidth;if(i.borderBottomWidth===g&&i.borderRightWidth===g&&i.borderLeftWidth===g){var p=(parseFloat(g)||0)/f;p&&(a.lineWidth=p)}else a.lineWidth={top:(parseFloat(i.borderTopWidth)||0)/f,right:(parseFloat(i.borderRightWidth)||0)/f,bottom:(parseFloat(i.borderBottomWidth)||0)/f,left:(parseFloat(i.borderLeftWidth)||0)/f},a.lineWidth.top||(a.lineWidth.right?c="borderRightColor":a.lineWidth.bottom?c="borderBottomColor":a.lineWidth.left&&(c="borderLeftColor"));console.log(a.lineWidth);var y=r(e,(function(t){return l.getComputedStyle(t)[c]}));null!=y&&(a.lineColor=y);var v=["left","right","center","justify"];-1!==v.indexOf(i.textAlign)&&(a.halign=i.textAlign),-1!==(v=["middle","bottom","top"]).indexOf(i.verticalAlign)&&(a.valign=i.verticalAlign);var m=parseInt(i.fontSize||"");isNaN(m)||(a.fontSize=m/s);var b=function(t){var e="";("bold"===t.fontWeight||"bolder"===t.fontWeight||parseInt(t.fontWeight)>=700)&&(e="bold");"italic"!==t.fontStyle&&"oblique"!==t.fontStyle||(e+="italic");return e}(i);b&&(a.fontStyle=b);var w=(i.fontFamily||"").toLowerCase();return-1!==t.indexOf(w)&&(a.font=w),a}},323:function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.DocHandler=void 0;var n={},o=function(){function t(t){this.jsPDFDocument=t,this.userStyles={textColor:t.getTextColor?this.jsPDFDocument.getTextColor():0,fontSize:t.internal.getFontSize(),fontStyle:t.internal.getFont().fontStyle,font:t.internal.getFont().fontName,lineWidth:t.getLineWidth?this.jsPDFDocument.getLineWidth():0,lineColor:t.getDrawColor?this.jsPDFDocument.getDrawColor():0}}return t.setDefaults=function(t,e){void 0===e&&(e=null),e?e.__autoTableDocumentDefaults=t:n=t},t.unifyColor=function(t){return Array.isArray(t)?t:"number"==typeof t?[t,t,t]:"string"==typeof t?[t]:null},t.prototype.applyStyles=function(e,n){var o,r,i;void 0===n&&(n=!1),e.fontStyle&&this.jsPDFDocument.setFontStyle&&this.jsPDFDocument.setFontStyle(e.fontStyle);var l=this.jsPDFDocument.internal.getFont(),a=l.fontStyle,s=l.fontName;if(e.font&&(s=e.font),e.fontStyle){a=e.fontStyle;var u=this.getFontList()[s];u&&-1===u.indexOf(a)&&(this.jsPDFDocument.setFontStyle&&this.jsPDFDocument.setFontStyle(u[0]),a=u[0])}if(this.jsPDFDocument.setFont(s,a),e.fontSize&&this.jsPDFDocument.setFontSize(e.fontSize),!n){var d=t.unifyColor(e.fillColor);d&&(o=this.jsPDFDocument).setFillColor.apply(o,d),(d=t.unifyColor(e.textColor))&&(r=this.jsPDFDocument).setTextColor.apply(r,d),(d=t.unifyColor(e.lineColor))&&(i=this.jsPDFDocument).setDrawColor.apply(i,d),"number"==typeof e.lineWidth&&this.jsPDFDocument.setLineWidth(e.lineWidth)}},t.prototype.splitTextToSize=function(t,e,n){return this.jsPDFDocument.splitTextToSize(t,e,n)},t.prototype.rect=function(t,e,n,o,r){return this.jsPDFDocument.rect(t,e,n,o,r)},t.prototype.getLastAutoTable=function(){return this.jsPDFDocument.lastAutoTable||null},t.prototype.getTextWidth=function(t){return this.jsPDFDocument.getTextWidth(t)},t.prototype.getDocument=function(){return this.jsPDFDocument},t.prototype.setPage=function(t){this.jsPDFDocument.setPage(t)},t.prototype.addPage=function(){return this.jsPDFDocument.addPage()},t.prototype.getFontList=function(){return this.jsPDFDocument.getFontList()},t.prototype.getGlobalOptions=function(){return n||{}},t.prototype.getDocumentOptions=function(){return this.jsPDFDocument.__autoTableDocumentDefaults||{}},t.prototype.pageSize=function(){var t=this.jsPDFDocument.internal.pageSize;return null==t.width&&(t={width:t.getWidth(),height:t.getHeight()}),t},t.prototype.scaleFactor=function(){return this.jsPDFDocument.internal.scaleFactor},Object.defineProperty(t.prototype,"lineHeightFactor",{get:function(){var t=this.jsPDFDocument;return t.getLineHeightFactor?t.getLineHeightFactor():1.15},enumerable:!1,configurable:!0}),t.prototype.getLineHeight=function(t){return t/this.scaleFactor()*this.lineHeightFactor},t.prototype.pageNumber=function(){var t=this.jsPDFDocument.internal.getCurrentPageInfo();return t?t.pageNumber:this.jsPDFDocument.internal.getNumberOfPages()},t}();e.DocHandler=o},148:function(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.parseHtml=void 0;var o=n(259),r=n(913);function i(t,e,n,i,a,s){for(var u=new r.HtmlRowInput(i),d=0;d0&&(a||"none"!==g.display))return u}function l(t){var e=t.cloneNode(!0);return e.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/ +/g," "),e.innerHTML=e.innerHTML.split(//).map((function(t){return t.trim()})).join("\n"),e.innerText||e.textContent||""}e.parseHtml=function(t,e,n,o,r){var l,a,s;void 0===o&&(o=!1),void 0===r&&(r=!1),s="string"==typeof e?n.document.querySelector(e):e;var u=Object.keys(t.getFontList()),d=t.scaleFactor(),h=[],c=[],f=[];if(!s)return console.error("Html table could not be found with input: ",e),{head:h,body:c,foot:f};for(var g=0;g0?"_".concat(i):"")};r.push(l)}})),r}(r,i,l);return{columns:u,head:r,body:i,foot:l}}(n,h,d);return{id:e.tableId,content:p,hooks:f,styles:c,settings:g}}},291:function(t,e){function n(t){t.rowHeight?(console.error("Use of deprecated style rowHeight. It is renamed to minCellHeight."),t.minCellHeight||(t.minCellHeight=t.rowHeight)):t.columnWidth&&(console.error("Use of deprecated style columnWidth. It is renamed to cellWidth."),t.cellWidth||(t.cellWidth=t.columnWidth))}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e,o,r){for(var i=function(e){e&&"object"!=typeof e&&console.error("The options parameter should be of type object, is: "+typeof e),void 0!==e.extendWidth&&(e.tableWidth=e.extendWidth?"auto":"wrap",console.error("Use of deprecated option: extendWidth, use tableWidth instead.")),void 0!==e.margins&&(void 0===e.margin&&(e.margin=e.margins),console.error("Use of deprecated option: margins, use margin instead.")),e.startY&&"number"!=typeof e.startY&&(console.error("Invalid value for startY option",e.startY),delete e.startY),!e.didDrawPage&&(e.afterPageContent||e.beforePageContent||e.afterPageAdd)&&(console.error("The afterPageContent, beforePageContent and afterPageAdd hooks are deprecated. Use didDrawPage instead"),e.didDrawPage=function(n){t.applyStyles(t.userStyles),e.beforePageContent&&e.beforePageContent(n),t.applyStyles(t.userStyles),e.afterPageContent&&e.afterPageContent(n),t.applyStyles(t.userStyles),e.afterPageAdd&&n.pageNumber>1&&n.afterPageAdd(n),t.applyStyles(t.userStyles)}),["createdHeaderCell","drawHeaderRow","drawRow","drawHeaderCell"].forEach((function(t){e[t]&&console.error('The "'.concat(t,'" 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(t){var n=t[0],o=t[1];e[o]&&(console.error("Use of deprecated option ".concat(o,". Use ").concat(n," instead")),e[n]=e[o])})),[["padding","cellPadding"],["lineHeight","rowHeight"],"fontSize","overflow"].forEach((function(t){var n="string"==typeof t?t:t[0],o="string"==typeof t?t:t[1];void 0!==e[n]&&(void 0===e.styles[o]&&(e.styles[o]=e[n]),console.error("Use of deprecated option: "+n+", use the style "+o+" instead."))}));for(var o=0,r=["styles","bodyStyles","headStyles","footStyles"];o1})).length>0},t.prototype.canEntireRowFit=function(t,e){return this.getMaxCellHeight(e)<=t},t.prototype.getMinimumRowHeight=function(t,e){var n=this;return t.reduce((function(t,o){var r=n.cells[o.index];if(!r)return 0;var i=e.getLineHeight(r.styles.fontSize),l=r.padding("vertical")+i;return l>t?l:t}),0)},t}();e.Row=a;var s=function(){function t(t,e,n){var o,r;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=e,this.section=n,this.raw=t;var i=t;null==t||"object"!=typeof t||Array.isArray(t)?(this.rowSpan=1,this.colSpan=1):(this.rowSpan=t.rowSpan||1,this.colSpan=t.colSpan||1,i=null!==(r=null!==(o=t.content)&&void 0!==o?o:t.title)&&void 0!==r?r:t,t._element&&(this.raw=t._element));var l=null!=i?""+i:"";this.text=l.split(/\r\n|\r|\n/g)}return t.prototype.getTextPos=function(){var t,e;if("top"===this.styles.valign)t=this.y+this.padding("top");else if("bottom"===this.styles.valign)t=this.y+this.height-this.padding("bottom");else{var n=this.height-this.padding("vertical");t=this.y+n/2+this.padding("top")}if("right"===this.styles.halign)e=this.x+this.width-this.padding("right");else if("center"===this.styles.halign){var o=this.width-this.padding("horizontal");e=this.x+o/2+this.padding("left")}else e=this.x+this.padding("left");return{x:e,y:t}},t.prototype.getContentHeight=function(t,e){void 0===e&&(e=1.15);var n=(Array.isArray(this.text)?this.text.length:1)*(this.styles.fontSize/t*e)+this.padding("vertical");return Math.max(n,this.styles.minCellHeight)},t.prototype.padding=function(t){var e=(0,i.parseSpacing)(this.styles.cellPadding,0);return"vertical"===t?e.top+e.bottom:"horizontal"===t?e.left+e.right:e[t]},t}();e.Cell=s;var u=function(){function t(t,e,n){this.wrappedWidth=0,this.minReadableWidth=0,this.minWidth=0,this.width=0,this.dataKey=t,this.raw=e,this.index=n}return t.prototype.getMaxCustomCellWidth=function(t){for(var e=0,n=0,o=t.allRows();n0?n:null}function d(t,e,n,o,r,i,s){var u,d=(0,l.getTheme)(o);"head"===t?u=r.headStyles:"body"===t?u=r.bodyStyles:"foot"===t&&(u=r.footStyles);var h=(0,a.assign)({},d.table,d[t],r.styles,u),c=r.columnStyles[e.dataKey]||r.columnStyles[e.index]||{},f="body"===t?c:{},g="body"===t&&n%2==0?(0,a.assign)({},d.alternateRow,r.alternateRowStyles):{},p=(0,l.defaultStyles)(i),y=(0,a.assign)({},p,h,g,f);return(0,a.assign)(y,s)}e.createTable=function(t,e){var n=new o.DocHandler(t),l=function(t,e){var n=t.content,o=function(t){return t.map((function(t,e){var n,o,i;return i="object"==typeof t&&null!==(o=null!==(n=t.dataKey)&&void 0!==n?n:t.key)&&void 0!==o?o:e,new r.Column(i,t,e)}))}(n.columns);if(0===n.head.length){(i=u(o,"head"))&&n.head.push(i)}if(0===n.foot.length){var i;(i=u(o,"foot"))&&n.foot.push(i)}var l=t.settings.theme,a=t.styles;return{columns:o,head:s("head",n.head,o,a,l,e),body:s("body",n.body,o,a,l,e),foot:s("foot",n.foot,o,a,l,e)}}(e,n.scaleFactor()),a=new r.Table(e,l);return(0,i.calculateWidths)(n,a),n.applyStyles(n.userStyles),a}},49:function(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.addPage=e.drawTable=void 0;var o=n(200),r=n(287),i=n(323),l=n(360),a=n(938),s=n(435);function u(t,e,n){var o=n.getLineHeight(t.styles.fontSize),r=t.padding("vertical"),i=Math.floor((e-r)/o);return Math.max(0,i)}function d(t,e,n,o,i,a,s){var c=function(t,e,n,o){var r=e.settings.margin.bottom,i=e.settings.showFoot;("everyPage"===i||"lastPage"===i&&n)&&(r+=e.getFootHeight(e.columns));return t.pageSize().height-o.y-r}(t,e,o,a);if(n.canEntireRowFit(c,s))h(t,e,n,a,s);else if(function(t,e,n,o){var r=t.pageSize().height,i=o.settings.margin,l=r-(i.top+i.bottom);"body"===e.section&&(l-=o.getHeadHeight(o.columns)+o.getFootHeight(o.columns));var a=e.getMinimumRowHeight(o.columns,t),s=al)return console.error("Will not be able to print row ".concat(e.index," correctly since it's minimum height is larger than page height")),!0;if(!s)return!1;var u=e.hasRowSpan(o.columns);return e.getMaxCellHeight(o.columns)>l?(u&&console.error("The content of row ".concat(e.index," will not be drawn correctly since drawing rows with a height larger than the page height and has cells with rowspans is not supported.")),!0):!u&&"avoid"!==o.settings.rowPageBreak}(t,n,c,e)){var g=function(t,e,n,o){var i={};t.spansMultiplePages=!0,t.height=0;for(var a=0,s=0,d=n.columns;sf&&(c.text=b.text.splice(f,b.text.length));var g=o.scaleFactor(),p=o.lineHeightFactor;b.contentHeight=b.getContentHeight(g,p),b.contentHeight>=e&&(b.contentHeight=e,c.styles.minCellHeight-=e),b.contentHeight>t.height&&(t.height=b.contentHeight),c.contentHeight=c.getContentHeight(g,p),c.contentHeight>a&&(a=c.contentHeight),i[h.index]=c}}var y=new r.Row(t.raw,-1,t.section,i,!0);y.height=a;for(var v=0,m=n.columns;vy.pageSize().height)&&(g(y),u.y=a.top),e.callWillDrawPageHooks(y,u);var v=(0,l.assign)({},u);e.startPageNumber=y.pageNumber(),n.horizontalPageBreak?function(t,e,n,o){var r=(0,s.calculateAllColumnsCanFitInPage)(t,e);r.map((function(r,i){t.applyStyles(t.userStyles),i>0?f(t,e,n,o,r.columns):function(t,e,n,o){var r=e.settings;t.applyStyles(t.userStyles),("firstPage"===r.showHead||"everyPage"===r.showHead)&&e.head.forEach((function(r){return h(t,e,r,n,o)}))}(t,e,o,r.columns),function(t,e,n,o,r){t.applyStyles(t.userStyles),e.body.forEach((function(i,l){var a=l===e.body.length-1;d(t,e,i,a,n,o,r)}))}(t,e,n,o,r.columns),function(t,e,n,o){var r=e.settings;t.applyStyles(t.userStyles),("lastPage"===r.showFoot||"everyPage"===r.showFoot)&&e.foot.forEach((function(r){return h(t,e,r,n,o)}))}(t,e,o,r.columns)}))}(y,e,v,u):(y.applyStyles(y.userStyles),"firstPage"!==n.showHead&&"everyPage"!==n.showHead||e.head.forEach((function(t){return h(y,e,t,u,e.columns)})),y.applyStyles(y.userStyles),e.body.forEach((function(t,n){var o=n===e.body.length-1;d(y,e,t,o,v,u,e.columns)})),y.applyStyles(y.userStyles),"lastPage"!==n.showFoot&&"everyPage"!==n.showFoot||e.foot.forEach((function(t){return h(y,e,t,u,e.columns)}))),(0,o.addTableBorder)(y,e,v,u),e.callEndPageHooks(y,u),e.finalY=u.y,t.lastAutoTable=e,t.previousAutoTable=e,t.autoTable&&(t.autoTable.previous=e),y.applyStyles(y.userStyles)},e.addPage=f},435:function(t,e,n){Object.defineProperty(e,"__esModule",{value:!0}),e.calculateAllColumnsCanFitInPage=void 0;var o=n(200);function r(t,e,n){var r;void 0===n&&(n={});var i=(0,o.getPageAvailableWidth)(t,e),l=new Map,a=[],s=[],u=[];e.settings.horizontalPageBreakRepeat,Array.isArray(e.settings.horizontalPageBreakRepeat)?u=e.settings.horizontalPageBreakRepeat:"string"!=typeof e.settings.horizontalPageBreakRepeat&&"number"!=typeof e.settings.horizontalPageBreakRepeat||(u=[e.settings.horizontalPageBreakRepeat]),u.forEach((function(t){var n=e.columns.find((function(e){return e.dataKey===t||e.index===t}));n&&!l.has(n.index)&&(l.set(n.index,!0),a.push(n.index),s.push(e.columns[n.index]),i-=n.wrappedWidth)}));for(var d=!0,h=null!==(r=null==n?void 0:n.start)&&void 0!==r?r:0;h=c))break;d=!1,a.push(h),s.push(e.columns[h]),i-=c,h++}return{colIndexes:a,columns:s,lastIndex:h-1}}e.calculateAllColumnsCanFitInPage=function(t,e){for(var n=[],o=0;on(t)}));c.length&&(e=r(c,e,n))}return e}function i(t,e,n,r,i){return t.map((function(t){return function(t,e,n,r,i){var l=1e4*r.scaleFactor();if(e=Math.ceil(e*l)/l,e>=(0,o.getStringWidth)(t,n,r))return t;for(;e<(0,o.getStringWidth)(t+i,n,r)&&!(t.length<=1);)t=t.substring(0,t.length-1);return t.trim()+i}(t,e,n,r,i)}))}e.calculateWidths=function(t,e){!function(t,e){var n=t.scaleFactor(),r=e.settings.horizontalPageBreak,i=(0,o.getPageAvailableWidth)(t,e);e.allRows().forEach((function(l){for(var a=0,s=e.columns;ai?(d.minWidth=i,d.wrappedWidth=i):(d.minWidth=d.contentWidth,d.wrappedWidth=d.contentWidth);else{var g=10/n;d.minWidth=d.styles.minCellWidth||g,d.wrappedWidth=d.contentWidth,d.minWidth>d.wrappedWidth&&(d.wrappedWidth=d.minWidth)}}}})),e.allRows().forEach((function(t){for(var n=0,o=e.columns;n1&&!r.minWidth&&(r.minWidth=i.minWidth),i.colSpan>1&&!r.wrappedWidth&&(r.wrappedWidth=i.minWidth))}}))}(t,e);var n=[],l=0;e.columns.forEach((function(t){var o=t.getMaxCustomCellWidth(e);o?t.width=o:(t.width=t.wrappedWidth,n.push(t)),l+=t.width}));var a=e.getWidth(t.pageSize().width)-l;a&&(a=r(n,a,(function(t){return Math.max(t.minReadableWidth,t.minWidth)}))),a&&(a=r(n,a,(function(t){return t.minWidth}))),a=Math.abs(a),!e.settings.horizontalPageBreak&&a>.1/t.scaleFactor()&&(a=a<1?a:Math.round(a),console.warn("Of the table content, ".concat(a," units width could not fit page"))),function(t){for(var e=t.allRows(),n=0;n1&&t.columns[a+1])i+=s.width,delete o.cells[s.index];else if(r){var u=r;delete o.cells[s.index],r=null,u.width=s.width+i}else{if(!(u=o.cells[s.index]))continue;if(l=u.colSpan,i=0,u.colSpan>1){r=u,i+=s.width;continue}u.width=s.width+i}}}(e),function(t,e){for(var n={count:0,height:0},o=0,r=t.allRows();o1&&n.count*n.height0&&n.height>f&&(f=n.height),f>l.height&&(l.height=f)}}n.count--}}(e,t),function(t){for(var e={},n=1,o=t.allRows(),r=0;r1)n--,delete i.cells[s.index];else if(u)u.cell.height+=i.height,n=u.cell.colSpan,delete i.cells[s.index],u.left--,u.left<=1&&delete e[s.index];else{var d=i.cells[s.index];if(!d)continue;if(d.height=i.height,d.rowSpan>1){var h=o.length-r,c=d.rowSpan>h?h:d.rowSpan;e[s.index]={cell:d,left:c,row:i}}}}}(e)},e.resizeColumns=r,e.ellipsize=i},84:function(e){if(void 0===t){var n=new Error("Cannot find module 'undefined'");throw n.code="MODULE_NOT_FOUND",n}e.exports=t}},n={};function o(t){var r=n[t];if(void 0!==r)return r.exports;var i=n[t]={exports:{}};return e[t].call(i.exports,i,i.exports,o),i.exports}var r={};return function(){var t=r;Object.defineProperty(t,"__esModule",{value:!0}),t.Cell=t.Column=t.Row=t.Table=t.CellHookData=t.__drawTable=t.__createTable=t.applyPlugin=void 0;var e=o(790),n=o(587),i=o(49),l=o(858),a=o(287);Object.defineProperty(t,"Table",{enumerable:!0,get:function(){return a.Table}});var s=o(662);Object.defineProperty(t,"CellHookData",{enumerable:!0,get:function(){return s.CellHookData}});var u=o(287);function d(t){(0,e.default)(t)}Object.defineProperty(t,"Cell",{enumerable:!0,get:function(){return u.Cell}}),Object.defineProperty(t,"Column",{enumerable:!0,get:function(){return u.Column}}),Object.defineProperty(t,"Row",{enumerable:!0,get:function(){return u.Row}}),t.applyPlugin=d,t.__createTable=function(t,e){var o=(0,n.parseInput)(t,e);return(0,l.createTable)(t,o)},t.__drawTable=function(t,e){(0,i.drawTable)(t,e)};try{var h=o(84);h.jsPDF&&(h=h.jsPDF),d(h)}catch(t){}t.default=function(t,e){var o=(0,n.parseInput)(t,e),r=(0,l.createTable)(t,o);(0,i.drawTable)(t,r)}}(),r}()})); \ No newline at end of file diff --git a/dist/jspdf.plugin.autotable.mjs b/dist/jspdf.plugin.autotable.mjs index 8759f370..72705adc 100644 --- a/dist/jspdf.plugin.autotable.mjs +++ b/dist/jspdf.plugin.autotable.mjs @@ -87,6 +87,10 @@ function parseSpacing(value, defaultValue) { } return { top: value, right: value, bottom: value, left: value }; } +function getPageAvailableWidth(doc, table) { + var margins = parseSpacing(table.settings.margin, 0); + return doc.pageSize().width - (margins.left + margins.right); +} // Limitations // - No support for border spacing @@ -104,19 +108,46 @@ function parseCss(supportedFonts, element, scaleFactor, style, window) { }); 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'; + } + } + } + console.log(result.lineWidth); var borderColor = parseColor(element, function (elem) { - return window.getComputedStyle(elem)['borderTopColor']; + return window.getComputedStyle(elem)[borderColorSide]; }); if (borderColor != null) result.lineColor = borderColor; - var padding = parsePadding(style, scaleFactor); - if (padding) - result.cellPadding = padding; - // style.borderWidth only works in chrome (borderTopWidth etc works in firefox and ie as well) - var bw = parseInt(style.borderTopWidth || ''); - bw = bw / pxScaleFactor / scaleFactor; - if (bw) - result.lineWidth = bw; var accepted = ['left', 'right', 'center', 'justify']; if (accepted.indexOf(style.textAlign) !== -1) { result.halign = style.textAlign; @@ -236,25 +267,11 @@ function __extends(d, b) { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } -function __spreadArray(to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -} - typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { var e = new Error(message); return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; }; -/** - * Ratio between font size and font height. The number comes from jspdf's source code - */ -var FONT_ROW_RATIO = 1.15; var HtmlRowInput = /** @class */ (function (_super) { __extends(HtmlRowInput, _super); function HtmlRowInput(element) { @@ -391,7 +408,7 @@ function parseCellContent(orgCell) { cell.innerHTML = cell.innerHTML.replace(/\n/g, '').replace(/ +/g, ' '); // Preserve
tags as line breaks in the pdf cell.innerHTML = cell.innerHTML - .split(/\/) //start with ''. + .split(//) //start with ''. .map(function (part) { return part.trim(); }) .join('\n'); // innerText for ie @@ -404,9 +421,13 @@ function parseCellContent(orgCell) { */ function autoTableText (text, x, y, styles, doc) { styles = styles || {}; - var FONT_ROW_RATIO = 1.15; + 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; @@ -418,11 +439,11 @@ function autoTableText (text, x, y, styles, doc) { lineCount = splitText.length || 1; } // Align the top - y += fontSize * (2 - FONT_ROW_RATIO); + y += fontSize * (2 - PHYSICAL_LINE_HEIGHT); if (styles.valign === 'middle') - y -= (lineCount / 2) * fontSize * FONT_ROW_RATIO; + y -= (lineCount / 2) * lineHeight; else if (styles.valign === 'bottom') - y -= lineCount * fontSize * FONT_ROW_RATIO; + y -= lineCount * lineHeight; if (styles.halign === 'center' || styles.halign === 'right') { var alignSize = fontSize; if (styles.halign === 'center') @@ -430,7 +451,7 @@ function autoTableText (text, x, y, styles, doc) { if (splitText && lineCount >= 1) { for (var iLine = 0; iLine < splitText.length; iLine++) { doc.text(splitText[iLine], x - doc.getStringUnitWidth(splitText[iLine]) * alignSize, y); - y += fontSize * FONT_ROW_RATIO; + y += lineHeight; } return doc; } @@ -545,12 +566,12 @@ var DocHandler = /** @class */ (function () { * @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. In "compat" API mode, a null value postpones setting the style so that a shape may be composed using multiple method calls. The last drawing method call used to define the shape should not have a null style argument. **In "advanced" API mode this parameter is deprecated.** + * @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) { - if (!['S', 'F', 'DF', 'FD', null].some(function (v) { return v === fillStyle; })) { - throw new TypeError("Invalid value '".concat(fillStyle, "' passed to rect. Allowed values are: 'S', 'F', 'DF', 'FD', null")); - } + // 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 () { @@ -591,6 +612,17 @@ var DocHandler = /** @class */ (function () { DocHandler.prototype.scaleFactor = function () { return this.jsPDFDocument.internal.scaleFactor; }; + Object.defineProperty(DocHandler.prototype, "lineHeightFactor", { + get: function () { + var doc = this.jsPDFDocument; + return doc.getLineHeightFactor ? doc.getLineHeightFactor() : 1.15; + }, + enumerable: false, + configurable: true + }); + DocHandler.prototype.getLineHeight = function (fontSize) { + return (fontSize / this.scaleFactor()) * this.lineHeightFactor; + }; DocHandler.prototype.pageNumber = function () { var pageInfo = this.jsPDFDocument.internal.getCurrentPageInfo(); if (!pageInfo) { @@ -1063,9 +1095,9 @@ var Row = /** @class */ (function () { var cell = _this.cells[column.index]; if (!cell) return 0; - var fontHeight = (cell.styles.fontSize / doc.scaleFactor()) * FONT_ROW_RATIO; + var lineHeight = doc.getLineHeight(cell.styles.fontSize); var vPadding = cell.padding('vertical'); - var oneRowHeight = vPadding + fontHeight; + var oneRowHeight = vPadding + lineHeight; return oneRowHeight > acc ? oneRowHeight : acc; }, 0); }; @@ -1129,10 +1161,12 @@ var Cell = /** @class */ (function () { } return { x: x, y: y }; }; - Cell.prototype.getContentHeight = function (scaleFactor) { + // TODO (v4): replace parameters with only (lineHeight) + Cell.prototype.getContentHeight = function (scaleFactor, lineHeightFactor) { + if (lineHeightFactor === void 0) { lineHeightFactor = 1.15; } var lineCount = Array.isArray(this.text) ? this.text.length : 1; - var fontHeight = (this.styles.fontSize / scaleFactor) * FONT_ROW_RATIO; - var height = lineCount * fontHeight + this.padding('vertical'); + var lineHeight = (this.styles.fontSize / scaleFactor) * lineHeightFactor; + var height = lineCount * lineHeight + this.padding('vertical'); return Math.max(height, this.styles.minCellHeight); }; Cell.prototype.padding = function (name) { @@ -1173,104 +1207,70 @@ var Column = /** @class */ (function () { return Column; }()); -var getPageAvailableWidth = function (doc, table) { - var margins = parseSpacing(table.settings.margin, 0); - var availablePageWidth = doc.pageSize().width - (margins.left + margins.right); - return availablePageWidth; -}; // get columns can be fit into page -var getColumnsCanFitInPage = function (doc, table, config) { +function getColumnsCanFitInPage(doc, table, config) { var _a; if (config === void 0) { config = {}; } // Get page width - var availablePageWidth = getPageAvailableWidth(doc, table); - var remainingWidth = availablePageWidth; + var remainingWidth = getPageAvailableWidth(doc, table); // Get column data key to repeat var repeatColumnsMap = new Map(); - var repeatColumn = null; - var cols = []; + var colIndexes = []; var columns = []; - var len = table.columns.length; - var i = (_a = config === null || config === void 0 ? void 0 : config.start) !== null && _a !== void 0 ? _a : 0; - var horizontalPageBreakRepeat = table.settings.horizontalPageBreakRepeat; - // Code to repeat the given column in split pages - if (horizontalPageBreakRepeat !== null && horizontalPageBreakRepeat !== undefined && Array.isArray(horizontalPageBreakRepeat)) { - var _loop_1 = function (field) { - var col = table.columns.find(function (item) { - return item.dataKey === field || - item.index === field; - }); - if (col) { - repeatColumnsMap.set(col.index, col); - cols.push(col.index); - columns.push(table.columns[col.index]); - remainingWidth = remainingWidth - col.wrappedWidth; - } - }; - for (var _i = 0, horizontalPageBreakRepeat_1 = horizontalPageBreakRepeat; _i < horizontalPageBreakRepeat_1.length; _i++) { - var field = horizontalPageBreakRepeat_1[_i]; - _loop_1(field); - } + var horizontalPageBreakRepeat = []; + table.settings.horizontalPageBreakRepeat; + if (Array.isArray(table.settings.horizontalPageBreakRepeat)) { + horizontalPageBreakRepeat = table.settings.horizontalPageBreakRepeat; // It can be a single value of type string or number (even number: 0) } - else if (horizontalPageBreakRepeat !== null && horizontalPageBreakRepeat !== undefined) { - repeatColumn = table.columns.find(function (item) { - return item.dataKey === horizontalPageBreakRepeat || - item.index === horizontalPageBreakRepeat; - }); - if (repeatColumn) { - cols.push(repeatColumn.index); - columns.push(table.columns[repeatColumn.index]); - remainingWidth = remainingWidth - repeatColumn.wrappedWidth; - } + else if (typeof table.settings.horizontalPageBreakRepeat === 'string' || + typeof table.settings.horizontalPageBreakRepeat === 'number') { + horizontalPageBreakRepeat = [table.settings.horizontalPageBreakRepeat]; } - while (i < len) { - // Prevent columnDataKeyToRepeat from being pushed twice on a page - if ((Array.isArray(horizontalPageBreakRepeat) && repeatColumnsMap.get(i)) - || (repeatColumn === null || repeatColumn === void 0 ? void 0 : repeatColumn.index) === i) { + // Code to repeat the given column in split pages + horizontalPageBreakRepeat.forEach(function (field) { + var col = table.columns.find(function (item) { return item.dataKey === field || item.index === field; }); + if (col && !repeatColumnsMap.has(col.index)) { + repeatColumnsMap.set(col.index, true); + colIndexes.push(col.index); + columns.push(table.columns[col.index]); + remainingWidth -= col.wrappedWidth; + } + }); + var first = true; + var i = (_a = config === null || config === void 0 ? void 0 : config.start) !== null && _a !== void 0 ? _a : 0; // make sure couter is initiated outside the loop + while (i < table.columns.length) { + // Prevent duplicates + if (repeatColumnsMap.has(i)) { i++; continue; } var colWidth = table.columns[i].wrappedWidth; - if (remainingWidth < colWidth) { - if (i === 0 || i === config.start) { - cols.push(i); - columns.push(table.columns[i]); - } + // Take at least one column even if it doesn't fit + if (first || remainingWidth >= colWidth) { + first = false; + colIndexes.push(i); + columns.push(table.columns[i]); + remainingWidth -= colWidth; + } + else { break; } - cols.push(i); - columns.push(table.columns[i]); - remainingWidth -= colWidth; i++; } - return { colIndexes: cols, columns: columns, lastIndex: i }; -}; -var calculateAllColumnsCanFitInPage = function (doc, table) { - // const margins = table.settings.margin; - // const availablePageWidth = doc.pageSize().width - (margins.left + margins.right); + return { colIndexes: colIndexes, columns: columns, lastIndex: i - 1 }; +} +function calculateAllColumnsCanFitInPage(doc, table) { var allResults = []; - var index = 0; - var len = table.columns.length; - while (index < len) { - var result = getColumnsCanFitInPage(doc, table, { - start: index === 0 ? 0 : index, - }); - if (result && result.columns && result.columns.length) { - index = result.lastIndex; + for (var i = 0; i < table.columns.length; i++) { + var result = getColumnsCanFitInPage(doc, table, { start: i }); + if (result.columns.length) { allResults.push(result); - } - else { - index++; + i = result.lastIndex; } } return allResults; -}; -var TablePrinter = { - getColumnsCanFitInPage: getColumnsCanFitInPage, - calculateAllColumnsCanFitInPage: calculateAllColumnsCanFitInPage, - getPageAvailableWidth: getPageAvailableWidth, -}; +} function drawTable(jsPDFDoc, table) { var settings = table.settings; @@ -1296,7 +1296,7 @@ function drawTable(jsPDFDoc, table) { table.callWillDrawPageHooks(doc, cursor); var startPos = assign({}, cursor); table.startPageNumber = doc.pageNumber(); - if (settings.horizontalPageBreak === true) { + if (settings.horizontalPageBreak) { // managed flow for split columns printTableWithHorizontalPageBreak(doc, table, startPos, cursor); } @@ -1332,7 +1332,7 @@ function drawTable(jsPDFDoc, table) { } function printTableWithHorizontalPageBreak(doc, table, startPos, cursor) { // calculate width of columns and render only those which can fit into page - var allColumnsCanFitResult = TablePrinter.calculateAllColumnsCanFitInPage(doc, table); + var allColumnsCanFitResult = calculateAllColumnsCanFitInPage(doc, table); allColumnsCanFitResult.map(function (colsAndIndexes, index) { doc.applyStyles(doc.userStyles); // add page to print next columns in new page @@ -1343,9 +1343,8 @@ function printTableWithHorizontalPageBreak(doc, table, startPos, cursor) { // print head for selected columns printHead(doc, table, cursor, colsAndIndexes.columns); } - // print body for selected columns + // print body & footer for selected columns printBody(doc, table, startPos, cursor, colsAndIndexes.columns); - // print foot for selected columns printFoot(doc, table, cursor, colsAndIndexes.columns); }); } @@ -1371,9 +1370,9 @@ function printFoot(doc, table, cursor, columns) { } } function getRemainingLineCount(cell, remainingPageSpace, doc) { - var fontHeight = (cell.styles.fontSize / doc.scaleFactor()) * FONT_ROW_RATIO; + var lineHeight = doc.getLineHeight(cell.styles.fontSize); var vPadding = cell.padding('vertical'); - var remainingLines = Math.floor((remainingPageSpace - vPadding) / fontHeight); + var remainingLines = Math.floor((remainingPageSpace - vPadding) / lineHeight); return Math.max(0, remainingLines); } function modifyRowToFit(row, remainingPageSpace, table, doc) { @@ -1397,7 +1396,8 @@ function modifyRowToFit(row, remainingPageSpace, table, doc) { remainderCell.text = cell.text.splice(remainingLineCount, cell.text.length); } var scaleFactor = doc.scaleFactor(); - cell.contentHeight = cell.getContentHeight(scaleFactor); + var lineHeightFactor = doc.lineHeightFactor; + cell.contentHeight = cell.getContentHeight(scaleFactor, lineHeightFactor); if (cell.contentHeight >= remainingPageSpace) { cell.contentHeight = remainingPageSpace; remainderCell.styles.minCellHeight -= remainingPageSpace; @@ -1405,7 +1405,7 @@ function modifyRowToFit(row, remainingPageSpace, table, doc) { if (cell.contentHeight > row.height) { row.height = cell.contentHeight; } - remainderCell.contentHeight = remainderCell.getContentHeight(scaleFactor); + remainderCell.contentHeight = remainderCell.getContentHeight(scaleFactor, lineHeightFactor); if (remainderCell.contentHeight > rowHeight) { rowHeight = remainderCell.contentHeight; } @@ -1499,7 +1499,7 @@ function printRow(doc, table, row, cursor, columns) { cursor.x += column.width; continue; } - drawCellBorders(doc, cell, cursor); + drawCellRect(doc, cell, cursor); var textPos = cell.getTextPos(); autoTableText(cell.text, textPos.x, textPos.y, { halign: cell.styles.halign, @@ -1511,32 +1511,27 @@ function printRow(doc, table, row, cursor, columns) { } cursor.y += row.height; } -function drawCellBorders(doc, cell, cursor) { +function drawCellRect(doc, cell, cursor) { var cellStyles = cell.styles; + // https://github.com/simonbengtsson/jsPDF-AutoTable/issues/774 + // TODO (v4): better solution? doc.getDocument().setFillColor(doc.getDocument().getFillColor()); if (typeof cellStyles.lineWidth === 'number') { - // prints normal cell border using rect's stroke + // Draw cell background with normal borders var fillStyle = getFillStyle(cellStyles.lineWidth, cellStyles.fillColor); if (fillStyle) { doc.rect(cell.x, cursor.y, cell.width, cell.height, fillStyle); } } else if (typeof cellStyles.lineWidth === 'object') { - drawCellBackground(doc, cell, cursor, cellStyles.fillColor); - drawBorders(doc, cell, cursor, cellStyles.fillColor, cellStyles.lineWidth); + // Draw cell background + if (cellStyles.fillColor) { + doc.rect(cell.x, cursor.y, cell.width, cell.height, 'F'); + } + // Draw cell individual borders + drawCellBorders(doc, cell, cursor, cellStyles.lineWidth); } } -/** - * Prints cell background without borders and allows transparent color. - * @param doc - * @param cell - * @param cursor - * @param fillColor - passed to getFillStyle; `false` will map to transparent, `truthy` values to 'F' from jsPDF.rect - */ -function drawCellBackground(doc, cell, cursor, fillColor) { - var fillStyle = getFillStyle(0, fillColor); - doc.rect(cell.x, cursor.y, cell.width, cell.height, fillStyle); -} /** * Draw all specified borders. Borders are centered on cell's edge and lengthened * to overlap with neighbours to create sharp corners. @@ -1546,7 +1541,7 @@ function drawCellBackground(doc, cell, cursor, fillColor) { * @param fillColor * @param lineWidth */ -function drawBorders(doc, cell, cursor, fillColor, lineWidth) { +function drawCellBorders(doc, cell, cursor, lineWidth) { var x1, y1, x2, y2; if (lineWidth.top) { x1 = cursor.x; @@ -1559,7 +1554,7 @@ function drawBorders(doc, cell, cursor, fillColor, lineWidth) { if (lineWidth.left) { x1 -= 0.5 * lineWidth.left; } - drawLine([x1, y1, x2, y2], lineWidth.top, fillColor); + drawLine(lineWidth.top, x1, y1, x2, y2); } if (lineWidth.bottom) { x1 = cursor.x; @@ -1572,7 +1567,7 @@ function drawBorders(doc, cell, cursor, fillColor, lineWidth) { if (lineWidth.left) { x1 -= 0.5 * lineWidth.left; } - drawLine([x1, y1, x2, y2], lineWidth.bottom, fillColor); + drawLine(lineWidth.bottom, x1, y1, x2, y2); } if (lineWidth.left) { x1 = cursor.x; @@ -1585,7 +1580,7 @@ function drawBorders(doc, cell, cursor, fillColor, lineWidth) { if (lineWidth.bottom) { y2 += 0.5 * lineWidth.bottom; } - drawLine([x1, y1, x2, y2], lineWidth.left, fillColor); + drawLine(lineWidth.left, x1, y1, x2, y2); } if (lineWidth.right) { x1 = cursor.x + cell.width; @@ -1598,12 +1593,11 @@ function drawBorders(doc, cell, cursor, fillColor, lineWidth) { if (lineWidth.bottom) { y2 += 0.5 * lineWidth.bottom; } - drawLine([x1, y1, x2, y2], lineWidth.right, fillColor); + drawLine(lineWidth.right, x1, y1, x2, y2); } - function drawLine(coords, width, color) { - var _a; + function drawLine(width, x1, y1, x2, y2) { doc.getDocument().setLineWidth(width); - (_a = doc.getDocument()).line.apply(_a, __spreadArray(__spreadArray([], coords, false), [getFillStyle(width, color)], false)); + doc.getDocument().line(x1, y1, x2, y2, 'S'); } } function getRemainingPageSpace(doc, table, isLastRow, cursor) { @@ -1698,7 +1692,7 @@ function calculateWidths(doc, table) { function calculate(doc, table) { var sf = doc.scaleFactor(); var horizontalPageBreak = table.settings.horizontalPageBreak; - var availablePageWidth = TablePrinter.getPageAvailableWidth(doc, table); + var availablePageWidth = getPageAvailableWidth(doc, table); table.allRows().forEach(function (row) { for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { var column = _a[_i]; @@ -1912,7 +1906,7 @@ function fitContent(table, doc) { cell.text = result; } } - cell.contentHeight = cell.getContentHeight(doc.scaleFactor()); + cell.contentHeight = cell.getContentHeight(doc.scaleFactor(), doc.lineHeightFactor); var realContentHeight = cell.contentHeight / cell.rowSpan; if (cell.rowSpan > 1 && rowSpanHeight.count * rowSpanHeight.height < diff --git a/package-lock.json b/package-lock.json index 0a6964ec..96422305 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "jspdf-autotable", - "version": "3.6.0", + "version": "3.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "jspdf-autotable", - "version": "3.6.0", + "version": "3.7.0", "license": "MIT", "devDependencies": { "@rollup/plugin-typescript": "^11.1.5", diff --git a/package.json b/package.json index a385e5d9..02eb7463 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jspdf-autotable", - "version": "3.6.0", + "version": "3.7.0", "description": "Generate pdf tables with javascript (jsPDF plugin)", "main": "dist/jspdf.plugin.autotable.js", "exports": {