1/*! 2 * 3 * jsPDF AutoTable plugin v3.5.3 4 * 5 * Copyright (c) 2020 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable 6 * Licensed under the MIT License. 7 * http://opensource.org/licenses/mit-license 8 * 9 */ 10(function webpackUniversalModuleDefinition(root, factory) { 11 if(typeof exports === 'object' && typeof module === 'object') 12 module.exports = factory((function webpackLoadOptionalExternalModule() { try { return require("jspdf"); } catch(e) {} }())); 13 else if(typeof define === 'function' && define.amd) 14 define(["jspdf"], factory); 15 else { 16 var a = typeof exports === 'object' ? factory((function webpackLoadOptionalExternalModule() { try { return require("jspdf"); } catch(e) {} }())) : factory(root["jsPDF"]); 17 for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; 18 } 19})(this, function(__WEBPACK_EXTERNAL_MODULE__15__) { 20return /******/ (function(modules) { // webpackBootstrap 21/******/ // The module cache 22/******/ var installedModules = {}; 23/******/ 24/******/ // The require function 25/******/ function __webpack_require__(moduleId) { 26/******/ 27/******/ // Check if module is in cache 28/******/ if(installedModules[moduleId]) { 29/******/ return installedModules[moduleId].exports; 30/******/ } 31/******/ // Create a new module (and put it into the cache) 32/******/ var module = installedModules[moduleId] = { 33/******/ i: moduleId, 34/******/ l: false, 35/******/ exports: {} 36/******/ }; 37/******/ 38/******/ // Execute the module function 39/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 40/******/ 41/******/ // Flag the module as loaded 42/******/ module.l = true; 43/******/ 44/******/ // Return the exports of the module 45/******/ return module.exports; 46/******/ } 47/******/ 48/******/ 49/******/ // expose the modules object (__webpack_modules__) 50/******/ __webpack_require__.m = modules; 51/******/ 52/******/ // expose the module cache 53/******/ __webpack_require__.c = installedModules; 54/******/ 55/******/ // define getter function for harmony exports 56/******/ __webpack_require__.d = function(exports, name, getter) { 57/******/ if(!__webpack_require__.o(exports, name)) { 58/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 59/******/ } 60/******/ }; 61/******/ 62/******/ // define __esModule on exports 63/******/ __webpack_require__.r = function(exports) { 64/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 65/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 66/******/ } 67/******/ Object.defineProperty(exports, '__esModule', { value: true }); 68/******/ }; 69/******/ 70/******/ // create a fake namespace object 71/******/ // mode & 1: value is a module id, require it 72/******/ // mode & 2: merge all properties of value into the ns 73/******/ // mode & 4: return value when already ns object 74/******/ // mode & 8|1: behave like require 75/******/ __webpack_require__.t = function(value, mode) { 76/******/ if(mode & 1) value = __webpack_require__(value); 77/******/ if(mode & 8) return value; 78/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 79/******/ var ns = Object.create(null); 80/******/ __webpack_require__.r(ns); 81/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 82/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 83/******/ return ns; 84/******/ }; 85/******/ 86/******/ // getDefaultExport function for compatibility with non-harmony modules 87/******/ __webpack_require__.n = function(module) { 88/******/ var getter = module && module.__esModule ? 89/******/ function getDefault() { return module['default']; } : 90/******/ function getModuleExports() { return module; }; 91/******/ __webpack_require__.d(getter, 'a', getter); 92/******/ return getter; 93/******/ }; 94/******/ 95/******/ // Object.prototype.hasOwnProperty.call 96/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 97/******/ 98/******/ // __webpack_public_path__ 99/******/ __webpack_require__.p = ""; 100/******/ 101/******/ 102/******/ // Load entry module and return exports 103/******/ return __webpack_require__(__webpack_require__.s = 9); 104/******/ }) 105/************************************************************************/ 106/******/ ([ 107/* 0 */ 108/***/ (function(module, exports, __webpack_require__) { 109 110"use strict"; 111 112Object.defineProperty(exports, "__esModule", { value: true }); 113function getStringWidth(text, styles, doc) { 114 doc.applyStyles(styles, true); 115 var textArr = Array.isArray(text) ? text : [text]; 116 var widestLineWidth = textArr 117 .map(function (text) { return doc.getTextWidth(text); }) 118 .reduce(function (a, b) { return Math.max(a, b); }, 0); 119 return widestLineWidth; 120} 121exports.getStringWidth = getStringWidth; 122function addTableBorder(table, doc) { 123 var lineWidth = table.settings.tableLineWidth; 124 var lineColor = table.settings.tableLineColor; 125 doc.applyStyles({ lineWidth: lineWidth, lineColor: lineColor }); 126 var fillStyle = getFillStyle(lineWidth, false); 127 if (fillStyle) { 128 doc.rect(table.pageStartX, table.pageStartY, table.width, table.cursor.y - table.pageStartY, fillStyle); 129 } 130} 131exports.addTableBorder = addTableBorder; 132function getFillStyle(lineWidth, fillColor) { 133 var drawLine = lineWidth > 0;
134 var drawBackground = fillColor || fillColor === 0; 135 if (drawLine && drawBackground) { 136 return 'DF'; // Fill then stroke 137 } 138 else if (drawLine) { 139 return 'S'; // Only stroke (transparent background) 140 } 141 else if (drawBackground) { 142 return 'F'; // Only fill, no stroke 143 } 144 else { 145 return null; 146 } 147} 148exports.getFillStyle = getFillStyle; 149function marginOrPadding(value, defaultValue) { 150 var _a, _b, _c, _d; 151 value = value || defaultValue; 152 if (Array.isArray(value)) { 153 if (value.length >= 4) { 154 return { 155 top: value[0], 156 right: value[1], 157 bottom: value[2], 158 left: value[3], 159 }; 160 } 161 else if (value.length === 3) { 162 return { 163 top: value[0], 164 right: value[1], 165 bottom: value[2], 166 left: value[1], 167 }; 168 } 169 else if (value.length === 2) { 170 return { 171 top: value[0], 172 right: value[1], 173 bottom: value[0], 174 left: value[1], 175 }; 176 } 177 else if (value.length === 1) { 178 value = value[0]; 179 } 180 else { 181 value = defaultValue; 182 } 183 } 184 if (typeof value === 'object') { 185 if (typeof value.vertical === 'number') { 186 value.top = value.vertical; 187 value.bottom = value.vertical; 188 } 189 if (typeof value.horizontal === 'number') { 190 value.right = value.horizontal; 191 value.left = value.horizontal; 192 } 193 return { 194 left: (_a = value.left) !== null && _a !== void 0 ? _a : defaultValue, 195 top: (_b = value.top) !== null && _b !== void 0 ? _b : defaultValue, 196 right: (_c = value.right) !== null && _c !== void 0 ? _c : defaultValue, 197 bottom: (_d = value.bottom) !== null && _d !== void 0 ? _d : defaultValue, 198 }; 199 } 200 if (typeof value !== 'number') { 201 value = defaultValue; 202 } 203 return { top: value, right: value, bottom: value, left: value }; 204} 205exports.marginOrPadding = marginOrPadding; 206 207 208/***/ }), 209/* 1 */ 210/***/ (function(module, exports, __webpack_require__) { 211 212"use strict"; 213 214var __extends = (this && this.__extends) || (function () { 215 var extendStatics = function (d, b) { 216 extendStatics = Object.setPrototypeOf || 217 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 218 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 219 return extendStatics(d, b); 220 }; 221 return function (d, b) { 222 extendStatics(d, b); 223 function __() { this.constructor = d; } 224 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 225 }; 226})(); 227Object.defineProperty(exports, "__esModule", { value: true }); 228/** 229 * Ratio between font size and font height. The number comes from jspdf's source code 230 */ 231exports.FONT_ROW_RATIO = 1.15; 232var HtmlRowInput = /** @class */ (function (_super) { 233 __extends(HtmlRowInput, _super); 234 function HtmlRowInput(element) { 235 var _this = _super.call(this) || this; 236 _this._element = element; 237 return _this; 238 } 239 return HtmlRowInput; 240}(Array)); 241exports.HtmlRowInput = HtmlRowInput; 242// Base style for all themes 243function defaultStyles(scaleFactor) { 244 return { 245 font: 'helvetica', 246 fontStyle: 'normal', 247 overflow: 'linebreak', 248 fillColor: false, 249 textColor: 20, 250 halign: 'left', 251 valign: 'top', 252 fontSize: 10, 253 cellPadding: 5 / scaleFactor, 254 lineColor: 200, 255 lineWidth: 0, 256 cellWidth: 'auto', 257 minCellHeight: 0, 258 minCellWidth: 0, 259 }; 260} 261exports.defaultStyles = defaultStyles; 262function getTheme(name) { 263 var themes = { 264 striped: { 265 table: { fillColor: 255, textColor: 80, fontStyle: 'normal' }, 266 head: { textColor: 255, fillColor: [41, 128, 185], fontStyle: 'bold' }, 267 body: {}, 268 foot: { textColor: 255, fillColor: [41, 128, 185], fontStyle: 'bold' }, 269 alternateRow: { fillColor: 245 }, 270 }, 271 grid: { 272 table: { 273 fillColor: 255, 274 textColor: 80, 275 fontStyle: 'normal', 276 lineWidth: 0.1, 277 }, 278 head: { 279 textColor: 255, 280 fillColor: [26, 188, 156], 281 fontStyle: 'bold', 282 lineWidth: 0, 283 }, 284 body: {}, 285 foot: { 286 textColor: 255, 287 fillColor: [26, 188, 156], 288 fontStyle: 'bold', 289 lineWidth: 0, 290 }, 291 alternateRow: {}, 292 }, 293 plain: { 294 head: { fontStyle: 'bold' }, 295 foot: { fontStyle: 'bold' }, 296 }, 297 }; 298 return themes[name]; 299} 300exports.getTheme = getTheme; 301 302 303/***/ }), 304/* 2 */ 305/***/ (function(module, exports, __webpack_require__) { 306 307"use strict"; 308 309Object.defineProperty(exports, "__esModule", { value: true }); 310var globalDefaults = {}; 311var DocHandler = /** @class */ (function () {
vendor: 4,971 bytes, lines 312-450
312 function DocHandler(jsPDFDocument) { 313 this.jsPDFDocument = jsPDFDocument; 314 this.userStyles = { 315 // Black for versions of jspdf without getTextColor 316 textColor: jsPDFDocument.getTextColor 317 ? this.jsPDFDocument.getTextColor() 318 : 0, 319 fontSize: jsPDFDocument.internal.getFontSize(), 320 fontStyle: jsPDFDocument.internal.getFont().fontStyle, 321 font: jsPDFDocument.internal.getFont().fontName, 322 }; 323 } 324 DocHandler.setDefaults = function (defaults, doc) { 325 if (doc === void 0) { doc = null; } 326 if (doc) { 327 doc.__autoTableDocumentDefaults = defaults; 328 } 329 else { 330 globalDefaults = defaults; 331 } 332 }; 333 DocHandler.unifyColor = function (c) { 334 if (Array.isArray(c)) { 335 return c; 336 } 337 else if (typeof c === 'number') { 338 return [c, c, c]; 339 } 340 else if (typeof c === 'string') { 341 return [c]; 342 } 343 else { 344 return null; 345 } 346 }; 347 DocHandler.prototype.applyStyles = function (styles, fontOnly) { 348 var _a, _b, _c; 349 if (fontOnly === void 0) { fontOnly = false; } 350 // Font style needs to be applied before font 351 // https://github.com/simonbengtsson/jsPDF-AutoTable/issues/632 352 if (styles.fontStyle) 353 this.jsPDFDocument.setFontStyle(styles.fontStyle); 354 if (styles.font) 355 this.jsPDFDocument.setFont(styles.font); 356 if (styles.fontSize) 357 this.jsPDFDocument.setFontSize(styles.fontSize); 358 if (fontOnly) { 359 return; // Performance improvement 360 } 361 var color = DocHandler.unifyColor(styles.fillColor); 362 if (color) 363 (_a = this.jsPDFDocument).setFillColor.apply(_a, color); 364 color = DocHandler.unifyColor(styles.textColor); 365 if (color) 366 (_b = this.jsPDFDocument).setTextColor.apply(_b, color); 367 color = DocHandler.unifyColor(styles.lineColor); 368 if (color) 369 (_c = this.jsPDFDocument).setDrawColor.apply(_c, color); 370 if (typeof styles.lineWidth === 'number') { 371 this.jsPDFDocument.setLineWidth(styles.lineWidth); 372 } 373 }; 374 DocHandler.prototype.splitTextToSize = function (text, size, opts) { 375 return this.jsPDFDocument.splitTextToSize(text, size, opts); 376 }; 377 DocHandler.prototype.rect = function (x, y, width, height, fillStyle) { 378 return this.jsPDFDocument.rect(x, y, width, height, fillStyle); 379 }; 380 DocHandler.prototype.getPreviousAutoTable = function () { 381 return this.jsPDFDocument.previousAutoTable; 382 }; 383 DocHandler.prototype.getTextWidth = function (text) { 384 return this.jsPDFDocument.getTextWidth(text); 385 }; 386 DocHandler.prototype.getDocument = function () { 387 return this.jsPDFDocument; 388 }; 389 DocHandler.prototype.setPage = function (page) { 390 this.jsPDFDocument.setPage(page); 391 }; 392 DocHandler.prototype.addPage = function () { 393 return this.jsPDFDocument.addPage(); 394 }; 395 DocHandler.prototype.getFontList = function () { 396 return this.jsPDFDocument.getFontList(); 397 }; 398 DocHandler.prototype.getGlobalOptions = function () { 399 return globalDefaults || {}; 400 }; 401 DocHandler.prototype.getDocumentOptions = function () { 402 return this.jsPDFDocument.__autoTableDocumentDefaults || {}; 403 }; 404 DocHandler.prototype.pageSize = function () { 405 var pageSize = this.jsPDFDocument.internal.pageSize; 406 // JSPDF 1.4 uses get functions instead of properties on pageSize 407 if (pageSize.width == null) { 408 pageSize = { 409 width: pageSize.getWidth(), 410 height: pageSize.getHeight(), 411 }; 412 } 413 return pageSize; 414 }; 415 DocHandler.prototype.scaleFactor = function () { 416 return this.jsPDFDocument.internal.scaleFactor; 417 }; 418 DocHandler.prototype.pageNumber = function () { 419 var pageInfo = this.jsPDFDocument.internal.getCurrentPageInfo(); 420 if (!pageInfo) { 421 // Only recent versions of jspdf has pageInfo 422 return this.jsPDFDocument.internal.getNumberOfPages(); 423 } 424 return pageInfo.pageNumber; 425 }; 426 return DocHandler; 427}()); 428exports.DocHandler = DocHandler; 429 430 431/***/ }), 432/* 3 */ 433/***/ (function(module, exports, __webpack_require__) { 434 435"use strict"; 436 437Object.defineProperty(exports, "__esModule", { value: true }); 438var cssParser_1 = __webpack_require__(11); 439var config_1 = __webpack_require__(1); 440function parseHtml(doc, input, window, includeHiddenHtml, useCss) { 441 if (includeHiddenHtml === void 0) { includeHiddenHtml = false; } 442 if (useCss === void 0) { useCss = false; } 443 var _a, _b; 444 var tableElement; 445 if (typeof input === 'string') { 446 tableElement = window.document.querySelector(input); 447 } 448 else { 449 tableElement = input; 450 }
451 var supportedFonts = Object.keys(doc.getFontList()); 452 var scaleFactor = doc.scaleFactor(); 453 var head = [], body = [], foot = []; 454 if (!tableElement) { 455 console.error('Html table could not be found with input: ', input); 456 return { head: head, body: body, foot: foot }; 457 } 458 for (var i = 0; i < tableElement.rows.length; i++) { 459 var element = tableElement.rows[i]; 460 var tagName = (_b = (_a = element === null || element === void 0 ? void 0 : element.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === null || _b === void 0 ? void 0 : _b.toLowerCase(); 461 var row = parseRowContent(supportedFonts, scaleFactor, window, element, includeHiddenHtml, useCss); 462 if (!row) 463 continue; 464 if (tagName === 'thead') { 465 head.push(row); 466 } 467 else if (tagName === 'tfoot') { 468 foot.push(row); 469 } 470 else { 471 // Add to body both if parent is tbody or table 472 body.push(row); 473 } 474 } 475 return { head: head, body: body, foot: foot }; 476} 477exports.parseHtml = parseHtml; 478function parseRowContent(supportedFonts, scaleFactor, window, row, includeHidden, useCss) { 479 var resultRow = new config_1.HtmlRowInput(row); 480 for (var i = 0; i < row.cells.length; i++) { 481 var cell = row.cells[i]; 482 var style_1 = window.getComputedStyle(cell); 483 if (includeHidden || style_1.display !== 'none') { 484 var cellStyles = void 0; 485 if (useCss) { 486 cellStyles = cssParser_1.parseCss(supportedFonts, cell, scaleFactor, style_1, window); 487 } 488 resultRow.push({ 489 rowSpan: cell.rowSpan, 490 colSpan: cell.colSpan, 491 styles: cellStyles, 492 _element: cell, 493 content: parseCellContent(cell), 494 }); 495 } 496 } 497 var style = window.getComputedStyle(row); 498 if (resultRow.length > 0 && (includeHidden || style.display !== 'none')) { 499 return resultRow; 500 } 501} 502function parseCellContent(orgCell) { 503 // Work on cloned node to make sure no changes are applied to html table 504 var cell = orgCell.cloneNode(true); 505 // Remove extra space and line breaks in markup to make it more similar to 506 // what would be shown in html 507 cell.innerHTML = cell.innerHTML.replace(/\n/g, '').replace(/ +/g, ' '); 508 // Preserve <br> tags as line breaks in the pdf 509 cell.innerHTML = cell.innerHTML 510 .split('<br>') 511 .map(function (part) { return part.trim(); }) 512 .join('\n'); 513 // innerText for ie 514 return cell.innerText || cell.textContent || ''; 515} 516 517 518/***/ }), 519/* 4 */ 520/***/ (function(module, exports, __webpack_require__) { 521 522"use strict"; 523 524Object.defineProperty(exports, "__esModule", { value: true }); 525/** 526 * Improved text function with halign and valign support 527 * Inspiration from: http://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113#28433113 528 */ 529function default_1(text, x, y, styles, doc) { 530 styles = styles || {}; 531 var FONT_ROW_RATIO = 1.15; 532 var k = doc.internal.scaleFactor; 533 var fontSize = doc.internal.getFontSize() / k; 534 var splitRegex = /\r\n|\r|\n/g; 535 var splitText = ''; 536 var lineCount = 1; 537 if (styles.valign === 'middle' || 538 styles.valign === 'bottom' || 539 styles.halign === 'center' || 540 styles.halign === 'right') { 541 splitText = typeof text === 'string' ? text.split(splitRegex) : text; 542 lineCount = splitText.length || 1; 543 } 544 // Align the top 545 y += fontSize * (2 - FONT_ROW_RATIO); 546 if (styles.valign === 'middle') 547 y -= (lineCount / 2) * fontSize * FONT_ROW_RATIO; 548 else if (styles.valign === 'bottom') 549 y -= lineCount * fontSize * FONT_ROW_RATIO; 550 if (styles.halign === 'center' || styles.halign === 'right') { 551 var alignSize = fontSize; 552 if (styles.halign === 'center') 553 alignSize *= 0.5; 554 if (splitText && lineCount >= 1) { 555 for (var iLine = 0; iLine < splitText.length; iLine++) { 556 doc.text(splitText[iLine], x - doc.getStringUnitWidth(splitText[iLine]) * alignSize, y); 557 y += fontSize * FONT_ROW_RATIO; 558 } 559 return doc; 560 } 561 x -= doc.getStringUnitWidth(text) * alignSize; 562 } 563 if (styles.halign === 'justify') { 564 doc.text(text, x, y, { 565 maxWidth: styles.maxWidth || 100, 566 align: 'justify', 567 }); 568 } 569 else { 570 doc.text(text, x, y); 571 } 572 return doc; 573} 574exports.default = default_1; 575 576 577/***/ }), 578/* 5 */ 579/***/ (function(module, exports, __webpack_require__) { 580 581"use strict"; 582 583Object.defineProperty(exports, "__esModule", { value: true }); 584var config_1 = __webpack_require__(1); 585var htmlParser_1 = __webpack_require__(3); 586var polyfills_1 = __webpack_require__(6); 587var common_1 = __webpack_require__(0); 588var documentHandler_1 = __webpack_require__(2); 589var inputValidator_1 = __webpack_require__(12); 590var models_1 = __webpack_require__(7); 591var widthCalculator_1 = __webpack_require__(14); 592function createTable(jsPDFDoc, current) { 593 var doc = new documentHandler_1.DocHandler(jsPDFDoc); 594 var document = doc.getDocumentOptions(); 595 var global = doc.getGlobalOptions(); 596 inputValidator_1.default(global, document, current, doc); 597 var options = polyfills_1.assign({}, global, document, current); 598 var previous = doc.getPreviousAutoTable(); 599 var sf = doc.scaleFactor(); 600 var margin = common_1.marginOrPadding(options.margin, 40 / sf); 601 var startY = getStartY(previous, sf, doc.pageNumber(), options, margin.top); 602 var settings = parseSettings(options, sf, startY, margin); 603 var styles = parseStyles(global, document, current); 604 var win; 605 if (typeof window !== 'undefined') { 606 win = window; 607 } 608 var content = parseContent(doc, options, styles, settings.theme, sf, win); 609 var table = new models_1.Table(current.tableId, settings, styles, parseHooks(global, document, current), content); 610 calculate(table, sf, doc); 611 table.minWidth = table.columns.reduce(function (total, col) { return total + col.minWidth; }, 0); 612 table.wrappedWidth = table.columns.reduce(function (total, col) { return total + col.wrappedWidth; }, 0); 613 if (typeof table.settings.tableWidth === 'number') { 614 table.width = table.settings.tableWidth; 615 } 616 else if (table.settings.tableWidth === 'wrap') { 617 table.width = table.wrappedWidth; 618 } 619 else { 620 table.width = doc.pageSize().width - margin.left - margin.right; 621 } 622 widthCalculator_1.calculateWidths(doc, table); 623 doc.applyStyles(doc.userStyles); 624 return table; 625} 626exports.createTable = createTable; 627function calculate(table, sf, doc) {
628 table.allRows().forEach(function (row) { 629 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { 630 var column = _a[_i]; 631 var cell = row.cells[column.index]; 632 if (!cell) 633 continue; 634 table.callCellHooks(doc, table.hooks.didParseCell, cell, row, column); 635 var padding = cell.padding('horizontal'); 636 cell.contentWidth = common_1.getStringWidth(cell.text, cell.styles, doc) + padding; 637 var longestWordWidth = common_1.getStringWidth(cell.text.join(' ').split(/\s+/), cell.styles, doc); 638 cell.minReadableWidth = longestWordWidth + cell.padding('horizontal'); 639 if (typeof cell.styles.cellWidth === 'number') { 640 cell.minWidth = cell.styles.cellWidth; 641 cell.wrappedWidth = cell.styles.cellWidth; 642 } 643 else if (cell.styles.cellWidth === 'wrap') { 644 cell.minWidth = cell.contentWidth; 645 cell.wrappedWidth = cell.contentWidth; 646 } 647 else { 648 // auto 649 var defaultMinWidth = 10 / sf; 650 cell.minWidth = cell.styles.minCellWidth || defaultMinWidth; 651 cell.wrappedWidth = cell.contentWidth; 652 if (cell.minWidth > cell.wrappedWidth) { 653 cell.wrappedWidth = cell.minWidth; 654 } 655 } 656 } 657 }); 658 table.allRows().forEach(function (row) { 659 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { 660 var column = _a[_i]; 661 var cell = row.cells[column.index]; 662 // For now we ignore the minWidth and wrappedWidth of colspan cells when calculating colspan widths. 663 // Could probably be improved upon however. 664 if (cell && cell.colSpan === 1) { 665 column.wrappedWidth = Math.max(column.wrappedWidth, cell.wrappedWidth); 666 column.minWidth = Math.max(column.minWidth, cell.minWidth); 667 column.minReadableWidth = Math.max(column.minReadableWidth, cell.minReadableWidth); 668 } 669 else { 670 // Respect cellWidth set in columnStyles even if there is no cells for this column 671 // or if the column only have colspan cells. Since the width of colspan cells 672 // does not affect the width of columns, setting columnStyles cellWidth enables the 673 // user to at least do it manually. 674 // Note that this is not perfect for now since for example row and table styles are 675 // not accounted for 676 var columnStyles = table.styles.columnStyles[column.dataKey] || 677 table.styles.columnStyles[column.index] || 678 {}; 679 var cellWidth = columnStyles.cellWidth; 680 if (cellWidth && typeof cellWidth === 'number') { 681 column.minWidth = cellWidth; 682 column.wrappedWidth = cellWidth; 683 } 684 } 685 if (cell) { 686 // Make sure all columns get at least min width even though width calculations are not based on them 687 if (cell.colSpan > 1 && !column.minWidth) { 688 column.minWidth = cell.minWidth; 689 } 690 if (cell.colSpan > 1 && !column.wrappedWidth) { 691 column.wrappedWidth = cell.minWidth; 692 } 693 } 694 } 695 }); 696} 697function parseStyles(gInput, dInput, cInput) { 698 var styleOptions = { 699 styles: {}, 700 headStyles: {}, 701 bodyStyles: {}, 702 footStyles: {}, 703 alternateRowStyles: {}, 704 columnStyles: {}, 705 }; 706 var _loop_1 = function (prop) { 707 if (prop === 'columnStyles') { 708 var global_1 = gInput[prop]; 709 var document_1 = dInput[prop]; 710 var current = cInput[prop]; 711 styleOptions.columnStyles = polyfills_1.assign({}, global_1, document_1, current); 712 } 713 else { 714 var allOptions = [gInput, dInput, cInput]; 715 var styles = allOptions.map(function (opts) { return opts[prop] || {}; }); 716 styleOptions[prop] = polyfills_1.assign({}, styles[0], styles[1], styles[2]); 717 } 718 }; 719 for (var _i = 0, _a = Object.keys(styleOptions); _i < _a.length; _i++) { 720 var prop = _a[_i]; 721 _loop_1(prop); 722 } 723 return styleOptions; 724} 725function parseHooks(global, document, current) { 726 var allOptions = [global, document, current]; 727 var result = { 728 didParseCell: [], 729 willDrawCell: [], 730 didDrawCell: [], 731 didDrawPage: [], 732 }; 733 for (var _i = 0, allOptions_1 = allOptions; _i < allOptions_1.length; _i++) { 734 var options = allOptions_1[_i]; 735 if (options.didParseCell) 736 result.didParseCell.push(options.didParseCell); 737 if (options.willDrawCell) 738 result.willDrawCell.push(options.willDrawCell); 739 if (options.didDrawCell) 740 result.didDrawCell.push(options.didDrawCell); 741 if (options.didDrawPage) 742 result.didDrawPage.push(options.didDrawPage); 743 } 744 return result; 745} 746function parseSettings(options, sf, startY, margin) { 747 var _a, _b, _c, _d, _e, _f, _g, _h, _j; 748 var showFoot; 749 if (options.showFoot === true) { 750 showFoot = 'everyPage'; 751 } 752 else if (options.showFoot === false) { 753 showFoot = 'never'; 754 } 755 else { 756 showFoot = (_a = options.showFoot) !== null && _a !== void 0 ? _a : 'everyPage'; 757 } 758 var showHead; 759 if (options.showHead === true) { 760 showHead = 'everyPage'; 761 } 762 else if (options.showHead === false) { 763 showHead = 'never'; 764 } 765 else 766 showHead = (_b = options.showHead) !== null && _b !== void 0 ? _b : 'everyPage'; 767 var useCss = (_c = options.useCss) !== null && _c !== void 0 ? _c : false;
768 var theme = options.theme || (useCss ? 'plain' : 'striped'); 769 var settings = { 770 includeHiddenHtml: (_d = options.includeHiddenHtml) !== null && _d !== void 0 ? _d : false, 771 useCss: useCss, 772 theme: theme, 773 startY: startY, 774 margin: margin, 775 pageBreak: (_e = options.pageBreak) !== null && _e !== void 0 ? _e : 'auto', 776 rowPageBreak: (_f = options.rowPageBreak) !== null && _f !== void 0 ? _f : 'auto', 777 tableWidth: (_g = options.tableWidth) !== null && _g !== void 0 ? _g : 'auto', 778 showHead: showHead, 779 showFoot: showFoot, 780 tableLineWidth: (_h = options.tableLineWidth) !== null && _h !== void 0 ? _h : 0, 781 tableLineColor: (_j = options.tableLineColor) !== null && _j !== void 0 ? _j : 200, 782 }; 783 return settings; 784} 785function getStartY(previous, sf, currentPage, options, marginTop) { 786 var isSamePageAsPreviousTable = false; 787 if (previous) { 788 var endingPage = previous.startPageNumber + previous.pageNumber - 1; 789 isSamePageAsPreviousTable = endingPage === currentPage; 790 } 791 var startY = options.startY; 792 if (startY == null || startY === false) { 793 if (isSamePageAsPreviousTable) { 794 // Some users had issues with overlapping tables when they used multiple 795 // tables without setting startY so setting it here to a sensible default. 796 startY = previous.finalY + 20 / sf; 797 } 798 } 799 return startY || marginTop; 800} 801function parseContent(doc, options, styles, theme, sf, window) { 802 var head = options.head || []; 803 var body = options.body || []; 804 var foot = options.foot || []; 805 if (options.html) { 806 var hidden = options.includeHiddenHtml; 807 if (window) { 808 var htmlContent = htmlParser_1.parseHtml(doc, options.html, window, hidden, options.useCss) || {}; 809 head = htmlContent.head || head; 810 body = htmlContent.body || head; 811 foot = htmlContent.foot || head; 812 } 813 else { 814 console.error('Cannot parse html in non browser environment'); 815 } 816 } 817 var columnInputs = options.columns || getColumnDef(head, body, foot); 818 var columns = createColumns(columnInputs); 819 // If no head or foot is set, try generating it with content from columns 820 if (head.length === 0 && options.columns) { 821 var sectionRow = generateTitleRow(columns, 'head'); 822 if (sectionRow) 823 head.push(sectionRow); 824 } 825 if (foot.length === 0 && options.columns) { 826 var sectionRow = generateTitleRow(columns, 'foot'); 827 if (sectionRow) 828 foot.push(sectionRow); 829 } 830 return { 831 columns: columns, 832 head: parseSection('head', head, options, columns, styles, theme, sf), 833 body: parseSection('body', body, options, columns, styles, theme, sf), 834 foot: parseSection('foot', foot, options, columns, styles, theme, sf), 835 }; 836} 837function parseSection(sectionName, sectionRows, settings, columns, styleProps, theme, scaleFactor) { 838 var rowSpansLeftForColumn = {}; 839 return sectionRows.map(function (rawRow, rowIndex) { 840 var skippedRowForRowSpans = 0; 841 var row = new models_1.Row(rawRow, rowIndex, sectionName); 842 var colSpansAdded = 0; 843 var columnSpansLeft = 0; 844 for (var _i = 0, columns_1 = columns; _i < columns_1.length; _i++) { 845 var column = columns_1[_i]; 846 if (rowSpansLeftForColumn[column.index] == null || 847 rowSpansLeftForColumn[column.index].left === 0) { 848 if (columnSpansLeft === 0) { 849 var rawCell = void 0; 850 if (Array.isArray(rawRow)) { 851 rawCell = 852 rawRow[column.index - colSpansAdded - skippedRowForRowSpans]; 853 } 854 else { 855 rawCell = rawRow[column.dataKey]; 856 } 857 var cellInputStyles = {}; 858 if (typeof rawCell === 'object' && !Array.isArray(rawCell)) { 859 cellInputStyles = (rawCell === null || rawCell === void 0 ? void 0 : rawCell.styles) || {}; 860 } 861 var styles = cellStyles(sectionName, column, rowIndex, theme, styleProps, scaleFactor, cellInputStyles); 862 var cell = new models_1.Cell(rawCell, styles, sectionName); 863 // dataKey is not used internally no more but keep for 864 // backwards compat in hooks 865 row.cells[column.dataKey] = cell; 866 row.cells[column.index] = cell; 867 columnSpansLeft = cell.colSpan - 1; 868 rowSpansLeftForColumn[column.index] = { 869 left: cell.rowSpan - 1, 870 times: columnSpansLeft, 871 }; 872 } 873 else { 874 columnSpansLeft--; 875 colSpansAdded++; 876 } 877 } 878 else { 879 rowSpansLeftForColumn[column.index].left--; 880 columnSpansLeft = rowSpansLeftForColumn[column.index].times; 881 skippedRowForRowSpans++; 882 } 883 } 884 return row; 885 }); 886} 887function generateTitleRow(columns, section) { 888 var sectionRow = {}; 889 columns.forEach(function (col) { 890 if (col.raw != null) { 891 var title = getSectionTitle(section, col.raw); 892 if (title != null) 893 sectionRow[col.dataKey] = title; 894 } 895 }); 896 return Object.keys(sectionRow).length > 0 ? sectionRow : null; 897} 898function getSectionTitle(section, column) { 899 if (section === 'head') { 900 if (typeof column === 'object') { 901 return column.header || column.title || null; 902 } 903 else if (typeof column === 'string' || typeof column === 'number') { 904 return column; 905 } 906 } 907 else if (section === 'foot' && typeof column === 'object') { 908 return column.footer; 909 } 910 return null; 911} 912function getColumnDef(head, body, foot) { 913 var firstRow = head[0] || body[0] || foot[0] || []; 914 var result = [];
915 Object.keys(firstRow) 916 .filter(function (key) { return key !== '_element'; }) 917 .forEach(function (key) { 918 var colSpan = 1; 919 var input; 920 if (Array.isArray(firstRow)) { 921 input = firstRow[parseInt(key)]; 922 } 923 else { 924 input = firstRow[key]; 925 } 926 if (typeof input === 'object' && !Array.isArray(input)) { 927 colSpan = (input === null || input === void 0 ? void 0 : input.colSpan) || 1; 928 } 929 for (var i = 0; i < colSpan; i++) { 930 var id = void 0; 931 if (Array.isArray(firstRow)) { 932 id = result.length; 933 } 934 else { 935 id = key + (i > 0 ? "_" + i : ''); 936 } 937 result.push({ dataKey: id, header: input }); 938 } 939 }); 940 return result; 941} 942exports.getColumnDef = getColumnDef; 943function createColumns(columns) { 944 return columns.map(function (input, index) { 945 var _a, _b; 946 var key; 947 if (typeof input === 'object') { 948 key = (_b = (_a = input.dataKey) !== null && _a !== void 0 ? _a : input.key) !== null && _b !== void 0 ? _b : index; 949 } 950 else { 951 key = index; 952 } 953 return new models_1.Column(key, input, index); 954 }); 955} 956function cellStyles(sectionName, column, rowIndex, themeName, styles, scaleFactor, cellInputStyles) { 957 var theme = config_1.getTheme(themeName); 958 var sectionStyles; 959 if (sectionName === 'head') { 960 sectionStyles = styles.headStyles; 961 } 962 else if (sectionName === 'body') { 963 sectionStyles = styles.bodyStyles; 964 } 965 else if (sectionName === 'foot') { 966 sectionStyles = styles.footStyles; 967 } 968 var otherStyles = polyfills_1.assign({}, theme.table, theme[sectionName], styles.styles, sectionStyles); 969 var columnStyles = styles.columnStyles[column.dataKey] || 970 styles.columnStyles[column.index] || 971 {}; 972 var colStyles = sectionName === 'body' ? columnStyles : {}; 973 var rowStyles = sectionName === 'body' && rowIndex % 2 === 0 974 ? polyfills_1.assign({}, theme.alternateRow, styles.alternateRowStyles) 975 : {}; 976 var defaultStyle = config_1.defaultStyles(scaleFactor); 977 var themeStyles = polyfills_1.assign({}, defaultStyle, otherStyles, rowStyles, colStyles); 978 return polyfills_1.assign(themeStyles, cellInputStyles); 979} 980 981 982/***/ }), 983/* 6 */ 984/***/ (function(module, exports, __webpack_require__) { 985 986"use strict"; 987 988/* eslint-disable @typescript-eslint/no-unused-vars */ 989Object.defineProperty(exports, "__esModule", { value: true }); 990// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign 991function assign(target, s, s1, s2, s3) { 992 if (target == null) { 993 throw new TypeError('Cannot convert undefined or null to object'); 994 } 995 var to = Object(target); 996 for (var index = 1; index < arguments.length; index++) { 997 // eslint-disable-next-line prefer-rest-params 998 var nextSource = arguments[index]; 999 if (nextSource != null) { 1000 // Skip over if undefined or null 1001 for (var nextKey in nextSource) { 1002 // Avoid bugs when hasOwnProperty is shadowed 1003 if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { 1004 to[nextKey] = nextSource[nextKey]; 1005 } 1006 } 1007 } 1008 } 1009 return to; 1010} 1011exports.assign = assign; 1012 1013 1014/***/ }), 1015/* 7 */ 1016/***/ (function(module, exports, __webpack_require__) { 1017 1018"use strict"; 1019 1020Object.defineProperty(exports, "__esModule", { value: true }); 1021var config_1 = __webpack_require__(1); 1022var HookData_1 = __webpack_require__(13); 1023var common_1 = __webpack_require__(0); 1024var Table = /** @class */ (function () { 1025 function Table(id, settings, styles, hooks, content) { 1026 this.cursor = { x: 0, y: 0 }; 1027 this.columns = []; 1028 this.head = []; 1029 this.body = []; 1030 this.foot = []; 1031 this.wrappedWidth = 0; 1032 this.minWidth = 0; 1033 this.width = 0; 1034 this.height = 0; 1035 this.headHeight = 0; 1036 this.footHeight = 0; 1037 this.startPageNumber = 1; 1038 this.pageNumber = 1; 1039 // Deprecated, use pageNumber instead 1040 // Not using getter since: 1041 // https://github.com/simonbengtsson/jsPDF-AutoTable/issues/596 1042 this.pageCount = 1; 1043 this.pageStartX = 0; 1044 this.pageStartY = 0; 1045 this.finalY = 0; 1046 this.id = id; 1047 this.settings = settings; 1048 this.styles = styles; 1049 this.hooks = hooks; 1050 this.columns = content.columns; 1051 this.head = content.head; 1052 this.body = content.body; 1053 this.foot = content.foot; 1054 } 1055 Table.prototype.allRows = function () { 1056 return this.head.concat(this.body).concat(this.foot); 1057 }; 1058 Table.prototype.callCellHooks = function (doc, handlers, cell, row, column) { 1059 for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) { 1060 var handler = handlers_1[_i]; 1061 var data = new HookData_1.CellHookData(this, doc, cell, row, column); 1062 var result = handler(data) === false; 1063 // Make sure text is always string[] since user can assign string 1064 cell.text = Array.isArray(cell.text) ? cell.text : [cell.text]; 1065 if (result) { 1066 return false;
1067 } 1068 } 1069 return true; 1070 }; 1071 Table.prototype.callEndPageHooks = function (doc) { 1072 doc.applyStyles(doc.userStyles); 1073 for (var _i = 0, _a = this.hooks.didDrawPage; _i < _a.length; _i++) { 1074 var handler = _a[_i]; 1075 handler(new HookData_1.HookData(this, doc)); 1076 } 1077 }; 1078 return Table; 1079}()); 1080exports.Table = Table; 1081var Row = /** @class */ (function () { 1082 function Row(raw, index, section) { 1083 this.cells = {}; 1084 this.height = 0; 1085 this.maxCellHeight = 0; 1086 this.x = 0; 1087 this.y = 0; 1088 this.spansMultiplePages = false; 1089 this.raw = raw; 1090 if (raw instanceof config_1.HtmlRowInput) { 1091 this.raw = raw._element; 1092 this.element = raw._element; 1093 } 1094 this.index = index; 1095 this.section = section; 1096 } 1097 Row.prototype.hasRowSpan = function (columns) { 1098 var _this = this; 1099 return (columns.filter(function (column) { 1100 var cell = _this.cells[column.index]; 1101 if (!cell) 1102 return false; 1103 return cell.rowSpan > 1; 1104 }).length > 0); 1105 }; 1106 Row.prototype.canEntireRowFit = function (height) { 1107 return this.maxCellHeight <= height; 1108 }; 1109 Row.prototype.getMinimumRowHeight = function (columns, doc) { 1110 var _this = this; 1111 return columns.reduce(function (acc, column) { 1112 var cell = _this.cells[column.index]; 1113 if (!cell) 1114 return 0; 1115 var fontHeight = (cell.styles.fontSize / doc.scaleFactor()) * config_1.FONT_ROW_RATIO; 1116 var vPadding = cell.padding('vertical'); 1117 var oneRowHeight = vPadding + fontHeight; 1118 return oneRowHeight > acc ? oneRowHeight : acc; 1119 }, 0); 1120 }; 1121 return Row; 1122}()); 1123exports.Row = Row; 1124var Cell = /** @class */ (function () { 1125 function Cell(raw, styles, section) { 1126 var _a, _b; 1127 this.contentHeight = 0; 1128 this.contentWidth = 0; 1129 this.wrappedWidth = 0; 1130 this.minReadableWidth = 0; 1131 this.minWidth = 0; 1132 this.width = 0; 1133 this.height = 0; 1134 this.textPos = { y: 0, x: 0 }; 1135 this.x = 0; 1136 this.y = 0; 1137 this.colSpan = 1; 1138 this.rowSpan = 1; 1139 this.styles = styles; 1140 this.section = section; 1141 this.raw = raw; 1142 var content = raw; 1143 if (raw != null && typeof raw === 'object' && !Array.isArray(raw)) { 1144 this.rowSpan = raw.rowSpan || 1; 1145 this.colSpan = raw.colSpan || 1; 1146 content = (_b = (_a = raw.content) !== null && _a !== void 0 ? _a : raw.title) !== null && _b !== void 0 ? _b : raw; 1147 if (raw._element) { 1148 this.raw = raw._element; 1149 } 1150 } 1151 // Stringify 0 and false, but not undefined or null 1152 var text = content != null ? '' + content : ''; 1153 var splitRegex = /\r\n|\r|\n/g; 1154 this.text = text.split(splitRegex); 1155 } 1156 Cell.prototype.getContentHeight = function (scaleFactor) { 1157 var lineCount = Array.isArray(this.text) ? this.text.length : 1; 1158 var fontHeight = (this.styles.fontSize / scaleFactor) * config_1.FONT_ROW_RATIO; 1159 return lineCount * fontHeight + this.padding('vertical'); 1160 }; 1161 Cell.prototype.padding = function (name) { 1162 var padding = common_1.marginOrPadding(this.styles.cellPadding, 0); 1163 if (name === 'vertical') { 1164 return padding.top + padding.bottom; 1165 } 1166 else if (name === 'horizontal') { 1167 return padding.left + padding.right; 1168 } 1169 else { 1170 return padding[name]; 1171 } 1172 }; 1173 return Cell; 1174}()); 1175exports.Cell = Cell; 1176var Column = /** @class */ (function () { 1177 function Column(dataKey, raw, index) { 1178 this.wrappedWidth = 0; 1179 this.minReadableWidth = 0; 1180 this.minWidth = 0; 1181 this.width = 0; 1182 this.dataKey = dataKey; 1183 this.raw = raw; 1184 this.index = index; 1185 } 1186 Column.prototype.getMaxCustomCellWidth = function (table) { 1187 var max = 0; 1188 for (var _i = 0, _a = table.allRows(); _i < _a.length; _i++) { 1189 var row = _a[_i]; 1190 var cell = row.cells[this.index]; 1191 if (cell && typeof cell.styles.cellWidth === 'number') { 1192 max = Math.max(max, cell.styles.cellWidth); 1193 } 1194 } 1195 return max; 1196 }; 1197 return Column; 1198}()); 1199exports.Column = Column; 1200 1201 1202/***/ }), 1203/* 8 */ 1204/***/ (function(module, exports, __webpack_require__) { 1205 1206"use strict"; 1207 1208Object.defineProperty(exports, "__esModule", { value: true }); 1209var config_1 = __webpack_require__(1); 1210var common_1 = __webpack_require__(0); 1211var models_1 = __webpack_require__(7); 1212var documentHandler_1 = __webpack_require__(2); 1213var polyfills_1 = __webpack_require__(6); 1214var autoTableText_1 = __webpack_require__(4); 1215function drawTable(jsPDFDoc, table) { 1216 var settings = table.settings; 1217 var startY = settings.startY; 1218 var margin = settings.margin; 1219 table.cursor = { 1220 x: margin.left, 1221 y: startY, 1222 }; 1223 var minTableBottomPos = startY + margin.bottom + table.headHeight + table.footHeight; 1224 if (settings.pageBreak === 'avoid') { 1225 minTableBottomPos += table.height; 1226 } 1227 var doc = new documentHandler_1.DocHandler(jsPDFDoc); 1228 if (settings.pageBreak === 'always' ||
1229 (settings.startY != null && minTableBottomPos > doc.pageSize().height)) { 1230 nextPage(doc); 1231 table.cursor.y = margin.top; 1232 } 1233 table.pageStartX = table.cursor.x; 1234 table.pageStartY = table.cursor.y; 1235 table.startPageNumber = doc.pageNumber(); 1236 doc.applyStyles(doc.userStyles); 1237 if (settings.showHead === 'firstPage' || settings.showHead === 'everyPage') { 1238 table.head.forEach(function (row) { return printRow(table, row, doc); }); 1239 } 1240 doc.applyStyles(doc.userStyles); 1241 table.body.forEach(function (row, index) { 1242 printFullRow(table, row, index === table.body.length - 1, doc); 1243 }); 1244 doc.applyStyles(doc.userStyles); 1245 if (settings.showFoot === 'lastPage' || settings.showFoot === 'everyPage') { 1246 table.foot.forEach(function (row) { return printRow(table, row, doc); }); 1247 } 1248 common_1.addTableBorder(table, doc); 1249 table.callEndPageHooks(doc); 1250 table.finalY = table.cursor.y; 1251 jsPDFDoc.previousAutoTable = table; 1252 jsPDFDoc.lastAutoTable = table; // Deprecated 1253 if (jsPDFDoc.autoTable) 1254 jsPDFDoc.autoTable.previous = table; // Deprecated 1255 doc.applyStyles(doc.userStyles); 1256} 1257exports.drawTable = drawTable; 1258function getRemainingLineCount(cell, remainingPageSpace, doc) { 1259 var fontHeight = (cell.styles.fontSize / doc.scaleFactor()) * config_1.FONT_ROW_RATIO; 1260 var vPadding = cell.padding('vertical'); 1261 var remainingLines = Math.floor((remainingPageSpace - vPadding) / fontHeight); 1262 return Math.max(0, remainingLines); 1263} 1264function modifyRowToFit(row, remainingPageSpace, table, doc) { 1265 var remainderRow = new models_1.Row(row.raw, -1, row.section); 1266 remainderRow.spansMultiplePages = true; 1267 row.spansMultiplePages = true; 1268 row.height = 0; 1269 row.maxCellHeight = 0; 1270 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { 1271 var column = _a[_i]; 1272 var cell = row.cells[column.index]; 1273 if (!cell) 1274 continue; 1275 if (!Array.isArray(cell.text)) { 1276 cell.text = [cell.text]; 1277 } 1278 var remainderCell = new models_1.Cell(cell.raw, cell.styles, cell.section); 1279 remainderCell = polyfills_1.assign(remainderCell, cell); 1280 remainderCell.textPos = polyfills_1.assign({}, cell.textPos); 1281 remainderCell.text = []; 1282 var remainingLineCount = getRemainingLineCount(cell, remainingPageSpace, doc); 1283 if (cell.text.length > remainingLineCount) { 1284 remainderCell.text = cell.text.splice(remainingLineCount, cell.text.length); 1285 } 1286 var scaleFactor = doc.scaleFactor(); 1287 cell.contentHeight = cell.getContentHeight(scaleFactor); 1288 if (cell.contentHeight > row.height) { 1289 row.height = cell.contentHeight; 1290 row.maxCellHeight = cell.contentHeight; 1291 } 1292 remainderCell.contentHeight = remainderCell.getContentHeight(scaleFactor); 1293 if (remainderCell.contentHeight > remainderRow.height) { 1294 remainderRow.height = remainderCell.contentHeight; 1295 remainderRow.maxCellHeight = remainderCell.contentHeight; 1296 } 1297 remainderRow.cells[column.index] = remainderCell; 1298 } 1299 for (var _b = 0, _c = table.columns; _b < _c.length; _b++) { 1300 var column = _c[_b]; 1301 var remainderCell = remainderRow.cells[column.index]; 1302 if (remainderCell) { 1303 remainderCell.height = remainderRow.height; 1304 } 1305 var cell = row.cells[column.index]; 1306 if (cell) { 1307 cell.height = row.height; 1308 } 1309 } 1310 return remainderRow; 1311} 1312function shouldPrintOnCurrentPage(doc, row, remainingPageSpace, table) { 1313 var pageHeight = doc.pageSize().height; 1314 var margin = table.settings.margin; 1315 var marginHeight = margin.top + margin.bottom; 1316 var maxRowHeight = pageHeight - marginHeight; 1317 if (row.section === 'body') { 1318 // Should also take into account that head and foot is not 1319 // on every page with some settings 1320 maxRowHeight -= table.headHeight + table.footHeight; 1321 } 1322 var minRowHeight = row.getMinimumRowHeight(table.columns, doc); 1323 var minRowFits = minRowHeight < remainingPageSpace; 1324 if (minRowHeight > maxRowHeight) { 1325 console.error("Will not be able to print row " + row.index + " correctly since it's minimum height is larger than page height"); 1326 return true; 1327 } 1328 if (!minRowFits) { 1329 return false;
1330 } 1331 var rowHasRowSpanCell = row.hasRowSpan(table.columns); 1332 var rowHigherThanPage = row.maxCellHeight > maxRowHeight; 1333 if (rowHigherThanPage) { 1334 if (rowHasRowSpanCell) { 1335 console.error("The content of row " + row.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."); 1336 } 1337 return true; 1338 } 1339 if (rowHasRowSpanCell) { 1340 // Currently a new page is required whenever a rowspan row don't fit a page. 1341 return false; 1342 } 1343 if (table.settings.rowPageBreak === 'avoid') { 1344 return false; 1345 } 1346 // In all other cases print the row on current page 1347 return true; 1348} 1349function printFullRow(table, row, isLastRow, doc) { 1350 var remainingPageSpace = getRemainingPageSpace(table, isLastRow, doc); 1351 if (row.canEntireRowFit(remainingPageSpace)) { 1352 printRow(table, row, doc); 1353 } 1354 else { 1355 if (shouldPrintOnCurrentPage(doc, row, remainingPageSpace, table)) { 1356 var remainderRow = modifyRowToFit(row, remainingPageSpace, table, doc); 1357 printRow(table, row, doc); 1358 addPage(table, doc); 1359 printFullRow(table, remainderRow, isLastRow, doc); 1360 } 1361 else { 1362 addPage(table, doc); 1363 printFullRow(table, row, isLastRow, doc); 1364 } 1365 } 1366} 1367function printRow(table, row, doc) { 1368 table.cursor.x = table.settings.margin.left; 1369 row.y = table.cursor.y; 1370 row.x = table.cursor.x; 1371 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { 1372 var column = _a[_i]; 1373 var cell = row.cells[column.index]; 1374 if (!cell) { 1375 table.cursor.x += column.width; 1376 continue; 1377 } 1378 doc.applyStyles(cell.styles); 1379 cell.x = table.cursor.x; 1380 cell.y = row.y; 1381 if (cell.styles.valign === 'top') { 1382 cell.textPos.y = table.cursor.y + cell.padding('top'); 1383 } 1384 else if (cell.styles.valign === 'bottom') { 1385 cell.textPos.y = table.cursor.y + cell.height - cell.padding('bottom'); 1386 } 1387 else { 1388 var netHeight = cell.height - cell.padding('vertical'); 1389 cell.textPos.y = table.cursor.y + netHeight / 2 + cell.padding('top'); 1390 } 1391 if (cell.styles.halign === 'right') { 1392 cell.textPos.x = cell.x + cell.width - cell.padding('right'); 1393 } 1394 else if (cell.styles.halign === 'center') { 1395 var netWidth = cell.width - cell.padding('horizontal'); 1396 cell.textPos.x = cell.x + netWidth / 2 + cell.padding('left'); 1397 } 1398 else { 1399 cell.textPos.x = cell.x + cell.padding('left'); 1400 } 1401 var result = table.callCellHooks(doc, table.hooks.willDrawCell, cell, row, column); 1402 if (result === false) { 1403 table.cursor.x += column.width; 1404 continue; 1405 } 1406 var cellStyles = cell.styles; 1407 var fillStyle = common_1.getFillStyle(cellStyles.lineWidth, cellStyles.fillColor); 1408 if (fillStyle) { 1409 doc.rect(cell.x, table.cursor.y, cell.width, cell.height, fillStyle); 1410 } 1411 autoTableText_1.default(cell.text, cell.textPos.x, cell.textPos.y, { 1412 halign: cell.styles.halign, 1413 valign: cell.styles.valign, 1414 maxWidth: Math.ceil(cell.width - cell.padding('left') - cell.padding('right')), 1415 }, doc.getDocument()); 1416 table.callCellHooks(doc, table.hooks.didDrawCell, cell, row, column); 1417 table.cursor.x += column.width; 1418 } 1419 table.cursor.y += row.height; 1420} 1421function getRemainingPageSpace(table, isLastRow, doc) { 1422 var bottomContentHeight = table.settings.margin.bottom; 1423 var showFoot = table.settings.showFoot; 1424 if (showFoot === 'everyPage' || (showFoot === 'lastPage' && isLastRow)) { 1425 bottomContentHeight += table.footHeight; 1426 } 1427 return doc.pageSize().height - table.cursor.y - bottomContentHeight; 1428} 1429function addPage(table, doc) { 1430 doc.applyStyles(doc.userStyles); 1431 if (table.settings.showFoot === 'everyPage') { 1432 table.foot.forEach(function (row) { return printRow(table, row, doc); }); 1433 } 1434 table.finalY = table.cursor.y; 1435 // Add user content just before adding new page ensure it will 1436 // be drawn above other things on the page 1437 table.callEndPageHooks(doc); 1438 var margin = table.settings.margin; 1439 common_1.addTableBorder(table, doc); 1440 nextPage(doc); 1441 table.pageNumber++; 1442 table.pageCount++; 1443 table.cursor = { x: margin.left, y: margin.top }; 1444 table.pageStartX = table.cursor.x; 1445 table.pageStartY = table.cursor.y; 1446 if (table.settings.showHead === 'everyPage') {
1447 table.head.forEach(function (row) { return printRow(table, row, doc); }); 1448 } 1449} 1450exports.addPage = addPage; 1451function nextPage(doc) { 1452 var current = doc.pageNumber(); 1453 doc.setPage(current + 1); 1454 var newCurrent = doc.pageNumber(); 1455 if (newCurrent === current) { 1456 doc.addPage(); 1457 } 1458} 1459 1460 1461/***/ }), 1462/* 9 */ 1463/***/ (function(module, exports, __webpack_require__) { 1464 1465"use strict"; 1466 1467Object.defineProperty(exports, "__esModule", { value: true }); 1468var applyPlugin_1 = __webpack_require__(10); 1469var inputParser_1 = __webpack_require__(5); 1470var tableDrawer_1 = __webpack_require__(8); 1471// export { applyPlugin } didn't export applyPlugin 1472// to index.d.ts for some reason 1473function applyPlugin(jsPDF) { 1474 applyPlugin_1.default(jsPDF); 1475} 1476exports.applyPlugin = applyPlugin; 1477function autoTable(doc, options) { 1478 var table = inputParser_1.createTable(doc, options); 1479 tableDrawer_1.drawTable(doc, table); 1480} 1481exports.default = autoTable; 1482try { 1483 // eslint-disable-next-line @typescript-eslint/no-var-requires 1484 var jsPDF = __webpack_require__(15); 1485 applyPlugin(jsPDF); 1486} 1487catch (error) { 1488 // Importing jspdf in nodejs environments does not work as of jspdf 1489 // 1.5.3 so we need to silence potential errors to support using for example 1490 // the nodejs jspdf dist files with the exported applyPlugin 1491} 1492 1493 1494/***/ }), 1495/* 10 */ 1496/***/ (function(module, exports, __webpack_require__) { 1497 1498"use strict"; 1499 1500Object.defineProperty(exports, "__esModule", { value: true }); 1501var htmlParser_1 = __webpack_require__(3); 1502var autoTableText_1 = __webpack_require__(4); 1503var documentHandler_1 = __webpack_require__(2); 1504var inputParser_1 = __webpack_require__(5); 1505var tableDrawer_1 = __webpack_require__(8); 1506function default_1(jsPDF) { 1507 // eslint-disable-next-line @typescript-eslint/no-explicit-any 1508 jsPDF.API.autoTable = function () { 1509 var args = []; 1510 for (var _i = 0; _i < arguments.length; _i++) { 1511 args[_i] = arguments[_i]; 1512 } 1513 var options; 1514 if (args.length === 1) { 1515 options = args[0]; 1516 } 1517 else { 1518 console.error('Use of deprecated autoTable initiation'); 1519 options = args[2] || {}; 1520 options.columns = args[0]; 1521 options.body = args[1]; 1522 } 1523 var table = inputParser_1.createTable(this, options); 1524 tableDrawer_1.drawTable(this, table); 1525 return this; 1526 }; 1527 // Assign false to enable `doc.lastAutoTable.finalY || 40` sugar 1528 jsPDF.API.lastAutoTable = false; 1529 jsPDF.API.previousAutoTable = false; // deprecated in v3 1530 jsPDF.API.autoTable.previous = false; // deprecated in v3 1531 jsPDF.API.autoTableText = function (text, x, y, styles) { 1532 autoTableText_1.default(text, x, y, styles, this); 1533 }; 1534 jsPDF.API.autoTableSetDefaults = function (defaults) { 1535 documentHandler_1.DocHandler.setDefaults(defaults, this); 1536 return this; 1537 }; 1538 jsPDF.autoTableSetDefaults = function (defaults, doc) { 1539 documentHandler_1.DocHandler.setDefaults(defaults, doc); 1540 }; 1541 jsPDF.API.autoTableHtmlToJson = function (tableElem, includeHiddenElements) { 1542 if (includeHiddenElements === void 0) { includeHiddenElements = false; } 1543 if (typeof window === 'undefined') { 1544 console.error('Cannot run autoTableHtmlToJson in non browser environment'); 1545 return null; 1546 } 1547 var doc = new documentHandler_1.DocHandler(this); 1548 var _a = htmlParser_1.parseHtml(doc, tableElem, window, includeHiddenElements, false), head = _a.head, body = _a.body, foot = _a.foot; 1549 var columns = inputParser_1.getColumnDef(head, body, foot); 1550 return { columns: columns, rows: body, data: body }; 1551 }; 1552 /** 1553 * @deprecated 1554 */ 1555 jsPDF.API.autoTableEndPosY = function () { 1556 console.error('Use of deprecated function: autoTableEndPosY. Use doc.previousAutoTable.finalY instead.'); 1557 var prev = this.previousAutoTable; 1558 if (prev.cursor && typeof prev.cursor.y === 'number') { 1559 return prev.cursor.y; 1560 } 1561 else { 1562 return 0; 1563 } 1564 }; 1565 /** 1566 * @deprecated 1567 */ 1568 jsPDF.API.autoTableAddPageContent = function (hook) { 1569 console.error('Use of deprecated function: autoTableAddPageContent. Use jsPDF.autoTableSetDefaults({didDrawPage: () => {}}) instead.'); 1570 if (!jsPDF.API.autoTable.globalDefaults) { 1571 jsPDF.API.autoTable.globalDefaults = {}; 1572 } 1573 jsPDF.API.autoTable.globalDefaults.addPageContent = hook; 1574 return this; 1575 }; 1576 /** 1577 * @deprecated 1578 */ 1579 jsPDF.API.autoTableAddPage = function () { 1580 console.error('Use of deprecated function: autoTableAddPage. Use doc.addPage()'); 1581 this.addPage(); 1582 return this; 1583 }; 1584} 1585exports.default = default_1; 1586 1587 1588/***/ }), 1589/* 11 */ 1590/***/ (function(module, exports, __webpack_require__) { 1591 1592"use strict"; 1593 1594Object.defineProperty(exports, "__esModule", { value: true }); 1595// Limitations 1596// - No support for border spacing 1597// - No support for transparency 1598var common_1 = __webpack_require__(0); 1599function parseCss(supportedFonts, element, scaleFactor, style, window) { 1600 var result = {}; 1601 var pxScaleFactor = 96 / 72; 1602 var color = parseColor(element, function (elem) { 1603 return window.getComputedStyle(elem)['backgroundColor']; 1604 }); 1605 if (color != null) 1606 result.fillColor = color; 1607 color = parseColor(element, function (elem) { 1608 return window.getComputedStyle(elem)['color']; 1609 }); 1610 if (color != null) 1611 result.textColor = color; 1612 color = parseColor(element, function (elem) { 1613 return window.getComputedStyle(elem)['borderTopColor']; 1614 }); 1615 if (color != null) 1616 result.lineColor = color; 1617 var padding = parsePadding(style, scaleFactor); 1618 if (padding) 1619 result.cellPadding = padding; 1620 // style.borderWidth only works in chrome (borderTopWidth etc works in firefox and ie as well) 1621 var bw = parseInt(style.borderTopWidth || ''); 1622 bw = bw / pxScaleFactor / scaleFactor; 1623 if (bw) 1624 result.lineWidth = bw; 1625 var accepted = ['left', 'right', 'center', 'justify']; 1626 if (accepted.indexOf(style.textAlign) !== -1) { 1627 result.halign = style.textAlign; 1628 } 1629 accepted = ['middle', 'bottom', 'top']; 1630 if (accepted.indexOf(style.verticalAlign) !== -1) { 1631 result.valign = style.verticalAlign; 1632 } 1633 var res = parseInt(style.fontSize || ''); 1634 if (!isNaN(res)) 1635 result.fontSize = res / pxScaleFactor; 1636 var fontStyle = parseFontStyle(style); 1637 if (fontStyle) 1638 result.fontStyle = fontStyle; 1639 var font = (style.fontFamily || '').toLowerCase(); 1640 if (supportedFonts.indexOf(font) !== -1) { 1641 result.font = font; 1642 } 1643 return result; 1644} 1645exports.parseCss = parseCss; 1646function parseFontStyle(style) { 1647 var res = ''; 1648 if (style.fontWeight === 'bold' || 1649 style.fontWeight === 'bolder' || 1650 parseInt(style.fontWeight) >= 700) { 1651 res = 'bold'; 1652 } 1653 if (style.fontStyle === 'italic' || style.fontStyle === 'oblique') { 1654 res += 'italic'; 1655 } 1656 return res; 1657} 1658function parseColor(element, styleGetter) { 1659 var cssColor = realColor(element, styleGetter); 1660 if (!cssColor) 1661 return null; 1662 var rgba = cssColor.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/); 1663 if (!rgba || !Array.isArray(rgba)) { 1664 return null; 1665 } 1666 var color = [ 1667 parseInt(rgba[1]), 1668 parseInt(rgba[2]), 1669 parseInt(rgba[3]), 1670 ]; 1671 var alpha = parseInt(rgba[4]); 1672 if (alpha === 0 || isNaN(color[0]) || isNaN(color[1]) || isNaN(color[2])) { 1673 return null; 1674 } 1675 return color; 1676} 1677function realColor(elem, styleGetter) { 1678 var bg = styleGetter(elem); 1679 if (bg === 'rgba(0, 0, 0, 0)' || 1680 bg === 'transparent' || 1681 bg === 'initial' || 1682 bg === 'inherit') { 1683 if (elem.parentElement == null) { 1684 return null; 1685 } 1686 return realColor(elem.parentElement, styleGetter); 1687 } 1688 else { 1689 return bg; 1690 } 1691} 1692function parsePadding(style, scaleFactor) { 1693 var val = [ 1694 style.paddingTop, 1695 style.paddingRight, 1696 style.paddingBottom, 1697 style.paddingLeft, 1698 ]; 1699 var pxScaleFactor = 96 / (72 / scaleFactor); 1700 var linePadding = (parseInt(style.lineHeight) - parseInt(style.fontSize)) / scaleFactor / 2; 1701 var inputPadding = val.map(function (n) { 1702 return parseInt(n) / pxScaleFactor; 1703 }); 1704 var padding = common_1.marginOrPadding(inputPadding, 0); 1705 if (linePadding > padding.top) { 1706 padding.top = linePadding; 1707 } 1708 if (linePadding > padding.bottom) { 1709 padding.bottom = linePadding; 1710 } 1711 return padding; 1712} 1713 1714 1715/***/ }), 1716/* 12 */ 1717/***/ (function(module, exports, __webpack_require__) { 1718 1719"use strict"; 1720 1721Object.defineProperty(exports, "__esModule", { value: true }); 1722function default_1(global, document, current, doc) { 1723 var _loop_1 = function (options) { 1724 if (options && typeof options !== 'object') { 1725 console.error('The options parameter should be of type object, is: ' + typeof options); 1726 } 1727 if (typeof options.extendWidth !== 'undefined') { 1728 options.tableWidth = options.extendWidth ? 'auto' : 'wrap'; 1729 console.error('Use of deprecated option: extendWidth, use tableWidth instead.'); 1730 } 1731 if (typeof options.margins !== 'undefined') { 1732 if (typeof options.margin === 'undefined') 1733 options.margin = options.margins; 1734 console.error('Use of deprecated option: margins, use margin instead.'); 1735 } 1736 if (options.startY && typeof options.startY !== 'number') { 1737 console.error('Invalid value for startY option', options.startY); 1738 delete options.startY; 1739 } 1740 if (!options.didDrawPage && 1741 (options.afterPageContent || 1742 options.beforePageContent || 1743 options.afterPageAdd)) { 1744 console.error('The afterPageContent, beforePageContent and afterPageAdd hooks are deprecated. Use didDrawPage instead'); 1745 options.didDrawPage = function (data) { 1746 doc.applyStyles(doc.userStyles); 1747 if (options.beforePageContent) 1748 options.beforePageContent(data); 1749 doc.applyStyles(doc.userStyles); 1750 if (options.afterPageContent) 1751 options.afterPageContent(data); 1752 doc.applyStyles(doc.userStyles); 1753 if (options.afterPageAdd && data.pageNumber > 1) { 1754 ; 1755 data.afterPageAdd(data); 1756 } 1757 doc.applyStyles(doc.userStyles); 1758 }; 1759 } 1760 ; 1761 [ 1762 'createdHeaderCell', 1763 'drawHeaderRow', 1764 'drawRow', 1765 'drawHeaderCell', 1766 ].forEach(function (name) { 1767 if (options[name]) { 1768 console.error("The \"" + name + "\" hook has changed in version 3.0, check the changelog for how to migrate."); 1769 } 1770 }); 1771 [ 1772 ['showFoot', 'showFooter'], 1773 ['showHead', 'showHeader'], 1774 ['didDrawPage', 'addPageContent'], 1775 ['didParseCell', 'createdCell'], 1776 ['headStyles', 'headerStyles'], 1777 ].forEach(function (_a) { 1778 var current = _a[0], deprecated = _a[1]; 1779 if (options[deprecated]) { 1780 console.error("Use of deprecated option " + deprecated + ". Use " + current + " instead"); 1781 options[current] = options[deprecated]; 1782 } 1783 }); 1784 [ 1785 ['padding', 'cellPadding'], 1786 ['lineHeight', 'rowHeight'], 1787 'fontSize', 1788 'overflow', 1789 ].forEach(function (o) { 1790 var deprecatedOption = typeof o === 'string' ? o : o[0]; 1791 var style = typeof o === 'string' ? o : o[1]; 1792 if (typeof options[deprecatedOption] !== 'undefined') { 1793 if (typeof options.styles[style] === 'undefined') { 1794 options.styles[style] = options[deprecatedOption]; 1795 } 1796 console.error('Use of deprecated option: ' + 1797 deprecatedOption + 1798 ', use the style ' + 1799 style + 1800 ' instead.'); 1801 } 1802 }); 1803 for (var _i = 0, _a = [ 1804 'styles', 1805 'bodyStyles', 1806 'headStyles', 1807 'footStyles', 1808 ]; _i < _a.length; _i++) { 1809 var styleProp = _a[_i]; 1810 checkStyles(options[styleProp] || {}); 1811 } 1812 var columnStyles = options['columnStyles'] || {}; 1813 for (var _b = 0, _c = Object.keys(columnStyles); _b < _c.length; _b++) { 1814 var key = _c[_b]; 1815 checkStyles(columnStyles[key] || {}); 1816 } 1817 }; 1818 for (var _i = 0, _a = [global, document, current]; _i < _a.length; _i++) { 1819 var options = _a[_i]; 1820 _loop_1(options); 1821 } 1822} 1823exports.default = default_1; 1824function checkStyles(styles) { 1825 if (styles.rowHeight) { 1826 console.error('Use of deprecated style rowHeight. It is renamed to minCellHeight.'); 1827 if (!styles.minCellHeight) { 1828 styles.minCellHeight = styles.rowHeight; 1829 } 1830 } 1831 else if (styles.columnWidth) { 1832 console.error('Use of deprecated style columnWidth. It is renamed to cellWidth.'); 1833 if (!styles.cellWidth) { 1834 styles.cellWidth = styles.columnWidth; 1835 } 1836 } 1837} 1838 1839 1840/***/ }), 1841/* 13 */ 1842/***/ (function(module, exports, __webpack_require__) { 1843 1844"use strict"; 1845 1846var __extends = (this && this.__extends) || (function () { 1847 var extendStatics = function (d, b) { 1848 extendStatics = Object.setPrototypeOf || 1849 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 1850 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 1851 return extendStatics(d, b); 1852 }; 1853 return function (d, b) { 1854 extendStatics(d, b); 1855 function __() { this.constructor = d; } 1856 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 1857 }; 1858})(); 1859Object.defineProperty(exports, "__esModule", { value: true }); 1860var HookData = /** @class */ (function () { 1861 function HookData(table, doc) { 1862 this.table = table; 1863 this.pageNumber = table.pageNumber; 1864 this.pageCount = this.pageNumber; 1865 this.settings = table.settings; 1866 this.cursor = table.cursor; 1867 this.doc = doc.getDocument(); 1868 } 1869 return HookData; 1870}()); 1871exports.HookData = HookData; 1872var CellHookData = /** @class */ (function (_super) { 1873 __extends(CellHookData, _super); 1874 function CellHookData(table, doc, cell, row, column) { 1875 var _this = _super.call(this, table, doc) || this; 1876 _this.cell = cell; 1877 _this.row = row; 1878 _this.column = column; 1879 _this.section = row.section; 1880 return _this; 1881 } 1882 return CellHookData; 1883}(HookData)); 1884exports.CellHookData = CellHookData; 1885 1886 1887/***/ }), 1888/* 14 */ 1889/***/ (function(module, exports, __webpack_require__) { 1890 1891"use strict"; 1892 1893Object.defineProperty(exports, "__esModule", { value: true }); 1894var common_1 = __webpack_require__(0); 1895/** 1896 * Calculate the column widths 1897 */ 1898function calculateWidths(doc, table) { 1899 var resizableColumns = []; 1900 var initialTableWidth = 0; 1901 table.columns.forEach(function (column) { 1902 var customWidth = column.getMaxCustomCellWidth(table); 1903 if (customWidth) { 1904 // final column width 1905 column.width = customWidth; 1906 } 1907 else { 1908 // initial column width (will be resized) 1909 column.width = column.wrappedWidth; 1910 resizableColumns.push(column); 1911 } 1912 initialTableWidth += column.width; 1913 }); 1914 // width difference that needs to be distributed 1915 var resizeWidth = table.width - initialTableWidth; 1916 // first resize attempt: with respect to minReadableWidth and minWidth 1917 if (resizeWidth) { 1918 resizeWidth = resizeColumns(resizableColumns, resizeWidth, function (column) { 1919 return Math.max(column.minReadableWidth, column.minWidth); 1920 }); 1921 } 1922 // second resize attempt: ignore minReadableWidth but respect minWidth 1923 if (resizeWidth) { 1924 resizeWidth = resiz
1924eColumns(resizableColumns, resizeWidth, function (column) { return column.minWidth; }); 1925 } 1926 resizeWidth = Math.abs(resizeWidth); 1927 if (resizeWidth > 1e-10) { 1928 // Table can't get smaller due to custom-width or minWidth restrictions 1929 // We can't really do much here. Up to user to for example 1930 // reduce font size, increase page size or remove custom cell widths 1931 // to allow more columns to be reduced in size 1932 resizeWidth = resizeWidth < 1 ? resizeWidth : Math.round(resizeWidth); 1933 console.error("Of the table content, " + resizeWidth + " units width could not fit page"); 1934 } 1935 applyColSpans(table); 1936 fitContent(table, doc); 1937 applyRowSpans(table); 1938} 1939exports.calculateWidths = calculateWidths; 1940/** 1941 * Distribute resizeWidth on passed resizable columns 1942 */ 1943function resizeColumns(columns, resizeWidth, getMinWidth) { 1944 var initialResizeWidth = resizeWidth; 1945 var sumWrappedWidth = columns.reduce(function (acc, column) { return acc + column.wrappedWidth; }, 0); 1946 for (var i = 0; i < columns.length; i++) { 1947 var column = columns[i]; 1948 var ratio = column.wrappedWidth / sumWrappedWidth; 1949 var suggestedChange = initialResizeWidth * ratio; 1950 var suggestedWidth = column.width + suggestedChange; 1951 var minWidth = getMinWidth(column); 1952 var newWidth = suggestedWidth < minWidth ? minWidth : suggestedWidth; 1953 resizeWidth -= newWidth - column.width; 1954 column.width = newWidth; 1955 } 1956 resizeWidth = Math.round(resizeWidth * 1e10) / 1e10; 1957 // Run the resizer again if there's remaining width needs 1958 // to be distributed and there're columns that can be resized 1959 if (resizeWidth) { 1960 var resizableColumns = columns.filter(function (column) { 1961 return resizeWidth < 0 1962 ? column.width > getMinWidth(column) // check if column can shrink 1963 : true; // check if column can grow 1964 }); 1965 if (resizableColumns.length) { 1966 resizeWidth = resizeColumns(resizableColumns, resizeWidth, getMinWidth); 1967 } 1968 } 1969 return resizeWidth; 1970} 1971exports.resizeColumns = resizeColumns; 1972function applyRowSpans(table) { 1973 var rowSpanCells = {}; 1974 var colRowSpansLeft = 1; 1975 var all = table.allRows(); 1976 for (var rowIndex = 0; rowIndex < all.length; rowIndex++) { 1977 var row = all[rowIndex]; 1978 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) { 1979 var column = _a[_i]; 1980 var data = rowSpanCells[column.index]; 1981 if (colRowSpansLeft > 1) { 1982 colRowSpansLeft--; 1983 delete row.cells[column.index]; 1984 } 1985 else if (data) { 1986 data.cell.height += row.height; 1987 if (data.cell.height > row.maxCellHeight) { 1988 data.row.maxCellHeight = data.cell.height; 1989 } 1990 colRowSpansLeft = data.cell.colSpan; 1991 delete row.cells[column.index]; 1992 data.left--; 1993 if (data.left <= 1) { 1994 delete rowSpanCells[column.index]; 1995 } 1996 } 1997 else { 1998 var cell = row.cells[column.index]; 1999 if (!cell) { 2000 continue; 2001 } 2002 cell.height = row.height; 2003 if (cell.rowSpan > 1) { 2004 var remaining = all.length - rowIndex; 2005 var left = cell.rowSpan > remaining ? remaining : cell.rowSpan; 2006 rowSpanCells[column.index] = { cell: cell, left: left, row: row }; 2007 } 2008 } 2009 } 2010 if (row.section === 'head') { 2011 table.headHeight += row.maxCellHeight; 2012 } 2013 if (row.section === 'foot') { 2014 table.footHeight += row.maxCellHeight; 2015 } 2016 table.height += row.height; 2017 } 2018} 2019function applyColSpans(table) { 2020 var all = table.allRows(); 2021 for (var rowIndex = 0; rowIndex < all.length; rowIndex++) { 2022 var row = all[rowIndex]; 2023 var colSpanCell = null; 2024 var combinedColSpanWidth = 0; 2025 var colSpansLeft = 0; 2026 for (var columnIndex = 0; columnIndex < table.columns.length; columnIndex++) { 2027 var column = table.columns[columnIndex];
2028 // Width and colspan 2029 colSpansLeft -= 1; 2030 if (colSpansLeft > 1 && table.columns[columnIndex + 1]) { 2031 combinedColSpanWidth += column.width; 2032 delete row.cells[column.index]; 2033 } 2034 else if (colSpanCell) { 2035 var cell = colSpanCell; 2036 delete row.cells[column.index]; 2037 colSpanCell = null; 2038 cell.width = column.width + combinedColSpanWidth; 2039 } 2040 else { 2041 var cell = row.cells[column.index]; 2042 if (!cell) 2043 continue; 2044 colSpansLeft = cell.colSpan; 2045 combinedColSpanWidth = 0; 2046 if (cell.colSpan > 1) { 2047 colSpanCell = cell; 2048 combinedColSpanWidth += column.width; 2049 continue; 2050 } 2051 cell.width = column.width + combinedColSpanWidth; 2052 } 2053 } 2054 } 2055} 2056function fitContent(table, doc) { 2057 var rowSpanHeight = { count: 0, height: 0 }; 2058 for (var _i = 0, _a = table.allRows(); _i < _a.length; _i++) { 2059 var row = _a[_i]; 2060 for (var _b = 0, _c = table.columns; _b < _c.length; _b++) { 2061 var column = _c[_b]; 2062 var cell = row.cells[column.index]; 2063 if (!cell) 2064 continue; 2065 doc.applyStyles(cell.styles, true); 2066 var textSpace = cell.width - cell.padding('horizontal'); 2067 if (cell.styles.overflow === 'linebreak') { 2068 // Add one pt to textSpace to fix rounding error 2069 cell.text = doc.splitTextToSize(cell.text, textSpace + 1 / doc.scaleFactor(), { fontSize: cell.styles.fontSize }); 2070 } 2071 else if (cell.styles.overflow === 'ellipsize') { 2072 cell.text = ellipsize(cell.text, textSpace, cell.styles, doc, '...'); 2073 } 2074 else if (cell.styles.overflow === 'hidden') { 2075 cell.text = ellipsize(cell.text, textSpace, cell.styles, doc, ''); 2076 } 2077 else if (typeof cell.styles.overflow === 'function') { 2078 cell.text = cell.styles.overflow(cell.text, textSpace); 2079 } 2080 cell.contentHeight = cell.getContentHeight(doc.scaleFactor()); 2081 if (cell.styles.minCellHeight > cell.contentHeight) { 2082 cell.contentHeight = cell.styles.minCellHeight; 2083 } 2084 var realContentHeight = cell.contentHeight / cell.rowSpan; 2085 if (cell.rowSpan > 1 && 2086 rowSpanHeight.count * rowSpanHeight.height < 2087 realContentHeight * cell.rowSpan) { 2088 rowSpanHeight = { height: realContentHeight, count: cell.rowSpan }; 2089 } 2090 else if (rowSpanHeight && rowSpanHeight.count > 0) { 2091 if (rowSpanHeight.height > realContentHeight) { 2092 realContentHeight = rowSpanHeight.height; 2093 } 2094 } 2095 if (realContentHeight > row.height) { 2096 row.height = realContentHeight; 2097 row.maxCellHeight = realContentHeight; 2098 } 2099 } 2100 rowSpanHeight.count--; 2101 } 2102} 2103function ellipsize(text, width, styles, doc, overflow) { 2104 return text.map(function (str) { return ellipsizeStr(str, width, styles, doc, overflow); }); 2105} 2106exports.ellipsize = ellipsize; 2107function ellipsizeStr(text, width, styles, doc, overflow) { 2108 var precision = 10000 * doc.scaleFactor(); 2109 width = Math.ceil(width * precision) / precision; 2110 if (width >= common_1.getStringWidth(text, styles, doc)) { 2111 return text; 2112 } 2113 while (width < common_1.getStringWidth(text + overflow, styles, doc)) { 2114 if (text.length <= 1) { 2115 break; 2116 } 2117 text = text.substring(0, text.length - 1); 2118 } 2119 return text.trim() + overflow; 2120} 2121 2122 2123/***/ }), 2124/* 15 */ 2125/***/ (function(module, exports) { 2126 2127if(typeof __WEBPACK_EXTERNAL_MODULE__15__ === 'undefined') {var e = new Error("Cannot find module 'undefined'"); e.code = 'MODULE_NOT_FOUND'; throw e;} 2128module.exports = __WEBPACK_EXTERNAL_MODULE__15__; 2129 2130/***/ }) 2131/******/ ]); 2132});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.