Built files from Bizgaze WebServer
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

jspdf.plugin.autotable.js 104KB

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