-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjspdf.plugin.autotable.js
2207 lines (2141 loc) · 80.7 KB
/
jspdf.plugin.autotable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
*
* jsPDF AutoTable plugin v3.5.12
*
* Copyright (c) 2020 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable
* Licensed under the MIT License.
* http://opensource.org/licenses/mit-license
*
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory((function webpackLoadOptionalExternalModule() { try { return require("jspdf"); } catch(e) {} }()));
else if(typeof define === 'function' && define.amd)
define(["jspdf"], factory);
else {
var a = typeof exports === 'object' ? factory((function webpackLoadOptionalExternalModule() { try { return require("jspdf"); } catch(e) {} }())) : factory(root["jsPDF"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(typeof this !== 'undefined' ? this : window, function(__WEBPACK_EXTERNAL_MODULE__16__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 10);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseSpacing = exports.getFillStyle = exports.addTableBorder = exports.getStringWidth = void 0;
function getStringWidth(text, styles, doc) {
doc.applyStyles(styles, true);
var textArr = Array.isArray(text) ? text : [text];
var widestLineWidth = textArr
.map(function (text) { return doc.getTextWidth(text); })
.reduce(function (a, b) { return Math.max(a, b); }, 0);
return widestLineWidth;
}
exports.getStringWidth = getStringWidth;
function addTableBorder(doc, table, startPos, cursor) {
var lineWidth = table.settings.tableLineWidth;
var lineColor = table.settings.tableLineColor;
doc.applyStyles({ lineWidth: lineWidth, lineColor: lineColor });
var fillStyle = getFillStyle(lineWidth, false);
if (fillStyle) {
doc.rect(startPos.x, startPos.y, table.getWidth(doc.pageSize().width), cursor.y - startPos.y, fillStyle);
}
}
exports.addTableBorder = addTableBorder;
function getFillStyle(lineWidth, fillColor) {
var drawLine = lineWidth > 0;
var drawBackground = fillColor || fillColor === 0;
if (drawLine && drawBackground) {
return 'DF'; // Fill then stroke
}
else if (drawLine) {
return 'S'; // Only stroke (transparent background)
}
else if (drawBackground) {
return 'F'; // Only fill, no stroke
}
else {
return null;
}
}
exports.getFillStyle = getFillStyle;
function parseSpacing(value, defaultValue) {
var _a, _b, _c, _d;
value = value || defaultValue;
if (Array.isArray(value)) {
if (value.length >= 4) {
return {
top: value[0],
right: value[1],
bottom: value[2],
left: value[3],
};
}
else if (value.length === 3) {
return {
top: value[0],
right: value[1],
bottom: value[2],
left: value[1],
};
}
else if (value.length === 2) {
return {
top: value[0],
right: value[1],
bottom: value[0],
left: value[1],
};
}
else if (value.length === 1) {
value = value[0];
}
else {
value = defaultValue;
}
}
if (typeof value === 'object') {
if (typeof value.vertical === 'number') {
value.top = value.vertical;
value.bottom = value.vertical;
}
if (typeof value.horizontal === 'number') {
value.right = value.horizontal;
value.left = value.horizontal;
}
return {
left: (_a = value.left) !== null && _a !== void 0 ? _a : defaultValue,
top: (_b = value.top) !== null && _b !== void 0 ? _b : defaultValue,
right: (_c = value.right) !== null && _c !== void 0 ? _c : defaultValue,
bottom: (_d = value.bottom) !== null && _d !== void 0 ? _d : defaultValue,
};
}
if (typeof value !== 'number') {
value = defaultValue;
}
return { top: value, right: value, bottom: value, left: value };
}
exports.parseSpacing = parseSpacing;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTheme = exports.defaultStyles = exports.HtmlRowInput = exports.FONT_ROW_RATIO = void 0;
/**
* Ratio between font size and font height. The number comes from jspdf's source code
*/
exports.FONT_ROW_RATIO = 1.15;
var HtmlRowInput = /** @class */ (function (_super) {
__extends(HtmlRowInput, _super);
function HtmlRowInput(element) {
var _this = _super.call(this) || this;
_this._element = element;
return _this;
}
return HtmlRowInput;
}(Array));
exports.HtmlRowInput = HtmlRowInput;
// Base style for all themes
function defaultStyles(scaleFactor) {
return {
font: 'helvetica',
fontStyle: 'normal',
overflow: 'linebreak',
fillColor: false,
textColor: 20,
halign: 'left',
valign: 'top',
fontSize: 10,
cellPadding: 5 / scaleFactor,
lineColor: 200,
lineWidth: 0,
cellWidth: 'auto',
minCellHeight: 0,
minCellWidth: 0,
};
}
exports.defaultStyles = defaultStyles;
function getTheme(name) {
var themes = {
striped: {
table: { fillColor: 255, textColor: 80, fontStyle: 'normal' },
head: { textColor: 255, fillColor: [41, 128, 185], fontStyle: 'bold' },
body: {},
foot: { textColor: 255, fillColor: [41, 128, 185], fontStyle: 'bold' },
alternateRow: { fillColor: 245 },
},
grid: {
table: {
fillColor: 255,
textColor: 80,
fontStyle: 'normal',
lineWidth: 0.1,
},
head: {
textColor: 255,
fillColor: [26, 188, 156],
fontStyle: 'bold',
lineWidth: 0,
},
body: {},
foot: {
textColor: 255,
fillColor: [26, 188, 156],
fontStyle: 'bold',
lineWidth: 0,
},
alternateRow: {},
},
plain: {
head: { fontStyle: 'bold' },
foot: { fontStyle: 'bold' },
},
};
return themes[name];
}
exports.getTheme = getTheme;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocHandler = void 0;
var globalDefaults = {};
var DocHandler = /** @class */ (function () {
function DocHandler(jsPDFDocument) {
this.jsPDFDocument = jsPDFDocument;
this.userStyles = {
// Black for versions of jspdf without getTextColor
textColor: jsPDFDocument.getTextColor
? this.jsPDFDocument.getTextColor()
: 0,
fontSize: jsPDFDocument.internal.getFontSize(),
fontStyle: jsPDFDocument.internal.getFont().fontStyle,
font: jsPDFDocument.internal.getFont().fontName,
};
}
DocHandler.setDefaults = function (defaults, doc) {
if (doc === void 0) { doc = null; }
if (doc) {
doc.__autoTableDocumentDefaults = defaults;
}
else {
globalDefaults = defaults;
}
};
DocHandler.unifyColor = function (c) {
if (Array.isArray(c)) {
return c;
}
else if (typeof c === 'number') {
return [c, c, c];
}
else if (typeof c === 'string') {
return [c];
}
else {
return null;
}
};
DocHandler.prototype.applyStyles = function (styles, fontOnly) {
// Font style needs to be applied before font
// https://github.com/simonbengtsson/jsPDF-AutoTable/issues/632
var _a, _b, _c;
if (fontOnly === void 0) { fontOnly = false; }
if (styles.fontStyle)
this.jsPDFDocument.setFontStyle && this.jsPDFDocument.setFontStyle(styles.fontStyle);
var _d = this.jsPDFDocument.internal.getFont(), fontStyle = _d.fontStyle, fontName = _d.fontName;
if (styles.font)
fontName = styles.font;
if (styles.fontStyle) {
fontStyle = styles.fontStyle;
var availableFontStyles = this.getFontList()[fontName];
if (availableFontStyles && availableFontStyles.indexOf(fontStyle) === -1) {
// Common issue was that the default bold in headers
// made custom fonts not work. For example:
// https://github.com/simonbengtsson/jsPDF-AutoTable/issues/653
this.jsPDFDocument.setFontStyle && this.jsPDFDocument.setFontStyle(availableFontStyles[0]);
fontStyle = availableFontStyles[0];
}
}
this.jsPDFDocument.setFont(fontName, fontStyle);
if (styles.fontSize)
this.jsPDFDocument.setFontSize(styles.fontSize);
if (fontOnly) {
return; // Performance improvement
}
var color = DocHandler.unifyColor(styles.fillColor);
if (color)
(_a = this.jsPDFDocument).setFillColor.apply(_a, color);
color = DocHandler.unifyColor(styles.textColor);
if (color)
(_b = this.jsPDFDocument).setTextColor.apply(_b, color);
color = DocHandler.unifyColor(styles.lineColor);
if (color)
(_c = this.jsPDFDocument).setDrawColor.apply(_c, color);
if (typeof styles.lineWidth === 'number') {
this.jsPDFDocument.setLineWidth(styles.lineWidth);
}
};
DocHandler.prototype.splitTextToSize = function (text, size, opts) {
return this.jsPDFDocument.splitTextToSize(text, size, opts);
};
DocHandler.prototype.rect = function (x, y, width, height, fillStyle) {
return this.jsPDFDocument.rect(x, y, width, height, fillStyle);
};
DocHandler.prototype.getLastAutoTable = function () {
return this.jsPDFDocument.lastAutoTable || null;
};
DocHandler.prototype.getTextWidth = function (text) {
return this.jsPDFDocument.getTextWidth(text);
};
DocHandler.prototype.getDocument = function () {
return this.jsPDFDocument;
};
DocHandler.prototype.setPage = function (page) {
this.jsPDFDocument.setPage(page);
};
DocHandler.prototype.addPage = function () {
return this.jsPDFDocument.addPage();
};
DocHandler.prototype.getFontList = function () {
return this.jsPDFDocument.getFontList();
};
DocHandler.prototype.getGlobalOptions = function () {
return globalDefaults || {};
};
DocHandler.prototype.getDocumentOptions = function () {
return this.jsPDFDocument.__autoTableDocumentDefaults || {};
};
DocHandler.prototype.pageSize = function () {
var pageSize = this.jsPDFDocument.internal.pageSize;
// JSPDF 1.4 uses get functions instead of properties on pageSize
if (pageSize.width == null) {
pageSize = {
width: pageSize.getWidth(),
height: pageSize.getHeight(),
};
}
return pageSize;
};
DocHandler.prototype.scaleFactor = function () {
return this.jsPDFDocument.internal.scaleFactor;
};
DocHandler.prototype.pageNumber = function () {
var pageInfo = this.jsPDFDocument.internal.getCurrentPageInfo();
if (!pageInfo) {
// Only recent versions of jspdf has pageInfo
return this.jsPDFDocument.internal.getNumberOfPages();
}
return pageInfo.pageNumber;
};
return DocHandler;
}());
exports.DocHandler = DocHandler;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* eslint-disable @typescript-eslint/no-unused-vars */
Object.defineProperty(exports, "__esModule", { value: true });
exports.assign = void 0;
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
function assign(target, s, s1, s2, s3) {
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
// eslint-disable-next-line prefer-rest-params
var nextSource = arguments[index];
if (nextSource != null) {
// Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
}
exports.assign = assign;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseHtml = void 0;
var cssParser_1 = __webpack_require__(12);
var config_1 = __webpack_require__(1);
function parseHtml(doc, input, window, includeHiddenHtml, useCss) {
var _a, _b;
if (includeHiddenHtml === void 0) { includeHiddenHtml = false; }
if (useCss === void 0) { useCss = false; }
var tableElement;
if (typeof input === 'string') {
tableElement = window.document.querySelector(input);
}
else {
tableElement = input;
}
var supportedFonts = Object.keys(doc.getFontList());
var scaleFactor = doc.scaleFactor();
var head = [], body = [], foot = [];
if (!tableElement) {
console.error('Html table could not be found with input: ', input);
return { head: head, body: body, foot: foot };
}
for (var i = 0; i < tableElement.rows.length; i++) {
var element = tableElement.rows[i];
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();
var row = parseRowContent(supportedFonts, scaleFactor, window, element, includeHiddenHtml, useCss);
if (!row)
continue;
if (tagName === 'thead') {
head.push(row);
}
else if (tagName === 'tfoot') {
foot.push(row);
}
else {
// Add to body both if parent is tbody or table
body.push(row);
}
}
return { head: head, body: body, foot: foot };
}
exports.parseHtml = parseHtml;
function parseRowContent(supportedFonts, scaleFactor, window, row, includeHidden, useCss) {
var resultRow = new config_1.HtmlRowInput(row);
for (var i = 0; i < row.cells.length; i++) {
var cell = row.cells[i];
var style_1 = window.getComputedStyle(cell);
if (includeHidden || style_1.display !== 'none') {
var cellStyles = void 0;
if (useCss) {
cellStyles = cssParser_1.parseCss(supportedFonts, cell, scaleFactor, style_1, window);
}
resultRow.push({
rowSpan: cell.rowSpan,
colSpan: cell.colSpan,
styles: cellStyles,
_element: cell,
content: parseCellContent(cell),
});
}
}
var style = window.getComputedStyle(row);
if (resultRow.length > 0 && (includeHidden || style.display !== 'none')) {
return resultRow;
}
}
function parseCellContent(orgCell) {
// Work on cloned node to make sure no changes are applied to html table
var cell = orgCell.cloneNode(true);
// Remove extra space and line breaks in markup to make it more similar to
// what would be shown in html
cell.innerHTML = cell.innerHTML.replace(/\n/g, '').replace(/ +/g, ' ');
// Preserve <br> tags as line breaks in the pdf
cell.innerHTML = cell.innerHTML
.split('<br>')
.map(function (part) { return part.trim(); })
.join('\n');
// innerText for ie
return cell.innerText || cell.textContent || '';
}
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Improved text function with halign and valign support
* Inspiration from: http://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113#28433113
*/
function default_1(text, x, y, styles, doc) {
styles = styles || {};
var FONT_ROW_RATIO = 1.15;
var k = doc.internal.scaleFactor;
var fontSize = doc.internal.getFontSize() / k;
var splitRegex = /\r\n|\r|\n/g;
var splitText = '';
var lineCount = 1;
if (styles.valign === 'middle' ||
styles.valign === 'bottom' ||
styles.halign === 'center' ||
styles.halign === 'right') {
splitText = typeof text === 'string' ? text.split(splitRegex) : text;
lineCount = splitText.length || 1;
}
// Align the top
y += fontSize * (2 - FONT_ROW_RATIO);
if (styles.valign === 'middle')
y -= (lineCount / 2) * fontSize * FONT_ROW_RATIO;
else if (styles.valign === 'bottom')
y -= lineCount * fontSize * FONT_ROW_RATIO;
if (styles.halign === 'center' || styles.halign === 'right') {
var alignSize = fontSize;
if (styles.halign === 'center')
alignSize *= 0.5;
if (splitText && lineCount >= 1) {
for (var iLine = 0; iLine < splitText.length; iLine++) {
doc.text(splitText[iLine], x - doc.getStringUnitWidth(splitText[iLine]) * alignSize, y);
y += fontSize * FONT_ROW_RATIO;
}
return doc;
}
x -= doc.getStringUnitWidth(text) * alignSize;
}
if (styles.halign === 'justify') {
doc.text(text, x, y, {
maxWidth: styles.maxWidth || 100,
align: 'justify',
});
}
else {
doc.text(text, x, y);
}
return doc;
}
exports.default = default_1;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseInput = void 0;
var htmlParser_1 = __webpack_require__(4);
var polyfills_1 = __webpack_require__(3);
var common_1 = __webpack_require__(0);
var documentHandler_1 = __webpack_require__(2);
var inputValidator_1 = __webpack_require__(13);
function parseInput(d, current) {
var doc = new documentHandler_1.DocHandler(d);
var document = doc.getDocumentOptions();
var global = doc.getGlobalOptions();
inputValidator_1.default(doc, global, document, current);
var options = polyfills_1.assign({}, global, document, current);
var win;
if (typeof window !== 'undefined') {
win = window;
}
var styles = parseStyles(global, document, current);
var hooks = parseHooks(global, document, current);
var settings = parseSettings(doc, options);
var content = parseContent(doc, options, win);
return {
id: current.tableId,
content: content,
hooks: hooks,
styles: styles,
settings: settings,
};
}
exports.parseInput = parseInput;
function parseStyles(gInput, dInput, cInput) {
var styleOptions = {
styles: {},
headStyles: {},
bodyStyles: {},
footStyles: {},
alternateRowStyles: {},
columnStyles: {},
};
var _loop_1 = function (prop) {
if (prop === 'columnStyles') {
var global_1 = gInput[prop];
var document_1 = dInput[prop];
var current = cInput[prop];
styleOptions.columnStyles = polyfills_1.assign({}, global_1, document_1, current);
}
else {
var allOptions = [gInput, dInput, cInput];
var styles = allOptions.map(function (opts) { return opts[prop] || {}; });
styleOptions[prop] = polyfills_1.assign({}, styles[0], styles[1], styles[2]);
}
};
for (var _i = 0, _a = Object.keys(styleOptions); _i < _a.length; _i++) {
var prop = _a[_i];
_loop_1(prop);
}
return styleOptions;
}
function parseHooks(global, document, current) {
var allOptions = [global, document, current];
var result = {
didParseCell: [],
willDrawCell: [],
didDrawCell: [],
didDrawPage: [],
};
for (var _i = 0, allOptions_1 = allOptions; _i < allOptions_1.length; _i++) {
var options = allOptions_1[_i];
if (options.didParseCell)
result.didParseCell.push(options.didParseCell);
if (options.willDrawCell)
result.willDrawCell.push(options.willDrawCell);
if (options.didDrawCell)
result.didDrawCell.push(options.didDrawCell);
if (options.didDrawPage)
result.didDrawPage.push(options.didDrawPage);
}
return result;
}
function parseSettings(doc, options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
var margin = common_1.parseSpacing(options.margin, 40 / doc.scaleFactor());
var startY = (_a = getStartY(doc, options.startY)) !== null && _a !== void 0 ? _a : margin.top;
var showFoot;
if (options.showFoot === true) {
showFoot = 'everyPage';
}
else if (options.showFoot === false) {
showFoot = 'never';
}
else {
showFoot = (_b = options.showFoot) !== null && _b !== void 0 ? _b : 'everyPage';
}
var showHead;
if (options.showHead === true) {
showHead = 'everyPage';
}
else if (options.showHead === false) {
showHead = 'never';
}
else {
showHead = (_c = options.showHead) !== null && _c !== void 0 ? _c : 'everyPage';
}
var useCss = (_d = options.useCss) !== null && _d !== void 0 ? _d : false;
var theme = options.theme || (useCss ? 'plain' : 'striped');
return {
includeHiddenHtml: (_e = options.includeHiddenHtml) !== null && _e !== void 0 ? _e : false,
useCss: useCss,
theme: theme,
startY: startY,
margin: margin,
pageBreak: (_f = options.pageBreak) !== null && _f !== void 0 ? _f : 'auto',
rowPageBreak: (_g = options.rowPageBreak) !== null && _g !== void 0 ? _g : 'auto',
tableWidth: (_h = options.tableWidth) !== null && _h !== void 0 ? _h : 'auto',
showHead: showHead,
showFoot: showFoot,
tableLineWidth: (_j = options.tableLineWidth) !== null && _j !== void 0 ? _j : 0,
tableLineColor: (_k = options.tableLineColor) !== null && _k !== void 0 ? _k : 200,
};
}
function getStartY(doc, userStartY) {
var previous = doc.getLastAutoTable();
var sf = doc.scaleFactor();
var currentPage = doc.pageNumber();
var isSamePageAsPreviousTable = false;
if (previous && previous.startPageNumber) {
var endingPage = previous.startPageNumber + previous.pageNumber - 1;
isSamePageAsPreviousTable = endingPage === currentPage;
}
if (typeof userStartY === 'number') {
return userStartY;
}
else if (userStartY == null || userStartY === false) {
if (isSamePageAsPreviousTable && (previous === null || previous === void 0 ? void 0 : previous.finalY) != null) {
// Some users had issues with overlapping tables when they used multiple
// tables without setting startY so setting it here to a sensible default.
return previous.finalY + 20 / sf;
}
}
return null;
}
function parseContent(doc, options, window) {
var head = options.head || [];
var body = options.body || [];
var foot = options.foot || [];
if (options.html) {
var hidden = options.includeHiddenHtml;
if (window) {
var htmlContent = htmlParser_1.parseHtml(doc, options.html, window, hidden, options.useCss) || {};
head = htmlContent.head || head;
body = htmlContent.body || head;
foot = htmlContent.foot || head;
}
else {
console.error('Cannot parse html in non browser environment');
}
}
var columns = options.columns || parseColumns(head, body, foot);
return {
columns: columns,
head: head,
body: body,
foot: foot,
};
}
function parseColumns(head, body, foot) {
var firstRow = head[0] || body[0] || foot[0] || [];
var result = [];
Object.keys(firstRow)
.filter(function (key) { return key !== '_element'; })
.forEach(function (key) {
var colSpan = 1;
var input;
if (Array.isArray(firstRow)) {
input = firstRow[parseInt(key)];
}
else {
input = firstRow[key];
}
if (typeof input === 'object' && !Array.isArray(input)) {
colSpan = (input === null || input === void 0 ? void 0 : input.colSpan) || 1;
}
for (var i = 0; i < colSpan; i++) {
var id = void 0;
if (Array.isArray(firstRow)) {
id = result.length;
}
else {
id = key + (i > 0 ? "_" + i : '');
}
var rowResult = { dataKey: id };
result.push(rowResult);
}
});
return result;
}
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addPage = exports.drawTable = void 0;
var config_1 = __webpack_require__(1);
var common_1 = __webpack_require__(0);
var models_1 = __webpack_require__(8);
var documentHandler_1 = __webpack_require__(2);
var polyfills_1 = __webpack_require__(3);
var autoTableText_1 = __webpack_require__(5);
function drawTable(jsPDFDoc, table) {
var settings = table.settings;
var startY = settings.startY;
var margin = settings.margin;
var cursor = {
x: margin.left,
y: startY,
};
var sectionsHeight = table.getHeadHeight(table.columns) + table.getFootHeight(table.columns);
var minTableBottomPos = startY + margin.bottom + sectionsHeight;
if (settings.pageBreak === 'avoid') {
var rows = table.allRows();
var tableHeight = rows.reduce(function (acc, row) { return acc + row.height; }, 0);
minTableBottomPos += tableHeight;
}
var doc = new documentHandler_1.DocHandler(jsPDFDoc);
if (settings.pageBreak === 'always' ||
(settings.startY != null && minTableBottomPos > doc.pageSize().height)) {
nextPage(doc);
cursor.y = margin.top;
}
var startPos = polyfills_1.assign({}, cursor);
table.startPageNumber = doc.pageNumber();
doc.applyStyles(doc.userStyles);
if (settings.showHead === 'firstPage' || settings.showHead === 'everyPage') {
table.head.forEach(function (row) { return printRow(doc, table, row, cursor); });
}
doc.applyStyles(doc.userStyles);
table.body.forEach(function (row, index) {
var isLastRow = index === table.body.length - 1;
printFullRow(doc, table, row, isLastRow, startPos, cursor);
});
doc.applyStyles(doc.userStyles);
if (settings.showFoot === 'lastPage' || settings.showFoot === 'everyPage') {
table.foot.forEach(function (row) { return printRow(doc, table, row, cursor); });
}
common_1.addTableBorder(doc, table, startPos, cursor);
table.callEndPageHooks(doc, cursor);
table.finalY = cursor.y;
jsPDFDoc.lastAutoTable = table;
jsPDFDoc.previousAutoTable = table; // Deprecated
if (jsPDFDoc.autoTable)
jsPDFDoc.autoTable.previous = table; // Deprecated
doc.applyStyles(doc.userStyles);
}
exports.drawTable = drawTable;
function getRemainingLineCount(cell, remainingPageSpace, doc) {
var fontHeight = (cell.styles.fontSize / doc.scaleFactor()) * config_1.FONT_ROW_RATIO;
var vPadding = cell.padding('vertical');
var remainingLines = Math.floor((remainingPageSpace - vPadding) / fontHeight);
return Math.max(0, remainingLines);
}
function modifyRowToFit(row, remainingPageSpace, table, doc) {
var cells = {};
row.spansMultiplePages = true;
var rowHeight = 0;
for (var _i = 0, _a = table.columns; _i < _a.length; _i++) {
var column = _a[_i];
var cell = row.cells[column.index];
if (!cell)
continue;
if (!Array.isArray(cell.text)) {
cell.text = [cell.text];
}
var remainderCell = new models_1.Cell(cell.raw, cell.styles, cell.section);
remainderCell = polyfills_1.assign(remainderCell, cell);
remainderCell.text = [];
var remainingLineCount = getRemainingLineCount(cell, remainingPageSpace, doc);
if (cell.text.length > remainingLineCount) {
remainderCell.text = cell.text.splice(remainingLineCount, cell.text.length);
}
var scaleFactor = doc.scaleFactor();
cell.contentHeight = cell.getContentHeight(scaleFactor);
if (cell.contentHeight >= remainingPageSpace) {
cell.contentHeight = remainingPageSpace;
remainderCell.styles.minCellHeight -= remainingPageSpace;
}
if (cell.contentHeight > row.height) {
row.height = cell.contentHeight;
}
remainderCell.contentHeight = remainderCell.getContentHeight(scaleFactor);
if (remainderCell.contentHeight > rowHeight) {
rowHeight = remainderCell.contentHeight;
}
cells[column.index] = remainderCell;
}
var remainderRow = new models_1.Row(row.raw, -1, row.section, cells, true);
remainderRow.height = rowHeight;
for (var _b = 0, _c = table.columns; _b < _c.length; _b++) {
var column = _c[_b];
var remainderCell = remainderRow.cells[column.index];
if (remainderCell) {
remainderCell.height = remainderRow.height;
}
var cell = row.cells[column.index];
if (cell) {
cell.height = row.height;
}
}
return remainderRow;
}
function shouldPrintOnCurrentPage(doc, row, remainingPageSpace, table) {
var pageHeight = doc.pageSize().height;
var margin = table.settings.margin;
var marginHeight = margin.top + margin.bottom;
var maxRowHeight = pageHeight - marginHeight;
if (row.section === 'body') {
// Should also take into account that head and foot is not
// on every page with some settings
maxRowHeight -=
table.getHeadHeight(table.columns) + table.getFootHeight(table.columns);
}
var minRowHeight = row.getMinimumRowHeight(table.columns, doc);
var minRowFits = minRowHeight < remainingPageSpace;
if (minRowHeight > maxRowHeight) {
console.error("Will not be able to print row " + row.index + " correctly since it's minimum height is larger than page height");
return true;
}
if (!minRowFits) {
return false;
}
var rowHasRowSpanCell = row.hasRowSpan(table.columns);
var rowHigherThanPage = row.getMaxCellHeight(table.columns) > maxRowHeight;
if (rowHigherThanPage) {
if (rowHasRowSpanCell) {
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.");
}
return true;
}
if (rowHasRowSpanCell) {
// Currently a new page is required whenever a rowspan row don't fit a page.
return false;
}
if (table.settings.rowPageBreak === 'avoid') {
return false;
}
// In all other cases print the row on current page
return true;
}
function printFullRow(doc, table, row, isLastRow, startPos, cursor) {
var remainingSpace = getRemainingPageSpace(doc, table, isLastRow, cursor);
if (row.canEntireRowFit(remainingSpace, table.columns)) {
printRow(doc, table, row, cursor);
}
else {
if (shouldPrintOnCurrentPage(doc, row, remainingSpace, table)) {
var remainderRow = modifyRowToFit(row, remainingSpace, table, doc);
printRow(doc, table, row, cursor);
addPage(doc, table, startPos, cursor);
printFullRow(doc, table, remainderRow, isLastRow, startPos, cursor);
}
else {
addPage(doc, table, startPos, cursor);
printFullRow(doc, table, row, isLastRow, startPos, cursor);
}
}