UNPKG

82.2 kBJavaScriptView Raw
1/*!
2 *
3 * jsPDF AutoTable plugin v3.5.7
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 applyPlugin(jsPDF);
1489}
1490catch (error) {
1491 // Importing jspdf in nodejs environments does not work as of jspdf
1492 // 1.5.3 so we need to silence potential errors to support using for example
1493 // the nodejs jspdf dist files with the exported applyPlugin
1494}
1495
1496
1497/***/ }),
1498/* 11 */
1499/***/ (function(module, exports, __webpack_require__) {
1500
1501"use strict";
1502
1503Object.defineProperty(exports, "__esModule", { value: true });
1504var htmlParser_1 = __webpack_require__(4);
1505var autoTableText_1 = __webpack_require__(5);
1506var documentHandler_1 = __webpack_require__(2);
1507var inputParser_1 = __webpack_require__(6);
1508var tableDrawer_1 = __webpack_require__(7);
1509var tableCalculator_1 = __webpack_require__(9);
1510function default_1(jsPDF) {
1511 // eslint-disable-next-line @typescript-eslint/no-explicit-any
1512 jsPDF.API.autoTable = function () {
1513 var args = [];
1514 for (var _i = 0; _i < arguments.length; _i++) {
1515 args[_i] = arguments[_i];
1516 }
1517 var options;
1518 if (args.length === 1) {
1519 options = args[0];
1520 }
1521 else {
1522 console.error('Use of deprecated autoTable initiation');
1523 options = args[2] || {};
1524 options.columns = args[0];
1525 options.body = args[1];
1526 }
1527 var input = inputParser_1.parseInput(this, options);
1528 var table = tableCalculator_1.createTable(this, input);
1529 tableDrawer_1.drawTable(this, table);
1530 return this;
1531 };
1532 // Assign false to enable `doc.lastAutoTable.finalY || 40` sugar
1533 jsPDF.API.lastAutoTable = false;
1534 jsPDF.API.previousAutoTable = false; // deprecated in v3
1535 jsPDF.API.autoTable.previous = false; // deprecated in v3
1536 jsPDF.API.autoTableText = function (text, x, y, styles) {
1537 autoTableText_1.default(text, x, y, styles, this);
1538 };
1539 jsPDF.API.autoTableSetDefaults = function (defaults) {
1540 documentHandler_1.DocHandler.setDefaults(defaults, this);
1541 return this;
1542 };
1543 jsPDF.autoTableSetDefaults = function (defaults, doc) {
1544 documentHandler_1.DocHandler.setDefaults(defaults, doc);
1545 };
1546 jsPDF.API.autoTableHtmlToJson = function (tableElem, includeHiddenElements) {
1547 if (includeHiddenElements === void 0) { includeHiddenElements = false; }
1548 if (typeof window === 'undefined') {
1549 console.error('Cannot run autoTableHtmlToJson in non browser environment');
1550 return null;
1551 }
1552 var doc = new documentHandler_1.DocHandler(this);
1553 var _a = htmlParser_1.parseHtml(doc, tableElem, window, includeHiddenElements, false), head = _a.head, body = _a.body;
1554 var columns = head[0].map(function (c) { return c.content; });
1555 return { columns: columns, rows: body, data: body };
1556 };
1557 /**
1558 * @deprecated
1559 */
1560 jsPDF.API.autoTableEndPosY = function () {
1561 console.error('Use of deprecated function: autoTableEndPosY. Use doc.lastAutoTable.finalY instead.');
1562 var prev = this.lastAutoTable;
1563 if (prev && prev.finalY) {
1564 return prev.finalY;
1565 }
1566 else {
1567 return 0;
1568 }
1569 };
1570 /**
1571 * @deprecated
1572 */
1573 jsPDF.API.autoTableAddPageContent = function (hook) {
1574 console.error('Use of deprecated function: autoTableAddPageContent. Use jsPDF.autoTableSetDefaults({didDrawPage: () => {}}) instead.');
1575 if (!jsPDF.API.autoTable.globalDefaults) {
1576 jsPDF.API.autoTable.globalDefaults = {};
1577 }
1578 jsPDF.API.autoTable.globalDefaults.addPageContent = hook;
1579 return this;
1580 };
1581 /**
1582 * @deprecated
1583 */
1584 jsPDF.API.autoTableAddPage = function () {
1585 console.error('Use of deprecated function: autoTableAddPage. Use doc.addPage()');
1586 this.addPage();
1587 return this;
1588 };
1589}
1590exports.default = default_1;
1591
1592
1593/***/ }),
1594/* 12 */
1595/***/ (function(module, exports, __webpack_require__) {
1596
1597"use strict";
1598
1599Object.defineProperty(exports, "__esModule", { value: true });
1600exports.parseCss = void 0;
1601// Limitations
1602// - No support for border spacing
1603// - No support for transparency
1604var common_1 = __webpack_require__(0);
1605function parseCss(supportedFonts, element, scaleFactor, style, window) {
1606 var result = {};
1607 var pxScaleFactor = 96 / 72;
1608 var color = parseColor(element, function (elem) {
1609 return window.getComputedStyle(elem)['backgroundColor'];
1610 });
1611 if (color != null)
1612 result.fillColor = color;
1613 color = parseColor(element, function (elem) {
1614 return window.getComputedStyle(elem)['color'];
1615 });
1616 if (color != null)
1617 result.textColor = color;
1618 color = parseColor(element, function (elem) {
1619 return window.getComputedStyle(elem)['borderTopColor'];
1620 });
1621 if (color != null)
1622 result.lineColor = color;
1623 var padding = parsePadding(style, scaleFactor);
1624 if (padding)
1625 result.cellPadding = padding;
1626 // style.borderWidth only works in chrome (borderTopWidth etc works in firefox and ie as well)
1627 var bw = parseInt(style.borderTopWidth || '');
1628 bw = bw / pxScaleFactor / scaleFactor;
1629 if (bw)
1630 result.lineWidth = bw;
1631 var accepted = ['left', 'right', 'center', 'justify'];
1632 if (accepted.indexOf(style.textAlign) !== -1) {
1633 result.halign = style.textAlign;
1634 }
1635 accepted = ['middle', 'bottom', 'top'];
1636 if (accepted.indexOf(style.verticalAlign) !== -1) {
1637 result.valign = style.verticalAlign;
1638 }
1639 var res = parseInt(style.fontSize || '');
1640 if (!isNaN(res))
1641 result.fontSize = res / pxScaleFactor;
1642 var fontStyle = parseFontStyle(style);
1643 if (fontStyle)
1644 result.fontStyle = fontStyle;
1645 var font = (style.fontFamily || '').toLowerCase();
1646 if (supportedFonts.indexOf(font) !== -1) {
1647 result.font = font;
1648 }
1649 return result;
1650}
1651exports.parseCss = parseCss;
1652function parseFontStyle(style) {
1653 var res = '';
1654 if (style.fontWeight === 'bold' ||
1655 style.fontWeight === 'bolder' ||
1656 parseInt(style.fontWeight) >= 700) {
1657 res = 'bold';
1658 }
1659 if (style.fontStyle === 'italic' || style.fontStyle === 'oblique') {
1660 res += 'italic';
1661 }
1662 return res;
1663}
1664function parseColor(element, styleGetter) {
1665 var cssColor = realColor(element, styleGetter);
1666 if (!cssColor)
1667 return null;
1668 var rgba = cssColor.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/);
1669 if (!rgba || !Array.isArray(rgba)) {
1670 return null;
1671 }
1672 var color = [
1673 parseInt(rgba[1]),
1674 parseInt(rgba[2]),
1675 parseInt(rgba[3]),
1676 ];
1677 var alpha = parseInt(rgba[4]);
1678 if (alpha === 0 || isNaN(color[0]) || isNaN(color[1]) || isNaN(color[2])) {
1679 return null;
1680 }
1681 return color;
1682}
1683function realColor(elem, styleGetter) {
1684 var bg = styleGetter(elem);
1685 if (bg === 'rgba(0, 0, 0, 0)' ||
1686 bg === 'transparent' ||
1687 bg === 'initial' ||
1688 bg === 'inherit') {
1689 if (elem.parentElement == null) {
1690 return null;
1691 }
1692 return realColor(elem.parentElement, styleGetter);
1693 }
1694 else {
1695 return bg;
1696 }
1697}
1698function parsePadding(style, scaleFactor) {
1699 var val = [
1700 style.paddingTop,
1701 style.paddingRight,
1702 style.paddingBottom,
1703 style.paddingLeft,
1704 ];
1705 var pxScaleFactor = 96 / (72 / scaleFactor);
1706 var linePadding = (parseInt(style.lineHeight) - parseInt(style.fontSize)) / scaleFactor / 2;
1707 var inputPadding = val.map(function (n) {
1708 return parseInt(n) / pxScaleFactor;
1709 });
1710 var padding = common_1.parseSpacing(inputPadding, 0);
1711 if (linePadding > padding.top) {
1712 padding.top = linePadding;
1713 }
1714 if (linePadding > padding.bottom) {
1715 padding.bottom = linePadding;
1716 }
1717 return padding;
1718}
1719
1720
1721/***/ }),
1722/* 13 */
1723/***/ (function(module, exports, __webpack_require__) {
1724
1725"use strict";
1726
1727Object.defineProperty(exports, "__esModule", { value: true });
1728function default_1(doc, global, document, current) {
1729 var _loop_1 = function (options) {
1730 if (options && typeof options !== 'object') {
1731 console.error('The options parameter should be of type object, is: ' + typeof options);
1732 }
1733 if (typeof options.extendWidth !== 'undefined') {
1734 options.tableWidth = options.extendWidth ? 'auto' : 'wrap';
1735 console.error('Use of deprecated option: extendWidth, use tableWidth instead.');
1736 }
1737 if (typeof options.margins !== 'undefined') {
1738 if (typeof options.margin === 'undefined')
1739 options.margin = options.margins;
1740 console.error('Use of deprecated option: margins, use margin instead.');
1741 }
1742 if (options.startY && typeof options.startY !== 'number') {
1743 console.error('Invalid value for startY option', options.startY);
1744 delete options.startY;
1745 }
1746 if (!options.didDrawPage &&
1747 (options.afterPageContent ||
1748 options.beforePageContent ||
1749 options.afterPageAdd)) {
1750 console.error('The afterPageContent, beforePageContent and afterPageAdd hooks are deprecated. Use didDrawPage instead');
1751 options.didDrawPage = function (data) {
1752 doc.applyStyles(doc.userStyles);
1753 if (options.beforePageContent)
1754 options.beforePageContent(data);
1755 doc.applyStyles(doc.userStyles);
1756 if (options.afterPageContent)
1757 options.afterPageContent(data);
1758 doc.applyStyles(doc.userStyles);
1759 if (options.afterPageAdd && data.pageNumber > 1) {
1760 ;
1761 data.afterPageAdd(data);
1762 }
1763 doc.applyStyles(doc.userStyles);
1764 };
1765 }
1766 ;
1767 [
1768 'createdHeaderCell',
1769 'drawHeaderRow',
1770 'drawRow',
1771 'drawHeaderCell',
1772 ].forEach(function (name) {
1773 if (options[name]) {
1774 console.error("The \"" + name + "\" hook has changed in version 3.0, check the changelog for how to migrate.");
1775 }
1776 });
1777 [
1778 ['showFoot', 'showFooter'],
1779 ['showHead', 'showHeader'],
1780 ['didDrawPage', 'addPageContent'],
1781 ['didParseCell', 'createdCell'],
1782 ['headStyles', 'headerStyles'],
1783 ].forEach(function (_a) {
1784 var current = _a[0], deprecated = _a[1];
1785 if (options[deprecated]) {
1786 console.error("Use of deprecated option " + deprecated + ". Use " + current + " instead");
1787 options[current] = options[deprecated];
1788 }
1789 });
1790 [
1791 ['padding', 'cellPadding'],
1792 ['lineHeight', 'rowHeight'],
1793 'fontSize',
1794 'overflow',
1795 ].forEach(function (o) {
1796 var deprecatedOption = typeof o === 'string' ? o : o[0];
1797 var style = typeof o === 'string' ? o : o[1];
1798 if (typeof options[deprecatedOption] !== 'undefined') {
1799 if (typeof options.styles[style] === 'undefined') {
1800 options.styles[style] = options[deprecatedOption];
1801 }
1802 console.error('Use of deprecated option: ' +
1803 deprecatedOption +
1804 ', use the style ' +
1805 style +
1806 ' instead.');
1807 }
1808 });
1809 for (var _i = 0, _a = [
1810 'styles',
1811 'bodyStyles',
1812 'headStyles',
1813 'footStyles',
1814 ]; _i < _a.length; _i++) {
1815 var styleProp = _a[_i];
1816 checkStyles(options[styleProp] || {});
1817 }
1818 var columnStyles = options['columnStyles'] || {};
1819 for (var _b = 0, _c = Object.keys(columnStyles); _b < _c.length; _b++) {
1820 var key = _c[_b];
1821 checkStyles(columnStyles[key] || {});
1822 }
1823 };
1824 for (var _i = 0, _a = [global, document, current]; _i < _a.length; _i++) {
1825 var options = _a[_i];
1826 _loop_1(options);
1827 }
1828}
1829exports.default = default_1;
1830function checkStyles(styles) {
1831 if (styles.rowHeight) {
1832 console.error('Use of deprecated style rowHeight. It is renamed to minCellHeight.');
1833 if (!styles.minCellHeight) {
1834 styles.minCellHeight = styles.rowHeight;
1835 }
1836 }
1837 else if (styles.columnWidth) {
1838 console.error('Use of deprecated style columnWidth. It is renamed to cellWidth.');
1839 if (!styles.cellWidth) {
1840 styles.cellWidth = styles.columnWidth;
1841 }
1842 }
1843}
1844
1845
1846/***/ }),
1847/* 14 */
1848/***/ (function(module, exports, __webpack_require__) {
1849
1850"use strict";
1851
1852var __extends = (this && this.__extends) || (function () {
1853 var extendStatics = function (d, b) {
1854 extendStatics = Object.setPrototypeOf ||
1855 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1856 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
1857 return extendStatics(d, b);
1858 };
1859 return function (d, b) {
1860 extendStatics(d, b);
1861 function __() { this.constructor = d; }
1862 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1863 };
1864})();
1865Object.defineProperty(exports, "__esModule", { value: true });
1866exports.CellHookData = exports.HookData = void 0;
1867var HookData = /** @class */ (function () {
1868 function HookData(doc, table, cursor) {
1869 this.table = table;
1870 this.pageNumber = table.pageNumber;
1871 this.pageCount = this.pageNumber;
1872 this.settings = table.settings;
1873 this.cursor = cursor;
1874 this.doc = doc.getDocument();
1875 }
1876 return HookData;
1877}());
1878exports.HookData = HookData;
1879var CellHookData = /** @class */ (function (_super) {
1880 __extends(CellHookData, _super);
1881 function CellHookData(doc, table, cell, row, column, cursor) {
1882 var _this = _super.call(this, doc, table, cursor) || this;
1883 _this.cell = cell;
1884 _this.row = row;
1885 _this.column = column;
1886 _this.section = row.section;
1887 return _this;
1888 }
1889 return CellHookData;
1890}(HookData));
1891exports.CellHookData = CellHookData;
1892
1893
1894/***/ }),
1895/* 15 */
1896/***/ (function(module, exports, __webpack_require__) {
1897
1898"use strict";
1899
1900Object.defineProperty(exports, "__esModule", { value: true });
1901exports.ellipsize = exports.resizeColumns = exports.calculateWidths = void 0;
1902var common_1 = __webpack_require__(0);
1903/**
1904 * Calculate the column widths
1905 */
1906function calculateWidths(doc, table) {
1907 calculate(doc, table);
1908 var resizableColumns = [];
1909 var initialTableWidth = 0;
1910 table.columns.forEach(function (column) {
1911 var customWidth = column.getMaxCustomCellWidth(table);
1912 if (customWidth) {
1913 // final column width
1914 column.width = customWidth;
1915 }
1916 else {
1917 // initial column width (will be resized)
1918 column.width = column.wrappedWidth;
1919 resizableColumns.push(column);
1920 }
1921 initialTableWidth += column.width;
1922 });
1923 // width difference that needs to be distributed
1924 var resizeWidth = table.getWidth(doc.pageSize().width) - initialTableWidth;
1925 // first resize attempt: with respect to minReadableWidth and minWidth
1926 if (resizeWidth) {
1927 resizeWidth = resizeColumns(resizableColumns, resizeWidth, function (column) {
1928 return Math.max(column.minReadableWidth, column.minWidth);
1929 });
1930 }
1931 // second resize attempt: ignore minReadableWidth but respect minWidth
1932 if (resizeWidth) {
1933 resizeWidth = resizeColumns(resizableColumns, resizeWidth, function (column) { return column.minWidth; });
1934 }
1935 resizeWidth = Math.abs(resizeWidth);
1936 if (resizeWidth > 0.1 / doc.scaleFactor()) {
1937 // Table can't get smaller due to custom-width or minWidth restrictions
1938 // We can't really do much here. Up to user to for example
1939 // reduce font size, increase page size or remove custom cell widths
1940 // to allow more columns to be reduced in size
1941 resizeWidth = resizeWidth < 1 ? resizeWidth : Math.round(resizeWidth);
1942 console.error("Of the table content, " + resizeWidth + " units width could not fit page");
1943 }
1944 applyColSpans(table);
1945 fitContent(table, doc);
1946 applyRowSpans(table);
1947}
1948exports.calculateWidths = calculateWidths;
1949function calculate(doc, table) {
1950 var sf = doc.scaleFactor();
1951 table.allRows().forEach(function (row) {
1952 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) {
1953 var column = _a[_i];
1954 var cell = row.cells[column.index];
1955 if (!cell)
1956 continue;
1957 var hooks = table.hooks.didParseCell;
1958 table.callCellHooks(doc, hooks, cell, row, column, null);
1959 var padding = cell.padding('horizontal');
1960 cell.contentWidth = common_1.getStringWidth(cell.text, cell.styles, doc) + padding;
1961 var longestWordWidth = common_1.getStringWidth(cell.text.join(' ').split(/\s+/), cell.styles, doc);
1962 cell.minReadableWidth = longestWordWidth + cell.padding('horizontal');
1963 if (typeof cell.styles.cellWidth === 'number') {
1964 cell.minWidth = cell.styles.cellWidth;
1965 cell.wrappedWidth = cell.styles.cellWidth;
1966 }
1967 else if (cell.styles.cellWidth === 'wrap') {
1968 cell.minWidth = cell.contentWidth;
1969 cell.wrappedWidth = cell.contentWidth;
1970 }
1971 else {
1972 // auto
1973 var defaultMinWidth = 10 / sf;
1974 cell.minWidth = cell.styles.minCellWidth || defaultMinWidth;
1975 cell.wrappedWidth = cell.contentWidth;
1976 if (cell.minWidth > cell.wrappedWidth) {
1977 cell.wrappedWidth = cell.minWidth;
1978 }
1979 }
1980 }
1981 });
1982 table.allRows().forEach(function (row) {
1983 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) {
1984 var column = _a[_i];
1985 var cell = row.cells[column.index];
1986 // For now we ignore the minWidth and wrappedWidth of colspan cells when calculating colspan widths.
1987 // Could probably be improved upon however.
1988 if (cell && cell.colSpan === 1) {
1989 column.wrappedWidth = Math.max(column.wrappedWidth, cell.wrappedWidth);
1990 column.minWidth = Math.max(column.minWidth, cell.minWidth);
1991 column.minReadableWidth = Math.max(column.minReadableWidth, cell.minReadableWidth);
1992 }
1993 else {
1994 // Respect cellWidth set in columnStyles even if there is no cells for this column
1995 // or if the column only have colspan cells. Since the width of colspan cells
1996 // does not affect the width of columns, setting columnStyles cellWidth enables the
1997 // user to at least do it manually.
1998 // Note that this is not perfect for now since for example row and table styles are
1999 // not accounted for
2000 var columnStyles = table.styles.columnStyles[column.dataKey] ||
2001 table.styles.columnStyles[column.index] ||
2002 {};
2003 var cellWidth = columnStyles.cellWidth;
2004 if (cellWidth && typeof cellWidth === 'number') {
2005 column.minWidth = cellWidth;
2006 column.wrappedWidth = cellWidth;
2007 }
2008 }
2009 if (cell) {
2010 // Make sure all columns get at least min width even though width calculations are not based on them
2011 if (cell.colSpan > 1 && !column.minWidth) {
2012 column.minWidth = cell.minWidth;
2013 }
2014 if (cell.colSpan > 1 && !column.wrappedWidth) {
2015 column.wrappedWidth = cell.minWidth;
2016 }
2017 }
2018 }
2019 });
2020}
2021/**
2022 * Distribute resizeWidth on passed resizable columns
2023 */
2024function resizeColumns(columns, resizeWidth, getMinWidth) {
2025 var initialResizeWidth = resizeWidth;
2026 var sumWrappedWidth = columns.reduce(function (acc, column) { return acc + column.wrappedWidth; }, 0);
2027 for (var i = 0; i < columns.length; i++) {
2028 var column = columns[i];
2029 var ratio = column.wrappedWidth / sumWrappedWidth;
2030 var suggestedChange = initialResizeWidth * ratio;
2031 var suggestedWidth = column.width + suggestedChange;
2032 var minWidth = getMinWidth(column);
2033 var newWidth = suggestedWidth < minWidth ? minWidth : suggestedWidth;
2034 resizeWidth -= newWidth - column.width;
2035 column.width = newWidth;
2036 }
2037 resizeWidth = Math.round(resizeWidth * 1e10) / 1e10;
2038 // Run the resizer again if there's remaining width needs
2039 // to be distributed and there're columns that can be resized
2040 if (resizeWidth) {
2041 var resizableColumns = columns.filter(function (column) {
2042 return resizeWidth < 0
2043 ? column.width > getMinWidth(column) // check if column can shrink
2044 : true; // check if column can grow
2045 });
2046 if (resizableColumns.length) {
2047 resizeWidth = resizeColumns(resizableColumns, resizeWidth, getMinWidth);
2048 }
2049 }
2050 return resizeWidth;
2051}
2052exports.resizeColumns = resizeColumns;
2053function applyRowSpans(table) {
2054 var rowSpanCells = {};
2055 var colRowSpansLeft = 1;
2056 var all = table.allRows();
2057 for (var rowIndex = 0; rowIndex < all.length; rowIndex++) {
2058 var row = all[rowIndex];
2059 for (var _i = 0, _a = table.columns; _i < _a.length; _i++) {
2060 var column = _a[_i];
2061 var data = rowSpanCells[column.index];
2062 if (colRowSpansLeft > 1) {
2063 colRowSpansLeft--;
2064 delete row.cells[column.index];
2065 }
2066 else if (data) {
2067 data.cell.height += row.height;
2068 colRowSpansLeft = data.cell.colSpan;
2069 delete row.cells[column.index];
2070 data.left--;
2071 if (data.left <= 1) {
2072 delete rowSpanCells[column.index];
2073 }
2074 }
2075 else {
2076 var cell = row.cells[column.index];
2077 if (!cell) {
2078 continue;
2079 }
2080 cell.height = row.height;
2081 if (cell.rowSpan > 1) {
2082 var remaining = all.length - rowIndex;
2083 var left = cell.rowSpan > remaining ? remaining : cell.rowSpan;
2084 rowSpanCells[column.index] = { cell: cell, left: left, row: row };
2085 }
2086 }
2087 }
2088 }
2089}
2090function applyColSpans(table) {
2091 var all = table.allRows();
2092 for (var rowIndex = 0; rowIndex < all.length; rowIndex++) {
2093 var row = all[rowIndex];
2094 var colSpanCell = null;
2095 var combinedColSpanWidth = 0;
2096 var colSpansLeft = 0;
2097 for (var columnIndex = 0; columnIndex < table.columns.length; columnIndex++) {
2098 var column = table.columns[columnIndex];
2099 // Width and colspan
2100 colSpansLeft -= 1;
2101 if (colSpansLeft > 1 && table.columns[columnIndex + 1]) {
2102 combinedColSpanWidth += column.width;
2103 delete row.cells[column.index];
2104 }
2105 else if (colSpanCell) {
2106 var cell = colSpanCell;
2107 delete row.cells[column.index];
2108 colSpanCell = null;
2109 cell.width = column.width + combinedColSpanWidth;
2110 }
2111 else {
2112 var cell = row.cells[column.index];
2113 if (!cell)
2114 continue;
2115 colSpansLeft = cell.colSpan;
2116 combinedColSpanWidth = 0;
2117 if (cell.colSpan > 1) {
2118 colSpanCell = cell;
2119 combinedColSpanWidth += column.width;
2120 continue;
2121 }
2122 cell.width = column.width + combinedColSpanWidth;
2123 }
2124 }
2125 }
2126}
2127function fitContent(table, doc) {
2128 var rowSpanHeight = { count: 0, height: 0 };
2129 for (var _i = 0, _a = table.allRows(); _i < _a.length; _i++) {
2130 var row = _a[_i];
2131 for (var _b = 0, _c = table.columns; _b < _c.length; _b++) {
2132 var column = _c[_b];
2133 var cell = row.cells[column.index];
2134 if (!cell)
2135 continue;
2136 doc.applyStyles(cell.styles, true);
2137 var textSpace = cell.width - cell.padding('horizontal');
2138 if (cell.styles.overflow === 'linebreak') {
2139 // Add one pt to textSpace to fix rounding error
2140 cell.text = doc.splitTextToSize(cell.text, textSpace + 1 / doc.scaleFactor(), { fontSize: cell.styles.fontSize });
2141 }
2142 else if (cell.styles.overflow === 'ellipsize') {
2143 cell.text = ellipsize(cell.text, textSpace, cell.styles, doc, '...');
2144 }
2145 else if (cell.styles.overflow === 'hidden') {
2146 cell.text = ellipsize(cell.text, textSpace, cell.styles, doc, '');
2147 }
2148 else if (typeof cell.styles.overflow === 'function') {
2149 cell.text = cell.styles.overflow(cell.text, textSpace);
2150 }
2151 cell.contentHeight = cell.getContentHeight(doc.scaleFactor());
2152 var realContentHeight = cell.contentHeight / cell.rowSpan;
2153 if (cell.rowSpan > 1 &&
2154 rowSpanHeight.count * rowSpanHeight.height <
2155 realContentHeight * cell.rowSpan) {
2156 rowSpanHeight = { height: realContentHeight, count: cell.rowSpan };
2157 }
2158 else if (rowSpanHeight && rowSpanHeight.count > 0) {
2159 if (rowSpanHeight.height > realContentHeight) {
2160 realContentHeight = rowSpanHeight.height;
2161 }
2162 }
2163 if (realContentHeight > row.height) {
2164 row.height = realContentHeight;
2165 }
2166 }
2167 rowSpanHeight.count--;
2168 }
2169}
2170function ellipsize(text, width, styles, doc, overflow) {
2171 return text.map(function (str) { return ellipsizeStr(str, width, styles, doc, overflow); });
2172}
2173exports.ellipsize = ellipsize;
2174function ellipsizeStr(text, width, styles, doc, overflow) {
2175 var precision = 10000 * doc.scaleFactor();
2176 width = Math.ceil(width * precision) / precision;
2177 if (width >= common_1.getStringWidth(text, styles, doc)) {
2178 return text;
2179 }
2180 while (width < common_1.getStringWidth(text + overflow, styles, doc)) {
2181 if (text.length <= 1) {
2182 break;
2183 }
2184 text = text.substring(0, text.length - 1);
2185 }
2186 return text.trim() + overflow;
2187}
2188
2189
2190/***/ }),
2191/* 16 */
2192/***/ (function(module, exports) {
2193
2194if(typeof __WEBPACK_EXTERNAL_MODULE__16__ === 'undefined') {var e = new Error("Cannot find module 'undefined'"); e.code = 'MODULE_NOT_FOUND'; throw e;}
2195module.exports = __WEBPACK_EXTERNAL_MODULE__16__;
2196
2197/***/ })
2198/******/ ]);
2199});
\No newline at end of file