jspdf-autotable
Advanced tools
Comparing version 2.0.26 to 2.0.27
12
build.js
var fs = require('fs'); | ||
var rollup = require('rollup'); | ||
var babel = require('rollup-plugin-babel'); | ||
var nodeResolve = require('rollup-plugin-node-resolve'); | ||
var commonjs = require('rollup-plugin-commonjs'); | ||
var uglify = require("uglify-js"); | ||
@@ -22,4 +24,7 @@ | ||
rollup.rollup({ | ||
entry: './src/main.js', | ||
plugins: [babel({presets: ["es2015-rollup"]})] | ||
entry: 'src/main.js', | ||
plugins: [nodeResolve({jsnext: true, main: true, skip: ['jspdf']}), commonjs({}), babel({ | ||
exclude: 'node_modules/**', | ||
presets: ["es2015-rollup"] | ||
})] | ||
}).then(function (bundle) { | ||
@@ -49,5 +54,6 @@ var code = bundle.generate({ | ||
console.log('Done'); | ||
}, function(err) { | ||
}).catch(function(err) { | ||
console.log('ROLLUP ERROR:'); | ||
console.error(err); | ||
}); | ||
} |
/** | ||
* jsPDF AutoTable plugin v2.0.26 | ||
* jsPDF AutoTable plugin v2.0.27 | ||
* Copyright (c) 2014 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable | ||
@@ -10,2 +10,2 @@ * | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("jspdf")):"function"==typeof define&&define.amd?define(["jspdf"],e):e(t.jsPDF)}(this,function(t){"use strict";function e(){return{theme:"striped",styles:{},headerStyles:{},bodyStyles:{},alternateRowStyles:{},columnStyles:{},startY:!1,margin:40,pageBreak:"auto",tableWidth:"auto",createdHeaderCell:function(t,e){},createdCell:function(t,e){},drawHeaderRow:function(t,e){},drawRow:function(t,e){},drawHeaderCell:function(t,e){},drawCell:function(t,e){},beforePageContent:function(t){},afterPageContent:function(t){}}}function n(){return{cellPadding:5,fontSize:10,font:"helvetica",lineColor:200,lineWidth:.1,fontStyle:"normal",overflow:"ellipsize",fillColor:255,textColor:20,halign:"left",valign:"top",fillStyle:"F",rowHeight:20,columnWidth:"auto"}}function o(t,e,n){t&&"object"===("undefined"==typeof t?"undefined":g["typeof"](t))||console.error("The headers should be an object or array, is: "+("undefined"==typeof t?"undefined":g["typeof"](t))),e&&"object"===("undefined"==typeof e?"undefined":g["typeof"](e))||console.error("The data should be an object or array, is: "+("undefined"==typeof e?"undefined":g["typeof"](e))),n&&"object"!==("undefined"==typeof n?"undefined":g["typeof"](n))&&console.error("The data should be an object or array, is: "+("undefined"==typeof e?"undefined":g["typeof"](e))),Array.prototype.forEach||console.error("The current browser does not support Array.prototype.forEach which is required for jsPDF-AutoTable. You can try polyfilling it by including this script https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Polyfill")}function i(t,e){A=new p;var n=/\r\n|\r|\n/g,o=new w(t);o.index=-1;var i=C.styles([x[z.theme].table,x[z.theme].header]);o.styles=Object.assign({},i,z.styles,z.headerStyles),t.forEach(function(t,e){"object"===("undefined"==typeof t?"undefined":g["typeof"](t))&&(e="undefined"!=typeof t.dataKey?t.dataKey:t.key),"undefined"!=typeof t.width&&console.error("Use of deprecated option: column.width, use column.styles.columnWidth instead.");var i=new m(e);i.styles=z.columnStyles[i.dataKey]||{},A.columns.push(i);var r=new b;r.raw="object"===("undefined"==typeof t?"undefined":g["typeof"](t))?t.title:t,r.styles=Object.assign({},o.styles),r.text=""+r.raw,r.contentWidth=2*r.styles.cellPadding+y(r.text,r.styles),r.text=r.text.split(n),o.cells[e]=r,z.createdHeaderCell(r,{column:i,row:o,settings:z})}),A.headerRow=o,e.forEach(function(t,e){var o=new w(t),i=e%2===0,r=C.styles([x[z.theme].table,i?x[z.theme].alternateRow:{}]),l=Object.assign({},z.styles,z.bodyStyles,i?z.alternateRowStyles:{});o.styles=Object.assign({},r,l),o.index=e,A.columns.forEach(function(e){var i=new b;i.raw=t[e.dataKey],i.styles=Object.assign({},o.styles,e.styles),i.text="undefined"!=typeof i.raw?""+i.raw:"",o.cells[e.dataKey]=i,z.createdCell(i,c({column:e,row:o})),i.contentWidth=2*i.styles.cellPadding+y(i.text,i.styles),i.text=i.text.split(n)}),A.rows.push(o)})}function r(t,e){var n=0;A.columns.forEach(function(t){t.contentWidth=A.headerRow.cells[t.dataKey].contentWidth,A.rows.forEach(function(e){var n=e.cells[t.dataKey].contentWidth;n>t.contentWidth&&(t.contentWidth=n)}),t.width=t.contentWidth,n+=t.contentWidth}),A.contentWidth=n;var o=e-z.margin.left-z.margin.right,i=o;"number"==typeof z.tableWidth?i=z.tableWidth:"wrap"===z.tableWidth&&(i=A.contentWidth),A.width=o>i?i:o;var r=[],a=0,s=A.width/A.columns.length,d=0;A.columns.forEach(function(t){var e=C.styles([x[z.theme].table,z.styles,t.styles]);"wrap"===e.columnWidth?t.width=t.contentWidth:"number"==typeof e.columnWidth?t.width=e.columnWidth:("auto"===e.columnWidth,t.contentWidth<=s&&A.contentWidth>A.width?t.width=t.contentWidth:(r.push(t),a+=t.contentWidth,t.width=0)),d+=t.width}),l(r,d,a,s),A.height=0;var h=A.rows.concat(A.headerRow);h.forEach(function(e,n){var o=0;A.columns.forEach(function(n){var i=e.cells[n.dataKey];f(i.styles);var r=n.width-2*i.styles.cellPadding;if("linebreak"===i.styles.overflow)try{i.text=t.splitTextToSize(i.text,r+1,{fontSize:i.styles.fontSize})}catch(l){if(!(l instanceof TypeError&&Array.isArray(i.text)))throw l;i.text=t.splitTextToSize(i.text.join(" "),r+1,{fontSize:i.styles.fontSize})}else"ellipsize"===i.styles.overflow?i.text=u(i.text,r,i.styles):"visible"===i.styles.overflow||("hidden"===i.styles.overflow?i.text=u(i.text,r,i.styles,""):"function"==typeof i.styles.overflow?i.text=i.styles.overflow(i.text,r):console.error("Unrecognized overflow type: "+i.styles.overflow));var a=Array.isArray(i.text)?i.text.length-1:0;a>o&&(o=a)}),e.heightStyle=e.styles.rowHeight,e.height=e.heightStyle+o*e.styles.fontSize*v,A.height+=e.height})}function l(t,e,n,o){for(var i=A.width-e-n,r=0;r<t.length;r++){var a=t[r],s=a.contentWidth/n,d=a.contentWidth+i*s<o;if(0>i&&d){t.splice(r,1),n-=a.contentWidth,a.width=o,e+=a.width,l(t,e,n,o);break}a.width=a.contentWidth+i*s}}function a(t){z.afterPageContent(c()),t(),A.pageCount++,W={x:z.margin.left,y:z.margin.top},z.beforePageContent(c()),z.drawHeaderRow(A.headerRow,c({row:A.headerRow}))!==!1&&h(A.headerRow,z.drawHeaderCell)}function s(t){var e=W.y+t+z.margin.bottom;return e>=j.height}function d(t){A.rows.forEach(function(e,n){if(s(e.height)){a(t)}e.y=W.y,z.drawRow(e,c({row:e}))!==!1&&h(e,z.drawCell)})}function h(t,e){W.x=z.margin.left;for(var n=0;n<A.columns.length;n++){var o=A.columns[n],i=t.cells[o.dataKey];if(i){f(i.styles),i.x=W.x,i.y=W.y,i.height=t.height,i.width=o.width,"top"===i.styles.valign?i.textPos.y=W.y+i.styles.cellPadding:"bottom"===i.styles.valign?i.textPos.y=W.y+t.height-i.styles.cellPadding:i.textPos.y=W.y+t.height/2,"right"===i.styles.halign?i.textPos.x=i.x+i.width-i.styles.cellPadding:"center"===i.styles.halign?i.textPos.x=i.x+i.width/2:i.textPos.x=i.x+i.styles.cellPadding;var r=c({column:o,row:t});e(i,r)!==!1&&(S.rect(i.x,i.y,i.width,i.height,i.styles.fillStyle),S.autoTableText(i.text,i.textPos.x,i.textPos.y,{halign:i.styles.halign,valign:i.styles.valign})),W.x+=i.width}}W.y+=t.height}function f(t){Object.keys(P).forEach(function(e){var n=t[e],o=P[e];"undefined"!=typeof n&&(n.constructor===Array?o.apply(this,n):o(n))})}function c(t){return Object.assign({pageCount:A.pageCount,settings:z,table:A,cursor:W},t||{})}function y(t,e){f(e);var n=S.getStringUnitWidth(t);return n*e.fontSize}function u(t,e,n,o){if(o="undefined"!=typeof o?o:"...",Array.isArray(t))return t.forEach(function(i,r){t[r]=u(i,e,n,o)}),t;if(e>=y(t,n))return t;for(;e<y(t+o,n)&&!(t.length<2);)t=t.substring(0,t.length-1);return t.trim()+o}t="default"in t?t["default"]:t;var g={};g["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},g.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},g.createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}();var p=function R(){g.classCallCheck(this,R),this.height=0,this.width=0,this.contentWidth=0,this.rows=[],this.columns=[],this.headerRow=null,this.settings={},this.pageCount=1},w=function T(t){g.classCallCheck(this,T),this.raw=t||{},this.index=0,this.styles={},this.cells={},this.height=0,this.y=0},b=function O(t){g.classCallCheck(this,O),this.raw=t,this.styles={},this.text="",this.contentWidth=0,this.textPos={},this.height=0,this.width=0,this.x=0,this.y=0},m=function E(t){g.classCallCheck(this,E),this.dataKey=t,this.options={},this.styles={},this.contentWidth=0,this.width=0,this.x=0},v=1.15,x={striped:{table:{fillColor:255,textColor:80,fontStyle:"normal",fillStyle:"F"},header:{textColor:255,fillColor:[41,128,185],rowHeight:23,fontStyle:"bold"},body:{},alternateRow:{fillColor:245}},grid:{table:{fillColor:255,textColor:80,fontStyle:"normal",lineWidth:.1,fillStyle:"DF"},header:{textColor:255,fillColor:[26,188,156],rowHeight:23,fillStyle:"F",fontStyle:"bold"},body:{},alternateRow:{}},plain:{header:{fontStyle:"bold"}}},C=function(){function t(){g.classCallCheck(this,t)}return g.createClass(t,null,[{key:"initSettings",value:function(t){var n=Object.assign({},e(),t);"undefined"!=typeof n.extendWidth&&(n.tableWidth=n.extendWidth?"auto":"wrap",console.error("Use of deprecated option: extendWidth, use tableWidth instead.")),"undefined"!=typeof n.margins&&("undefined"==typeof n.margin&&(n.margin=n.margins),console.error("Use of deprecated option: margins, use margin instead.")),[["padding","cellPadding"],["lineHeight","rowHeight"],"fontSize","overflow"].forEach(function(t){var e="string"==typeof t?t:t[0],o="string"==typeof t?t:t[1];"undefined"!=typeof n[e]&&("undefined"==typeof n.styles[o]&&(n.styles[o]=n[e]),console.error("Use of deprecated option: "+e+", use the style "+o+" instead."))});var o=n.margin;return n.margin={},"number"==typeof o.horizontal&&(o.right=o.horizontal,o.left=o.horizontal),"number"==typeof o.vertical&&(o.top=o.vertical,o.bottom=o.vertical),["top","right","bottom","left"].forEach(function(t,e){if("number"==typeof o)n.margin[t]=o;else{var i=Array.isArray(o)?e:t;n.margin[t]="number"==typeof o[i]?o[i]:40}}),n}},{key:"styles",value:function(t){return t.unshift(n()),t.unshift({}),Object.assign.apply(this,t)}}]),t}();"function"!=typeof Object.assign&&!function(){Object.assign=function(t){if(void 0===t||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n<arguments.length;n++){var o=arguments[n];if(void 0!==o&&null!==o)for(var i in o)o.hasOwnProperty(i)&&(e[i]=o[i])}return e}}(),Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),Object.values||(Object.values=function(t){return Object.keys(t).map(function(e){return t[e]})});var S,W,P,j,z,A;t.API.autoTable=function(t,e,n){o(t,e,n),S=this,j=S.internal.pageSize,P={fillColor:S.setFillColor,textColor:S.setTextColor,fontStyle:S.setFontStyle,lineColor:S.setDrawColor,lineWidth:S.setLineWidth,font:S.setFont,fontSize:S.setFontSize},z=C.initSettings(n||{}),W={x:z.margin.left,y:z.startY===!1?z.margin.top:z.startY};var l={textColor:30,fontSize:S.internal.getFontSize(),fontStyle:S.internal.getFont().fontStyle};i(t,e),r(this,j.width);var a=A.rows[0]&&"auto"===z.pageBreak?A.rows[0].height:0,s=z.startY+z.margin.bottom+A.headerRow.height+a;return"avoid"===z.pageBreak&&(s+=A.height),("always"===z.pageBreak&&z.startY!==!1||z.startY!==!1&&s>j.height)&&(this.addPage(this.addPage),W.y=z.margin.top),f(l),z.beforePageContent(c()),z.drawHeaderRow(A.headerRow,c({row:A.headerRow}))!==!1&&h(A.headerRow,z.drawHeaderCell),f(l),d(this.addPage),z.afterPageContent(c()),f(l),this},t.API.autoTableEndPosY=function(){return"undefined"==typeof W||"undefined"==typeof W.y?0:W.y},t.API.autoTableHtmlToJson=function(t,e){e=e||!1;for(var n={},o=[],i=t.rows[0],r=0;r<i.cells.length;r++){var l=i.cells[r],a=window.getComputedStyle(l);(e||"none"!==a.display)&&(n[r]=l?l.textContent.trim():"")}for(var s=1;s<t.rows.length;s++){var d=t.rows[s],a=window.getComputedStyle(d);if(e||"none"!==a.display){var h=[],f=!0,c=!1,y=void 0;try{for(var u,g=Object.keys(n)[Symbol.iterator]();!(f=(u=g.next()).done);f=!0){var p=u.value,l=d.cells[p],w=l?l.textContent.trim():"";h.push(w)}}catch(b){c=!0,y=b}finally{try{!f&&g["return"]&&g["return"]()}finally{if(c)throw y}}o.push(h)}}return{columns:Object.values(n),rows:o,data:o}},t.API.autoTableText=function(t,e,n,o){"number"==typeof e&&"number"==typeof n||console.error("The x and y parameters are required. Missing for the text: ",t);var i=this.internal.getFontSize()/this.internal.scaleFactor,r=v,l=/\r\n|\r|\n/g,a=null,s=1;if("middle"!==o.valign&&"bottom"!==o.valign&&"center"!==o.halign&&"right"!==o.halign||(a="string"==typeof t?t.split(l):t,s=a.length||1),n+=i*(2-r),"middle"===o.valign?n-=s/2*i:"bottom"===o.valign&&(n-=s*i),"center"===o.halign||"right"===o.halign){var d=i;if("center"===o.halign&&(d*=.5),s>=1){for(var h=0;h<a.length;h++)this.text(a[h],e-this.getStringUnitWidth(a[h])*d,n),n+=i;return S}e-=this.getStringUnitWidth(t)*d}return this.text(t,e,n),this}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("jspdf")):"function"==typeof define&&define.amd?define(["jspdf"],e):e(t.jsPDF)}(this,function(t){"use strict";function e(){return{theme:"striped",styles:{},headerStyles:{},bodyStyles:{},alternateRowStyles:{},columnStyles:{},startY:!1,margin:40,pageBreak:"auto",tableWidth:"auto",createdHeaderCell:function(t,e){},createdCell:function(t,e){},drawHeaderRow:function(t,e){},drawRow:function(t,e){},drawHeaderCell:function(t,e){},drawCell:function(t,e){},beforePageContent:function(t){},afterPageContent:function(t){}}}function n(){return{cellPadding:5,fontSize:10,font:"helvetica",lineColor:200,lineWidth:.1,fontStyle:"normal",overflow:"ellipsize",fillColor:255,textColor:20,halign:"left",valign:"top",fillStyle:"F",rowHeight:20,columnWidth:"auto"}}function o(t,e,n){t&&"object"===("undefined"==typeof t?"undefined":g(t))||console.error("The headers should be an object or array, is: "+("undefined"==typeof t?"undefined":g(t))),e&&"object"===("undefined"==typeof e?"undefined":g(e))||console.error("The data should be an object or array, is: "+("undefined"==typeof e?"undefined":g(e))),n&&"object"!==("undefined"==typeof n?"undefined":g(n))&&console.error("The data should be an object or array, is: "+("undefined"==typeof e?"undefined":g(e))),Array.prototype.forEach||console.error("The current browser does not support Array.prototype.forEach which is required for jsPDF-AutoTable. You can try polyfilling it by including this script https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Polyfill")}function i(t,e){T=new b;var n=/\r\n|\r|\n/g,o=new m(t);o.index=-1;var i=C.styles([W[R.theme].table,W[R.theme].header]);o.styles=Object.assign({},i,R.styles,R.headerStyles),t.forEach(function(t,e){"object"===("undefined"==typeof t?"undefined":g(t))&&(e="undefined"!=typeof t.dataKey?t.dataKey:t.key),"undefined"!=typeof t.width&&console.error("Use of deprecated option: column.width, use column.styles.columnWidth instead.");var i=new x(e);i.styles=R.columnStyles[i.dataKey]||{},T.columns.push(i);var r=new v;r.raw="object"===("undefined"==typeof t?"undefined":g(t))?t.title:t,r.styles=Object.assign({},o.styles),r.text=""+r.raw,r.contentWidth=2*r.styles.cellPadding+y(r.text,r.styles),r.text=r.text.split(n),o.cells[e]=r,R.createdHeaderCell(r,{column:i,row:o,settings:R})}),T.headerRow=o,e.forEach(function(t,e){var o=new m(t),i=e%2===0,r=C.styles([W[R.theme].table,i?W[R.theme].alternateRow:{}]),l=Object.assign({},R.styles,R.bodyStyles,i?R.alternateRowStyles:{});o.styles=Object.assign({},r,l),o.index=e,T.columns.forEach(function(e){var i=new v;i.raw=t[e.dataKey],i.styles=Object.assign({},o.styles,e.styles),i.text="undefined"!=typeof i.raw?""+i.raw:"",o.cells[e.dataKey]=i,R.createdCell(i,c({column:e,row:o})),i.contentWidth=2*i.styles.cellPadding+y(i.text,i.styles),i.text=i.text.split(n)}),T.rows.push(o)})}function r(t,e){var n=0;T.columns.forEach(function(t){t.contentWidth=T.headerRow.cells[t.dataKey].contentWidth,T.rows.forEach(function(e){var n=e.cells[t.dataKey].contentWidth;n>t.contentWidth&&(t.contentWidth=n)}),t.width=t.contentWidth,n+=t.contentWidth}),T.contentWidth=n;var o=e-R.margin.left-R.margin.right,i=o;"number"==typeof R.tableWidth?i=R.tableWidth:"wrap"===R.tableWidth&&(i=T.contentWidth),T.width=i<o?i:o;var r=[],a=0,s=T.width/T.columns.length,d=0;T.columns.forEach(function(t){var e=C.styles([W[R.theme].table,R.styles,t.styles]);"wrap"===e.columnWidth?t.width=t.contentWidth:"number"==typeof e.columnWidth?t.width=e.columnWidth:("auto"===e.columnWidth,t.contentWidth<=s&&T.contentWidth>T.width?t.width=t.contentWidth:(r.push(t),a+=t.contentWidth,t.width=0)),d+=t.width}),l(r,d,a,s),T.height=0;var h=T.rows.concat(T.headerRow);h.forEach(function(e,n){var o=0;T.columns.forEach(function(n){var i=e.cells[n.dataKey];f(i.styles);var r=n.width-2*i.styles.cellPadding;if("linebreak"===i.styles.overflow)try{i.text=t.splitTextToSize(i.text,r+1,{fontSize:i.styles.fontSize})}catch(e){if(!(e instanceof TypeError&&Array.isArray(i.text)))throw e;i.text=t.splitTextToSize(i.text.join(" "),r+1,{fontSize:i.styles.fontSize})}else"ellipsize"===i.styles.overflow?i.text=u(i.text,r,i.styles):"visible"===i.styles.overflow||("hidden"===i.styles.overflow?i.text=u(i.text,r,i.styles,""):"function"==typeof i.styles.overflow?i.text=i.styles.overflow(i.text,r):console.error("Unrecognized overflow type: "+i.styles.overflow));var l=Array.isArray(i.text)?i.text.length-1:0;l>o&&(o=l)}),e.heightStyle=e.styles.rowHeight,e.height=e.heightStyle+o*e.styles.fontSize*S,T.height+=e.height})}function l(t,e,n,o){for(var i=T.width-e-n,r=0;r<t.length;r++){var a=t[r],s=a.contentWidth/n,d=a.contentWidth+i*s<o;if(i<0&&d){t.splice(r,1),n-=a.contentWidth,a.width=o,e+=a.width,l(t,e,n,o);break}a.width=a.contentWidth+i*s}}function a(t){R.afterPageContent(c()),t(),T.pageCount++,j={x:R.margin.left,y:R.margin.top},R.beforePageContent(c()),R.drawHeaderRow(T.headerRow,c({row:T.headerRow}))!==!1&&h(T.headerRow,R.drawHeaderCell)}function s(t){var e=j.y+t+R.margin.bottom;return e>=A.height}function d(t){T.rows.forEach(function(e,n){if(s(e.height)){a(t)}e.y=j.y,R.drawRow(e,c({row:e}))!==!1&&h(e,R.drawCell)})}function h(t,e){j.x=R.margin.left;for(var n=0;n<T.columns.length;n++){var o=T.columns[n],i=t.cells[o.dataKey];if(i){f(i.styles),i.x=j.x,i.y=j.y,i.height=t.height,i.width=o.width,"top"===i.styles.valign?i.textPos.y=j.y+i.styles.cellPadding:"bottom"===i.styles.valign?i.textPos.y=j.y+t.height-i.styles.cellPadding:i.textPos.y=j.y+t.height/2,"right"===i.styles.halign?i.textPos.x=i.x+i.width-i.styles.cellPadding:"center"===i.styles.halign?i.textPos.x=i.x+i.width/2:i.textPos.x=i.x+i.styles.cellPadding;var r=c({column:o,row:t});e(i,r)!==!1&&(P.rect(i.x,i.y,i.width,i.height,i.styles.fillStyle),P.autoTableText(i.text,i.textPos.x,i.textPos.y,{halign:i.styles.halign,valign:i.styles.valign})),j.x+=i.width}}j.y+=t.height}function f(t){Object.keys(z).forEach(function(e){var n=t[e],o=z[e];"undefined"!=typeof n&&(n.constructor===Array?o.apply(this,n):o(n))})}function c(t){return Object.assign({pageCount:T.pageCount,settings:R,table:T,cursor:j},t||{})}function y(t,e){f(e);var n=P.getStringUnitWidth(t);return n*e.fontSize}function u(t,e,n,o){if(o="undefined"!=typeof o?o:"...",Array.isArray(t))return t.forEach(function(i,r){t[r]=u(i,e,n,o)}),t;if(e>=y(t,n))return t;for(;e<y(t+o,n)&&!(t.length<2);)t=t.substring(0,t.length-1);return t.trim()+o}t="default"in t?t.default:t;var g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},w=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},p=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),b=function t(){w(this,t),this.height=0,this.width=0,this.contentWidth=0,this.rows=[],this.columns=[],this.headerRow=null,this.settings={},this.pageCount=1},m=function t(e){w(this,t),this.raw=e||{},this.index=0,this.styles={},this.cells={},this.height=0,this.y=0},v=function t(e){w(this,t),this.raw=e,this.styles={},this.text="",this.contentWidth=0,this.textPos={},this.height=0,this.width=0,this.x=0,this.y=0},x=function t(e){w(this,t),this.dataKey=e,this.options={},this.styles={},this.contentWidth=0,this.width=0,this.x=0},S=1.15,W={striped:{table:{fillColor:255,textColor:80,fontStyle:"normal",fillStyle:"F"},header:{textColor:255,fillColor:[41,128,185],rowHeight:23,fontStyle:"bold"},body:{},alternateRow:{fillColor:245}},grid:{table:{fillColor:255,textColor:80,fontStyle:"normal",lineWidth:.1,fillStyle:"DF"},header:{textColor:255,fillColor:[26,188,156],rowHeight:23,fillStyle:"F",fontStyle:"bold"},body:{},alternateRow:{}},plain:{header:{fontStyle:"bold"}}},C=function(){function t(){w(this,t)}return p(t,null,[{key:"initSettings",value:function(t){var n=Object.assign({},e(),t);"undefined"!=typeof n.extendWidth&&(n.tableWidth=n.extendWidth?"auto":"wrap",console.error("Use of deprecated option: extendWidth, use tableWidth instead.")),"undefined"!=typeof n.margins&&("undefined"==typeof n.margin&&(n.margin=n.margins),console.error("Use of deprecated option: margins, use margin instead.")),[["padding","cellPadding"],["lineHeight","rowHeight"],"fontSize","overflow"].forEach(function(t){var e="string"==typeof t?t:t[0],o="string"==typeof t?t:t[1];"undefined"!=typeof n[e]&&("undefined"==typeof n.styles[o]&&(n.styles[o]=n[e]),console.error("Use of deprecated option: "+e+", use the style "+o+" instead."))});var o=n.margin;return n.margin={},"number"==typeof o.horizontal&&(o.right=o.horizontal,o.left=o.horizontal),"number"==typeof o.vertical&&(o.top=o.vertical,o.bottom=o.vertical),["top","right","bottom","left"].forEach(function(t,e){if("number"==typeof o)n.margin[t]=o;else{var i=Array.isArray(o)?e:t;n.margin[t]="number"==typeof o[i]?o[i]:40}}),n}},{key:"styles",value:function(t){return t.unshift(n()),t.unshift({}),Object.assign.apply(this,t)}}]),t}();"function"!=typeof Object.assign&&!function(){Object.assign=function(t){if(void 0===t||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n<arguments.length;n++){var o=arguments[n];if(void 0!==o&&null!==o)for(var i in o)o.hasOwnProperty(i)&&(e[i]=o[i])}return e}}(),Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),Object.values||(Object.values=function(t){return Object.keys(t).map(function(e){return t[e]})});var P,j,z,A,R,T;t.API.autoTable=function(t,e,n){o(t,e,n),P=this,A=P.internal.pageSize,z={fillColor:P.setFillColor,textColor:P.setTextColor,fontStyle:P.setFontStyle,lineColor:P.setDrawColor,lineWidth:P.setLineWidth,font:P.setFont,fontSize:P.setFontSize},R=C.initSettings(n||{}),j={x:R.margin.left,y:R.startY===!1?R.margin.top:R.startY};var l={textColor:30,fontSize:P.internal.getFontSize(),fontStyle:P.internal.getFont().fontStyle};i(t,e),r(this,A.width);var a=T.rows[0]&&"auto"===R.pageBreak?T.rows[0].height:0,s=R.startY+R.margin.bottom+T.headerRow.height+a;return"avoid"===R.pageBreak&&(s+=T.height),("always"===R.pageBreak&&R.startY!==!1||R.startY!==!1&&s>A.height)&&(this.addPage(this.addPage),j.y=R.margin.top),f(l),R.beforePageContent(c()),R.drawHeaderRow(T.headerRow,c({row:T.headerRow}))!==!1&&h(T.headerRow,R.drawHeaderCell),f(l),d(this.addPage),R.afterPageContent(c()),f(l),this},t.API.autoTableEndPosY=function(){return"undefined"==typeof j||"undefined"==typeof j.y?0:j.y},t.API.autoTableHtmlToJson=function(t,e){e=e||!1;for(var n={},o=[],i=t.rows[0],r=0;r<i.cells.length;r++){var l=i.cells[r],a=window.getComputedStyle(l);(e||"none"!==a.display)&&(n[r]=l?l.textContent.trim():"")}for(var s=1;s<t.rows.length;s++){var d=t.rows[s],a=window.getComputedStyle(d);if(e||"none"!==a.display){var h=[],f=!0,c=!1,y=void 0;try{for(var u,g=Object.keys(n)[Symbol.iterator]();!(f=(u=g.next()).done);f=!0){var w=u.value,l=d.cells[w],p=l?l.textContent.trim():"";h.push(p)}}catch(t){c=!0,y=t}finally{try{!f&&g.return&&g.return()}finally{if(c)throw y}}o.push(h)}}return{columns:Object.values(n),rows:o,data:o}},t.API.autoTableText=function(t,e,n,o){"number"==typeof e&&"number"==typeof n||console.error("The x and y parameters are required. Missing for the text: ",t);var i=this.internal.getFontSize()/this.internal.scaleFactor,r=S,l=/\r\n|\r|\n/g,a=null,s=1;if("middle"!==o.valign&&"bottom"!==o.valign&&"center"!==o.halign&&"right"!==o.halign||(a="string"==typeof t?t.split(l):t,s=a.length||1),n+=i*(2-r),"middle"===o.valign?n-=s/2*i:"bottom"===o.valign&&(n-=s*i),"center"===o.halign||"right"===o.halign){var d=i;if("center"===o.halign&&(d*=.5),s>=1){for(var h=0;h<a.length;h++)this.text(a[h],e-this.getStringUnitWidth(a[h])*d,n),n+=i;return P}e-=this.getStringUnitWidth(t)*d}return this.text(t,e,n),this}}); |
/** | ||
* jsPDF AutoTable plugin v2.0.26 | ||
* jsPDF AutoTable plugin v2.0.27 | ||
* Copyright (c) 2014 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable | ||
@@ -11,813 +11,810 @@ * | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jspdf')) : | ||
typeof define === 'function' && define.amd ? define(['jspdf'], factory) : | ||
(factory(global.jsPDF)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jspdf')) : | ||
typeof define === 'function' && define.amd ? define(['jspdf'], factory) : | ||
(factory(global.jsPDF)); | ||
}(this, function (jsPDF) { 'use strict'; | ||
jsPDF = 'default' in jsPDF ? jsPDF['default'] : jsPDF; | ||
jsPDF = 'default' in jsPDF ? jsPDF['default'] : jsPDF; | ||
var babelHelpers = {}; | ||
babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
babelHelpers.classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
babelHelpers.createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
babelHelpers; | ||
var Table = function Table() { | ||
classCallCheck(this, Table); | ||
var Table = function Table() { | ||
babelHelpers.classCallCheck(this, Table); | ||
this.height = 0; | ||
this.width = 0; | ||
this.contentWidth = 0; | ||
this.rows = []; | ||
this.columns = []; | ||
this.headerRow = null; | ||
this.settings = {}; | ||
this.pageCount = 1; | ||
}; | ||
this.height = 0; | ||
this.width = 0; | ||
this.contentWidth = 0; | ||
this.rows = []; | ||
this.columns = []; | ||
this.headerRow = null; | ||
this.settings = {}; | ||
this.pageCount = 1; | ||
}; | ||
var Row = function Row(raw) { | ||
classCallCheck(this, Row); | ||
var Row = function Row(raw) { | ||
babelHelpers.classCallCheck(this, Row); | ||
this.raw = raw || {}; | ||
this.index = 0; | ||
this.styles = {}; | ||
this.cells = {}; | ||
this.height = 0; | ||
this.y = 0; | ||
}; | ||
this.raw = raw || {}; | ||
this.index = 0; | ||
this.styles = {}; | ||
this.cells = {}; | ||
this.height = 0; | ||
this.y = 0; | ||
}; | ||
var Cell = function Cell(raw) { | ||
classCallCheck(this, Cell); | ||
var Cell = function Cell(raw) { | ||
babelHelpers.classCallCheck(this, Cell); | ||
this.raw = raw; | ||
this.styles = {}; | ||
this.text = ''; | ||
this.contentWidth = 0; | ||
this.textPos = {}; | ||
this.height = 0; | ||
this.width = 0; | ||
this.x = 0; | ||
this.y = 0; | ||
}; | ||
this.raw = raw; | ||
this.styles = {}; | ||
this.text = ''; | ||
this.contentWidth = 0; | ||
this.textPos = {}; | ||
this.height = 0; | ||
this.width = 0; | ||
this.x = 0; | ||
this.y = 0; | ||
}; | ||
var Column = function Column(dataKey) { | ||
classCallCheck(this, Column); | ||
var Column = function Column(dataKey) { | ||
babelHelpers.classCallCheck(this, Column); | ||
this.dataKey = dataKey; | ||
this.options = {}; | ||
this.styles = {}; | ||
this.contentWidth = 0; | ||
this.width = 0; | ||
this.x = 0; | ||
}; | ||
this.dataKey = dataKey; | ||
this.options = {}; | ||
this.styles = {}; | ||
this.contentWidth = 0; | ||
this.width = 0; | ||
this.x = 0; | ||
}; | ||
/** | ||
* Ratio between font size and font height. The number comes from jspdf's source code | ||
*/ | ||
var FONT_ROW_RATIO = 1.15; | ||
/** | ||
* Ratio between font size and font height. The number comes from jspdf's source code | ||
*/ | ||
var FONT_ROW_RATIO = 1.15; | ||
/** | ||
* Styles for the themes (overriding the default styles) | ||
*/ | ||
var themes = { | ||
'striped': { | ||
table: { fillColor: 255, textColor: 80, fontStyle: 'normal', fillStyle: 'F' }, | ||
header: { textColor: 255, fillColor: [41, 128, 185], rowHeight: 23, fontStyle: 'bold' }, | ||
body: {}, | ||
alternateRow: { fillColor: 245 } | ||
}, | ||
'grid': { | ||
table: { fillColor: 255, textColor: 80, fontStyle: 'normal', lineWidth: 0.1, fillStyle: 'DF' }, | ||
header: { textColor: 255, fillColor: [26, 188, 156], rowHeight: 23, fillStyle: 'F', fontStyle: 'bold' }, | ||
body: {}, | ||
alternateRow: {} | ||
}, | ||
'plain': { | ||
header: { fontStyle: 'bold' } | ||
} | ||
}; | ||
/** | ||
* Styles for the themes (overriding the default styles) | ||
*/ | ||
var themes = { | ||
'striped': { | ||
table: { fillColor: 255, textColor: 80, fontStyle: 'normal', fillStyle: 'F' }, | ||
header: { textColor: 255, fillColor: [41, 128, 185], rowHeight: 23, fontStyle: 'bold' }, | ||
body: {}, | ||
alternateRow: { fillColor: 245 } | ||
}, | ||
'grid': { | ||
table: { fillColor: 255, textColor: 80, fontStyle: 'normal', lineWidth: 0.1, fillStyle: 'DF' }, | ||
header: { textColor: 255, fillColor: [26, 188, 156], rowHeight: 23, fillStyle: 'F', fontStyle: 'bold' }, | ||
body: {}, | ||
alternateRow: {} | ||
}, | ||
'plain': { | ||
header: { fontStyle: 'bold' } | ||
} | ||
}; | ||
function getDefaults() { | ||
return { | ||
// Styling | ||
theme: 'striped', // 'striped', 'grid' or 'plain' | ||
styles: {}, | ||
headerStyles: {}, | ||
bodyStyles: {}, | ||
alternateRowStyles: {}, | ||
columnStyles: {}, | ||
function getDefaults() { | ||
return { | ||
// Styling | ||
theme: 'striped', // 'striped', 'grid' or 'plain' | ||
styles: {}, | ||
headerStyles: {}, | ||
bodyStyles: {}, | ||
alternateRowStyles: {}, | ||
columnStyles: {}, | ||
// Properties | ||
startY: false, // false indicates the margin.top value | ||
margin: 40, | ||
pageBreak: 'auto', // 'auto', 'avoid', 'always' | ||
tableWidth: 'auto', // number, 'auto', 'wrap' | ||
// Properties | ||
startY: false, // false indicates the margin.top value | ||
margin: 40, | ||
pageBreak: 'auto', // 'auto', 'avoid', 'always' | ||
tableWidth: 'auto', // number, 'auto', 'wrap' | ||
// Hooks | ||
createdHeaderCell: function createdHeaderCell(cell, data) {}, | ||
createdCell: function createdCell(cell, data) {}, | ||
drawHeaderRow: function drawHeaderRow(row, data) {}, | ||
drawRow: function drawRow(row, data) {}, | ||
drawHeaderCell: function drawHeaderCell(cell, data) {}, | ||
drawCell: function drawCell(cell, data) {}, | ||
beforePageContent: function beforePageContent(data) {}, | ||
afterPageContent: function afterPageContent(data) {} | ||
}; | ||
} | ||
// Hooks | ||
createdHeaderCell: function createdHeaderCell(cell, data) {}, | ||
createdCell: function createdCell(cell, data) {}, | ||
drawHeaderRow: function drawHeaderRow(row, data) {}, | ||
drawRow: function drawRow(row, data) {}, | ||
drawHeaderCell: function drawHeaderCell(cell, data) {}, | ||
drawCell: function drawCell(cell, data) {}, | ||
beforePageContent: function beforePageContent(data) {}, | ||
afterPageContent: function afterPageContent(data) {} | ||
}; | ||
} | ||
// Base style for all themes | ||
function defaultStyles() { | ||
return { | ||
cellPadding: 5, | ||
fontSize: 10, | ||
font: "helvetica", // helvetica, times, courier | ||
lineColor: 200, | ||
lineWidth: 0.1, | ||
fontStyle: 'normal', // normal, bold, italic, bolditalic | ||
overflow: 'ellipsize', // visible, hidden, ellipsize or linebreak | ||
fillColor: 255, | ||
textColor: 20, | ||
halign: 'left', // left, center, right | ||
valign: 'top', // top, middle, bottom | ||
fillStyle: 'F', // 'S', 'F' or 'DF' (stroke, fill or fill then stroke) | ||
rowHeight: 20, | ||
columnWidth: 'auto' | ||
}; | ||
} | ||
// Base style for all themes | ||
function defaultStyles() { | ||
return { | ||
cellPadding: 5, | ||
fontSize: 10, | ||
font: "helvetica", // helvetica, times, courier | ||
lineColor: 200, | ||
lineWidth: 0.1, | ||
fontStyle: 'normal', // normal, bold, italic, bolditalic | ||
overflow: 'ellipsize', // visible, hidden, ellipsize or linebreak | ||
fillColor: 255, | ||
textColor: 20, | ||
halign: 'left', // left, center, right | ||
valign: 'top', // top, middle, bottom | ||
fillStyle: 'F', // 'S', 'F' or 'DF' (stroke, fill or fill then stroke) | ||
rowHeight: 20, | ||
columnWidth: 'auto' | ||
}; | ||
} | ||
var Config = function () { | ||
function Config() { | ||
classCallCheck(this, Config); | ||
} | ||
var Config = function () { | ||
function Config() { | ||
babelHelpers.classCallCheck(this, Config); | ||
} | ||
createClass(Config, null, [{ | ||
key: 'initSettings', | ||
value: function initSettings(userOptions) { | ||
var settings = Object.assign({}, getDefaults(), userOptions); | ||
babelHelpers.createClass(Config, null, [{ | ||
key: 'initSettings', | ||
value: function initSettings(userOptions) { | ||
var settings = Object.assign({}, getDefaults(), userOptions); | ||
// Options | ||
if (typeof settings.extendWidth !== 'undefined') { | ||
settings.tableWidth = settings.extendWidth ? 'auto' : 'wrap'; | ||
console.error("Use of deprecated option: extendWidth, use tableWidth instead."); | ||
} | ||
if (typeof settings.margins !== 'undefined') { | ||
if (typeof settings.margin === 'undefined') settings.margin = settings.margins; | ||
console.error("Use of deprecated option: margins, use margin instead."); | ||
} | ||
// Options | ||
if (typeof settings.extendWidth !== 'undefined') { | ||
settings.tableWidth = settings.extendWidth ? 'auto' : 'wrap'; | ||
console.error("Use of deprecated option: extendWidth, use tableWidth instead."); | ||
} | ||
if (typeof settings.margins !== 'undefined') { | ||
if (typeof settings.margin === 'undefined') settings.margin = settings.margins; | ||
console.error("Use of deprecated option: margins, use margin instead."); | ||
} | ||
[['padding', 'cellPadding'], ['lineHeight', 'rowHeight'], 'fontSize', 'overflow'].forEach(function (o) { | ||
var deprecatedOption = typeof o === 'string' ? o : o[0]; | ||
var style = typeof o === 'string' ? o : o[1]; | ||
if (typeof settings[deprecatedOption] !== 'undefined') { | ||
if (typeof settings.styles[style] === 'undefined') { | ||
settings.styles[style] = settings[deprecatedOption]; | ||
} | ||
console.error("Use of deprecated option: " + deprecatedOption + ", use the style " + style + " instead."); | ||
} | ||
}); | ||
[['padding', 'cellPadding'], ['lineHeight', 'rowHeight'], 'fontSize', 'overflow'].forEach(function (o) { | ||
var deprecatedOption = typeof o === 'string' ? o : o[0]; | ||
var style = typeof o === 'string' ? o : o[1]; | ||
if (typeof settings[deprecatedOption] !== 'undefined') { | ||
if (typeof settings.styles[style] === 'undefined') { | ||
settings.styles[style] = settings[deprecatedOption]; | ||
} | ||
console.error("Use of deprecated option: " + deprecatedOption + ", use the style " + style + " instead."); | ||
} | ||
}); | ||
// Unifying | ||
var marginSetting = settings.margin; | ||
settings.margin = {}; | ||
if (typeof marginSetting.horizontal === 'number') { | ||
marginSetting.right = marginSetting.horizontal; | ||
marginSetting.left = marginSetting.horizontal; | ||
} | ||
if (typeof marginSetting.vertical === 'number') { | ||
marginSetting.top = marginSetting.vertical; | ||
marginSetting.bottom = marginSetting.vertical; | ||
} | ||
['top', 'right', 'bottom', 'left'].forEach(function (side, i) { | ||
if (typeof marginSetting === 'number') { | ||
settings.margin[side] = marginSetting; | ||
} else { | ||
var key = Array.isArray(marginSetting) ? i : side; | ||
settings.margin[side] = typeof marginSetting[key] === 'number' ? marginSetting[key] : 40; | ||
} | ||
}); | ||
// Unifying | ||
var marginSetting = settings.margin; | ||
settings.margin = {}; | ||
if (typeof marginSetting.horizontal === 'number') { | ||
marginSetting.right = marginSetting.horizontal; | ||
marginSetting.left = marginSetting.horizontal; | ||
} | ||
if (typeof marginSetting.vertical === 'number') { | ||
marginSetting.top = marginSetting.vertical; | ||
marginSetting.bottom = marginSetting.vertical; | ||
} | ||
['top', 'right', 'bottom', 'left'].forEach(function (side, i) { | ||
if (typeof marginSetting === 'number') { | ||
settings.margin[side] = marginSetting; | ||
} else { | ||
var key = Array.isArray(marginSetting) ? i : side; | ||
settings.margin[side] = typeof marginSetting[key] === 'number' ? marginSetting[key] : 40; | ||
} | ||
}); | ||
return settings; | ||
} | ||
}, { | ||
key: 'styles', | ||
value: function styles(_styles) { | ||
_styles.unshift(defaultStyles()); | ||
_styles.unshift({}); | ||
return Object.assign.apply(this, _styles); | ||
} | ||
}]); | ||
return Config; | ||
}(); | ||
return settings; | ||
} | ||
}, { | ||
key: 'styles', | ||
value: function styles(_styles) { | ||
_styles.unshift(defaultStyles()); | ||
_styles.unshift({}); | ||
return Object.assign.apply(this, _styles); | ||
} | ||
}]); | ||
return Config; | ||
}(); | ||
// mdn.io/assign#Polyfill | ||
if (typeof Object.assign != 'function') { | ||
(function () { | ||
Object.assign = function (target) { | ||
'use strict'; | ||
// mdn.io/assign#Polyfill | ||
if (typeof Object.assign != 'function') { | ||
(function () { | ||
Object.assign = function (target) { | ||
'use strict'; | ||
if (target === undefined || target === null) { | ||
throw new TypeError('Cannot convert undefined or null to object'); | ||
} | ||
if (target === undefined || target === null) { | ||
throw new TypeError('Cannot convert undefined or null to object'); | ||
} | ||
var output = Object(target); | ||
for (var index = 1; index < arguments.length; index++) { | ||
var source = arguments[index]; | ||
if (source !== undefined && source !== null) { | ||
for (var nextKey in source) { | ||
if (source.hasOwnProperty(nextKey)) { | ||
output[nextKey] = source[nextKey]; | ||
} | ||
} | ||
} | ||
} | ||
return output; | ||
}; | ||
})(); | ||
} | ||
var output = Object(target); | ||
for (var index = 1; index < arguments.length; index++) { | ||
var source = arguments[index]; | ||
if (source !== undefined && source !== null) { | ||
for (var nextKey in source) { | ||
if (source.hasOwnProperty(nextKey)) { | ||
output[nextKey] = source[nextKey]; | ||
} | ||
} | ||
} | ||
} | ||
return output; | ||
}; | ||
})(); | ||
} | ||
// mdn.io/isarray#Polyfill | ||
if (!Array.isArray) { | ||
Array.isArray = function (arg) { | ||
return Object.prototype.toString.call(arg) === '[object Array]'; | ||
}; | ||
} | ||
// mdn.io/isarray#Polyfill | ||
if (!Array.isArray) { | ||
Array.isArray = function (arg) { | ||
return Object.prototype.toString.call(arg) === '[object Array]'; | ||
}; | ||
} | ||
if (!Object.values) { | ||
Object.values = function (obj) { | ||
return Object.keys(obj).map(function (key) { | ||
return obj[key]; | ||
}); | ||
}; | ||
} | ||
if (!Object.values) { | ||
Object.values = function (obj) { | ||
return Object.keys(obj).map(function (key) { | ||
return obj[key]; | ||
}); | ||
}; | ||
} | ||
var doc; | ||
var cursor; | ||
var styleModifiers; | ||
var pageSize; | ||
var settings; | ||
var table; | ||
// The current Table instance | ||
var doc; | ||
var cursor; | ||
var styleModifiers; | ||
var pageSize; | ||
var settings; | ||
var table; | ||
// The current Table instance | ||
/** | ||
* Create a table from a set of rows and columns. | ||
* | ||
* @param {Object[]|String[]} headers Either as an array of objects or array of strings | ||
* @param {Object[][]|String[][]} data Either as an array of objects or array of strings | ||
* @param {Object} [options={}] Options that will override the default ones | ||
*/ | ||
jsPDF.API.autoTable = function (headers, data, options) { | ||
validateInput(headers, data, options); | ||
doc = this; | ||
/** | ||
* Create a table from a set of rows and columns. | ||
* | ||
* @param {Object[]|String[]} headers Either as an array of objects or array of strings | ||
* @param {Object[][]|String[][]} data Either as an array of objects or array of strings | ||
* @param {Object} [options={}] Options that will override the default ones | ||
*/ | ||
jsPDF.API.autoTable = function (headers, data, options) { | ||
validateInput(headers, data, options); | ||
doc = this; | ||
pageSize = doc.internal.pageSize; | ||
styleModifiers = { | ||
fillColor: doc.setFillColor, | ||
textColor: doc.setTextColor, | ||
fontStyle: doc.setFontStyle, | ||
lineColor: doc.setDrawColor, | ||
lineWidth: doc.setLineWidth, | ||
font: doc.setFont, | ||
fontSize: doc.setFontSize | ||
}; | ||
pageSize = doc.internal.pageSize; | ||
styleModifiers = { | ||
fillColor: doc.setFillColor, | ||
textColor: doc.setTextColor, | ||
fontStyle: doc.setFontStyle, | ||
lineColor: doc.setDrawColor, | ||
lineWidth: doc.setLineWidth, | ||
font: doc.setFont, | ||
fontSize: doc.setFontSize | ||
}; | ||
settings = Config.initSettings(options || {}); | ||
settings = Config.initSettings(options || {}); | ||
// Need a cursor y as it needs to be reset after each page (row.y can't do that) | ||
// Also prefer cursor to column.x as the cursor is easier to modify in the hooks | ||
cursor = { | ||
x: settings.margin.left, | ||
y: settings.startY === false ? settings.margin.top : settings.startY | ||
}; | ||
// Need a cursor y as it needs to be reset after each page (row.y can't do that) | ||
// Also prefer cursor to column.x as the cursor is easier to modify in the hooks | ||
cursor = { | ||
x: settings.margin.left, | ||
y: settings.startY === false ? settings.margin.top : settings.startY | ||
}; | ||
var userStyles = { | ||
textColor: 30, // Setting text color to dark gray as it can't be obtained from jsPDF | ||
fontSize: doc.internal.getFontSize(), | ||
fontStyle: doc.internal.getFont().fontStyle | ||
}; | ||
var userStyles = { | ||
textColor: 30, // Setting text color to dark gray as it can't be obtained from jsPDF | ||
fontSize: doc.internal.getFontSize(), | ||
fontStyle: doc.internal.getFont().fontStyle | ||
}; | ||
// Create the table model with its columns, rows and cells | ||
createModels(headers, data); | ||
calculateWidths(this, pageSize.width); | ||
// Create the table model with its columns, rows and cells | ||
createModels(headers, data); | ||
calculateWidths(this, pageSize.width); | ||
// Page break if there is room for only the first data row | ||
var firstRowHeight = table.rows[0] && settings.pageBreak === 'auto' ? table.rows[0].height : 0; | ||
var minTableBottomPos = settings.startY + settings.margin.bottom + table.headerRow.height + firstRowHeight; | ||
if (settings.pageBreak === 'avoid') { | ||
minTableBottomPos += table.height; | ||
} | ||
if (settings.pageBreak === 'always' && settings.startY !== false || settings.startY !== false && minTableBottomPos > pageSize.height) { | ||
this.addPage(this.addPage); | ||
cursor.y = settings.margin.top; | ||
} | ||
// Page break if there is room for only the first data row | ||
var firstRowHeight = table.rows[0] && settings.pageBreak === 'auto' ? table.rows[0].height : 0; | ||
var minTableBottomPos = settings.startY + settings.margin.bottom + table.headerRow.height + firstRowHeight; | ||
if (settings.pageBreak === 'avoid') { | ||
minTableBottomPos += table.height; | ||
} | ||
if (settings.pageBreak === 'always' && settings.startY !== false || settings.startY !== false && minTableBottomPos > pageSize.height) { | ||
this.addPage(this.addPage); | ||
cursor.y = settings.margin.top; | ||
} | ||
applyStyles(userStyles); | ||
settings.beforePageContent(hooksData()); | ||
if (settings.drawHeaderRow(table.headerRow, hooksData({ row: table.headerRow })) !== false) { | ||
printRow(table.headerRow, settings.drawHeaderCell); | ||
} | ||
applyStyles(userStyles); | ||
printRows(this.addPage); | ||
settings.afterPageContent(hooksData()); | ||
applyStyles(userStyles); | ||
settings.beforePageContent(hooksData()); | ||
if (settings.drawHeaderRow(table.headerRow, hooksData({ row: table.headerRow })) !== false) { | ||
printRow(table.headerRow, settings.drawHeaderCell); | ||
} | ||
applyStyles(userStyles); | ||
printRows(this.addPage); | ||
settings.afterPageContent(hooksData()); | ||
applyStyles(userStyles); | ||
applyStyles(userStyles); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
/** | ||
* Returns the Y position of the last drawn cell | ||
* @returns int | ||
*/ | ||
jsPDF.API.autoTableEndPosY = function () { | ||
if (typeof cursor === 'undefined' || typeof cursor.y === 'undefined') { | ||
return 0; | ||
} | ||
return cursor.y; | ||
}; | ||
/** | ||
* Returns the Y position of the last drawn cell | ||
* @returns int | ||
*/ | ||
jsPDF.API.autoTableEndPosY = function () { | ||
if (typeof cursor === 'undefined' || typeof cursor.y === 'undefined') { | ||
return 0; | ||
} | ||
return cursor.y; | ||
}; | ||
/** | ||
* Parses an html table | ||
* | ||
* @param tableElem Html table element | ||
* @param includeHiddenElements If to include hidden rows and columns (defaults to false) | ||
* @returns Object Object with two properties, columns and rows | ||
*/ | ||
jsPDF.API.autoTableHtmlToJson = function (tableElem, includeHiddenElements) { | ||
includeHiddenElements = includeHiddenElements || false; | ||
/** | ||
* Parses an html table | ||
* | ||
* @param tableElem Html table element | ||
* @param includeHiddenElements If to include hidden rows and columns (defaults to false) | ||
* @returns Object Object with two properties, columns and rows | ||
*/ | ||
jsPDF.API.autoTableHtmlToJson = function (tableElem, includeHiddenElements) { | ||
includeHiddenElements = includeHiddenElements || false; | ||
var columns = {}, | ||
rows = []; | ||
var columns = {}, | ||
rows = []; | ||
var header = tableElem.rows[0]; | ||
var header = tableElem.rows[0]; | ||
for (var k = 0; k < header.cells.length; k++) { | ||
var cell = header.cells[k]; | ||
var style = window.getComputedStyle(cell); | ||
if (includeHiddenElements || style.display !== 'none') { | ||
columns[k] = cell ? cell.textContent.trim() : ''; | ||
} | ||
} | ||
for (var k = 0; k < header.cells.length; k++) { | ||
var cell = header.cells[k]; | ||
var style = window.getComputedStyle(cell); | ||
if (includeHiddenElements || style.display !== 'none') { | ||
columns[k] = cell ? cell.textContent.trim() : ''; | ||
} | ||
} | ||
for (var i = 1; i < tableElem.rows.length; i++) { | ||
var tableRow = tableElem.rows[i]; | ||
var style = window.getComputedStyle(tableRow); | ||
if (includeHiddenElements || style.display !== 'none') { | ||
var rowData = []; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
for (var i = 1; i < tableElem.rows.length; i++) { | ||
var tableRow = tableElem.rows[i]; | ||
var style = window.getComputedStyle(tableRow); | ||
if (includeHiddenElements || style.display !== 'none') { | ||
var rowData = []; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = Object.keys(columns)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var j = _step.value; | ||
try { | ||
for (var _iterator = Object.keys(columns)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var j = _step.value; | ||
var cell = tableRow.cells[j]; | ||
var val = cell ? cell.textContent.trim() : ''; | ||
rowData.push(val); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
var cell = tableRow.cells[j]; | ||
var val = cell ? cell.textContent.trim() : ''; | ||
rowData.push(val); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
rows.push(rowData); | ||
} | ||
} | ||
rows.push(rowData); | ||
} | ||
} | ||
return { columns: Object.values(columns), rows: rows, data: rows }; // data prop deprecated | ||
}; | ||
return { columns: Object.values(columns), rows: rows, data: rows }; // data prop deprecated | ||
}; | ||
/** | ||
* Improved text function with halign and valign support | ||
* Inspiration from: http://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113#28433113 | ||
*/ | ||
jsPDF.API.autoTableText = function (text, x, y, styles) { | ||
if (typeof x !== 'number' || typeof y !== 'number') { | ||
console.error('The x and y parameters are required. Missing for the text: ', text); | ||
} | ||
var fontSize = this.internal.getFontSize() / this.internal.scaleFactor; | ||
/** | ||
* Improved text function with halign and valign support | ||
* Inspiration from: http://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113#28433113 | ||
*/ | ||
jsPDF.API.autoTableText = function (text, x, y, styles) { | ||
if (typeof x !== 'number' || typeof y !== 'number') { | ||
console.error('The x and y parameters are required. Missing for the text: ', text); | ||
} | ||
var fontSize = this.internal.getFontSize() / this.internal.scaleFactor; | ||
// As defined in jsPDF source code | ||
var lineHeightProportion = FONT_ROW_RATIO; | ||
// As defined in jsPDF source code | ||
var lineHeightProportion = FONT_ROW_RATIO; | ||
var splitRegex = /\r\n|\r|\n/g; | ||
var splittedText = null; | ||
var lineCount = 1; | ||
if (styles.valign === 'middle' || styles.valign === 'bottom' || styles.halign === 'center' || styles.halign === 'right') { | ||
splittedText = typeof text === 'string' ? text.split(splitRegex) : text; | ||
var splitRegex = /\r\n|\r|\n/g; | ||
var splittedText = null; | ||
var lineCount = 1; | ||
if (styles.valign === 'middle' || styles.valign === 'bottom' || styles.halign === 'center' || styles.halign === 'right') { | ||
splittedText = typeof text === 'string' ? text.split(splitRegex) : text; | ||
lineCount = splittedText.length || 1; | ||
} | ||
lineCount = splittedText.length || 1; | ||
} | ||
// Align the top | ||
y += fontSize * (2 - lineHeightProportion); | ||
// Align the top | ||
y += fontSize * (2 - lineHeightProportion); | ||
if (styles.valign === 'middle') y -= lineCount / 2 * fontSize;else if (styles.valign === 'bottom') y -= lineCount * fontSize; | ||
if (styles.valign === 'middle') y -= lineCount / 2 * fontSize;else if (styles.valign === 'bottom') y -= lineCount * fontSize; | ||
if (styles.halign === 'center' || styles.halign === 'right') { | ||
var alignSize = fontSize; | ||
if (styles.halign === 'center') alignSize *= 0.5; | ||
if (styles.halign === 'center' || styles.halign === 'right') { | ||
var alignSize = fontSize; | ||
if (styles.halign === 'center') alignSize *= 0.5; | ||
if (lineCount >= 1) { | ||
for (var iLine = 0; iLine < splittedText.length; iLine++) { | ||
this.text(splittedText[iLine], x - this.getStringUnitWidth(splittedText[iLine]) * alignSize, y); | ||
y += fontSize; | ||
} | ||
return doc; | ||
} | ||
x -= this.getStringUnitWidth(text) * alignSize; | ||
} | ||
if (lineCount >= 1) { | ||
for (var iLine = 0; iLine < splittedText.length; iLine++) { | ||
this.text(splittedText[iLine], x - this.getStringUnitWidth(splittedText[iLine]) * alignSize, y); | ||
y += fontSize; | ||
} | ||
return doc; | ||
} | ||
x -= this.getStringUnitWidth(text) * alignSize; | ||
} | ||
this.text(text, x, y); | ||
this.text(text, x, y); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
function validateInput(headers, data, options) { | ||
if (!headers || (typeof headers === 'undefined' ? 'undefined' : _typeof(headers)) !== 'object') { | ||
console.error("The headers should be an object or array, is: " + (typeof headers === 'undefined' ? 'undefined' : _typeof(headers))); | ||
} | ||
function validateInput(headers, data, options) { | ||
if (!headers || (typeof headers === 'undefined' ? 'undefined' : babelHelpers.typeof(headers)) !== 'object') { | ||
console.error("The headers should be an object or array, is: " + (typeof headers === 'undefined' ? 'undefined' : babelHelpers.typeof(headers))); | ||
} | ||
if (!data || (typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object') { | ||
console.error("The data should be an object or array, is: " + (typeof data === 'undefined' ? 'undefined' : _typeof(data))); | ||
} | ||
if (!data || (typeof data === 'undefined' ? 'undefined' : babelHelpers.typeof(data)) !== 'object') { | ||
console.error("The data should be an object or array, is: " + (typeof data === 'undefined' ? 'undefined' : babelHelpers.typeof(data))); | ||
} | ||
if (!!options && (typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') { | ||
console.error("The data should be an object or array, is: " + (typeof data === 'undefined' ? 'undefined' : _typeof(data))); | ||
} | ||
if (!!options && (typeof options === 'undefined' ? 'undefined' : babelHelpers.typeof(options)) !== 'object') { | ||
console.error("The data should be an object or array, is: " + (typeof data === 'undefined' ? 'undefined' : babelHelpers.typeof(data))); | ||
} | ||
if (!Array.prototype.forEach) { | ||
console.error("The current browser does not support Array.prototype.forEach which is required for " + "jsPDF-AutoTable. You can try polyfilling it by including this script " + "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Polyfill"); | ||
} | ||
} | ||
if (!Array.prototype.forEach) { | ||
console.error("The current browser does not support Array.prototype.forEach which is required for " + "jsPDF-AutoTable. You can try polyfilling it by including this script " + "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Polyfill"); | ||
} | ||
} | ||
/** | ||
* Create models from the user input | ||
* | ||
* @param inputHeaders | ||
* @param inputData | ||
*/ | ||
function createModels(inputHeaders, inputData) { | ||
table = new Table(); | ||
/** | ||
* Create models from the user input | ||
* | ||
* @param inputHeaders | ||
* @param inputData | ||
*/ | ||
function createModels(inputHeaders, inputData) { | ||
table = new Table(); | ||
var splitRegex = /\r\n|\r|\n/g; | ||
var splitRegex = /\r\n|\r|\n/g; | ||
// Header row and columns | ||
var headerRow = new Row(inputHeaders); | ||
headerRow.index = -1; | ||
// Header row and columns | ||
var headerRow = new Row(inputHeaders); | ||
headerRow.index = -1; | ||
var themeStyles = Config.styles([themes[settings.theme].table, themes[settings.theme].header]); | ||
headerRow.styles = Object.assign({}, themeStyles, settings.styles, settings.headerStyles); | ||
var themeStyles = Config.styles([themes[settings.theme].table, themes[settings.theme].header]); | ||
headerRow.styles = Object.assign({}, themeStyles, settings.styles, settings.headerStyles); | ||
// Columns and header row | ||
inputHeaders.forEach(function (rawColumn, dataKey) { | ||
if ((typeof rawColumn === 'undefined' ? 'undefined' : _typeof(rawColumn)) === 'object') { | ||
dataKey = typeof rawColumn.dataKey !== 'undefined' ? rawColumn.dataKey : rawColumn.key; | ||
} | ||
// Columns and header row | ||
inputHeaders.forEach(function (rawColumn, dataKey) { | ||
if ((typeof rawColumn === 'undefined' ? 'undefined' : babelHelpers.typeof(rawColumn)) === 'object') { | ||
dataKey = typeof rawColumn.dataKey !== 'undefined' ? rawColumn.dataKey : rawColumn.key; | ||
} | ||
if (typeof rawColumn.width !== 'undefined') { | ||
console.error("Use of deprecated option: column.width, use column.styles.columnWidth instead."); | ||
} | ||
if (typeof rawColumn.width !== 'undefined') { | ||
console.error("Use of deprecated option: column.width, use column.styles.columnWidth instead."); | ||
} | ||
var col = new Column(dataKey); | ||
col.styles = settings.columnStyles[col.dataKey] || {}; | ||
table.columns.push(col); | ||
var col = new Column(dataKey); | ||
col.styles = settings.columnStyles[col.dataKey] || {}; | ||
table.columns.push(col); | ||
var cell = new Cell(); | ||
cell.raw = (typeof rawColumn === 'undefined' ? 'undefined' : _typeof(rawColumn)) === 'object' ? rawColumn.title : rawColumn; | ||
cell.styles = Object.assign({}, headerRow.styles); | ||
cell.text = '' + cell.raw; | ||
cell.contentWidth = cell.styles.cellPadding * 2 + getStringWidth(cell.text, cell.styles); | ||
cell.text = cell.text.split(splitRegex); | ||
var cell = new Cell(); | ||
cell.raw = (typeof rawColumn === 'undefined' ? 'undefined' : babelHelpers.typeof(rawColumn)) === 'object' ? rawColumn.title : rawColumn; | ||
cell.styles = Object.assign({}, headerRow.styles); | ||
cell.text = '' + cell.raw; | ||
cell.contentWidth = cell.styles.cellPadding * 2 + getStringWidth(cell.text, cell.styles); | ||
cell.text = cell.text.split(splitRegex); | ||
headerRow.cells[dataKey] = cell; | ||
settings.createdHeaderCell(cell, { column: col, row: headerRow, settings: settings }); | ||
}); | ||
table.headerRow = headerRow; | ||
headerRow.cells[dataKey] = cell; | ||
settings.createdHeaderCell(cell, { column: col, row: headerRow, settings: settings }); | ||
}); | ||
table.headerRow = headerRow; | ||
// Rows och cells | ||
inputData.forEach(function (rawRow, i) { | ||
var row = new Row(rawRow); | ||
var isAlternate = i % 2 === 0; | ||
var themeStyles = Config.styles([themes[settings.theme].table, isAlternate ? themes[settings.theme].alternateRow : {}]); | ||
var userStyles = Object.assign({}, settings.styles, settings.bodyStyles, isAlternate ? settings.alternateRowStyles : {}); | ||
row.styles = Object.assign({}, themeStyles, userStyles); | ||
row.index = i; | ||
table.columns.forEach(function (column) { | ||
var cell = new Cell(); | ||
cell.raw = rawRow[column.dataKey]; | ||
cell.styles = Object.assign({}, row.styles, column.styles); | ||
cell.text = typeof cell.raw !== 'undefined' ? '' + cell.raw : ''; // Stringify 0 and false, but not undefined | ||
row.cells[column.dataKey] = cell; | ||
settings.createdCell(cell, hooksData({ column: column, row: row })); | ||
cell.contentWidth = cell.styles.cellPadding * 2 + getStringWidth(cell.text, cell.styles); | ||
cell.text = cell.text.split(splitRegex); | ||
}); | ||
table.rows.push(row); | ||
}); | ||
} | ||
// Rows och cells | ||
inputData.forEach(function (rawRow, i) { | ||
var row = new Row(rawRow); | ||
var isAlternate = i % 2 === 0; | ||
var themeStyles = Config.styles([themes[settings.theme].table, isAlternate ? themes[settings.theme].alternateRow : {}]); | ||
var userStyles = Object.assign({}, settings.styles, settings.bodyStyles, isAlternate ? settings.alternateRowStyles : {}); | ||
row.styles = Object.assign({}, themeStyles, userStyles); | ||
row.index = i; | ||
table.columns.forEach(function (column) { | ||
var cell = new Cell(); | ||
cell.raw = rawRow[column.dataKey]; | ||
cell.styles = Object.assign({}, row.styles, column.styles); | ||
cell.text = typeof cell.raw !== 'undefined' ? '' + cell.raw : ''; // Stringify 0 and false, but not undefined | ||
row.cells[column.dataKey] = cell; | ||
settings.createdCell(cell, hooksData({ column: column, row: row })); | ||
cell.contentWidth = cell.styles.cellPadding * 2 + getStringWidth(cell.text, cell.styles); | ||
cell.text = cell.text.split(splitRegex); | ||
}); | ||
table.rows.push(row); | ||
}); | ||
} | ||
/** | ||
* Calculate the column widths | ||
*/ | ||
function calculateWidths(doc, pageWidth) { | ||
// Column and table content width | ||
var tableContentWidth = 0; | ||
table.columns.forEach(function (column) { | ||
column.contentWidth = table.headerRow.cells[column.dataKey].contentWidth; | ||
table.rows.forEach(function (row) { | ||
var cellWidth = row.cells[column.dataKey].contentWidth; | ||
if (cellWidth > column.contentWidth) { | ||
column.contentWidth = cellWidth; | ||
} | ||
}); | ||
column.width = column.contentWidth; | ||
tableContentWidth += column.contentWidth; | ||
}); | ||
table.contentWidth = tableContentWidth; | ||
/** | ||
* Calculate the column widths | ||
*/ | ||
function calculateWidths(doc, pageWidth) { | ||
// Column and table content width | ||
var tableContentWidth = 0; | ||
table.columns.forEach(function (column) { | ||
column.contentWidth = table.headerRow.cells[column.dataKey].contentWidth; | ||
table.rows.forEach(function (row) { | ||
var cellWidth = row.cells[column.dataKey].contentWidth; | ||
if (cellWidth > column.contentWidth) { | ||
column.contentWidth = cellWidth; | ||
} | ||
}); | ||
column.width = column.contentWidth; | ||
tableContentWidth += column.contentWidth; | ||
}); | ||
table.contentWidth = tableContentWidth; | ||
var maxTableWidth = pageWidth - settings.margin.left - settings.margin.right; | ||
var preferredTableWidth = maxTableWidth; // settings.tableWidth === 'auto' | ||
if (typeof settings.tableWidth === 'number') { | ||
preferredTableWidth = settings.tableWidth; | ||
} else if (settings.tableWidth === 'wrap') { | ||
preferredTableWidth = table.contentWidth; | ||
} | ||
table.width = preferredTableWidth < maxTableWidth ? preferredTableWidth : maxTableWidth; | ||
var maxTableWidth = pageWidth - settings.margin.left - settings.margin.right; | ||
var preferredTableWidth = maxTableWidth; // settings.tableWidth === 'auto' | ||
if (typeof settings.tableWidth === 'number') { | ||
preferredTableWidth = settings.tableWidth; | ||
} else if (settings.tableWidth === 'wrap') { | ||
preferredTableWidth = table.contentWidth; | ||
} | ||
table.width = preferredTableWidth < maxTableWidth ? preferredTableWidth : maxTableWidth; | ||
// To avoid subjecting columns with little content with the chosen overflow method, | ||
// never shrink a column more than the table divided by column count (its "fair part") | ||
var dynamicColumns = []; | ||
var dynamicColumnsContentWidth = 0; | ||
var fairWidth = table.width / table.columns.length; | ||
var staticWidth = 0; | ||
table.columns.forEach(function (column) { | ||
var colStyles = Config.styles([themes[settings.theme].table, settings.styles, column.styles]); | ||
if (colStyles.columnWidth === 'wrap') { | ||
column.width = column.contentWidth; | ||
} else if (typeof colStyles.columnWidth === 'number') { | ||
column.width = colStyles.columnWidth; | ||
} else if (colStyles.columnWidth === 'auto' || true) { | ||
if (column.contentWidth <= fairWidth && table.contentWidth > table.width) { | ||
column.width = column.contentWidth; | ||
} else { | ||
dynamicColumns.push(column); | ||
dynamicColumnsContentWidth += column.contentWidth; | ||
column.width = 0; | ||
} | ||
} | ||
staticWidth += column.width; | ||
}); | ||
// To avoid subjecting columns with little content with the chosen overflow method, | ||
// never shrink a column more than the table divided by column count (its "fair part") | ||
var dynamicColumns = []; | ||
var dynamicColumnsContentWidth = 0; | ||
var fairWidth = table.width / table.columns.length; | ||
var staticWidth = 0; | ||
table.columns.forEach(function (column) { | ||
var colStyles = Config.styles([themes[settings.theme].table, settings.styles, column.styles]); | ||
if (colStyles.columnWidth === 'wrap') { | ||
column.width = column.contentWidth; | ||
} else if (typeof colStyles.columnWidth === 'number') { | ||
column.width = colStyles.columnWidth; | ||
} else if (colStyles.columnWidth === 'auto' || true) { | ||
if (column.contentWidth <= fairWidth && table.contentWidth > table.width) { | ||
column.width = column.contentWidth; | ||
} else { | ||
dynamicColumns.push(column); | ||
dynamicColumnsContentWidth += column.contentWidth; | ||
column.width = 0; | ||
} | ||
} | ||
staticWidth += column.width; | ||
}); | ||
// Distributes extra width or trims columns down to fit | ||
distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth); | ||
// Distributes extra width or trims columns down to fit | ||
distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth); | ||
// Row height, table height and text overflow | ||
table.height = 0; | ||
var all = table.rows.concat(table.headerRow); | ||
all.forEach(function (row, i) { | ||
var lineBreakCount = 0; | ||
table.columns.forEach(function (col) { | ||
var cell = row.cells[col.dataKey]; | ||
applyStyles(cell.styles); | ||
var textSpace = col.width - cell.styles.cellPadding * 2; | ||
if (cell.styles.overflow === 'linebreak') { | ||
// Add one pt to textSpace to fix rounding error | ||
try { | ||
cell.text = doc.splitTextToSize(cell.text, textSpace + 1, { fontSize: cell.styles.fontSize }); | ||
} catch (e) { | ||
if (e instanceof TypeError && Array.isArray(cell.text)) { | ||
cell.text = doc.splitTextToSize(cell.text.join(' '), textSpace + 1, { fontSize: cell.styles.fontSize }); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} else if (cell.styles.overflow === 'ellipsize') { | ||
cell.text = ellipsize(cell.text, textSpace, cell.styles); | ||
} else if (cell.styles.overflow === 'visible') { | ||
// Do nothing | ||
} else if (cell.styles.overflow === 'hidden') { | ||
cell.text = ellipsize(cell.text, textSpace, cell.styles, ''); | ||
} else if (typeof cell.styles.overflow === 'function') { | ||
cell.text = cell.styles.overflow(cell.text, textSpace); | ||
} else { | ||
console.error("Unrecognized overflow type: " + cell.styles.overflow); | ||
} | ||
var count = Array.isArray(cell.text) ? cell.text.length - 1 : 0; | ||
if (count > lineBreakCount) { | ||
lineBreakCount = count; | ||
} | ||
}); | ||
// Row height, table height and text overflow | ||
table.height = 0; | ||
var all = table.rows.concat(table.headerRow); | ||
all.forEach(function (row, i) { | ||
var lineBreakCount = 0; | ||
table.columns.forEach(function (col) { | ||
var cell = row.cells[col.dataKey]; | ||
applyStyles(cell.styles); | ||
var textSpace = col.width - cell.styles.cellPadding * 2; | ||
if (cell.styles.overflow === 'linebreak') { | ||
// Add one pt to textSpace to fix rounding error | ||
try { | ||
cell.text = doc.splitTextToSize(cell.text, textSpace + 1, { fontSize: cell.styles.fontSize }); | ||
} catch (e) { | ||
if (e instanceof TypeError && Array.isArray(cell.text)) { | ||
cell.text = doc.splitTextToSize(cell.text.join(' '), textSpace + 1, { fontSize: cell.styles.fontSize }); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} else if (cell.styles.overflow === 'ellipsize') { | ||
cell.text = ellipsize(cell.text, textSpace, cell.styles); | ||
} else if (cell.styles.overflow === 'visible') { | ||
// Do nothing | ||
} else if (cell.styles.overflow === 'hidden') { | ||
cell.text = ellipsize(cell.text, textSpace, cell.styles, ''); | ||
} else if (typeof cell.styles.overflow === 'function') { | ||
cell.text = cell.styles.overflow(cell.text, textSpace); | ||
} else { | ||
console.error("Unrecognized overflow type: " + cell.styles.overflow); | ||
} | ||
var count = Array.isArray(cell.text) ? cell.text.length - 1 : 0; | ||
if (count > lineBreakCount) { | ||
lineBreakCount = count; | ||
} | ||
}); | ||
row.heightStyle = row.styles.rowHeight; | ||
// TODO Pick the highest row based on font size as well | ||
row.height = row.heightStyle + lineBreakCount * row.styles.fontSize * FONT_ROW_RATIO; | ||
table.height += row.height; | ||
}); | ||
} | ||
row.heightStyle = row.styles.rowHeight; | ||
// TODO Pick the highest row based on font size as well | ||
row.height = row.heightStyle + lineBreakCount * row.styles.fontSize * FONT_ROW_RATIO; | ||
table.height += row.height; | ||
}); | ||
} | ||
function distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth) { | ||
var extraWidth = table.width - staticWidth - dynamicColumnsContentWidth; | ||
for (var i = 0; i < dynamicColumns.length; i++) { | ||
var col = dynamicColumns[i]; | ||
var ratio = col.contentWidth / dynamicColumnsContentWidth; | ||
// A column turned out to be none dynamic, start over recursively | ||
var isNoneDynamic = col.contentWidth + extraWidth * ratio < fairWidth; | ||
if (extraWidth < 0 && isNoneDynamic) { | ||
dynamicColumns.splice(i, 1); | ||
dynamicColumnsContentWidth -= col.contentWidth; | ||
col.width = fairWidth; | ||
staticWidth += col.width; | ||
distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth); | ||
break; | ||
} else { | ||
col.width = col.contentWidth + extraWidth * ratio; | ||
} | ||
} | ||
} | ||
function distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth) { | ||
var extraWidth = table.width - staticWidth - dynamicColumnsContentWidth; | ||
for (var i = 0; i < dynamicColumns.length; i++) { | ||
var col = dynamicColumns[i]; | ||
var ratio = col.contentWidth / dynamicColumnsContentWidth; | ||
// A column turned out to be none dynamic, start over recursively | ||
var isNoneDynamic = col.contentWidth + extraWidth * ratio < fairWidth; | ||
if (extraWidth < 0 && isNoneDynamic) { | ||
dynamicColumns.splice(i, 1); | ||
dynamicColumnsContentWidth -= col.contentWidth; | ||
col.width = fairWidth; | ||
staticWidth += col.width; | ||
distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth); | ||
break; | ||
} else { | ||
col.width = col.contentWidth + extraWidth * ratio; | ||
} | ||
} | ||
} | ||
function addPage(jspdfAddPage) { | ||
settings.afterPageContent(hooksData()); | ||
jspdfAddPage(); | ||
table.pageCount++; | ||
cursor = { x: settings.margin.left, y: settings.margin.top }; | ||
settings.beforePageContent(hooksData()); | ||
if (settings.drawHeaderRow(table.headerRow, hooksData({ row: table.headerRow })) !== false) { | ||
printRow(table.headerRow, settings.drawHeaderCell); | ||
} | ||
} | ||
function addPage(jspdfAddPage) { | ||
settings.afterPageContent(hooksData()); | ||
jspdfAddPage(); | ||
table.pageCount++; | ||
cursor = { x: settings.margin.left, y: settings.margin.top }; | ||
settings.beforePageContent(hooksData()); | ||
if (settings.drawHeaderRow(table.headerRow, hooksData({ row: table.headerRow })) !== false) { | ||
printRow(table.headerRow, settings.drawHeaderCell); | ||
} | ||
} | ||
/** | ||
* Add a new page if cursor is at the end of page | ||
*/ | ||
function isNewPage(rowHeight) { | ||
var afterRowPos = cursor.y + rowHeight + settings.margin.bottom; | ||
return afterRowPos >= pageSize.height; | ||
} | ||
/** | ||
* Add a new page if cursor is at the end of page | ||
*/ | ||
function isNewPage(rowHeight) { | ||
var afterRowPos = cursor.y + rowHeight + settings.margin.bottom; | ||
return afterRowPos >= pageSize.height; | ||
} | ||
function printRows(jspdfAddPage) { | ||
table.rows.forEach(function (row, i) { | ||
if (isNewPage(row.height)) { | ||
var samePageThreshold = 3; | ||
// TODO Fix cell height > page height | ||
/*if (row.height > row.heightStyle * samePageThreshold) { | ||
var remainingPageSpace = pageSize.height - cursor.y - settings.margin.bottom; | ||
var lineCount = Math.floor(remainingPageSpace / (row.styles.fontSize * FONT_ROW_RATIO)); | ||
table.columns.forEach(function(col) { | ||
var arr = row.cells[col.dataKey].text; | ||
if (arr.length > lineCount) { | ||
arr.splice(lineCount - 1, arr.length, "..."); | ||
} | ||
}); | ||
row.height = remainingPageSpace; | ||
if (settings.drawRow(row, hooksData({row: row})) !== false) { | ||
printRow(row, settings.drawCell); | ||
} | ||
row = new Row(rawRow); | ||
}*/ | ||
addPage(jspdfAddPage); | ||
} | ||
row.y = cursor.y; | ||
if (settings.drawRow(row, hooksData({ row: row })) !== false) { | ||
printRow(row, settings.drawCell); | ||
} | ||
}); | ||
} | ||
function printRows(jspdfAddPage) { | ||
table.rows.forEach(function (row, i) { | ||
if (isNewPage(row.height)) { | ||
var samePageThreshold = 3; | ||
// TODO Fix cell height > page height | ||
/*if (row.height > row.heightStyle * samePageThreshold) { | ||
var remainingPageSpace = pageSize.height - cursor.y - settings.margin.bottom; | ||
var lineCount = Math.floor(remainingPageSpace / (row.styles.fontSize * FONT_ROW_RATIO)); | ||
table.columns.forEach(function(col) { | ||
var arr = row.cells[col.dataKey].text; | ||
if (arr.length > lineCount) { | ||
arr.splice(lineCount - 1, arr.length, "..."); | ||
} | ||
}); | ||
row.height = remainingPageSpace; | ||
if (settings.drawRow(row, hooksData({row: row})) !== false) { | ||
printRow(row, settings.drawCell); | ||
} | ||
row = new Row(rawRow); | ||
}*/ | ||
addPage(jspdfAddPage); | ||
} | ||
row.y = cursor.y; | ||
if (settings.drawRow(row, hooksData({ row: row })) !== false) { | ||
printRow(row, settings.drawCell); | ||
} | ||
}); | ||
} | ||
function printRow(row, hookHandler) { | ||
cursor.x = settings.margin.left; | ||
for (var i = 0; i < table.columns.length; i++) { | ||
var column = table.columns[i]; | ||
var cell = row.cells[column.dataKey]; | ||
if (!cell) { | ||
continue; | ||
} | ||
applyStyles(cell.styles); | ||
function printRow(row, hookHandler) { | ||
cursor.x = settings.margin.left; | ||
for (var i = 0; i < table.columns.length; i++) { | ||
var column = table.columns[i]; | ||
var cell = row.cells[column.dataKey]; | ||
if (!cell) { | ||
continue; | ||
} | ||
applyStyles(cell.styles); | ||
cell.x = cursor.x; | ||
cell.y = cursor.y; | ||
cell.height = row.height; | ||
cell.width = column.width; | ||
cell.x = cursor.x; | ||
cell.y = cursor.y; | ||
cell.height = row.height; | ||
cell.width = column.width; | ||
if (cell.styles.valign === 'top') { | ||
cell.textPos.y = cursor.y + cell.styles.cellPadding; | ||
} else if (cell.styles.valign === 'bottom') { | ||
cell.textPos.y = cursor.y + row.height - cell.styles.cellPadding; | ||
} else { | ||
cell.textPos.y = cursor.y + row.height / 2; | ||
} | ||
if (cell.styles.valign === 'top') { | ||
cell.textPos.y = cursor.y + cell.styles.cellPadding; | ||
} else if (cell.styles.valign === 'bottom') { | ||
cell.textPos.y = cursor.y + row.height - cell.styles.cellPadding; | ||
} else { | ||
cell.textPos.y = cursor.y + row.height / 2; | ||
} | ||
if (cell.styles.halign === 'right') { | ||
cell.textPos.x = cell.x + cell.width - cell.styles.cellPadding; | ||
} else if (cell.styles.halign === 'center') { | ||
cell.textPos.x = cell.x + cell.width / 2; | ||
} else { | ||
cell.textPos.x = cell.x + cell.styles.cellPadding; | ||
} | ||
if (cell.styles.halign === 'right') { | ||
cell.textPos.x = cell.x + cell.width - cell.styles.cellPadding; | ||
} else if (cell.styles.halign === 'center') { | ||
cell.textPos.x = cell.x + cell.width / 2; | ||
} else { | ||
cell.textPos.x = cell.x + cell.styles.cellPadding; | ||
} | ||
var data = hooksData({ column: column, row: row }); | ||
if (hookHandler(cell, data) !== false) { | ||
doc.rect(cell.x, cell.y, cell.width, cell.height, cell.styles.fillStyle); | ||
doc.autoTableText(cell.text, cell.textPos.x, cell.textPos.y, { | ||
halign: cell.styles.halign, | ||
valign: cell.styles.valign | ||
}); | ||
} | ||
cursor.x += cell.width; | ||
} | ||
var data = hooksData({ column: column, row: row }); | ||
if (hookHandler(cell, data) !== false) { | ||
doc.rect(cell.x, cell.y, cell.width, cell.height, cell.styles.fillStyle); | ||
doc.autoTableText(cell.text, cell.textPos.x, cell.textPos.y, { | ||
halign: cell.styles.halign, | ||
valign: cell.styles.valign | ||
}); | ||
} | ||
cursor.x += cell.width; | ||
} | ||
cursor.y += row.height; | ||
} | ||
cursor.y += row.height; | ||
} | ||
function applyStyles(styles) { | ||
Object.keys(styleModifiers).forEach(function (name) { | ||
var style = styles[name]; | ||
var modifier = styleModifiers[name]; | ||
if (typeof style !== 'undefined') { | ||
if (style.constructor === Array) { | ||
modifier.apply(this, style); | ||
} else { | ||
modifier(style); | ||
} | ||
} | ||
}); | ||
} | ||
function applyStyles(styles) { | ||
Object.keys(styleModifiers).forEach(function (name) { | ||
var style = styles[name]; | ||
var modifier = styleModifiers[name]; | ||
if (typeof style !== 'undefined') { | ||
if (style.constructor === Array) { | ||
modifier.apply(this, style); | ||
} else { | ||
modifier(style); | ||
} | ||
} | ||
}); | ||
} | ||
function hooksData(additionalData) { | ||
return Object.assign({ | ||
pageCount: table.pageCount, | ||
settings: settings, | ||
table: table, | ||
cursor: cursor | ||
}, additionalData || {}); | ||
} | ||
function hooksData(additionalData) { | ||
return Object.assign({ | ||
pageCount: table.pageCount, | ||
settings: settings, | ||
table: table, | ||
cursor: cursor | ||
}, additionalData || {}); | ||
} | ||
function getStringWidth(text, styles) { | ||
applyStyles(styles); | ||
var w = doc.getStringUnitWidth(text); | ||
return w * styles.fontSize; | ||
} | ||
function getStringWidth(text, styles) { | ||
applyStyles(styles); | ||
var w = doc.getStringUnitWidth(text); | ||
return w * styles.fontSize; | ||
} | ||
/** | ||
* Ellipsize the text to fit in the width | ||
*/ | ||
function ellipsize(text, width, styles, ellipsizeStr) { | ||
ellipsizeStr = typeof ellipsizeStr !== 'undefined' ? ellipsizeStr : '...'; | ||
/** | ||
* Ellipsize the text to fit in the width | ||
*/ | ||
function ellipsize(text, width, styles, ellipsizeStr) { | ||
ellipsizeStr = typeof ellipsizeStr !== 'undefined' ? ellipsizeStr : '...'; | ||
if (Array.isArray(text)) { | ||
text.forEach(function (str, i) { | ||
text[i] = ellipsize(str, width, styles, ellipsizeStr); | ||
}); | ||
return text; | ||
} | ||
if (Array.isArray(text)) { | ||
text.forEach(function (str, i) { | ||
text[i] = ellipsize(str, width, styles, ellipsizeStr); | ||
}); | ||
return text; | ||
} | ||
if (width >= getStringWidth(text, styles)) { | ||
return text; | ||
} | ||
while (width < getStringWidth(text + ellipsizeStr, styles)) { | ||
if (text.length < 2) { | ||
break; | ||
} | ||
text = text.substring(0, text.length - 1); | ||
} | ||
return text.trim() + ellipsizeStr; | ||
} | ||
if (width >= getStringWidth(text, styles)) { | ||
return text; | ||
} | ||
while (width < getStringWidth(text + ellipsizeStr, styles)) { | ||
if (text.length < 2) { | ||
break; | ||
} | ||
text = text.substring(0, text.length - 1); | ||
} | ||
return text.trim() + ellipsizeStr; | ||
} | ||
})); |
/** | ||
* jsPDF AutoTable plugin v2.0.26 | ||
* jsPDF AutoTable plugin v2.0.27 | ||
* Copyright (c) 2014 Simon Bengtsson, https://github.com/simonbengtsson/jsPDF-AutoTable | ||
@@ -11,813 +11,810 @@ * | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jspdf')) : | ||
typeof define === 'function' && define.amd ? define(['jspdf'], factory) : | ||
(factory(global.jsPDF)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jspdf')) : | ||
typeof define === 'function' && define.amd ? define(['jspdf'], factory) : | ||
(factory(global.jsPDF)); | ||
}(this, function (jsPDF) { 'use strict'; | ||
jsPDF = 'default' in jsPDF ? jsPDF['default'] : jsPDF; | ||
jsPDF = 'default' in jsPDF ? jsPDF['default'] : jsPDF; | ||
var babelHelpers = {}; | ||
babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
babelHelpers.classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
babelHelpers.createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
babelHelpers; | ||
var Table = function Table() { | ||
classCallCheck(this, Table); | ||
var Table = function Table() { | ||
babelHelpers.classCallCheck(this, Table); | ||
this.height = 0; | ||
this.width = 0; | ||
this.contentWidth = 0; | ||
this.rows = []; | ||
this.columns = []; | ||
this.headerRow = null; | ||
this.settings = {}; | ||
this.pageCount = 1; | ||
}; | ||
this.height = 0; | ||
this.width = 0; | ||
this.contentWidth = 0; | ||
this.rows = []; | ||
this.columns = []; | ||
this.headerRow = null; | ||
this.settings = {}; | ||
this.pageCount = 1; | ||
}; | ||
var Row = function Row(raw) { | ||
classCallCheck(this, Row); | ||
var Row = function Row(raw) { | ||
babelHelpers.classCallCheck(this, Row); | ||
this.raw = raw || {}; | ||
this.index = 0; | ||
this.styles = {}; | ||
this.cells = {}; | ||
this.height = 0; | ||
this.y = 0; | ||
}; | ||
this.raw = raw || {}; | ||
this.index = 0; | ||
this.styles = {}; | ||
this.cells = {}; | ||
this.height = 0; | ||
this.y = 0; | ||
}; | ||
var Cell = function Cell(raw) { | ||
classCallCheck(this, Cell); | ||
var Cell = function Cell(raw) { | ||
babelHelpers.classCallCheck(this, Cell); | ||
this.raw = raw; | ||
this.styles = {}; | ||
this.text = ''; | ||
this.contentWidth = 0; | ||
this.textPos = {}; | ||
this.height = 0; | ||
this.width = 0; | ||
this.x = 0; | ||
this.y = 0; | ||
}; | ||
this.raw = raw; | ||
this.styles = {}; | ||
this.text = ''; | ||
this.contentWidth = 0; | ||
this.textPos = {}; | ||
this.height = 0; | ||
this.width = 0; | ||
this.x = 0; | ||
this.y = 0; | ||
}; | ||
var Column = function Column(dataKey) { | ||
classCallCheck(this, Column); | ||
var Column = function Column(dataKey) { | ||
babelHelpers.classCallCheck(this, Column); | ||
this.dataKey = dataKey; | ||
this.options = {}; | ||
this.styles = {}; | ||
this.contentWidth = 0; | ||
this.width = 0; | ||
this.x = 0; | ||
}; | ||
this.dataKey = dataKey; | ||
this.options = {}; | ||
this.styles = {}; | ||
this.contentWidth = 0; | ||
this.width = 0; | ||
this.x = 0; | ||
}; | ||
/** | ||
* Ratio between font size and font height. The number comes from jspdf's source code | ||
*/ | ||
var FONT_ROW_RATIO = 1.15; | ||
/** | ||
* Ratio between font size and font height. The number comes from jspdf's source code | ||
*/ | ||
var FONT_ROW_RATIO = 1.15; | ||
/** | ||
* Styles for the themes (overriding the default styles) | ||
*/ | ||
var themes = { | ||
'striped': { | ||
table: { fillColor: 255, textColor: 80, fontStyle: 'normal', fillStyle: 'F' }, | ||
header: { textColor: 255, fillColor: [41, 128, 185], rowHeight: 23, fontStyle: 'bold' }, | ||
body: {}, | ||
alternateRow: { fillColor: 245 } | ||
}, | ||
'grid': { | ||
table: { fillColor: 255, textColor: 80, fontStyle: 'normal', lineWidth: 0.1, fillStyle: 'DF' }, | ||
header: { textColor: 255, fillColor: [26, 188, 156], rowHeight: 23, fillStyle: 'F', fontStyle: 'bold' }, | ||
body: {}, | ||
alternateRow: {} | ||
}, | ||
'plain': { | ||
header: { fontStyle: 'bold' } | ||
} | ||
}; | ||
/** | ||
* Styles for the themes (overriding the default styles) | ||
*/ | ||
var themes = { | ||
'striped': { | ||
table: { fillColor: 255, textColor: 80, fontStyle: 'normal', fillStyle: 'F' }, | ||
header: { textColor: 255, fillColor: [41, 128, 185], rowHeight: 23, fontStyle: 'bold' }, | ||
body: {}, | ||
alternateRow: { fillColor: 245 } | ||
}, | ||
'grid': { | ||
table: { fillColor: 255, textColor: 80, fontStyle: 'normal', lineWidth: 0.1, fillStyle: 'DF' }, | ||
header: { textColor: 255, fillColor: [26, 188, 156], rowHeight: 23, fillStyle: 'F', fontStyle: 'bold' }, | ||
body: {}, | ||
alternateRow: {} | ||
}, | ||
'plain': { | ||
header: { fontStyle: 'bold' } | ||
} | ||
}; | ||
function getDefaults() { | ||
return { | ||
// Styling | ||
theme: 'striped', // 'striped', 'grid' or 'plain' | ||
styles: {}, | ||
headerStyles: {}, | ||
bodyStyles: {}, | ||
alternateRowStyles: {}, | ||
columnStyles: {}, | ||
function getDefaults() { | ||
return { | ||
// Styling | ||
theme: 'striped', // 'striped', 'grid' or 'plain' | ||
styles: {}, | ||
headerStyles: {}, | ||
bodyStyles: {}, | ||
alternateRowStyles: {}, | ||
columnStyles: {}, | ||
// Properties | ||
startY: false, // false indicates the margin.top value | ||
margin: 40, | ||
pageBreak: 'auto', // 'auto', 'avoid', 'always' | ||
tableWidth: 'auto', // number, 'auto', 'wrap' | ||
// Properties | ||
startY: false, // false indicates the margin.top value | ||
margin: 40, | ||
pageBreak: 'auto', // 'auto', 'avoid', 'always' | ||
tableWidth: 'auto', // number, 'auto', 'wrap' | ||
// Hooks | ||
createdHeaderCell: function createdHeaderCell(cell, data) {}, | ||
createdCell: function createdCell(cell, data) {}, | ||
drawHeaderRow: function drawHeaderRow(row, data) {}, | ||
drawRow: function drawRow(row, data) {}, | ||
drawHeaderCell: function drawHeaderCell(cell, data) {}, | ||
drawCell: function drawCell(cell, data) {}, | ||
beforePageContent: function beforePageContent(data) {}, | ||
afterPageContent: function afterPageContent(data) {} | ||
}; | ||
} | ||
// Hooks | ||
createdHeaderCell: function createdHeaderCell(cell, data) {}, | ||
createdCell: function createdCell(cell, data) {}, | ||
drawHeaderRow: function drawHeaderRow(row, data) {}, | ||
drawRow: function drawRow(row, data) {}, | ||
drawHeaderCell: function drawHeaderCell(cell, data) {}, | ||
drawCell: function drawCell(cell, data) {}, | ||
beforePageContent: function beforePageContent(data) {}, | ||
afterPageContent: function afterPageContent(data) {} | ||
}; | ||
} | ||
// Base style for all themes | ||
function defaultStyles() { | ||
return { | ||
cellPadding: 5, | ||
fontSize: 10, | ||
font: "helvetica", // helvetica, times, courier | ||
lineColor: 200, | ||
lineWidth: 0.1, | ||
fontStyle: 'normal', // normal, bold, italic, bolditalic | ||
overflow: 'ellipsize', // visible, hidden, ellipsize or linebreak | ||
fillColor: 255, | ||
textColor: 20, | ||
halign: 'left', // left, center, right | ||
valign: 'top', // top, middle, bottom | ||
fillStyle: 'F', // 'S', 'F' or 'DF' (stroke, fill or fill then stroke) | ||
rowHeight: 20, | ||
columnWidth: 'auto' | ||
}; | ||
} | ||
// Base style for all themes | ||
function defaultStyles() { | ||
return { | ||
cellPadding: 5, | ||
fontSize: 10, | ||
font: "helvetica", // helvetica, times, courier | ||
lineColor: 200, | ||
lineWidth: 0.1, | ||
fontStyle: 'normal', // normal, bold, italic, bolditalic | ||
overflow: 'ellipsize', // visible, hidden, ellipsize or linebreak | ||
fillColor: 255, | ||
textColor: 20, | ||
halign: 'left', // left, center, right | ||
valign: 'top', // top, middle, bottom | ||
fillStyle: 'F', // 'S', 'F' or 'DF' (stroke, fill or fill then stroke) | ||
rowHeight: 20, | ||
columnWidth: 'auto' | ||
}; | ||
} | ||
var Config = function () { | ||
function Config() { | ||
classCallCheck(this, Config); | ||
} | ||
var Config = function () { | ||
function Config() { | ||
babelHelpers.classCallCheck(this, Config); | ||
} | ||
createClass(Config, null, [{ | ||
key: 'initSettings', | ||
value: function initSettings(userOptions) { | ||
var settings = Object.assign({}, getDefaults(), userOptions); | ||
babelHelpers.createClass(Config, null, [{ | ||
key: 'initSettings', | ||
value: function initSettings(userOptions) { | ||
var settings = Object.assign({}, getDefaults(), userOptions); | ||
// Options | ||
if (typeof settings.extendWidth !== 'undefined') { | ||
settings.tableWidth = settings.extendWidth ? 'auto' : 'wrap'; | ||
console.error("Use of deprecated option: extendWidth, use tableWidth instead."); | ||
} | ||
if (typeof settings.margins !== 'undefined') { | ||
if (typeof settings.margin === 'undefined') settings.margin = settings.margins; | ||
console.error("Use of deprecated option: margins, use margin instead."); | ||
} | ||
// Options | ||
if (typeof settings.extendWidth !== 'undefined') { | ||
settings.tableWidth = settings.extendWidth ? 'auto' : 'wrap'; | ||
console.error("Use of deprecated option: extendWidth, use tableWidth instead."); | ||
} | ||
if (typeof settings.margins !== 'undefined') { | ||
if (typeof settings.margin === 'undefined') settings.margin = settings.margins; | ||
console.error("Use of deprecated option: margins, use margin instead."); | ||
} | ||
[['padding', 'cellPadding'], ['lineHeight', 'rowHeight'], 'fontSize', 'overflow'].forEach(function (o) { | ||
var deprecatedOption = typeof o === 'string' ? o : o[0]; | ||
var style = typeof o === 'string' ? o : o[1]; | ||
if (typeof settings[deprecatedOption] !== 'undefined') { | ||
if (typeof settings.styles[style] === 'undefined') { | ||
settings.styles[style] = settings[deprecatedOption]; | ||
} | ||
console.error("Use of deprecated option: " + deprecatedOption + ", use the style " + style + " instead."); | ||
} | ||
}); | ||
[['padding', 'cellPadding'], ['lineHeight', 'rowHeight'], 'fontSize', 'overflow'].forEach(function (o) { | ||
var deprecatedOption = typeof o === 'string' ? o : o[0]; | ||
var style = typeof o === 'string' ? o : o[1]; | ||
if (typeof settings[deprecatedOption] !== 'undefined') { | ||
if (typeof settings.styles[style] === 'undefined') { | ||
settings.styles[style] = settings[deprecatedOption]; | ||
} | ||
console.error("Use of deprecated option: " + deprecatedOption + ", use the style " + style + " instead."); | ||
} | ||
}); | ||
// Unifying | ||
var marginSetting = settings.margin; | ||
settings.margin = {}; | ||
if (typeof marginSetting.horizontal === 'number') { | ||
marginSetting.right = marginSetting.horizontal; | ||
marginSetting.left = marginSetting.horizontal; | ||
} | ||
if (typeof marginSetting.vertical === 'number') { | ||
marginSetting.top = marginSetting.vertical; | ||
marginSetting.bottom = marginSetting.vertical; | ||
} | ||
['top', 'right', 'bottom', 'left'].forEach(function (side, i) { | ||
if (typeof marginSetting === 'number') { | ||
settings.margin[side] = marginSetting; | ||
} else { | ||
var key = Array.isArray(marginSetting) ? i : side; | ||
settings.margin[side] = typeof marginSetting[key] === 'number' ? marginSetting[key] : 40; | ||
} | ||
}); | ||
// Unifying | ||
var marginSetting = settings.margin; | ||
settings.margin = {}; | ||
if (typeof marginSetting.horizontal === 'number') { | ||
marginSetting.right = marginSetting.horizontal; | ||
marginSetting.left = marginSetting.horizontal; | ||
} | ||
if (typeof marginSetting.vertical === 'number') { | ||
marginSetting.top = marginSetting.vertical; | ||
marginSetting.bottom = marginSetting.vertical; | ||
} | ||
['top', 'right', 'bottom', 'left'].forEach(function (side, i) { | ||
if (typeof marginSetting === 'number') { | ||
settings.margin[side] = marginSetting; | ||
} else { | ||
var key = Array.isArray(marginSetting) ? i : side; | ||
settings.margin[side] = typeof marginSetting[key] === 'number' ? marginSetting[key] : 40; | ||
} | ||
}); | ||
return settings; | ||
} | ||
}, { | ||
key: 'styles', | ||
value: function styles(_styles) { | ||
_styles.unshift(defaultStyles()); | ||
_styles.unshift({}); | ||
return Object.assign.apply(this, _styles); | ||
} | ||
}]); | ||
return Config; | ||
}(); | ||
return settings; | ||
} | ||
}, { | ||
key: 'styles', | ||
value: function styles(_styles) { | ||
_styles.unshift(defaultStyles()); | ||
_styles.unshift({}); | ||
return Object.assign.apply(this, _styles); | ||
} | ||
}]); | ||
return Config; | ||
}(); | ||
// mdn.io/assign#Polyfill | ||
if (typeof Object.assign != 'function') { | ||
(function () { | ||
Object.assign = function (target) { | ||
'use strict'; | ||
// mdn.io/assign#Polyfill | ||
if (typeof Object.assign != 'function') { | ||
(function () { | ||
Object.assign = function (target) { | ||
'use strict'; | ||
if (target === undefined || target === null) { | ||
throw new TypeError('Cannot convert undefined or null to object'); | ||
} | ||
if (target === undefined || target === null) { | ||
throw new TypeError('Cannot convert undefined or null to object'); | ||
} | ||
var output = Object(target); | ||
for (var index = 1; index < arguments.length; index++) { | ||
var source = arguments[index]; | ||
if (source !== undefined && source !== null) { | ||
for (var nextKey in source) { | ||
if (source.hasOwnProperty(nextKey)) { | ||
output[nextKey] = source[nextKey]; | ||
} | ||
} | ||
} | ||
} | ||
return output; | ||
}; | ||
})(); | ||
} | ||
var output = Object(target); | ||
for (var index = 1; index < arguments.length; index++) { | ||
var source = arguments[index]; | ||
if (source !== undefined && source !== null) { | ||
for (var nextKey in source) { | ||
if (source.hasOwnProperty(nextKey)) { | ||
output[nextKey] = source[nextKey]; | ||
} | ||
} | ||
} | ||
} | ||
return output; | ||
}; | ||
})(); | ||
} | ||
// mdn.io/isarray#Polyfill | ||
if (!Array.isArray) { | ||
Array.isArray = function (arg) { | ||
return Object.prototype.toString.call(arg) === '[object Array]'; | ||
}; | ||
} | ||
// mdn.io/isarray#Polyfill | ||
if (!Array.isArray) { | ||
Array.isArray = function (arg) { | ||
return Object.prototype.toString.call(arg) === '[object Array]'; | ||
}; | ||
} | ||
if (!Object.values) { | ||
Object.values = function (obj) { | ||
return Object.keys(obj).map(function (key) { | ||
return obj[key]; | ||
}); | ||
}; | ||
} | ||
if (!Object.values) { | ||
Object.values = function (obj) { | ||
return Object.keys(obj).map(function (key) { | ||
return obj[key]; | ||
}); | ||
}; | ||
} | ||
var doc; | ||
var cursor; | ||
var styleModifiers; | ||
var pageSize; | ||
var settings; | ||
var table; | ||
// The current Table instance | ||
var doc; | ||
var cursor; | ||
var styleModifiers; | ||
var pageSize; | ||
var settings; | ||
var table; | ||
// The current Table instance | ||
/** | ||
* Create a table from a set of rows and columns. | ||
* | ||
* @param {Object[]|String[]} headers Either as an array of objects or array of strings | ||
* @param {Object[][]|String[][]} data Either as an array of objects or array of strings | ||
* @param {Object} [options={}] Options that will override the default ones | ||
*/ | ||
jsPDF.API.autoTable = function (headers, data, options) { | ||
validateInput(headers, data, options); | ||
doc = this; | ||
/** | ||
* Create a table from a set of rows and columns. | ||
* | ||
* @param {Object[]|String[]} headers Either as an array of objects or array of strings | ||
* @param {Object[][]|String[][]} data Either as an array of objects or array of strings | ||
* @param {Object} [options={}] Options that will override the default ones | ||
*/ | ||
jsPDF.API.autoTable = function (headers, data, options) { | ||
validateInput(headers, data, options); | ||
doc = this; | ||
pageSize = doc.internal.pageSize; | ||
styleModifiers = { | ||
fillColor: doc.setFillColor, | ||
textColor: doc.setTextColor, | ||
fontStyle: doc.setFontStyle, | ||
lineColor: doc.setDrawColor, | ||
lineWidth: doc.setLineWidth, | ||
font: doc.setFont, | ||
fontSize: doc.setFontSize | ||
}; | ||
pageSize = doc.internal.pageSize; | ||
styleModifiers = { | ||
fillColor: doc.setFillColor, | ||
textColor: doc.setTextColor, | ||
fontStyle: doc.setFontStyle, | ||
lineColor: doc.setDrawColor, | ||
lineWidth: doc.setLineWidth, | ||
font: doc.setFont, | ||
fontSize: doc.setFontSize | ||
}; | ||
settings = Config.initSettings(options || {}); | ||
settings = Config.initSettings(options || {}); | ||
// Need a cursor y as it needs to be reset after each page (row.y can't do that) | ||
// Also prefer cursor to column.x as the cursor is easier to modify in the hooks | ||
cursor = { | ||
x: settings.margin.left, | ||
y: settings.startY === false ? settings.margin.top : settings.startY | ||
}; | ||
// Need a cursor y as it needs to be reset after each page (row.y can't do that) | ||
// Also prefer cursor to column.x as the cursor is easier to modify in the hooks | ||
cursor = { | ||
x: settings.margin.left, | ||
y: settings.startY === false ? settings.margin.top : settings.startY | ||
}; | ||
var userStyles = { | ||
textColor: 30, // Setting text color to dark gray as it can't be obtained from jsPDF | ||
fontSize: doc.internal.getFontSize(), | ||
fontStyle: doc.internal.getFont().fontStyle | ||
}; | ||
var userStyles = { | ||
textColor: 30, // Setting text color to dark gray as it can't be obtained from jsPDF | ||
fontSize: doc.internal.getFontSize(), | ||
fontStyle: doc.internal.getFont().fontStyle | ||
}; | ||
// Create the table model with its columns, rows and cells | ||
createModels(headers, data); | ||
calculateWidths(this, pageSize.width); | ||
// Create the table model with its columns, rows and cells | ||
createModels(headers, data); | ||
calculateWidths(this, pageSize.width); | ||
// Page break if there is room for only the first data row | ||
var firstRowHeight = table.rows[0] && settings.pageBreak === 'auto' ? table.rows[0].height : 0; | ||
var minTableBottomPos = settings.startY + settings.margin.bottom + table.headerRow.height + firstRowHeight; | ||
if (settings.pageBreak === 'avoid') { | ||
minTableBottomPos += table.height; | ||
} | ||
if (settings.pageBreak === 'always' && settings.startY !== false || settings.startY !== false && minTableBottomPos > pageSize.height) { | ||
this.addPage(this.addPage); | ||
cursor.y = settings.margin.top; | ||
} | ||
// Page break if there is room for only the first data row | ||
var firstRowHeight = table.rows[0] && settings.pageBreak === 'auto' ? table.rows[0].height : 0; | ||
var minTableBottomPos = settings.startY + settings.margin.bottom + table.headerRow.height + firstRowHeight; | ||
if (settings.pageBreak === 'avoid') { | ||
minTableBottomPos += table.height; | ||
} | ||
if (settings.pageBreak === 'always' && settings.startY !== false || settings.startY !== false && minTableBottomPos > pageSize.height) { | ||
this.addPage(this.addPage); | ||
cursor.y = settings.margin.top; | ||
} | ||
applyStyles(userStyles); | ||
settings.beforePageContent(hooksData()); | ||
if (settings.drawHeaderRow(table.headerRow, hooksData({ row: table.headerRow })) !== false) { | ||
printRow(table.headerRow, settings.drawHeaderCell); | ||
} | ||
applyStyles(userStyles); | ||
printRows(this.addPage); | ||
settings.afterPageContent(hooksData()); | ||
applyStyles(userStyles); | ||
settings.beforePageContent(hooksData()); | ||
if (settings.drawHeaderRow(table.headerRow, hooksData({ row: table.headerRow })) !== false) { | ||
printRow(table.headerRow, settings.drawHeaderCell); | ||
} | ||
applyStyles(userStyles); | ||
printRows(this.addPage); | ||
settings.afterPageContent(hooksData()); | ||
applyStyles(userStyles); | ||
applyStyles(userStyles); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
/** | ||
* Returns the Y position of the last drawn cell | ||
* @returns int | ||
*/ | ||
jsPDF.API.autoTableEndPosY = function () { | ||
if (typeof cursor === 'undefined' || typeof cursor.y === 'undefined') { | ||
return 0; | ||
} | ||
return cursor.y; | ||
}; | ||
/** | ||
* Returns the Y position of the last drawn cell | ||
* @returns int | ||
*/ | ||
jsPDF.API.autoTableEndPosY = function () { | ||
if (typeof cursor === 'undefined' || typeof cursor.y === 'undefined') { | ||
return 0; | ||
} | ||
return cursor.y; | ||
}; | ||
/** | ||
* Parses an html table | ||
* | ||
* @param tableElem Html table element | ||
* @param includeHiddenElements If to include hidden rows and columns (defaults to false) | ||
* @returns Object Object with two properties, columns and rows | ||
*/ | ||
jsPDF.API.autoTableHtmlToJson = function (tableElem, includeHiddenElements) { | ||
includeHiddenElements = includeHiddenElements || false; | ||
/** | ||
* Parses an html table | ||
* | ||
* @param tableElem Html table element | ||
* @param includeHiddenElements If to include hidden rows and columns (defaults to false) | ||
* @returns Object Object with two properties, columns and rows | ||
*/ | ||
jsPDF.API.autoTableHtmlToJson = function (tableElem, includeHiddenElements) { | ||
includeHiddenElements = includeHiddenElements || false; | ||
var columns = {}, | ||
rows = []; | ||
var columns = {}, | ||
rows = []; | ||
var header = tableElem.rows[0]; | ||
var header = tableElem.rows[0]; | ||
for (var k = 0; k < header.cells.length; k++) { | ||
var cell = header.cells[k]; | ||
var style = window.getComputedStyle(cell); | ||
if (includeHiddenElements || style.display !== 'none') { | ||
columns[k] = cell ? cell.textContent.trim() : ''; | ||
} | ||
} | ||
for (var k = 0; k < header.cells.length; k++) { | ||
var cell = header.cells[k]; | ||
var style = window.getComputedStyle(cell); | ||
if (includeHiddenElements || style.display !== 'none') { | ||
columns[k] = cell ? cell.textContent.trim() : ''; | ||
} | ||
} | ||
for (var i = 1; i < tableElem.rows.length; i++) { | ||
var tableRow = tableElem.rows[i]; | ||
var style = window.getComputedStyle(tableRow); | ||
if (includeHiddenElements || style.display !== 'none') { | ||
var rowData = []; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
for (var i = 1; i < tableElem.rows.length; i++) { | ||
var tableRow = tableElem.rows[i]; | ||
var style = window.getComputedStyle(tableRow); | ||
if (includeHiddenElements || style.display !== 'none') { | ||
var rowData = []; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = Object.keys(columns)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var j = _step.value; | ||
try { | ||
for (var _iterator = Object.keys(columns)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var j = _step.value; | ||
var cell = tableRow.cells[j]; | ||
var val = cell ? cell.textContent.trim() : ''; | ||
rowData.push(val); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
var cell = tableRow.cells[j]; | ||
var val = cell ? cell.textContent.trim() : ''; | ||
rowData.push(val); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
rows.push(rowData); | ||
} | ||
} | ||
rows.push(rowData); | ||
} | ||
} | ||
return { columns: Object.values(columns), rows: rows, data: rows }; // data prop deprecated | ||
}; | ||
return { columns: Object.values(columns), rows: rows, data: rows }; // data prop deprecated | ||
}; | ||
/** | ||
* Improved text function with halign and valign support | ||
* Inspiration from: http://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113#28433113 | ||
*/ | ||
jsPDF.API.autoTableText = function (text, x, y, styles) { | ||
if (typeof x !== 'number' || typeof y !== 'number') { | ||
console.error('The x and y parameters are required. Missing for the text: ', text); | ||
} | ||
var fontSize = this.internal.getFontSize() / this.internal.scaleFactor; | ||
/** | ||
* Improved text function with halign and valign support | ||
* Inspiration from: http://stackoverflow.com/questions/28327510/align-text-right-using-jspdf/28433113#28433113 | ||
*/ | ||
jsPDF.API.autoTableText = function (text, x, y, styles) { | ||
if (typeof x !== 'number' || typeof y !== 'number') { | ||
console.error('The x and y parameters are required. Missing for the text: ', text); | ||
} | ||
var fontSize = this.internal.getFontSize() / this.internal.scaleFactor; | ||
// As defined in jsPDF source code | ||
var lineHeightProportion = FONT_ROW_RATIO; | ||
// As defined in jsPDF source code | ||
var lineHeightProportion = FONT_ROW_RATIO; | ||
var splitRegex = /\r\n|\r|\n/g; | ||
var splittedText = null; | ||
var lineCount = 1; | ||
if (styles.valign === 'middle' || styles.valign === 'bottom' || styles.halign === 'center' || styles.halign === 'right') { | ||
splittedText = typeof text === 'string' ? text.split(splitRegex) : text; | ||
var splitRegex = /\r\n|\r|\n/g; | ||
var splittedText = null; | ||
var lineCount = 1; | ||
if (styles.valign === 'middle' || styles.valign === 'bottom' || styles.halign === 'center' || styles.halign === 'right') { | ||
splittedText = typeof text === 'string' ? text.split(splitRegex) : text; | ||
lineCount = splittedText.length || 1; | ||
} | ||
lineCount = splittedText.length || 1; | ||
} | ||
// Align the top | ||
y += fontSize * (2 - lineHeightProportion); | ||
// Align the top | ||
y += fontSize * (2 - lineHeightProportion); | ||
if (styles.valign === 'middle') y -= lineCount / 2 * fontSize;else if (styles.valign === 'bottom') y -= lineCount * fontSize; | ||
if (styles.valign === 'middle') y -= lineCount / 2 * fontSize;else if (styles.valign === 'bottom') y -= lineCount * fontSize; | ||
if (styles.halign === 'center' || styles.halign === 'right') { | ||
var alignSize = fontSize; | ||
if (styles.halign === 'center') alignSize *= 0.5; | ||
if (styles.halign === 'center' || styles.halign === 'right') { | ||
var alignSize = fontSize; | ||
if (styles.halign === 'center') alignSize *= 0.5; | ||
if (lineCount >= 1) { | ||
for (var iLine = 0; iLine < splittedText.length; iLine++) { | ||
this.text(splittedText[iLine], x - this.getStringUnitWidth(splittedText[iLine]) * alignSize, y); | ||
y += fontSize; | ||
} | ||
return doc; | ||
} | ||
x -= this.getStringUnitWidth(text) * alignSize; | ||
} | ||
if (lineCount >= 1) { | ||
for (var iLine = 0; iLine < splittedText.length; iLine++) { | ||
this.text(splittedText[iLine], x - this.getStringUnitWidth(splittedText[iLine]) * alignSize, y); | ||
y += fontSize; | ||
} | ||
return doc; | ||
} | ||
x -= this.getStringUnitWidth(text) * alignSize; | ||
} | ||
this.text(text, x, y); | ||
this.text(text, x, y); | ||
return this; | ||
}; | ||
return this; | ||
}; | ||
function validateInput(headers, data, options) { | ||
if (!headers || (typeof headers === 'undefined' ? 'undefined' : _typeof(headers)) !== 'object') { | ||
console.error("The headers should be an object or array, is: " + (typeof headers === 'undefined' ? 'undefined' : _typeof(headers))); | ||
} | ||
function validateInput(headers, data, options) { | ||
if (!headers || (typeof headers === 'undefined' ? 'undefined' : babelHelpers.typeof(headers)) !== 'object') { | ||
console.error("The headers should be an object or array, is: " + (typeof headers === 'undefined' ? 'undefined' : babelHelpers.typeof(headers))); | ||
} | ||
if (!data || (typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object') { | ||
console.error("The data should be an object or array, is: " + (typeof data === 'undefined' ? 'undefined' : _typeof(data))); | ||
} | ||
if (!data || (typeof data === 'undefined' ? 'undefined' : babelHelpers.typeof(data)) !== 'object') { | ||
console.error("The data should be an object or array, is: " + (typeof data === 'undefined' ? 'undefined' : babelHelpers.typeof(data))); | ||
} | ||
if (!!options && (typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') { | ||
console.error("The data should be an object or array, is: " + (typeof data === 'undefined' ? 'undefined' : _typeof(data))); | ||
} | ||
if (!!options && (typeof options === 'undefined' ? 'undefined' : babelHelpers.typeof(options)) !== 'object') { | ||
console.error("The data should be an object or array, is: " + (typeof data === 'undefined' ? 'undefined' : babelHelpers.typeof(data))); | ||
} | ||
if (!Array.prototype.forEach) { | ||
console.error("The current browser does not support Array.prototype.forEach which is required for " + "jsPDF-AutoTable. You can try polyfilling it by including this script " + "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Polyfill"); | ||
} | ||
} | ||
if (!Array.prototype.forEach) { | ||
console.error("The current browser does not support Array.prototype.forEach which is required for " + "jsPDF-AutoTable. You can try polyfilling it by including this script " + "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#Polyfill"); | ||
} | ||
} | ||
/** | ||
* Create models from the user input | ||
* | ||
* @param inputHeaders | ||
* @param inputData | ||
*/ | ||
function createModels(inputHeaders, inputData) { | ||
table = new Table(); | ||
/** | ||
* Create models from the user input | ||
* | ||
* @param inputHeaders | ||
* @param inputData | ||
*/ | ||
function createModels(inputHeaders, inputData) { | ||
table = new Table(); | ||
var splitRegex = /\r\n|\r|\n/g; | ||
var splitRegex = /\r\n|\r|\n/g; | ||
// Header row and columns | ||
var headerRow = new Row(inputHeaders); | ||
headerRow.index = -1; | ||
// Header row and columns | ||
var headerRow = new Row(inputHeaders); | ||
headerRow.index = -1; | ||
var themeStyles = Config.styles([themes[settings.theme].table, themes[settings.theme].header]); | ||
headerRow.styles = Object.assign({}, themeStyles, settings.styles, settings.headerStyles); | ||
var themeStyles = Config.styles([themes[settings.theme].table, themes[settings.theme].header]); | ||
headerRow.styles = Object.assign({}, themeStyles, settings.styles, settings.headerStyles); | ||
// Columns and header row | ||
inputHeaders.forEach(function (rawColumn, dataKey) { | ||
if ((typeof rawColumn === 'undefined' ? 'undefined' : _typeof(rawColumn)) === 'object') { | ||
dataKey = typeof rawColumn.dataKey !== 'undefined' ? rawColumn.dataKey : rawColumn.key; | ||
} | ||
// Columns and header row | ||
inputHeaders.forEach(function (rawColumn, dataKey) { | ||
if ((typeof rawColumn === 'undefined' ? 'undefined' : babelHelpers.typeof(rawColumn)) === 'object') { | ||
dataKey = typeof rawColumn.dataKey !== 'undefined' ? rawColumn.dataKey : rawColumn.key; | ||
} | ||
if (typeof rawColumn.width !== 'undefined') { | ||
console.error("Use of deprecated option: column.width, use column.styles.columnWidth instead."); | ||
} | ||
if (typeof rawColumn.width !== 'undefined') { | ||
console.error("Use of deprecated option: column.width, use column.styles.columnWidth instead."); | ||
} | ||
var col = new Column(dataKey); | ||
col.styles = settings.columnStyles[col.dataKey] || {}; | ||
table.columns.push(col); | ||
var col = new Column(dataKey); | ||
col.styles = settings.columnStyles[col.dataKey] || {}; | ||
table.columns.push(col); | ||
var cell = new Cell(); | ||
cell.raw = (typeof rawColumn === 'undefined' ? 'undefined' : _typeof(rawColumn)) === 'object' ? rawColumn.title : rawColumn; | ||
cell.styles = Object.assign({}, headerRow.styles); | ||
cell.text = '' + cell.raw; | ||
cell.contentWidth = cell.styles.cellPadding * 2 + getStringWidth(cell.text, cell.styles); | ||
cell.text = cell.text.split(splitRegex); | ||
var cell = new Cell(); | ||
cell.raw = (typeof rawColumn === 'undefined' ? 'undefined' : babelHelpers.typeof(rawColumn)) === 'object' ? rawColumn.title : rawColumn; | ||
cell.styles = Object.assign({}, headerRow.styles); | ||
cell.text = '' + cell.raw; | ||
cell.contentWidth = cell.styles.cellPadding * 2 + getStringWidth(cell.text, cell.styles); | ||
cell.text = cell.text.split(splitRegex); | ||
headerRow.cells[dataKey] = cell; | ||
settings.createdHeaderCell(cell, { column: col, row: headerRow, settings: settings }); | ||
}); | ||
table.headerRow = headerRow; | ||
headerRow.cells[dataKey] = cell; | ||
settings.createdHeaderCell(cell, { column: col, row: headerRow, settings: settings }); | ||
}); | ||
table.headerRow = headerRow; | ||
// Rows och cells | ||
inputData.forEach(function (rawRow, i) { | ||
var row = new Row(rawRow); | ||
var isAlternate = i % 2 === 0; | ||
var themeStyles = Config.styles([themes[settings.theme].table, isAlternate ? themes[settings.theme].alternateRow : {}]); | ||
var userStyles = Object.assign({}, settings.styles, settings.bodyStyles, isAlternate ? settings.alternateRowStyles : {}); | ||
row.styles = Object.assign({}, themeStyles, userStyles); | ||
row.index = i; | ||
table.columns.forEach(function (column) { | ||
var cell = new Cell(); | ||
cell.raw = rawRow[column.dataKey]; | ||
cell.styles = Object.assign({}, row.styles, column.styles); | ||
cell.text = typeof cell.raw !== 'undefined' ? '' + cell.raw : ''; // Stringify 0 and false, but not undefined | ||
row.cells[column.dataKey] = cell; | ||
settings.createdCell(cell, hooksData({ column: column, row: row })); | ||
cell.contentWidth = cell.styles.cellPadding * 2 + getStringWidth(cell.text, cell.styles); | ||
cell.text = cell.text.split(splitRegex); | ||
}); | ||
table.rows.push(row); | ||
}); | ||
} | ||
// Rows och cells | ||
inputData.forEach(function (rawRow, i) { | ||
var row = new Row(rawRow); | ||
var isAlternate = i % 2 === 0; | ||
var themeStyles = Config.styles([themes[settings.theme].table, isAlternate ? themes[settings.theme].alternateRow : {}]); | ||
var userStyles = Object.assign({}, settings.styles, settings.bodyStyles, isAlternate ? settings.alternateRowStyles : {}); | ||
row.styles = Object.assign({}, themeStyles, userStyles); | ||
row.index = i; | ||
table.columns.forEach(function (column) { | ||
var cell = new Cell(); | ||
cell.raw = rawRow[column.dataKey]; | ||
cell.styles = Object.assign({}, row.styles, column.styles); | ||
cell.text = typeof cell.raw !== 'undefined' ? '' + cell.raw : ''; // Stringify 0 and false, but not undefined | ||
row.cells[column.dataKey] = cell; | ||
settings.createdCell(cell, hooksData({ column: column, row: row })); | ||
cell.contentWidth = cell.styles.cellPadding * 2 + getStringWidth(cell.text, cell.styles); | ||
cell.text = cell.text.split(splitRegex); | ||
}); | ||
table.rows.push(row); | ||
}); | ||
} | ||
/** | ||
* Calculate the column widths | ||
*/ | ||
function calculateWidths(doc, pageWidth) { | ||
// Column and table content width | ||
var tableContentWidth = 0; | ||
table.columns.forEach(function (column) { | ||
column.contentWidth = table.headerRow.cells[column.dataKey].contentWidth; | ||
table.rows.forEach(function (row) { | ||
var cellWidth = row.cells[column.dataKey].contentWidth; | ||
if (cellWidth > column.contentWidth) { | ||
column.contentWidth = cellWidth; | ||
} | ||
}); | ||
column.width = column.contentWidth; | ||
tableContentWidth += column.contentWidth; | ||
}); | ||
table.contentWidth = tableContentWidth; | ||
/** | ||
* Calculate the column widths | ||
*/ | ||
function calculateWidths(doc, pageWidth) { | ||
// Column and table content width | ||
var tableContentWidth = 0; | ||
table.columns.forEach(function (column) { | ||
column.contentWidth = table.headerRow.cells[column.dataKey].contentWidth; | ||
table.rows.forEach(function (row) { | ||
var cellWidth = row.cells[column.dataKey].contentWidth; | ||
if (cellWidth > column.contentWidth) { | ||
column.contentWidth = cellWidth; | ||
} | ||
}); | ||
column.width = column.contentWidth; | ||
tableContentWidth += column.contentWidth; | ||
}); | ||
table.contentWidth = tableContentWidth; | ||
var maxTableWidth = pageWidth - settings.margin.left - settings.margin.right; | ||
var preferredTableWidth = maxTableWidth; // settings.tableWidth === 'auto' | ||
if (typeof settings.tableWidth === 'number') { | ||
preferredTableWidth = settings.tableWidth; | ||
} else if (settings.tableWidth === 'wrap') { | ||
preferredTableWidth = table.contentWidth; | ||
} | ||
table.width = preferredTableWidth < maxTableWidth ? preferredTableWidth : maxTableWidth; | ||
var maxTableWidth = pageWidth - settings.margin.left - settings.margin.right; | ||
var preferredTableWidth = maxTableWidth; // settings.tableWidth === 'auto' | ||
if (typeof settings.tableWidth === 'number') { | ||
preferredTableWidth = settings.tableWidth; | ||
} else if (settings.tableWidth === 'wrap') { | ||
preferredTableWidth = table.contentWidth; | ||
} | ||
table.width = preferredTableWidth < maxTableWidth ? preferredTableWidth : maxTableWidth; | ||
// To avoid subjecting columns with little content with the chosen overflow method, | ||
// never shrink a column more than the table divided by column count (its "fair part") | ||
var dynamicColumns = []; | ||
var dynamicColumnsContentWidth = 0; | ||
var fairWidth = table.width / table.columns.length; | ||
var staticWidth = 0; | ||
table.columns.forEach(function (column) { | ||
var colStyles = Config.styles([themes[settings.theme].table, settings.styles, column.styles]); | ||
if (colStyles.columnWidth === 'wrap') { | ||
column.width = column.contentWidth; | ||
} else if (typeof colStyles.columnWidth === 'number') { | ||
column.width = colStyles.columnWidth; | ||
} else if (colStyles.columnWidth === 'auto' || true) { | ||
if (column.contentWidth <= fairWidth && table.contentWidth > table.width) { | ||
column.width = column.contentWidth; | ||
} else { | ||
dynamicColumns.push(column); | ||
dynamicColumnsContentWidth += column.contentWidth; | ||
column.width = 0; | ||
} | ||
} | ||
staticWidth += column.width; | ||
}); | ||
// To avoid subjecting columns with little content with the chosen overflow method, | ||
// never shrink a column more than the table divided by column count (its "fair part") | ||
var dynamicColumns = []; | ||
var dynamicColumnsContentWidth = 0; | ||
var fairWidth = table.width / table.columns.length; | ||
var staticWidth = 0; | ||
table.columns.forEach(function (column) { | ||
var colStyles = Config.styles([themes[settings.theme].table, settings.styles, column.styles]); | ||
if (colStyles.columnWidth === 'wrap') { | ||
column.width = column.contentWidth; | ||
} else if (typeof colStyles.columnWidth === 'number') { | ||
column.width = colStyles.columnWidth; | ||
} else if (colStyles.columnWidth === 'auto' || true) { | ||
if (column.contentWidth <= fairWidth && table.contentWidth > table.width) { | ||
column.width = column.contentWidth; | ||
} else { | ||
dynamicColumns.push(column); | ||
dynamicColumnsContentWidth += column.contentWidth; | ||
column.width = 0; | ||
} | ||
} | ||
staticWidth += column.width; | ||
}); | ||
// Distributes extra width or trims columns down to fit | ||
distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth); | ||
// Distributes extra width or trims columns down to fit | ||
distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth); | ||
// Row height, table height and text overflow | ||
table.height = 0; | ||
var all = table.rows.concat(table.headerRow); | ||
all.forEach(function (row, i) { | ||
var lineBreakCount = 0; | ||
table.columns.forEach(function (col) { | ||
var cell = row.cells[col.dataKey]; | ||
applyStyles(cell.styles); | ||
var textSpace = col.width - cell.styles.cellPadding * 2; | ||
if (cell.styles.overflow === 'linebreak') { | ||
// Add one pt to textSpace to fix rounding error | ||
try { | ||
cell.text = doc.splitTextToSize(cell.text, textSpace + 1, { fontSize: cell.styles.fontSize }); | ||
} catch (e) { | ||
if (e instanceof TypeError && Array.isArray(cell.text)) { | ||
cell.text = doc.splitTextToSize(cell.text.join(' '), textSpace + 1, { fontSize: cell.styles.fontSize }); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} else if (cell.styles.overflow === 'ellipsize') { | ||
cell.text = ellipsize(cell.text, textSpace, cell.styles); | ||
} else if (cell.styles.overflow === 'visible') { | ||
// Do nothing | ||
} else if (cell.styles.overflow === 'hidden') { | ||
cell.text = ellipsize(cell.text, textSpace, cell.styles, ''); | ||
} else if (typeof cell.styles.overflow === 'function') { | ||
cell.text = cell.styles.overflow(cell.text, textSpace); | ||
} else { | ||
console.error("Unrecognized overflow type: " + cell.styles.overflow); | ||
} | ||
var count = Array.isArray(cell.text) ? cell.text.length - 1 : 0; | ||
if (count > lineBreakCount) { | ||
lineBreakCount = count; | ||
} | ||
}); | ||
// Row height, table height and text overflow | ||
table.height = 0; | ||
var all = table.rows.concat(table.headerRow); | ||
all.forEach(function (row, i) { | ||
var lineBreakCount = 0; | ||
table.columns.forEach(function (col) { | ||
var cell = row.cells[col.dataKey]; | ||
applyStyles(cell.styles); | ||
var textSpace = col.width - cell.styles.cellPadding * 2; | ||
if (cell.styles.overflow === 'linebreak') { | ||
// Add one pt to textSpace to fix rounding error | ||
try { | ||
cell.text = doc.splitTextToSize(cell.text, textSpace + 1, { fontSize: cell.styles.fontSize }); | ||
} catch (e) { | ||
if (e instanceof TypeError && Array.isArray(cell.text)) { | ||
cell.text = doc.splitTextToSize(cell.text.join(' '), textSpace + 1, { fontSize: cell.styles.fontSize }); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} else if (cell.styles.overflow === 'ellipsize') { | ||
cell.text = ellipsize(cell.text, textSpace, cell.styles); | ||
} else if (cell.styles.overflow === 'visible') { | ||
// Do nothing | ||
} else if (cell.styles.overflow === 'hidden') { | ||
cell.text = ellipsize(cell.text, textSpace, cell.styles, ''); | ||
} else if (typeof cell.styles.overflow === 'function') { | ||
cell.text = cell.styles.overflow(cell.text, textSpace); | ||
} else { | ||
console.error("Unrecognized overflow type: " + cell.styles.overflow); | ||
} | ||
var count = Array.isArray(cell.text) ? cell.text.length - 1 : 0; | ||
if (count > lineBreakCount) { | ||
lineBreakCount = count; | ||
} | ||
}); | ||
row.heightStyle = row.styles.rowHeight; | ||
// TODO Pick the highest row based on font size as well | ||
row.height = row.heightStyle + lineBreakCount * row.styles.fontSize * FONT_ROW_RATIO; | ||
table.height += row.height; | ||
}); | ||
} | ||
row.heightStyle = row.styles.rowHeight; | ||
// TODO Pick the highest row based on font size as well | ||
row.height = row.heightStyle + lineBreakCount * row.styles.fontSize * FONT_ROW_RATIO; | ||
table.height += row.height; | ||
}); | ||
} | ||
function distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth) { | ||
var extraWidth = table.width - staticWidth - dynamicColumnsContentWidth; | ||
for (var i = 0; i < dynamicColumns.length; i++) { | ||
var col = dynamicColumns[i]; | ||
var ratio = col.contentWidth / dynamicColumnsContentWidth; | ||
// A column turned out to be none dynamic, start over recursively | ||
var isNoneDynamic = col.contentWidth + extraWidth * ratio < fairWidth; | ||
if (extraWidth < 0 && isNoneDynamic) { | ||
dynamicColumns.splice(i, 1); | ||
dynamicColumnsContentWidth -= col.contentWidth; | ||
col.width = fairWidth; | ||
staticWidth += col.width; | ||
distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth); | ||
break; | ||
} else { | ||
col.width = col.contentWidth + extraWidth * ratio; | ||
} | ||
} | ||
} | ||
function distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth) { | ||
var extraWidth = table.width - staticWidth - dynamicColumnsContentWidth; | ||
for (var i = 0; i < dynamicColumns.length; i++) { | ||
var col = dynamicColumns[i]; | ||
var ratio = col.contentWidth / dynamicColumnsContentWidth; | ||
// A column turned out to be none dynamic, start over recursively | ||
var isNoneDynamic = col.contentWidth + extraWidth * ratio < fairWidth; | ||
if (extraWidth < 0 && isNoneDynamic) { | ||
dynamicColumns.splice(i, 1); | ||
dynamicColumnsContentWidth -= col.contentWidth; | ||
col.width = fairWidth; | ||
staticWidth += col.width; | ||
distributeWidth(dynamicColumns, staticWidth, dynamicColumnsContentWidth, fairWidth); | ||
break; | ||
} else { | ||
col.width = col.contentWidth + extraWidth * ratio; | ||
} | ||
} | ||
} | ||
function addPage(jspdfAddPage) { | ||
settings.afterPageContent(hooksData()); | ||
jspdfAddPage(); | ||
table.pageCount++; | ||
cursor = { x: settings.margin.left, y: settings.margin.top }; | ||
settings.beforePageContent(hooksData()); | ||
if (settings.drawHeaderRow(table.headerRow, hooksData({ row: table.headerRow })) !== false) { | ||
printRow(table.headerRow, settings.drawHeaderCell); | ||
} | ||
} | ||
function addPage(jspdfAddPage) { | ||
settings.afterPageContent(hooksData()); | ||
jspdfAddPage(); | ||
table.pageCount++; | ||
cursor = { x: settings.margin.left, y: settings.margin.top }; | ||
settings.beforePageContent(hooksData()); | ||
if (settings.drawHeaderRow(table.headerRow, hooksData({ row: table.headerRow })) !== false) { | ||
printRow(table.headerRow, settings.drawHeaderCell); | ||
} | ||
} | ||
/** | ||
* Add a new page if cursor is at the end of page | ||
*/ | ||
function isNewPage(rowHeight) { | ||
var afterRowPos = cursor.y + rowHeight + settings.margin.bottom; | ||
return afterRowPos >= pageSize.height; | ||
} | ||
/** | ||
* Add a new page if cursor is at the end of page | ||
*/ | ||
function isNewPage(rowHeight) { | ||
var afterRowPos = cursor.y + rowHeight + settings.margin.bottom; | ||
return afterRowPos >= pageSize.height; | ||
} | ||
function printRows(jspdfAddPage) { | ||
table.rows.forEach(function (row, i) { | ||
if (isNewPage(row.height)) { | ||
var samePageThreshold = 3; | ||
// TODO Fix cell height > page height | ||
/*if (row.height > row.heightStyle * samePageThreshold) { | ||
var remainingPageSpace = pageSize.height - cursor.y - settings.margin.bottom; | ||
var lineCount = Math.floor(remainingPageSpace / (row.styles.fontSize * FONT_ROW_RATIO)); | ||
table.columns.forEach(function(col) { | ||
var arr = row.cells[col.dataKey].text; | ||
if (arr.length > lineCount) { | ||
arr.splice(lineCount - 1, arr.length, "..."); | ||
} | ||
}); | ||
row.height = remainingPageSpace; | ||
if (settings.drawRow(row, hooksData({row: row})) !== false) { | ||
printRow(row, settings.drawCell); | ||
} | ||
row = new Row(rawRow); | ||
}*/ | ||
addPage(jspdfAddPage); | ||
} | ||
row.y = cursor.y; | ||
if (settings.drawRow(row, hooksData({ row: row })) !== false) { | ||
printRow(row, settings.drawCell); | ||
} | ||
}); | ||
} | ||
function printRows(jspdfAddPage) { | ||
table.rows.forEach(function (row, i) { | ||
if (isNewPage(row.height)) { | ||
var samePageThreshold = 3; | ||
// TODO Fix cell height > page height | ||
/*if (row.height > row.heightStyle * samePageThreshold) { | ||
var remainingPageSpace = pageSize.height - cursor.y - settings.margin.bottom; | ||
var lineCount = Math.floor(remainingPageSpace / (row.styles.fontSize * FONT_ROW_RATIO)); | ||
table.columns.forEach(function(col) { | ||
var arr = row.cells[col.dataKey].text; | ||
if (arr.length > lineCount) { | ||
arr.splice(lineCount - 1, arr.length, "..."); | ||
} | ||
}); | ||
row.height = remainingPageSpace; | ||
if (settings.drawRow(row, hooksData({row: row})) !== false) { | ||
printRow(row, settings.drawCell); | ||
} | ||
row = new Row(rawRow); | ||
}*/ | ||
addPage(jspdfAddPage); | ||
} | ||
row.y = cursor.y; | ||
if (settings.drawRow(row, hooksData({ row: row })) !== false) { | ||
printRow(row, settings.drawCell); | ||
} | ||
}); | ||
} | ||
function printRow(row, hookHandler) { | ||
cursor.x = settings.margin.left; | ||
for (var i = 0; i < table.columns.length; i++) { | ||
var column = table.columns[i]; | ||
var cell = row.cells[column.dataKey]; | ||
if (!cell) { | ||
continue; | ||
} | ||
applyStyles(cell.styles); | ||
function printRow(row, hookHandler) { | ||
cursor.x = settings.margin.left; | ||
for (var i = 0; i < table.columns.length; i++) { | ||
var column = table.columns[i]; | ||
var cell = row.cells[column.dataKey]; | ||
if (!cell) { | ||
continue; | ||
} | ||
applyStyles(cell.styles); | ||
cell.x = cursor.x; | ||
cell.y = cursor.y; | ||
cell.height = row.height; | ||
cell.width = column.width; | ||
cell.x = cursor.x; | ||
cell.y = cursor.y; | ||
cell.height = row.height; | ||
cell.width = column.width; | ||
if (cell.styles.valign === 'top') { | ||
cell.textPos.y = cursor.y + cell.styles.cellPadding; | ||
} else if (cell.styles.valign === 'bottom') { | ||
cell.textPos.y = cursor.y + row.height - cell.styles.cellPadding; | ||
} else { | ||
cell.textPos.y = cursor.y + row.height / 2; | ||
} | ||
if (cell.styles.valign === 'top') { | ||
cell.textPos.y = cursor.y + cell.styles.cellPadding; | ||
} else if (cell.styles.valign === 'bottom') { | ||
cell.textPos.y = cursor.y + row.height - cell.styles.cellPadding; | ||
} else { | ||
cell.textPos.y = cursor.y + row.height / 2; | ||
} | ||
if (cell.styles.halign === 'right') { | ||
cell.textPos.x = cell.x + cell.width - cell.styles.cellPadding; | ||
} else if (cell.styles.halign === 'center') { | ||
cell.textPos.x = cell.x + cell.width / 2; | ||
} else { | ||
cell.textPos.x = cell.x + cell.styles.cellPadding; | ||
} | ||
if (cell.styles.halign === 'right') { | ||
cell.textPos.x = cell.x + cell.width - cell.styles.cellPadding; | ||
} else if (cell.styles.halign === 'center') { | ||
cell.textPos.x = cell.x + cell.width / 2; | ||
} else { | ||
cell.textPos.x = cell.x + cell.styles.cellPadding; | ||
} | ||
var data = hooksData({ column: column, row: row }); | ||
if (hookHandler(cell, data) !== false) { | ||
doc.rect(cell.x, cell.y, cell.width, cell.height, cell.styles.fillStyle); | ||
doc.autoTableText(cell.text, cell.textPos.x, cell.textPos.y, { | ||
halign: cell.styles.halign, | ||
valign: cell.styles.valign | ||
}); | ||
} | ||
cursor.x += cell.width; | ||
} | ||
var data = hooksData({ column: column, row: row }); | ||
if (hookHandler(cell, data) !== false) { | ||
doc.rect(cell.x, cell.y, cell.width, cell.height, cell.styles.fillStyle); | ||
doc.autoTableText(cell.text, cell.textPos.x, cell.textPos.y, { | ||
halign: cell.styles.halign, | ||
valign: cell.styles.valign | ||
}); | ||
} | ||
cursor.x += cell.width; | ||
} | ||
cursor.y += row.height; | ||
} | ||
cursor.y += row.height; | ||
} | ||
function applyStyles(styles) { | ||
Object.keys(styleModifiers).forEach(function (name) { | ||
var style = styles[name]; | ||
var modifier = styleModifiers[name]; | ||
if (typeof style !== 'undefined') { | ||
if (style.constructor === Array) { | ||
modifier.apply(this, style); | ||
} else { | ||
modifier(style); | ||
} | ||
} | ||
}); | ||
} | ||
function applyStyles(styles) { | ||
Object.keys(styleModifiers).forEach(function (name) { | ||
var style = styles[name]; | ||
var modifier = styleModifiers[name]; | ||
if (typeof style !== 'undefined') { | ||
if (style.constructor === Array) { | ||
modifier.apply(this, style); | ||
} else { | ||
modifier(style); | ||
} | ||
} | ||
}); | ||
} | ||
function hooksData(additionalData) { | ||
return Object.assign({ | ||
pageCount: table.pageCount, | ||
settings: settings, | ||
table: table, | ||
cursor: cursor | ||
}, additionalData || {}); | ||
} | ||
function hooksData(additionalData) { | ||
return Object.assign({ | ||
pageCount: table.pageCount, | ||
settings: settings, | ||
table: table, | ||
cursor: cursor | ||
}, additionalData || {}); | ||
} | ||
function getStringWidth(text, styles) { | ||
applyStyles(styles); | ||
var w = doc.getStringUnitWidth(text); | ||
return w * styles.fontSize; | ||
} | ||
function getStringWidth(text, styles) { | ||
applyStyles(styles); | ||
var w = doc.getStringUnitWidth(text); | ||
return w * styles.fontSize; | ||
} | ||
/** | ||
* Ellipsize the text to fit in the width | ||
*/ | ||
function ellipsize(text, width, styles, ellipsizeStr) { | ||
ellipsizeStr = typeof ellipsizeStr !== 'undefined' ? ellipsizeStr : '...'; | ||
/** | ||
* Ellipsize the text to fit in the width | ||
*/ | ||
function ellipsize(text, width, styles, ellipsizeStr) { | ||
ellipsizeStr = typeof ellipsizeStr !== 'undefined' ? ellipsizeStr : '...'; | ||
if (Array.isArray(text)) { | ||
text.forEach(function (str, i) { | ||
text[i] = ellipsize(str, width, styles, ellipsizeStr); | ||
}); | ||
return text; | ||
} | ||
if (Array.isArray(text)) { | ||
text.forEach(function (str, i) { | ||
text[i] = ellipsize(str, width, styles, ellipsizeStr); | ||
}); | ||
return text; | ||
} | ||
if (width >= getStringWidth(text, styles)) { | ||
return text; | ||
} | ||
while (width < getStringWidth(text + ellipsizeStr, styles)) { | ||
if (text.length < 2) { | ||
break; | ||
} | ||
text = text.substring(0, text.length - 1); | ||
} | ||
return text.trim() + ellipsizeStr; | ||
} | ||
if (width >= getStringWidth(text, styles)) { | ||
return text; | ||
} | ||
while (width < getStringWidth(text + ellipsizeStr, styles)) { | ||
if (text.length < 2) { | ||
break; | ||
} | ||
text = text.substring(0, text.length - 1); | ||
} | ||
return text.trim() + ellipsizeStr; | ||
} | ||
})); |
{ | ||
"name": "jspdf-autotable", | ||
"version": "2.0.26", | ||
"version": "2.0.27", | ||
"description": "Generate pdf tables with javascript (jsPDF plugin)", | ||
@@ -10,3 +10,4 @@ "main": "dist/jspdf.plugin.autotable.js", | ||
"dependencies": { | ||
"jspdf": "<1.3" | ||
"babel-polyfill": "^6.9.1", | ||
"jspdf": "github:mrrio/jsPDF#76edb3387cda3d5292e212765134b06150030364" | ||
}, | ||
@@ -16,8 +17,10 @@ "devDependencies": { | ||
"nodemon": "^1.8.1", | ||
"rollup": "^0.25.1", | ||
"rollup-plugin-babel": "^2.3.9", | ||
"uglify-js": "^2.4.24" | ||
"rollup": "^0.34.1", | ||
"rollup-plugin-babel": "^2.6.1", | ||
"rollup-plugin-commonjs": "^3.1.0", | ||
"rollup-plugin-node-resolve": "^1.7.1", | ||
"uglify-js": "^2.7.0" | ||
}, | ||
"scripts": { | ||
"start": "nodemon --watch src -e js,ts build.js develop", | ||
"start": "nodemon --watch src build.js develop & static examples -a 0.0.0.0", | ||
"build": "node build.js build", | ||
@@ -24,0 +27,0 @@ "version": "npm run build && git add -A dist && git add -A examples/libs", |
@@ -16,3 +16,3 @@ # AutoTable - Table plugin for jsPDF | ||
<script src="bower_components/jspdf/dist/jspdf.min.js"></script> | ||
<script src="bower_components/jspdf-autotable/jspdf.plugin.autotable.js"></script> | ||
<script src="bower_components/jspdf-autotable/dist/jspdf.plugin.autotable.js"></script> | ||
``` | ||
@@ -19,0 +19,0 @@ |
@@ -0,1 +1,2 @@ | ||
// mdn.io/assign#Polyfill | ||
@@ -2,0 +3,0 @@ if (typeof Object.assign != 'function') { |
### Background | ||
The original goal for the plugin was to be able to generate good looking pdf tables from raw javascript objects. Additional features have since been added, but mostly to make the generated tables easier to customize. | ||
The goal for the plugin has always been to make it easy to generate good looking pdf tables with javascript. Additional features and customization options have been added over time. | ||
### Development | ||
The first was a quick proof of concept and was published to Github in the end of 2014. The first version was buggy, limited and basically only had one feature - automatic calculation of width of the columns based on the text in the cells (hence the name AutoTable). Surprisingly it got some traction and people started posting issues and star it. This spurred the development of version 1.0 which was completed in the beginning of 2015. Version 1.0 were also basic however and issues regarding styling and how to create a pdf from html were common. That was the main rationale for starting the development of 2.0 which was finished the summer of 2015. | ||
The first version was a quick proof of concept and was published to Github in the end of 2014. It only worked for limited use cases and basically only had one feature worth mentioning: automatic calculation of width of the columns based on the text in the cells (hence the name AutoTable). Surprisingly it got some traction and people started posting issues and star it. This spurred the development of version 1.0 which was completed in the beginning of 2015. Version 1.0 were also basic however and issues regarding styling and how to create a pdf from html were common. Version 2.0 was finished in the middle of 2015 and made it much easier easier to customize and style the tables. | ||
@@ -7,0 +7,0 @@ ### Production uses |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1570483
26
10439
2
7
3
1
5
1
+ Addedbabel-polyfill@^6.9.1
+ Addedbabel-polyfill@6.26.0(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedregenerator-runtime@0.10.50.11.1(transitive)
- Removedjspdf@1.2.61(transitive)
Updatedjspdf@github:mrrio/jsPDF#76edb3387cda3d5292e212765134b06150030364