UNPKG

67.3 kBJavaScriptView Raw
1/*!
2 *
3 * jsPDF AutoTable plugin v3.0.4
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 * * /if (typeof window === 'object') window.jspdfAutoTableVersion = '" + newVersion + "';/*"
10 *
11 */
12(function webpackUniversalModuleDefinition(root, factory) {
13 if(typeof exports === 'object' && typeof module === 'object')
14 module.exports = factory(require("jspdf"));
15 else if(typeof define === 'function' && define.amd)
16 define(["jspdf"], factory);
17 else {
18 var a = typeof exports === 'object' ? factory(require("jspdf")) : factory(root["jsPDF"]);
19 for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
20 }
21})(window, function(__WEBPACK_EXTERNAL_MODULE__4__) {
22return /******/ (function(modules) { // webpackBootstrap
23/******/ // The module cache
24/******/ var installedModules = {};
25/******/
26/******/ // The require function
27/******/ function __webpack_require__(moduleId) {
28/******/
29/******/ // Check if module is in cache
30/******/ if(installedModules[moduleId]) {
31/******/ return installedModules[moduleId].exports;
32/******/ }
33/******/ // Create a new module (and put it into the cache)
34/******/ var module = installedModules[moduleId] = {
35/******/ i: moduleId,
36/******/ l: false,
37/******/ exports: {}
38/******/ };
39/******/
40/******/ // Execute the module function
41/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
42/******/
43/******/ // Flag the module as loaded
44/******/ module.l = true;
45/******/
46/******/ // Return the exports of the module
47/******/ return module.exports;
48/******/ }
49/******/
50/******/
51/******/ // expose the modules object (__webpack_modules__)
52/******/ __webpack_require__.m = modules;
53/******/
54/******/ // expose the module cache
55/******/ __webpack_require__.c = installedModules;
56/******/
57/******/ // define getter function for harmony exports
58/******/ __webpack_require__.d = function(exports, name, getter) {
59/******/ if(!__webpack_require__.o(exports, name)) {
60/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
61/******/ }
62/******/ };
63/******/
64/******/ // define __esModule on exports
65/******/ __webpack_require__.r = function(exports) {
66/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
67/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
68/******/ }
69/******/ Object.defineProperty(exports, '__esModule', { value: true });
70/******/ };
71/******/
72/******/ // create a fake namespace object
73/******/ // mode & 1: value is a module id, require it
74/******/ // mode & 2: merge all properties of value into the ns
75/******/ // mode & 4: return value when already ns object
76/******/ // mode & 8|1: behave like require
77/******/ __webpack_require__.t = function(value, mode) {
78/******/ if(mode & 1) value = __webpack_require__(value);
79/******/ if(mode & 8) return value;
80/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
81/******/ var ns = Object.create(null);
82/******/ __webpack_require__.r(ns);
83/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
84/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
85/******/ return ns;
86/******/ };
87/******/
88/******/ // getDefaultExport function for compatibility with non-harmony modules
89/******/ __webpack_require__.n = function(module) {
90/******/ var getter = module && module.__esModule ?
91/******/ function getDefault() { return module['default']; } :
92/******/ function getModuleExports() { return module; };
93/******/ __webpack_require__.d(getter, 'a', getter);
94/******/ return getter;
95/******/ };
96/******/
97/******/ // Object.prototype.hasOwnProperty.call
98/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
99/******/
100/******/ // __webpack_public_path__
101/******/ __webpack_require__.p = "";
102/******/
103/******/
104/******/ // Load entry module and return exports
105/******/ return __webpack_require__(__webpack_require__.s = 5);
106/******/ })
107/************************************************************************/
108/******/ ([
109/* 0 */
110/***/ (function(module, exports, __webpack_require__) {
111
112"use strict";
113
114Object.defineProperty(exports, "__esModule", { value: true });
115var defaultsDocument = null;
116var previousTableState;
117var tableState = null;
118exports.globalDefaults = {};
119exports.documentDefaults = {};
120function default_1() {
121 return tableState;
122}
123exports.default = default_1;
124function getGlobalOptions() {
125 return exports.globalDefaults;
126}
127exports.getGlobalOptions = getGlobalOptions;
128function getDocumentOptions() {
129 return exports.documentDefaults;
130}
131exports.getDocumentOptions = getDocumentOptions;
132var TableState = /** @class */ (function () {
133 function TableState(doc) {
134 this.doc = doc;
135 }
136 TableState.prototype.pageHeight = function () {
137 return this.pageSize().height;
138 };
139 ;
140 TableState.prototype.pageWidth = function () {
141 return this.pageSize().width;
142 };
143 ;
144 TableState.prototype.pageSize = function () {
145 var pageSize = this.doc.internal.pageSize;
146 // JSPDF 1.4 uses get functions instead of properties on pageSize
147 if (pageSize.width == null) {
148 pageSize = {
149 width: pageSize.getWidth(),
150 height: pageSize.getHeight()
151 };
152 }
153 return pageSize;
154 };
155 ;
156 TableState.prototype.scaleFactor = function () {
157 return this.doc.internal.scaleFactor;
158 };
159 ;
160 TableState.prototype.pageNumber = function () {
161 return this.doc.internal.getCurrentPageInfo().pageNumber;
162 };
163 return TableState;
164}());
165function setupState(doc) {
166 previousTableState = tableState;
167 tableState = new TableState(doc);
168 if (doc !== defaultsDocument) {
169 defaultsDocument = doc;
170 exports.documentDefaults = {};
171 }
172}
173exports.setupState = setupState;
174function resetState() {
175 tableState = previousTableState;
176}
177exports.resetState = resetState;
178function setDefaults(defaults, doc) {
179 if (doc === void 0) { doc = null; }
180 if (doc) {
181 exports.documentDefaults = defaults || {};
182 defaultsDocument = doc;
183 }
184 else {
185 exports.globalDefaults = defaults || {};
186 }
187}
188exports.setDefaults = setDefaults;
189
190
191/***/ }),
192/* 1 */
193/***/ (function(module, exports, __webpack_require__) {
194
195"use strict";
196
197Object.defineProperty(exports, "__esModule", { value: true });
198var config_1 = __webpack_require__(2);
199var state_1 = __webpack_require__(0);
200var polyfills_1 = __webpack_require__(3);
201function getStringWidth(text, styles) {
202 var fontSize = styles.fontSize / state_1.default().scaleFactor();
203 applyStyles(styles);
204 text = Array.isArray(text) ? text : [text];
205 var maxWidth = 0;
206 text.forEach(function (line) {
207 var width = state_1.default().doc.getStringUnitWidth(line);
208 if (width > maxWidth) {
209 maxWidth = width;
210 }
211 });
212 var precision = 10000 * state_1.default().scaleFactor();
213 maxWidth = Math.floor(maxWidth * precision) / precision;
214 return maxWidth * fontSize;
215}
216exports.getStringWidth = getStringWidth;
217/**
218 * Ellipsize the text to fit in the width
219 */
220function ellipsize(text, width, styles, ellipsizeStr) {
221 if (ellipsizeStr === void 0) { ellipsizeStr = '...'; }
222 if (Array.isArray(text)) {
223 var value_1 = [];
224 text.forEach(function (str, i) {
225 value_1[i] = ellipsize(str, width, styles, ellipsizeStr);
226 });
227 return value_1;
228 }
229 var precision = 10000 * state_1.default().scaleFactor();
230 width = Math.ceil(width * precision) / precision;
231 if (width >= getStringWidth(text, styles)) {
232 return text;
233 }
234 while (width < getStringWidth(text + ellipsizeStr, styles)) {
235 if (text.length <= 1) {
236 break;
237 }
238 text = text.substring(0, text.length - 1);
239 }
240 return text.trim() + ellipsizeStr;
241}
242exports.ellipsize = ellipsize;
243function addTableBorder() {
244 var table = state_1.default().table;
245 var styles = { lineWidth: table.settings.tableLineWidth, lineColor: table.settings.tableLineColor };
246 applyStyles(styles);
247 var fs = getFillStyle(styles);
248 if (fs) {
249 state_1.default().doc.rect(table.pageStartX, table.pageStartY, table.width, table.cursor.y - table.pageStartY, fs);
250 }
251}
252exports.addTableBorder = addTableBorder;
253function getFillStyle(styles) {
254 var drawLine = styles.lineWidth > 0;
255 var drawBackground = styles.fillColor || styles.fillColor === 0;
256 if (drawLine && drawBackground) {
257 return 'DF'; // Fill then stroke
258 }
259 else if (drawLine) {
260 return 'S'; // Only stroke (transparent background)
261 }
262 else if (drawBackground) {
263 return 'F'; // Only fill, no stroke
264 }
265 else {
266 return false;
267 }
268}
269exports.getFillStyle = getFillStyle;
270function applyUserStyles() {
271 applyStyles(state_1.default().table.userStyles);
272}
273exports.applyUserStyles = applyUserStyles;
274function applyStyles(styles) {
275 var doc = state_1.default().doc;
276 var styleModifiers = {
277 fillColor: doc.setFillColor,
278 textColor: doc.setTextColor,
279 fontStyle: doc.setFontStyle,
280 lineColor: doc.setDrawColor,
281 lineWidth: doc.setLineWidth,
282 font: doc.setFont,
283 fontSize: doc.setFontSize
284 };
285 Object.keys(styleModifiers).forEach(function (name) {
286 var style = styles[name];
287 var modifier = styleModifiers[name];
288 if (typeof style !== 'undefined') {
289 if (Array.isArray(style)) {
290 modifier.apply(this, style);
291 }
292 else {
293 modifier(style);
294 }
295 }
296 });
297}
298exports.applyStyles = applyStyles;
299// This is messy, only keep array and number format the next major version
300function marginOrPadding(value, defaultValue) {
301 var newValue = {};
302 if (Array.isArray(value)) {
303 if (value.length >= 4) {
304 newValue = { 'top': value[0], 'right': value[1], 'bottom': value[2], 'left': value[3] };
305 }
306 else if (value.length === 3) {
307 newValue = { 'top': value[0], 'right': value[1], 'bottom': value[2], 'left': value[1] };
308 }
309 else if (value.length === 2) {
310 newValue = { 'top': value[0], 'right': value[1], 'bottom': value[0], 'left': value[1] };
311 }
312 else if (value.length === 1) {
313 value = value[0];
314 }
315 else {
316 value = defaultValue;
317 }
318 }
319 else if (typeof value === 'object') {
320 if (value['vertical']) {
321 value['top'] = value['vertical'];
322 value['bottom'] = value['vertical'];
323 }
324 if (value['horizontal']) {
325 value['right'] = value['horizontal'];
326 value['left'] = value['horizontal'];
327 }
328 for (var _i = 0, _a = ['top', 'right', 'bottom', 'left']; _i < _a.length; _i++) {
329 var side = _a[_i];
330 newValue[side] = (value[side] || value[side] === 0) ? value[side] : defaultValue;
331 }
332 }
333 if (typeof value === 'number') {
334 newValue = { 'top': value, 'right': value, 'bottom': value, 'left': value };
335 }
336 return newValue;
337}
338exports.marginOrPadding = marginOrPadding;
339function styles(styles) {
340 styles = Array.isArray(styles) ? styles : [styles];
341 return polyfills_1.assign.apply(void 0, [config_1.defaultStyles()].concat(styles));
342}
343exports.styles = styles;
344
345
346/***/ }),
347/* 2 */
348/***/ (function(module, exports, __webpack_require__) {
349
350"use strict";
351
352Object.defineProperty(exports, "__esModule", { value: true });
353/**
354 * Ratio between font size and font height. The number comes from jspdf's source code
355 */
356exports.FONT_ROW_RATIO = 1.15;
357var state_1 = __webpack_require__(0);
358function defaultConfig() {
359 return {
360 // Html content
361 html: null,
362 // Custom content
363 head: null,
364 body: null,
365 foot: null,
366 // Properties
367 includeHiddenHtml: false,
368 startY: null,
369 margin: 40 / state_1.default().scaleFactor(),
370 pageBreak: 'auto',
371 rowPageBreak: 'auto',
372 tableWidth: 'auto',
373 showHead: 'everyPage',
374 showFoot: 'everyPage',
375 tableLineWidth: 0,
376 tableLineColor: 200,
377 tableId: null,
378 // Styling
379 theme: 'striped',
380 useCss: false,
381 styles: {},
382 headStyles: {},
383 bodyStyles: {},
384 footStyles: {},
385 alternateRowStyles: {},
386 columnStyles: {},
387 // Hooks
388 // Use to change the content of the cell before width calculations etc are performed
389 didParseCell: function (data) {
390 },
391 willDrawCell: function (data) {
392 },
393 // Use to draw additional content such as images in table cells
394 didDrawCell: function (data) {
395 },
396 // Use to draw additional content to each page such as headers and footers
397 didDrawPage: function (data) {
398 },
399 };
400}
401exports.defaultConfig = defaultConfig;
402// Base style for all themes
403function defaultStyles() {
404 return {
405 font: "helvetica",
406 fontStyle: 'normal',
407 overflow: 'linebreak',
408 fillColor: false,
409 textColor: 20,
410 halign: 'left',
411 valign: 'top',
412 fontSize: 10,
413 cellPadding: 5 / state_1.default().scaleFactor(),
414 lineColor: 200,
415 lineWidth: 0 / state_1.default().scaleFactor(),
416 cellWidth: 'auto',
417 minCellHeight: 0
418 };
419}
420exports.defaultStyles = defaultStyles;
421/**
422 * Styles for the themes (overriding the default styles)
423 */
424function getTheme(name) {
425 var themes = {
426 'striped': {
427 table: { fillColor: 255, textColor: 80, fontStyle: 'normal' },
428 head: { textColor: 255, fillColor: [41, 128, 185], fontStyle: 'bold' },
429 body: {},
430 foot: { textColor: 255, fillColor: [41, 128, 185], fontStyle: 'bold' },
431 alternateRow: { fillColor: 245 }
432 },
433 'grid': {
434 table: { fillColor: 255, textColor: 80, fontStyle: 'normal', lineWidth: 0.1 },
435 head: { textColor: 255, fillColor: [26, 188, 156], fontStyle: 'bold', lineWidth: 0 },
436 body: {},
437 foot: { textColor: 255, fillColor: [26, 188, 156], fontStyle: 'bold', lineWidth: 0 },
438 alternateRow: {}
439 },
440 'plain': {
441 head: { fontStyle: 'bold' },
442 foot: { fontStyle: 'bold' }
443 }
444 };
445 return themes[name];
446}
447exports.getTheme = getTheme;
448
449
450/***/ }),
451/* 3 */
452/***/ (function(module, exports, __webpack_require__) {
453
454"use strict";
455
456/*
457 * Include common small polyfills instead of requiring the user to to do it
458 */
459Object.defineProperty(exports, "__esModule", { value: true });
460// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
461function assign(target) {
462 'use strict';
463 var varArgs = [];
464 for (var _i = 1; _i < arguments.length; _i++) {
465 varArgs[_i - 1] = arguments[_i];
466 }
467 if (target == null) { // TypeError if undefined or null
468 throw new TypeError('Cannot convert undefined or null to object');
469 }
470 var to = Object(target);
471 for (var index = 1; index < arguments.length; index++) {
472 var nextSource = arguments[index];
473 if (nextSource != null) { // Skip over if undefined or null
474 for (var nextKey in nextSource) {
475 // Avoid bugs when hasOwnProperty is shadowed
476 if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
477 to[nextKey] = nextSource[nextKey];
478 }
479 }
480 }
481 }
482 return to;
483}
484exports.assign = assign;
485
486
487/***/ }),
488/* 4 */
489/***/ (function(module, exports) {
490
491module.exports = __WEBPACK_EXTERNAL_MODULE__4__;
492
493/***/ }),
494/* 5 */
495/***/ (function(module, exports, __webpack_require__) {
496
497"use strict";
498
499Object.defineProperty(exports, "__esModule", { value: true });
500var tableDrawer_1 = __webpack_require__(6);
501var widthCalculator_1 = __webpack_require__(7);
502var inputParser_1 = __webpack_require__(8);
503var state_1 = __webpack_require__(0);
504__webpack_require__(15);
505var common_1 = __webpack_require__(1);
506var jsPDF = __webpack_require__(4);
507jsPDF.API.autoTable = function () {
508 state_1.setupState(this);
509 // 1. Parse and unify user input
510 var table = inputParser_1.parseInput(arguments);
511 // 2. Calculate preliminary table, column, row and cell dimensions
512 widthCalculator_1.calculateWidths(table);
513 // 3. Output table to pdf
514 tableDrawer_1.drawTable(table);
515 table.finalY = table.cursor.y;
516 this.previousAutoTable = table;
517 this.lastAutoTable = table;
518 this.autoTable.previous = table; // Deprecated
519 common_1.applyUserStyles();
520 state_1.resetState();
521 return this;
522};
523// Assign false to enable `doc.lastAutoTable.finalY || 40` sugar;
524jsPDF.API.lastAutoTable = false;
525jsPDF.API.previousAutoTable = false; // deprecated in v3
526jsPDF.API.autoTable.previous = false; // deprecated in v3
527jsPDF.API.autoTableSetDefaults = function (defaults) {
528 state_1.setDefaults(defaults, this);
529 return this;
530};
531jsPDF.autoTableSetDefaults = function (defaults, doc) {
532 state_1.setDefaults(defaults, doc);
533 return this;
534};
535/**
536 * @Deprecated. Use html option instead doc.autoTable(html: '#table')
537 */
538jsPDF.API.autoTableHtmlToJson = function (tableElem, includeHiddenElements) {
539 console.error("Use of deprecated function: autoTableHtmlToJson. Use html option instead.");
540 includeHiddenElements = includeHiddenElements || false;
541 if (!tableElem || !(tableElem instanceof HTMLTableElement)) {
542 console.error("A HTMLTableElement has to be sent to autoTableHtmlToJson");
543 return null;
544 }
545 var columns = {}, rows = [];
546 var header = tableElem.rows[0];
547 for (var i = 0; i < header.cells.length; i++) {
548 var cell = header.cells[i];
549 var style = window.getComputedStyle(cell);
550 if (includeHiddenElements || style.display !== 'none') {
551 columns[i] = cell;
552 }
553 }
554 var _loop_1 = function (i) {
555 var tableRow = tableElem.rows[i];
556 var style = window.getComputedStyle(tableRow);
557 if (includeHiddenElements || style.display !== 'none') {
558 var rowData_1 = [];
559 Object.keys(columns).forEach(function (key) {
560 var cell = tableRow.cells[key];
561 rowData_1.push(cell);
562 });
563 rows.push(rowData_1);
564 }
565 };
566 for (var i = 1; i < tableElem.rows.length; i++) {
567 _loop_1(i);
568 }
569 var values = Object.keys(columns).map(function (key) {
570 return columns[key];
571 });
572 return { columns: values, rows: rows, data: rows };
573};
574/**
575 * @deprecated
576 */
577jsPDF.API.autoTableEndPosY = function () {
578 console.error("Use of deprecated function: autoTableEndPosY. Use doc.previousAutoTable.finalY instead.");
579 var prev = this.previousAutoTable;
580 if (prev.cursor && typeof prev.cursor.y === 'number') {
581 return prev.cursor.y;
582 }
583 else {
584 return 0;
585 }
586};
587/**
588 * @deprecated
589 */
590jsPDF.API.autoTableAddPageContent = function (hook) {
591 console.error("Use of deprecated function: autoTableAddPageContent. Use jsPDF.autoTableSetDefaults({didDrawPage: () => {}}) instead.");
592 if (!jsPDF.API.autoTable.globalDefaults) {
593 jsPDF.API.autoTable.globalDefaults = {};
594 }
595 jsPDF.API.autoTable.globalDefaults.addPageContent = hook;
596 return this;
597};
598/**
599 * @deprecated
600 */
601jsPDF.API.autoTableAddPage = function () {
602 console.error("Use of deprecated function: autoTableAddPage. Use doc.addPage()");
603 this.addPage();
604 return this;
605};
606
607
608/***/ }),
609/* 6 */
610/***/ (function(module, exports, __webpack_require__) {
611
612"use strict";
613
614Object.defineProperty(exports, "__esModule", { value: true });
615var config_1 = __webpack_require__(2);
616var common_1 = __webpack_require__(1);
617var state_1 = __webpack_require__(0);
618function drawTable(table) {
619 var settings = table.settings;
620 table.cursor = {
621 x: table.margin('left'),
622 y: settings.startY == null ? table.margin('top') : settings.startY
623 };
624 var minTableBottomPos = settings.startY + table.margin('bottom') + table.headHeight + table.footHeight;
625 if (settings.pageBreak === 'avoid') {
626 minTableBottomPos += table.height;
627 }
628 if (settings.pageBreak === 'always' || settings.startY != null && settings.startY !== false && minTableBottomPos > state_1.default().pageHeight()) {
629 nextPage(state_1.default().doc);
630 table.cursor.y = table.margin('top');
631 }
632 table.pageStartX = table.cursor.x;
633 table.pageStartY = table.cursor.y;
634 table.startPageNumber = state_1.default().pageNumber();
635 common_1.applyUserStyles();
636 if (settings.showHead === true || settings.showHead === 'firstPage' || settings.showHead === 'everyPage') {
637 table.head.forEach(function (row) { return printRow(row); });
638 }
639 common_1.applyUserStyles();
640 table.body.forEach(function (row) {
641 printFullRow(row);
642 });
643 common_1.applyUserStyles();
644 if (settings.showFoot === true || settings.showFoot === 'lastPage' || settings.showFoot === 'everyPage') {
645 table.foot.forEach(function (row) { return printRow(row); });
646 }
647 common_1.addTableBorder();
648 table.callEndPageHooks();
649}
650exports.drawTable = drawTable;
651function printFullRow(row) {
652 var remainingRowHeight = 0;
653 var remainingTexts = {};
654 var table = state_1.default().table;
655 if (!canFitOnPage(row.maxCellHeight)) {
656 if (row.maxCellLineCount <= 1 || (table.settings.rowPageBreak === 'avoid' && !rowHeightGreaterThanMaxTableHeight(row))) {
657 addPage();
658 }
659 else {
660 // Modify the row to fit the current page and calculate text and height of partial row
661 row.spansMultiplePages = true;
662 var maxCellHeight = 0;
663 var maxRowSpanCellHeight = 0;
664 for (var j = 0; j < table.columns.length; j++) {
665 var column = table.columns[j];
666 var cell = row.cells[column.dataKey];
667 if (!cell) {
668 continue;
669 }
670 var fontHeight = cell.styles.fontSize / state_1.default().scaleFactor() * config_1.FONT_ROW_RATIO;
671 var vPadding = cell.padding('vertical');
672 var pageHeight = state_1.default().pageHeight();
673 var remainingPageSpace = pageHeight - table.cursor.y - table.margin('bottom');
674 var remainingLineCount = Math.floor((remainingPageSpace - vPadding) / fontHeight);
675 if (Array.isArray(cell.text) && cell.text.length > remainingLineCount) {
676 var remainingLines = cell.text.splice(remainingLineCount, cell.text.length);
677 remainingTexts[column.dataKey] = remainingLines;
678 var cellHeight = cell.text.length * fontHeight + vPadding;
679 if (cellHeight > maxCellHeight) {
680 maxCellHeight = cellHeight;
681 }
682 var rCellHeight = remainingLines.length * fontHeight + vPadding;
683 if (rCellHeight > remainingRowHeight) {
684 remainingRowHeight = rCellHeight;
685 }
686 }
687 }
688 for (var j = 0; j < table.columns.length; j++) {
689 var column = table.columns[j];
690 var cell = row.cells[column.dataKey];
691 cell.height = maxCellHeight;
692 }
693 // Reset row height since text are now removed
694 row.height = maxCellHeight;
695 row.maxCellHeight = maxRowSpanCellHeight;
696 }
697 }
698 printRow(row);
699 // Parts of the row is now printed. Time for adding a new page, prune
700 // the text and start over
701 if (Object.keys(remainingTexts).length > 0) {
702 for (var j = 0; j < table.columns.length; j++) {
703 var col = table.columns[j];
704 var cell = row.cells[col.dataKey];
705 cell.height = remainingRowHeight;
706 if (cell) {
707 cell.text = remainingTexts[col.dataKey] || '';
708 }
709 }
710 addPage();
711 row.pageNumber++;
712 row.height = remainingRowHeight;
713 printFullRow(row);
714 }
715}
716function rowHeightGreaterThanMaxTableHeight(row) {
717 var table = state_1.default().table;
718 var pageHeight = state_1.default().pageHeight();
719 var maxTableHeight = pageHeight - table.margin('top') - table.margin('bottom');
720 return row.maxCellHeight > maxTableHeight;
721}
722function printRow(row) {
723 var table = state_1.default().table;
724 table.cursor.x = table.margin('left');
725 row.y = table.cursor.y;
726 row.x = table.cursor.x;
727 // For backwards compatibility reset those after addingRow event
728 table.cursor.x = table.margin('left');
729 row.y = table.cursor.y;
730 row.x = table.cursor.x;
731 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) {
732 var column = _a[_i];
733 var cell = row.cells[column.dataKey];
734 if (!cell) {
735 table.cursor.x += column.width;
736 continue;
737 }
738 common_1.applyStyles(cell.styles);
739 cell.x = table.cursor.x;
740 cell.y = row.y;
741 if (cell.styles.valign === 'top') {
742 cell.textPos.y = table.cursor.y + cell.padding('top');
743 }
744 else if (cell.styles.valign === 'bottom') {
745 cell.textPos.y = table.cursor.y + cell.height - cell.padding('bottom');
746 }
747 else {
748 cell.textPos.y = table.cursor.y + cell.height / 2;
749 }
750 if (cell.styles.halign === 'right') {
751 cell.textPos.x = cell.x + cell.width - cell.padding('right');
752 }
753 else if (cell.styles.halign === 'center') {
754 cell.textPos.x = cell.x + cell.width / 2;
755 }
756 else {
757 cell.textPos.x = cell.x + cell.padding('left');
758 }
759 if (table.callCellHooks(table.cellHooks.willDrawCell, cell, row, column) === false) {
760 table.cursor.x += column.width;
761 continue;
762 }
763 var fillStyle = common_1.getFillStyle(cell.styles);
764 if (fillStyle) {
765 state_1.default().doc.rect(cell.x, table.cursor.y, cell.width, cell.height, fillStyle);
766 }
767 state_1.default().doc.autoTableText(cell.text, cell.textPos.x, cell.textPos.y, {
768 halign: cell.styles.halign,
769 valign: cell.styles.valign,
770 maxWidth: cell.width - cell.padding('left') - cell.padding('right')
771 });
772 table.callCellHooks(table.cellHooks.didDrawCell, cell, row, column);
773 table.cursor.x += column.width;
774 }
775 table.cursor.y += row.height;
776}
777function canFitOnPage(rowHeight) {
778 var table = state_1.default().table;
779 var bottomContentHeight = table.margin('bottom');
780 var showFoot = table.settings.showFoot;
781 if (showFoot === true || showFoot === 'everyPage' || showFoot === 'lastPage') {
782 bottomContentHeight += table.footHeight;
783 }
784 var pos = rowHeight + table.cursor.y + bottomContentHeight;
785 return pos < state_1.default().pageHeight();
786}
787function addPage() {
788 var table = state_1.default().table;
789 common_1.applyUserStyles();
790 if (table.settings.showFoot === true || table.settings.showFoot === 'everyPage') {
791 table.foot.forEach(function (row) { return printRow(row); });
792 }
793 table.finalY = table.cursor.y;
794 // Add user content just before adding new page ensure it will
795 // be drawn above other things on the page
796 table.callEndPageHooks();
797 common_1.addTableBorder();
798 nextPage(state_1.default().doc);
799 table.pageNumber++;
800 table.cursor = { x: table.margin('left'), y: table.margin('top') };
801 table.pageStartX = table.cursor.x;
802 table.pageStartY = table.cursor.y;
803 if (table.settings.showHead === true || table.settings.showHead === 'everyPage') {
804 table.head.forEach(function (row) { return printRow(row); });
805 }
806}
807exports.addPage = addPage;
808function nextPage(doc) {
809 var current = state_1.default().pageNumber();
810 doc.setPage(current + 1);
811 var newCurrent = state_1.default().pageNumber();
812 if (newCurrent === current) {
813 doc.addPage();
814 }
815}
816
817
818/***/ }),
819/* 7 */
820/***/ (function(module, exports, __webpack_require__) {
821
822"use strict";
823
824Object.defineProperty(exports, "__esModule", { value: true });
825var config_1 = __webpack_require__(2);
826var common_1 = __webpack_require__(1);
827var state_1 = __webpack_require__(0);
828/**
829 * Calculate the column widths
830 */
831function calculateWidths(table) {
832 // TODO Fix those cases
833 var columnMinWidth = 10 / state_1.default().scaleFactor();
834 if (columnMinWidth * table.columns.length > table.width) {
835 console.error('Columns could not fit on page');
836 }
837 else if (table.minWidth > table.width) {
838 console.error("Column widths to wide and can't fit page");
839 }
840 var copy = table.columns.slice(0);
841 var diffWidth = table.width - table.wrappedWidth;
842 distributeWidth(copy, diffWidth, table.wrappedWidth);
843 applyColSpans(table);
844 fitContent(table);
845 applyRowSpans(table);
846}
847exports.calculateWidths = calculateWidths;
848function applyRowSpans(table) {
849 var rowSpanCells = {};
850 var colRowSpansLeft = 1;
851 var all = table.allRows();
852 for (var rowIndex = 0; rowIndex < all.length; rowIndex++) {
853 var row = all[rowIndex];
854 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) {
855 var column = _a[_i];
856 var data = rowSpanCells[column.dataKey];
857 if (colRowSpansLeft > 1) {
858 colRowSpansLeft--;
859 delete row.cells[column.dataKey];
860 }
861 else if (data) {
862 data.cell.height += row.height;
863 if (data.cell.height > row.maxCellHeight) {
864 data.row.maxCellHeight = data.cell.height;
865 data.row.maxCellLineCount = Array.isArray(data.cell.text) ? data.cell.text.length : 1;
866 }
867 colRowSpansLeft = data.cell.colSpan;
868 delete row.cells[column.dataKey];
869 data.left--;
870 if (data.left <= 1) {
871 delete rowSpanCells[column.dataKey];
872 }
873 }
874 else {
875 var cell = row.cells[column.dataKey];
876 if (!cell) {
877 continue;
878 }
879 cell.height = row.height;
880 if (cell.rowSpan > 1) {
881 var remaining = all.length - rowIndex;
882 var left = cell.rowSpan > remaining ? remaining : cell.rowSpan;
883 rowSpanCells[column.dataKey] = { cell: cell, left: left, row: row };
884 }
885 }
886 }
887 if (row.section === 'head') {
888 table.headHeight += row.maxCellHeight;
889 }
890 if (row.section === 'foot') {
891 table.footHeight += row.maxCellHeight;
892 }
893 table.height += row.height;
894 }
895}
896function applyColSpans(table) {
897 var all = table.allRows();
898 for (var rowIndex = 0; rowIndex < all.length; rowIndex++) {
899 var row = all[rowIndex];
900 var colSpanCell = null;
901 var combinedColSpanWidth = 0;
902 var colSpansLeft = 0;
903 for (var columnIndex = 0; columnIndex < table.columns.length; columnIndex++) {
904 var column = table.columns[columnIndex];
905 var cell = null;
906 // Width and colspan
907 colSpansLeft -= 1;
908 if (colSpansLeft > 1 && table.columns[columnIndex + 1]) {
909 combinedColSpanWidth += column.width;
910 delete row.cells[column.dataKey];
911 continue;
912 }
913 else if (colSpanCell) {
914 cell = colSpanCell;
915 delete row.cells[column.dataKey];
916 colSpanCell = null;
917 }
918 else {
919 cell = row.cells[column.dataKey];
920 if (!cell)
921 continue;
922 colSpansLeft = cell.colSpan;
923 combinedColSpanWidth = 0;
924 if (cell.colSpan > 1) {
925 colSpanCell = cell;
926 combinedColSpanWidth += column.width;
927 continue;
928 }
929 }
930 cell.width = column.width + combinedColSpanWidth;
931 }
932 }
933}
934function fitContent(table) {
935 for (var _i = 0, _a = table.allRows(); _i < _a.length; _i++) {
936 var row = _a[_i];
937 for (var _b = 0, _c = table.columns; _b < _c.length; _b++) {
938 var column = _c[_b];
939 var cell = row.cells[column.dataKey];
940 if (!cell)
941 continue;
942 common_1.applyStyles(cell.styles);
943 var textSpace = cell.width - cell.padding('horizontal');
944 if (cell.styles.overflow === 'linebreak') {
945 cell.text = Array.isArray(cell.text) ? cell.text.join(' ') : cell.text;
946 // Add one pt to textSpace to fix rounding error
947 cell.text = state_1.default().doc.splitTextToSize(cell.text, textSpace + 1 / (state_1.default().scaleFactor() || 1), { fontSize: cell.styles.fontSize });
948 }
949 else if (cell.styles.overflow === 'ellipsize') {
950 cell.text = common_1.ellipsize(cell.text, textSpace, cell.styles);
951 }
952 else if (cell.styles.overflow === 'hidden') {
953 cell.text = common_1.ellipsize(cell.text, textSpace, cell.styles, '');
954 }
955 else if (typeof cell.styles.overflow === 'function') {
956 cell.text = cell.styles.overflow(cell.text, textSpace);
957 }
958 var lineCount = Array.isArray(cell.text) ? cell.text.length : 1;
959 lineCount = cell.rowSpan <= 1 ? lineCount : 1;
960 var fontHeight = cell.styles.fontSize / state_1.default().scaleFactor() * config_1.FONT_ROW_RATIO;
961 cell.contentHeight = lineCount * fontHeight + cell.padding('vertical');
962 if (cell.styles.minCellHeight > cell.contentHeight) {
963 cell.contentHeight = cell.styles.minCellHeight;
964 }
965 if (cell.contentHeight > row.height) {
966 row.height = cell.contentHeight;
967 row.maxCellHeight = cell.contentHeight;
968 row.maxCellLineCount = lineCount;
969 }
970 }
971 }
972}
973function distributeWidth(autoColumns, diffWidth, wrappedAutoColumnsWidth) {
974 for (var i = 0; i < autoColumns.length; i++) {
975 var column = autoColumns[i];
976 var ratio = column.wrappedWidth / wrappedAutoColumnsWidth;
977 var suggestedChange = diffWidth * ratio;
978 var suggestedWidth = column.wrappedWidth + suggestedChange;
979 if (suggestedWidth >= column.minWidth) {
980 column.width = suggestedWidth;
981 }
982 else {
983 // We can't reduce the width of this column. Mark as none auto column and start over
984 // Add 1 to minWidth as linebreaks calc otherwise sometimes made two rows
985 column.width = column.minWidth + 1 / state_1.default().scaleFactor();
986 wrappedAutoColumnsWidth -= column.wrappedWidth;
987 autoColumns.splice(i, 1);
988 distributeWidth(autoColumns, diffWidth, wrappedAutoColumnsWidth);
989 break;
990 }
991 }
992}
993
994
995/***/ }),
996/* 8 */
997/***/ (function(module, exports, __webpack_require__) {
998
999"use strict";
1000
1001var __assign = (this && this.__assign) || function () {
1002 __assign = Object.assign || function(t) {
1003 for (var s, i = 1, n = arguments.length; i < n; i++) {
1004 s = arguments[i];
1005 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
1006 t[p] = s[p];
1007 }
1008 return t;
1009 };
1010 return __assign.apply(this, arguments);
1011};
1012Object.defineProperty(exports, "__esModule", { value: true });
1013var models_1 = __webpack_require__(9);
1014var config_1 = __webpack_require__(2);
1015var htmlParser_1 = __webpack_require__(12);
1016var polyfills_1 = __webpack_require__(3);
1017var common_1 = __webpack_require__(1);
1018var state_1 = __webpack_require__(0);
1019var inputValidator_1 = __webpack_require__(14);
1020/**
1021 * Create models from the user input
1022 */
1023function parseInput(args) {
1024 var tableOptions = parseUserArguments(args);
1025 var globalOptions = state_1.getGlobalOptions();
1026 var documentOptions = state_1.getDocumentOptions();
1027 var allOptions = [globalOptions, documentOptions, tableOptions];
1028 inputValidator_1.default(allOptions);
1029 var table = new models_1.Table();
1030 state_1.default().table = table;
1031 table.id = tableOptions.tableId;
1032 var doc = state_1.default().doc;
1033 table.userStyles = {
1034 // Setting to black for versions of jspdf without getTextColor
1035 textColor: doc.getTextColor ? doc.getTextColor() : 0,
1036 fontSize: doc.internal.getFontSize(),
1037 fontStyle: doc.internal.getFont().fontStyle,
1038 font: doc.internal.getFont().fontName
1039 };
1040 var _loop_1 = function (styleProp) {
1041 var styles = allOptions.map(function (opts) { return opts[styleProp] || {}; });
1042 table.styles[styleProp] = polyfills_1.assign.apply(void 0, [{}].concat(styles));
1043 };
1044 // Merge styles one level deeper
1045 for (var _i = 0, _a = Object.keys(table.styles); _i < _a.length; _i++) {
1046 var styleProp = _a[_i];
1047 _loop_1(styleProp);
1048 }
1049 // Append hooks
1050 for (var _b = 0, allOptions_1 = allOptions; _b < allOptions_1.length; _b++) {
1051 var opts = allOptions_1[_b];
1052 for (var _c = 0, _d = Object.keys(table.cellHooks); _c < _d.length; _c++) {
1053 var hookName = _d[_c];
1054 if (opts && typeof opts[hookName] === 'function') {
1055 table.cellHooks[hookName].push(opts[hookName]);
1056 delete opts[hookName];
1057 }
1058 }
1059 }
1060 table.settings = polyfills_1.assign.apply(void 0, [{}, config_1.defaultConfig()].concat(allOptions));
1061 table.settings.margin = common_1.marginOrPadding(table.settings.margin, config_1.defaultConfig().margin);
1062 if (table.settings.theme === 'auto') {
1063 table.settings.theme = table.settings.useCss ? 'plain' : 'striped';
1064 }
1065 if (table.settings.startY === false) {
1066 delete table.settings.startY;
1067 }
1068 var previous = state_1.default().doc.previousAutoTable;
1069 var isSamePageAsPrevious = previous && previous.startPageNumber + previous.pageNumber - 1 === state_1.default().pageNumber();
1070 if (table.settings.startY == null && isSamePageAsPrevious) {
1071 table.settings.startY = previous.finalY + 20 / state_1.default().scaleFactor();
1072 }
1073 var htmlContent = {};
1074 if (table.settings.html) {
1075 htmlContent = htmlParser_1.parseHtml(table.settings.html, table.settings.includeHiddenHtml, table.settings.useCss) || {};
1076 }
1077 table.settings.head = htmlContent.head || table.settings.head || [];
1078 table.settings.body = htmlContent.body || table.settings.body || [];
1079 table.settings.foot = htmlContent.foot || table.settings.foot || [];
1080 parseContent(table);
1081 table.minWidth = table.columns.reduce(function (total, col) { return (total + col.minWidth); }, 0);
1082 table.wrappedWidth = table.columns.reduce(function (total, col) { return (total + col.wrappedWidth); }, 0);
1083 if (typeof table.settings.tableWidth === 'number') {
1084 table.width = table.settings.tableWidth;
1085 }
1086 else if (table.settings.tableWidth === 'wrap') {
1087 table.width = table.wrappedWidth;
1088 }
1089 else {
1090 table.width = state_1.default().pageWidth() - table.margin('left') - table.margin('right');
1091 }
1092 return table;
1093}
1094exports.parseInput = parseInput;
1095function parseUserArguments(args) {
1096 // Normal initialization on format doc.autoTable(options)
1097 if (args.length === 1) {
1098 return args[0];
1099 }
1100 else {
1101 // Deprecated initialization on format doc.autoTable(columns, body, [options])
1102 var opts = args[2] || {};
1103 opts.body = args[1];
1104 opts.columns = args[0];
1105 // Support v2 title prop in v3
1106 opts.columns.forEach(function (col) {
1107 if (col.header == null) {
1108 col.header = col.title;
1109 }
1110 });
1111 return opts;
1112 }
1113}
1114function parseContent(table) {
1115 var settings = table.settings;
1116 table.columns = getTableColumns(settings);
1117 var _loop_2 = function (sectionName) {
1118 var rowSpansLeftForColumn = {};
1119 var sectionRows = settings[sectionName];
1120 if (sectionRows.length === 0 && settings.columns) {
1121 var sectionRow_1 = {};
1122 table.columns
1123 .forEach(function (col) {
1124 var columnData = col.raw;
1125 if (sectionName === 'head') {
1126 var val = typeof columnData === 'object' ? columnData.header : columnData;
1127 if (val) {
1128 sectionRow_1[col.dataKey] = val;
1129 }
1130 }
1131 else if (sectionName === 'foot' && columnData.footer) {
1132 sectionRow_1[col.dataKey] = columnData.footer;
1133 }
1134 });
1135 if (Object.keys(sectionRow_1).length) {
1136 sectionRows.push(sectionRow_1);
1137 }
1138 }
1139 sectionRows.forEach(function (rawRow, rowIndex) {
1140 var row = new models_1.Row(rawRow, rowIndex, sectionName);
1141 table[sectionName].push(row);
1142 var colSpansAdded = 0;
1143 var columnSpansLeft = 0;
1144 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) {
1145 var column = _a[_i];
1146 if (rowSpansLeftForColumn[column.dataKey] == null || rowSpansLeftForColumn[column.dataKey].left === 0) {
1147 if (columnSpansLeft === 0) {
1148 var rawCell = void 0;
1149 if (Array.isArray(rawRow)) {
1150 rawCell = rawRow[column.dataKey - colSpansAdded];
1151 }
1152 else {
1153 rawCell = rawRow[column.dataKey];
1154 }
1155 var styles = cellStyles(sectionName, column.dataKey, rowIndex);
1156 var cell = new models_1.Cell(rawCell, styles, sectionName);
1157 row.cells[column.dataKey] = cell;
1158 table.callCellHooks(table.cellHooks.didParseCell, cell, row, column);
1159 columnSpansLeft = cell.colSpan - 1;
1160 rowSpansLeftForColumn[column.dataKey] = { left: cell.rowSpan - 1, times: columnSpansLeft };
1161 }
1162 else {
1163 columnSpansLeft--;
1164 colSpansAdded++;
1165 }
1166 }
1167 else {
1168 rowSpansLeftForColumn[column.dataKey].left--;
1169 columnSpansLeft = rowSpansLeftForColumn[column.dataKey].times;
1170 }
1171 }
1172 });
1173 };
1174 for (var _i = 0, _a = ['head', 'body', 'foot']; _i < _a.length; _i++) {
1175 var sectionName = _a[_i];
1176 _loop_2(sectionName);
1177 }
1178 table.allRows().forEach(function (row) {
1179 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) {
1180 var column = _a[_i];
1181 var cell = row.cells[column.dataKey];
1182 // Kind of make sense to not consider width of cells with colspan columns
1183 // Consider this in a future release however
1184 if (cell && cell.colSpan === 1) {
1185 if (cell.wrappedWidth > column.wrappedWidth) {
1186 column.wrappedWidth = cell.wrappedWidth;
1187 }
1188 if (cell.minWidth > column.minWidth) {
1189 column.minWidth = cell.minWidth;
1190 }
1191 }
1192 }
1193 });
1194}
1195function getTableColumns(settings) {
1196 if (settings.columns) {
1197 return settings.columns.map(function (input, index) {
1198 var key = input.dataKey || input.key || index;
1199 var raw = input != null ? input : index;
1200 return new models_1.Column(key, raw, index);
1201 });
1202 }
1203 else {
1204 var merged = __assign({}, settings.head[0], settings.body[0], settings.foot[0]);
1205 delete merged._element;
1206 var dataKeys = Object.keys(merged);
1207 return dataKeys.map(function (key) { return new models_1.Column(key, key, key); });
1208 }
1209}
1210function cellStyles(sectionName, dataKey, rowIndex) {
1211 var table = state_1.default().table;
1212 var theme = config_1.getTheme(table.settings.theme);
1213 var otherStyles = [theme.table, theme[sectionName], table.styles.styles, table.styles[sectionName + "Styles"]];
1214 var colStyles = sectionName === 'body' ? table.styles.columnStyles[dataKey] || {} : {};
1215 var rowStyles = sectionName === 'body' && rowIndex % 2 === 0 ? polyfills_1.assign({}, theme.alternateRow, table.styles.alternateRowStyles) : {};
1216 return polyfills_1.assign.apply(void 0, [config_1.defaultStyles()].concat(otherStyles.concat([rowStyles, colStyles])));
1217}
1218
1219
1220/***/ }),
1221/* 9 */
1222/***/ (function(module, exports, __webpack_require__) {
1223
1224"use strict";
1225
1226Object.defineProperty(exports, "__esModule", { value: true });
1227var config_1 = __webpack_require__(2);
1228var state_1 = __webpack_require__(0);
1229var HookData_1 = __webpack_require__(10);
1230var common_1 = __webpack_require__(1);
1231var assign = __webpack_require__(11);
1232var CellHooks = /** @class */ (function () {
1233 function CellHooks() {
1234 this.willParseCell = [];
1235 this.didParseCell = [];
1236 this.willDrawCell = [];
1237 this.didDrawCell = [];
1238 this.didDrawPage = [];
1239 }
1240 return CellHooks;
1241}());
1242var Table = /** @class */ (function () {
1243 function Table() {
1244 this.columns = [];
1245 this.head = [];
1246 this.body = [];
1247 this.foot = [];
1248 this.height = 0;
1249 this.width = 0;
1250 this.preferredWidth = 0;
1251 this.wrappedWidth = 0;
1252 this.minWidth = 0;
1253 this.headHeight = 0;
1254 this.footHeight = 0;
1255 this.startPageNumber = 1;
1256 this.pageNumber = 1;
1257 this.styles = {
1258 styles: {},
1259 headStyles: {},
1260 bodyStyles: {},
1261 footStyles: {},
1262 alternateRowStyles: {},
1263 columnStyles: {},
1264 };
1265 this.cellHooks = new CellHooks();
1266 }
1267 Object.defineProperty(Table.prototype, "pageCount", {
1268 get: function () {
1269 return this.pageNumber;
1270 },
1271 enumerable: true,
1272 configurable: true
1273 });
1274 Table.prototype.allRows = function () {
1275 return this.head.concat(this.body).concat(this.foot);
1276 };
1277 Table.prototype.callCellHooks = function (handlers, cell, row, column) {
1278 for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) {
1279 var handler = handlers_1[_i];
1280 if (handler(new HookData_1.CellHookData(cell, row, column)) === false) {
1281 return false;
1282 }
1283 }
1284 return true;
1285 };
1286 Table.prototype.callEndPageHooks = function () {
1287 common_1.applyUserStyles();
1288 for (var _i = 0, _a = this.cellHooks.didDrawPage; _i < _a.length; _i++) {
1289 var handler = _a[_i];
1290 handler(new HookData_1.HookData());
1291 }
1292 };
1293 Table.prototype.margin = function (side) {
1294 return common_1.marginOrPadding(this.settings.margin, config_1.defaultConfig().margin)[side];
1295 };
1296 return Table;
1297}());
1298exports.Table = Table;
1299var Row = /** @class */ (function () {
1300 function Row(raw, index, section) {
1301 this.cells = {};
1302 this.height = 0;
1303 this.maxCellLineCount = 1;
1304 this.maxCellHeight = 0;
1305 this.pageNumber = 1;
1306 this.spansMultiplePages = false;
1307 this.raw = raw;
1308 if (raw._element) {
1309 this.raw = raw._element;
1310 }
1311 this.index = index;
1312 this.section = section;
1313 }
1314 Object.defineProperty(Row.prototype, "pageCount", {
1315 get: function () {
1316 return this.pageNumber;
1317 },
1318 enumerable: true,
1319 configurable: true
1320 });
1321 return Row;
1322}());
1323exports.Row = Row;
1324var Cell = /** @class */ (function () {
1325 function Cell(raw, themeStyles, section) {
1326 this.contentWidth = 0;
1327 this.wrappedWidth = 0;
1328 this.minWidth = 0;
1329 this.textPos = {};
1330 this.height = 0;
1331 this.width = 0;
1332 this.rowSpan = raw && raw.rowSpan || 1;
1333 this.colSpan = raw && raw.colSpan || 1;
1334 this.styles = assign(themeStyles, raw && raw.styles || {});
1335 this.section = section;
1336 var text = '';
1337 var content = raw && typeof raw.content !== 'undefined' ? raw.content : raw;
1338 content = content != undefined && content.dataKey != undefined ? content.title : content;
1339 var fromHtml = typeof window === 'object' && window.HTMLElement && content instanceof window.HTMLElement;
1340 this.raw = fromHtml ? content : raw;
1341 if (content && fromHtml) {
1342 text = (content.innerText || '').replace(/\s+/g, ' ').trim();
1343 }
1344 else {
1345 // Stringify 0 and false, but not undefined or null
1346 text = content != undefined ? '' + content : '';
1347 }
1348 var splitRegex = /\r\n|\r|\n/g;
1349 this.text = text.split(splitRegex);
1350 this.contentWidth = this.padding('horizontal') + common_1.getStringWidth(this.text, this.styles);
1351 if (typeof this.styles.cellWidth === 'number') {
1352 this.minWidth = this.styles.cellWidth;
1353 this.wrappedWidth = this.styles.cellWidth;
1354 }
1355 else if (this.styles.cellWidth === 'wrap') {
1356 this.minWidth = this.contentWidth;
1357 this.wrappedWidth = this.contentWidth;
1358 }
1359 else { // auto
1360 var defaultMinWidth = 10 / state_1.default().scaleFactor();
1361 this.minWidth = this.styles.minCellWidth || defaultMinWidth;
1362 this.wrappedWidth = this.contentWidth;
1363 if (this.minWidth > this.wrappedWidth) {
1364 this.wrappedWidth = this.minWidth;
1365 }
1366 }
1367 }
1368 Cell.prototype.padding = function (name) {
1369 var padding = common_1.marginOrPadding(this.styles.cellPadding, common_1.styles([]).cellPadding);
1370 if (name === 'vertical') {
1371 return padding.top + padding.bottom;
1372 }
1373 else if (name === 'horizontal') {
1374 return padding.left + padding.right;
1375 }
1376 else {
1377 return padding[name];
1378 }
1379 };
1380 return Cell;
1381}());
1382exports.Cell = Cell;
1383var Column = /** @class */ (function () {
1384 function Column(dataKey, raw, index) {
1385 this.preferredWidth = 0;
1386 this.minWidth = 0;
1387 this.wrappedWidth = 0;
1388 this.width = 0;
1389 this.dataKey = dataKey;
1390 this.raw = raw;
1391 this.index = index;
1392 }
1393 return Column;
1394}());
1395exports.Column = Column;
1396
1397
1398/***/ }),
1399/* 10 */
1400/***/ (function(module, exports, __webpack_require__) {
1401
1402"use strict";
1403
1404var __extends = (this && this.__extends) || (function () {
1405 var extendStatics = function (d, b) {
1406 extendStatics = Object.setPrototypeOf ||
1407 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1408 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
1409 return extendStatics(d, b);
1410 };
1411 return function (d, b) {
1412 extendStatics(d, b);
1413 function __() { this.constructor = d; }
1414 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1415 };
1416})();
1417Object.defineProperty(exports, "__esModule", { value: true });
1418var state_1 = __webpack_require__(0);
1419var HookData = /** @class */ (function () {
1420 function HookData() {
1421 var table = state_1.default().table;
1422 this.table = table;
1423 this.pageNumber = table.pageNumber;
1424 this.settings = table.settings;
1425 this.cursor = table.cursor;
1426 this.doc = state_1.default().doc;
1427 }
1428 Object.defineProperty(HookData.prototype, "pageCount", {
1429 get: function () {
1430 return this.pageNumber;
1431 },
1432 enumerable: true,
1433 configurable: true
1434 });
1435 return HookData;
1436}());
1437exports.HookData = HookData;
1438var CellHookData = /** @class */ (function (_super) {
1439 __extends(CellHookData, _super);
1440 function CellHookData(cell, row, column) {
1441 var _this = _super.call(this) || this;
1442 _this.cell = cell;
1443 _this.row = row;
1444 _this.column = column;
1445 _this.section = row.section;
1446 return _this;
1447 }
1448 return CellHookData;
1449}(HookData));
1450exports.CellHookData = CellHookData;
1451
1452
1453/***/ }),
1454/* 11 */
1455/***/ (function(module, exports, __webpack_require__) {
1456
1457"use strict";
1458/*
1459object-assign
1460(c) Sindre Sorhus
1461@license MIT
1462*/
1463
1464
1465/* eslint-disable no-unused-vars */
1466var getOwnPropertySymbols = Object.getOwnPropertySymbols;
1467var hasOwnProperty = Object.prototype.hasOwnProperty;
1468var propIsEnumerable = Object.prototype.propertyIsEnumerable;
1469
1470function toObject(val) {
1471 if (val === null || val === undefined) {
1472 throw new TypeError('Object.assign cannot be called with null or undefined');
1473 }
1474
1475 return Object(val);
1476}
1477
1478function shouldUseNative() {
1479 try {
1480 if (!Object.assign) {
1481 return false;
1482 }
1483
1484 // Detect buggy property enumeration order in older V8 versions.
1485
1486 // https://bugs.chromium.org/p/v8/issues/detail?id=4118
1487 var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
1488 test1[5] = 'de';
1489 if (Object.getOwnPropertyNames(test1)[0] === '5') {
1490 return false;
1491 }
1492
1493 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
1494 var test2 = {};
1495 for (var i = 0; i < 10; i++) {
1496 test2['_' + String.fromCharCode(i)] = i;
1497 }
1498 var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
1499 return test2[n];
1500 });
1501 if (order2.join('') !== '0123456789') {
1502 return false;
1503 }
1504
1505 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
1506 var test3 = {};
1507 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
1508 test3[letter] = letter;
1509 });
1510 if (Object.keys(Object.assign({}, test3)).join('') !==
1511 'abcdefghijklmnopqrst') {
1512 return false;
1513 }
1514
1515 return true;
1516 } catch (err) {
1517 // We don't expect any of the above to throw, but better to be safe.
1518 return false;
1519 }
1520}
1521
1522module.exports = shouldUseNative() ? Object.assign : function (target, source) {
1523 var from;
1524 var to = toObject(target);
1525 var symbols;
1526
1527 for (var s = 1; s < arguments.length; s++) {
1528 from = Object(arguments[s]);
1529
1530 for (var key in from) {
1531 if (hasOwnProperty.call(from, key)) {
1532 to[key] = from[key];
1533 }
1534 }
1535
1536 if (getOwnPropertySymbols) {
1537 symbols = getOwnPropertySymbols(from);
1538 for (var i = 0; i < symbols.length; i++) {
1539 if (propIsEnumerable.call(from, symbols[i])) {
1540 to[symbols[i]] = from[symbols[i]];
1541 }
1542 }
1543 }
1544 }
1545
1546 return to;
1547};
1548
1549
1550/***/ }),
1551/* 12 */
1552/***/ (function(module, exports, __webpack_require__) {
1553
1554"use strict";
1555
1556Object.defineProperty(exports, "__esModule", { value: true });
1557var cssParser_1 = __webpack_require__(13);
1558var state_1 = __webpack_require__(0);
1559var polyfills_1 = __webpack_require__(3);
1560function parseHtml(input, includeHiddenHtml, useCss) {
1561 if (includeHiddenHtml === void 0) { includeHiddenHtml = false; }
1562 if (useCss === void 0) { useCss = false; }
1563 var tableElement;
1564 if (typeof input === 'string') {
1565 tableElement = window.document.querySelector(input);
1566 }
1567 else {
1568 tableElement = input;
1569 }
1570 if (!tableElement) {
1571 console.error("Html table could not be found with input: ", input);
1572 return;
1573 }
1574 var head = parseTableSection(window, tableElement.tHead, includeHiddenHtml, useCss);
1575 var body = [];
1576 for (var i = 0; i < tableElement.tBodies.length; i++) {
1577 body = body.concat(parseTableSection(window, tableElement.tBodies[i], includeHiddenHtml, useCss));
1578 }
1579 var foot = parseTableSection(window, tableElement.tFoot, includeHiddenHtml, useCss);
1580 return { head: head, body: body, foot: foot };
1581}
1582exports.parseHtml = parseHtml;
1583function parseTableSection(window, sectionElement, includeHidden, useCss) {
1584 var results = [];
1585 if (!sectionElement) {
1586 return results;
1587 }
1588 for (var i = 0; i < sectionElement.rows.length; i++) {
1589 var row = sectionElement.rows[i];
1590 var resultRow = [];
1591 var rowStyles = useCss ? cssParser_1.parseCss(row, state_1.default().scaleFactor(), ['cellPadding', 'lineWidth', 'lineColor']) : {};
1592 for (var i_1 = 0; i_1 < row.cells.length; i_1++) {
1593 var cell = row.cells[i_1];
1594 var style = window.getComputedStyle(cell);
1595 if (includeHidden || style.display !== 'none') {
1596 var cellStyles = useCss ? cssParser_1.parseCss(cell, state_1.default().scaleFactor()) : {};
1597 resultRow.push({
1598 rowSpan: cell.rowSpan,
1599 colSpan: cell.colSpan,
1600 styles: useCss ? polyfills_1.assign(rowStyles, cellStyles) : null,
1601 content: cell
1602 });
1603 }
1604 }
1605 if (resultRow.length > 0 && (includeHidden || rowStyles.display !== 'none')) {
1606 resultRow._element = row;
1607 results.push(resultRow);
1608 }
1609 }
1610 return results;
1611}
1612
1613
1614/***/ }),
1615/* 13 */
1616/***/ (function(module, exports, __webpack_require__) {
1617
1618"use strict";
1619
1620Object.defineProperty(exports, "__esModule", { value: true });
1621// Limitations
1622// - No support for border spacing
1623// - No support for transparency
1624var common_1 = __webpack_require__(1);
1625function parseCss(element, scaleFactor, ignored) {
1626 if (ignored === void 0) { ignored = []; }
1627 var result = {};
1628 var style = window.getComputedStyle(element);
1629 function assign(name, value, accepted) {
1630 if (accepted === void 0) { accepted = []; }
1631 if ((accepted.length === 0 || accepted.indexOf(value) !== -1) && ignored.indexOf(name) === -1) {
1632 if (value === 0 || value) {
1633 result[name] = value;
1634 }
1635 }
1636 }
1637 var pxScaleFactor = 96 / 72;
1638 assign('fillColor', parseColor(element, 'backgroundColor') || 255);
1639 assign('lineColor', parseColor(element, 'borderColor'));
1640 assign('fontStyle', parseFontStyle(style));
1641 assign('textColor', parseColor(element, 'color'));
1642 assign('halign', style.textAlign, ['left', 'right', 'center', 'justify']);
1643 assign('valign', style.verticalAlign, ['middle', 'bottom', 'top']);
1644 assign('fontSize', parseInt(style.fontSize || '') / pxScaleFactor);
1645 assign('cellPadding', parsePadding(style.padding, style.fontSize, style.lineHeight, scaleFactor));
1646 assign('lineWidth', parseInt(style.borderWidth || '') / pxScaleFactor / scaleFactor);
1647 assign('font', (style.fontFamily || '').toLowerCase());
1648 return result;
1649}
1650exports.parseCss = parseCss;
1651function parseFontStyle(style) {
1652 var res = '';
1653 if (style.fontWeight === 'bold' || style.fontWeight === 'bolder' || parseInt(style.fontWeight) >= 700) {
1654 res += 'bold';
1655 }
1656 if (style.fontStyle === 'italic' || style.fontStyle === 'oblique') {
1657 res += 'italic';
1658 }
1659 return res;
1660}
1661function parseColor(element, colorProp) {
1662 var cssColor = realColor(element, colorProp);
1663 if (!cssColor)
1664 return null;
1665 var rgba = cssColor.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/);
1666 if (!rgba || !Array.isArray(rgba)) {
1667 return null;
1668 }
1669 var color = [parseInt(rgba[1]), parseInt(rgba[2]), parseInt(rgba[3])];
1670 var alpha = parseInt(rgba[4]);
1671 if (alpha === 0 || isNaN(color[0]) || isNaN(color[1]) || isNaN(color[2])) {
1672 return null;
1673 }
1674 return color;
1675}
1676function realColor(elem, colorProp) {
1677 if (!elem)
1678 return null;
1679 var bg = window.getComputedStyle(elem)[colorProp];
1680 if (bg === 'rgba(0, 0, 0, 0)' || bg === 'transparent' || bg === 'initial' || bg === 'inherit') {
1681 return realColor(elem.parentElement, colorProp);
1682 }
1683 else {
1684 return bg;
1685 }
1686}
1687function parsePadding(val, fontSize, lineHeight, scaleFactor) {
1688 if (!val)
1689 return null;
1690 var pxScaleFactor = (96 / (72 / scaleFactor));
1691 var linePadding = (parseInt(lineHeight) - parseInt(fontSize)) / scaleFactor / 2;
1692 var padding = val.split(' ').map(function (n) {
1693 return parseInt(n) / pxScaleFactor;
1694 });
1695 padding = common_1.marginOrPadding(padding, 0);
1696 if (linePadding > padding.top) {
1697 padding.top = linePadding;
1698 }
1699 if (linePadding > padding.bottom) {
1700 padding.bottom = linePadding;
1701 }
1702 return padding;
1703}
1704
1705
1706/***/ }),
1707/* 14 */
1708/***/ (function(module, exports, __webpack_require__) {
1709
1710"use strict";
1711
1712Object.defineProperty(exports, "__esModule", { value: true });
1713var common_1 = __webpack_require__(1);
1714function default_1(allOptions) {
1715 var _loop_1 = function (settings) {
1716 if (settings && typeof settings !== 'object') {
1717 console.error("The options parameter should be of type object, is: " + typeof settings);
1718 }
1719 if (typeof settings.extendWidth !== 'undefined') {
1720 settings.tableWidth = settings.extendWidth ? 'auto' : 'wrap';
1721 console.error("Use of deprecated option: extendWidth, use tableWidth instead.");
1722 }
1723 if (typeof settings.margins !== 'undefined') {
1724 if (typeof settings.margin === 'undefined')
1725 settings.margin = settings.margins;
1726 console.error("Use of deprecated option: margins, use margin instead.");
1727 }
1728 if (!settings.didDrawPage && (settings.afterPageContent || settings.beforePageContent || settings.afterPageAdd)) {
1729 console.error("The afterPageContent, beforePageContent and afterPageAdd hooks are deprecated. Use didDrawPage instead");
1730 settings.didDrawPage = function (data) {
1731 common_1.applyUserStyles();
1732 if (settings.beforePageContent)
1733 settings.beforePageContent(data);
1734 common_1.applyUserStyles();
1735 if (settings.afterPageContent)
1736 settings.afterPageContent(data);
1737 common_1.applyUserStyles();
1738 if (settings.afterPageAdd && data.pageNumber > 1) {
1739 data.afterPageAdd(data);
1740 }
1741 common_1.applyUserStyles();
1742 };
1743 }
1744 ["createdHeaderCell", "drawHeaderRow", "drawRow", "drawHeaderCell"].forEach(function (name) {
1745 if (settings[name]) {
1746 console.error("The \"" + name + "\" hook has changed in version 3.0, check the changelog for how to migrate.");
1747 }
1748 });
1749 [['showFoot', 'showFooter'], ['showHead', 'showHeader'], ['didDrawPage', 'addPageContent'], ['didParseCell', 'createdCell'], ['headStyles', 'headerStyles']].forEach(function (_a) {
1750 var current = _a[0], deprecated = _a[1];
1751 if (settings[deprecated]) {
1752 console.error("Use of deprecated option " + deprecated + ". Use " + current + " instead");
1753 settings[current] = settings[deprecated];
1754 }
1755 });
1756 [['padding', 'cellPadding'], ['lineHeight', 'rowHeight'], 'fontSize', 'overflow'].forEach(function (o) {
1757 var deprecatedOption = typeof o === 'string' ? o : o[0];
1758 var style = typeof o === 'string' ? o : o[1];
1759 if (typeof settings[deprecatedOption] !== 'undefined') {
1760 if (typeof settings.styles[style] === 'undefined') {
1761 settings.styles[style] = settings[deprecatedOption];
1762 }
1763 console.error("Use of deprecated option: " + deprecatedOption + ", use the style " + style + " instead.");
1764 }
1765 });
1766 for (var _i = 0, _a = ['styles', 'bodyStyles', 'headStyles', 'footStyles']; _i < _a.length; _i++) {
1767 var styleProp = _a[_i];
1768 checkStyles(settings[styleProp] || {});
1769 }
1770 var columnStyles = settings['columnStyles'] || {};
1771 for (var _b = 0, _c = Object.keys(columnStyles); _b < _c.length; _b++) {
1772 var dataKey = _c[_b];
1773 checkStyles(columnStyles[dataKey] || {});
1774 }
1775 };
1776 for (var _i = 0, allOptions_1 = allOptions; _i < allOptions_1.length; _i++) {
1777 var settings = allOptions_1[_i];
1778 _loop_1(settings);
1779 }
1780}
1781exports.default = default_1;
1782function checkStyles(styles) {
1783 if (styles.rowHeight) {
1784 console.error("Use of deprecated style rowHeight. It is renamed to minCellHeight.");
1785 if (!styles.minCellHeight) {
1786 styles.minCellHeight = styles.rowHeight;
1787 }
1788 }
1789 else if (styles.columnWidth) {
1790 console.error("Use of deprecated style columnWidth. It is renamed to cellWidth.");
1791 if (!styles.cellWidth) {
1792 styles.cellWidth = styles.columnWidth;
1793 }
1794 }
1795}
1796
1797
1798/***/ }),
1799/* 15 */
1800/***/ (function(module, exports, __webpack_require__) {
1801
1802var jsPDF = __webpack_require__(4);
1803/**
1804 * Improved text function with halign and valign support
1805 * Inspiration from: http://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113#28433113
1806 */
1807jsPDF.API.autoTableText = function (text, x, y, styles) {
1808 styles = styles || {};
1809 var FONT_ROW_RATIO = 1.15;
1810 if (typeof x !== 'number' || typeof y !== 'number') {
1811 console.error('The x and y parameters are required. Missing for text: ', text);
1812 }
1813 var k = this.internal.scaleFactor;
1814 var fontSize = this.internal.getFontSize() / k;
1815 var splitRegex = /\r\n|\r|\n/g;
1816 var splitText = null;
1817 var lineCount = 1;
1818 if (styles.valign === 'middle' || styles.valign === 'bottom' || styles.halign === 'center' || styles.halign === 'right') {
1819 splitText = typeof text === 'string' ? text.split(splitRegex) : text;
1820 lineCount = splitText.length || 1;
1821 }
1822 // Align the top
1823 y += fontSize * (2 - FONT_ROW_RATIO);
1824 if (styles.valign === 'middle')
1825 y -= (lineCount / 2) * fontSize * FONT_ROW_RATIO;
1826 else if (styles.valign === 'bottom')
1827 y -= lineCount * fontSize * FONT_ROW_RATIO;
1828 if (styles.halign === 'center' || styles.halign === 'right') {
1829 var alignSize = fontSize;
1830 if (styles.halign === 'center')
1831 alignSize *= 0.5;
1832 if (lineCount >= 1) {
1833 for (var iLine = 0; iLine < splitText.length; iLine++) {
1834 this.text(splitText[iLine], x - this.getStringUnitWidth(splitText[iLine]) * alignSize, y);
1835 y += fontSize;
1836 }
1837 return this;
1838 }
1839 x -= this.getStringUnitWidth(text) * alignSize;
1840 }
1841 if (styles.halign === 'justify') {
1842 this.text(text, x, y, { maxWidth: styles.maxWidth || 100, align: 'justify' });
1843 }
1844 else {
1845 this.text(text, x, y);
1846 }
1847 return this;
1848};
1849
1850
1851/***/ })
1852/******/ ]);
1853});
\No newline at end of file