UNPKG

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