UNPKG

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