function e(e,t,n,r,i){r||={};var a=1.15,o=i.internal.scaleFactor,s=i.internal.getFontSize()/o,c=s*(i.getLineHeightFactor?i.getLineHeightFactor():a),l=/\r\n|\r|\n/g,u=``,d=1;if((r.valign===`middle`||r.valign===`bottom`||r.halign===`center`||r.halign===`right`)&&(u=typeof e==`string`?e.split(l):e,d=u.length||1),n+=s*(2-a),r.valign===`middle`?n-=d/2*c:r.valign===`bottom`&&(n-=d*c),r.halign===`center`||r.halign===`right`){var f=s;if(r.halign===`center`&&(f*=.5),u&&d>=1){for(var p=0;p0,r=t||t===0;return n&&r?`DF`:n?`S`:r?`F`:null}function d(e,t){if(e||=t,Array.isArray(e)){if(e.length>=4)return{top:e[0],right:e[1],bottom:e[2],left:e[3]};if(e.length===3)return{top:e[0],right:e[1],bottom:e[2],left:e[1]};if(e.length===2)return{top:e[0],right:e[1],bottom:e[0],left:e[1]};e=e.length===1?e[0]:t}return typeof e==`object`?(typeof e.vertical==`number`&&(e.top=e.vertical,e.bottom=e.vertical),typeof e.horizontal==`number`&&(e.right=e.horizontal,e.left=e.horizontal),{left:e.left??t,top:e.top??t,right:e.right??t,bottom:e.bottom??t}):(typeof e!=`number`&&(e=t),{top:e,right:e,bottom:e,left:e})}function f(e,t){var n=d(t.settings.margin,0);return e.pageSize().width-(n.left+n.right)}function p(e,t,n,r,i){var a={},o=96/72,s=h(t,function(e){return i.getComputedStyle(e).backgroundColor});s!=null&&(a.fillColor=s);var c=h(t,function(e){return i.getComputedStyle(e).color});c!=null&&(a.textColor=c);var l=_(r,n);l&&(a.cellPadding=l);var u=`borderTopColor`,d=o*n,f=r.borderTopWidth;if(r.borderBottomWidth===f&&r.borderRightWidth===f&&r.borderLeftWidth===f){var p=(parseFloat(f)||0)/d;p&&(a.lineWidth=p)}else a.lineWidth={top:(parseFloat(r.borderTopWidth)||0)/d,right:(parseFloat(r.borderRightWidth)||0)/d,bottom:(parseFloat(r.borderBottomWidth)||0)/d,left:(parseFloat(r.borderLeftWidth)||0)/d},a.lineWidth.top||(a.lineWidth.right?u=`borderRightColor`:a.lineWidth.bottom?u=`borderBottomColor`:a.lineWidth.left&&(u=`borderLeftColor`));var g=h(t,function(e){return i.getComputedStyle(e)[u]});g!=null&&(a.lineColor=g);var v=[`left`,`right`,`center`,`justify`];v.indexOf(r.textAlign)!==-1&&(a.halign=r.textAlign),v=[`middle`,`bottom`,`top`],v.indexOf(r.verticalAlign)!==-1&&(a.valign=r.verticalAlign);var y=parseInt(r.fontSize||``);isNaN(y)||(a.fontSize=y/o);var b=m(r);b&&(a.fontStyle=b);var x=(r.fontFamily||``).toLowerCase();return e.indexOf(x)!==-1&&(a.font=x),a}function m(e){var t=``;return(e.fontWeight===`bold`||e.fontWeight===`bolder`||parseInt(e.fontWeight)>=700)&&(t=`bold`),(e.fontStyle===`italic`||e.fontStyle===`oblique`)&&(t+=`italic`),t}function h(e,t){var n=g(e,t);if(!n)return null;var r=n.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/);if(!r||!Array.isArray(r))return null;var i=[parseInt(r[1]),parseInt(r[2]),parseInt(r[3])];return parseInt(r[4])===0||isNaN(i[0])||isNaN(i[1])||isNaN(i[2])?null:i}function g(e,t){var n=t(e);return n===`rgba(0, 0, 0, 0)`||n===`transparent`||n===`initial`||n===`inherit`?e.parentElement==null?null:g(e.parentElement,t):n}function _(e,t){var n=[e.paddingTop,e.paddingRight,e.paddingBottom,e.paddingLeft],r=96/(72/t),i=(parseInt(e.lineHeight)-parseInt(e.fontSize))/t/2,a=d(n.map(function(e){return parseInt(e||`0`)/r}),0);return i>a.top&&(a.top=i),i>a.bottom&&(a.bottom=i),a}function v(e,t,n,r,i){r===void 0&&(r=!1),i===void 0&&(i=!1);var a=typeof t==`string`?n.document.querySelector(t):t,o=Object.keys(e.getFontList()),s=e.scaleFactor(),c=[],l=[],u=[];if(!a)return console.error(`Html table could not be found with input: `,t),{head:c,body:l,foot:u};for(var d=0;d0&&(i||f.display!==`none`))return s}function b(e){var t=e.cloneNode(!0);return t.innerHTML=t.innerHTML.replace(/\n/g,``).replace(/ +/g,` `),t.innerHTML=t.innerHTML.split(//).map(function(e){return e.trim()}).join(` `),t.innerText||t.textContent||``}function x(e,t,n){for(var r=0,i=[e,t,n];r0?`_${a}`:``);var s={dataKey:o};i.push(s)}}),i}var E=function(){function e(e,t,n){this.table=t,this.pageNumber=t.pageNumber,this.settings=t.settings,this.cursor=n,this.doc=e.getDocument()}return e}(),D=function(e){i(t,e);function t(t,n,r,i,a,o){var s=e.call(this,t,n,o)||this;return s.cell=r,s.row=i,s.column=a,s.section=i.section,s}return t}(E),ie=function(){function e(e,t){this.pageNumber=1,this.id=e.id,this.settings=e.settings,this.styles=e.styles,this.hooks=e.hooks,this.columns=t.columns,this.head=t.head,this.body=t.body,this.foot=t.foot}return e.prototype.getHeadHeight=function(e){return this.head.reduce(function(t,n){return t+n.getMaxCellHeight(e)},0)},e.prototype.getFootHeight=function(e){return this.foot.reduce(function(t,n){return t+n.getMaxCellHeight(e)},0)},e.prototype.allRows=function(){return this.head.concat(this.body).concat(this.foot)},e.prototype.callCellHooks=function(e,t,n,r,i,a){for(var o=0,s=t;o1:!1}).length>0},e.prototype.canEntireRowFit=function(e,t){return this.getMaxCellHeight(t)<=e},e.prototype.getMinimumRowHeight=function(e,t){var n=this;return e.reduce(function(e,r){var i=n.cells[r.index];if(!i)return 0;var a=t.getLineHeight(i.styles.fontSize),o=i.padding(`vertical`)+a;return o>e?o:e},0)},e}(),k=function(){function e(e,t,n){this.contentHeight=0,this.contentWidth=0,this.wrappedWidth=0,this.minReadableWidth=0,this.minWidth=0,this.width=0,this.height=0,this.x=0,this.y=0,this.styles=t,this.section=n,this.raw=e;var r=e;typeof e==`object`&&e&&!Array.isArray(e)?(this.rowSpan=e.rowSpan||1,this.colSpan=e.colSpan||1,r=e.content??e,e._element&&(this.raw=e._element)):(this.rowSpan=1,this.colSpan=1);var i=r==null?``:``+r,a=/\r\n|\r|\n/g;this.text=i.split(a)}return e.prototype.getTextPos=function(){var e;if(this.styles.valign===`top`)e=this.y+this.padding(`top`);else if(this.styles.valign===`bottom`)e=this.y+this.height-this.padding(`bottom`);else{var t=this.height-this.padding(`vertical`);e=this.y+t/2+this.padding(`top`)}var n;if(this.styles.halign===`right`)n=this.x+this.width-this.padding(`right`);else if(this.styles.halign===`center`){var r=this.width-this.padding(`horizontal`);n=this.x+r/2+this.padding(`left`)}else n=this.x+this.padding(`left`);return{x:n,y:e}},e.prototype.getContentHeight=function(e,t){t===void 0&&(t=1.15);var n=(Array.isArray(this.text)?this.text.length:1)*(this.styles.fontSize/e*t)+this.padding(`vertical`);return Math.max(n,this.styles.minCellHeight)},e.prototype.padding=function(e){var t=d(this.styles.cellPadding,0);return e===`vertical`?t.top+t.bottom:e===`horizontal`?t.left+t.right:t[e]},e}(),ae=function(){function e(e,t,n){this.wrappedWidth=0,this.minReadableWidth=0,this.minWidth=0,this.width=0,this.dataKey=e,this.raw=t,this.index=n}return e.prototype.getMaxCustomCellWidth=function(e){for(var t=0,n=0,r=e.allRows();n.1/e.scaleFactor()&&(i=i<1?i:Math.round(i),console.log(`Of the table content, ${i} units width could not fit page`)),se(t),ce(t,e),oe(t)}function j(e,t){var n=e.scaleFactor(),r=t.settings.horizontalPageBreak,i=f(e,t);t.allRows().forEach(function(a){for(var o=0,s=t.columns;oi?(u.minWidth=i,u.wrappedWidth=i):(u.minWidth=u.contentWidth,u.wrappedWidth=u.contentWidth);else{var p=10/n;u.minWidth=u.styles.minCellWidth||p,u.wrappedWidth=u.contentWidth,u.minWidth>u.wrappedWidth&&(u.wrappedWidth=u.minWidth)}}}}),t.allRows().forEach(function(e){for(var n=0,r=t.columns;n1&&!i.minWidth&&(i.minWidth=a.minWidth),a.colSpan>1&&!i.wrappedWidth&&(i.wrappedWidth=a.minWidth))}})}function M(e,t,n){for(var r=t,i=e.reduce(function(e,t){return e+t.wrappedWidth},0),a=0;an(e):!0});d.length&&(t=M(d,t,n))}return t}function oe(e){for(var t={},n=1,r=e.allRows(),i=0;i1)n--,delete a.cells[c.index];else if(l)l.cell.height+=a.height,n=l.cell.colSpan,delete a.cells[c.index],l.left--,l.left<=1&&delete t[c.index];else{var u=a.cells[c.index];if(!u)continue;if(u.height=a.height,u.rowSpan>1){var d=r.length-i,f=u.rowSpan>d?d:u.rowSpan;t[c.index]={cell:u,left:f,row:a}}}}}function se(e){for(var t=e.allRows(),n=0;n1&&e.columns[s+1])a+=c.width,delete r.cells[c.index];else if(i){var l=i;delete r.cells[c.index],i=null,l.width=c.width+a}else{var l=r.cells[c.index];if(!l)continue;if(o=l.colSpan,a=0,l.colSpan>1){i=l,a+=c.width;continue}l.width=c.width+a}}}function ce(e,t){for(var n={count:0,height:0},r=0,i=e.allRows();r1&&n.count*n.height0&&n.height>f&&(f=n.height),f>a.height&&(a.height=f)}}n.count--}}function N(e,t,n,r,i){return e.map(function(e){return le(e,t,n,r,i)})}function le(e,t,n,r,i){var a=1e4*r.scaleFactor();if(t=Math.ceil(t*a)/a,t>=c(e,n,r))return e;for(;t0?n:null}function L(e,t){if(e===`head`){if(typeof t==`object`)return t.header||null;if(typeof t==`string`||typeof t==`number`)return t}else if(e===`foot`&&typeof t==`object`)return t.footer;return null}function R(e){return e.map(function(e,t){return new ae(typeof e==`object`?e.dataKey??t:t,e,t)})}function z(e,t,n,r,i,a,c){var l=s(r),u;e===`head`?u=i.headStyles:e===`body`?u=i.bodyStyles:e===`foot`&&(u=i.footStyles);var d=S({},l.table,l[e],i.styles,u),f=i.columnStyles[t.dataKey]||i.columnStyles[t.index]||{},p=e===`body`?f:{},m=e===`body`&&n%2==0?S({},l.alternateRow,i.alternateRowStyles):{};return S(S({},o(a),d,m,p),c)}function B(e,t,n){n===void 0&&(n={});var r=f(e,t),i=new Map,a=[],o=[],s=[];Array.isArray(t.settings.horizontalPageBreakRepeat)?s=t.settings.horizontalPageBreakRepeat:(typeof t.settings.horizontalPageBreakRepeat==`string`||typeof t.settings.horizontalPageBreakRepeat==`number`)&&(s=[t.settings.horizontalPageBreakRepeat]),s.forEach(function(e){var n=t.columns.find(function(t){return t.dataKey===e||t.index===e});n&&!i.has(n.index)&&(i.set(n.index,!0),a.push(n.index),o.push(t.columns[n.index]),r-=n.wrappedWidth)});for(var c=!0,l=n?.start??0;l=u)c=!1,a.push(l),o.push(t.columns[l]),r-=u;else break;l++}return{colIndexes:a,columns:o,lastIndex:l-1}}function V(e,t){for(var n=[],r=0;rd.pageSize().height)&&(X(d),o.y=a.top),t.callWillDrawPageHooks(d,o);var f=S({},o);t.startPageNumber=d.pageNumber(),r.horizontalPageBreak?de(d,t,f,o):(d.applyStyles(d.userStyles),(r.showHead===`firstPage`||r.showHead===`everyPage`)&&t.head.forEach(function(e){return q(d,t,e,o,t.columns)}),d.applyStyles(d.userStyles),t.body.forEach(function(e,n){K(d,t,e,n===t.body.length-1,f,o,t.columns)}),d.applyStyles(d.userStyles),(r.showFoot===`lastPage`||r.showFoot===`everyPage`)&&t.foot.forEach(function(e){return q(d,t,e,o,t.columns)})),l(d,t,f,o),t.callEndPageHooks(d,o),t.finalY=o.y,e.lastAutoTable=t,d.applyStyles(d.userStyles)}function de(e,t,n,r){var i=V(e,t);if(t.settings.horizontalPageBreakBehaviour===`afterAllRows`)i.forEach(function(i,a){e.applyStyles(e.userStyles),a>0?Y(e,t,n,r,i.columns,!0):U(e,t,r,i.columns),fe(e,t,n,r,i.columns),G(e,t,r,i.columns)});else for(var a=-1,o=i[0],s=function(){var s=a;if(o){e.applyStyles(e.userStyles);var c=o.columns;a>=0?Y(e,t,n,r,c,!0):U(e,t,r,c),s=W(e,t,a+1,r,c),G(e,t,r,c)}var l=s-a;i.slice(1).forEach(function(i){e.applyStyles(e.userStyles),Y(e,t,n,r,i.columns,!0),W(e,t,a+1,r,i.columns,l),G(e,t,r,i.columns)}),a=s};ad&&(u.text=l.text.splice(d,l.text.length));var f=r.scaleFactor(),p=r.getLineHeightFactor();l.contentHeight=l.getContentHeight(f,p),l.contentHeight>=t&&(l.contentHeight=t,u.styles.minCellHeight-=t),l.contentHeight>e.height&&(e.height=l.contentHeight),u.contentHeight=u.getContentHeight(f,p),u.contentHeight>a&&(a=u.contentHeight),i[c.index]=u}}var m=new O(e.raw,-1,e.section,i,!0);m.height=a;for(var h=0,g=n.columns;ho)return console.log(`Will not be able to print row ${t.index} correctly since it's minimum height is larger than page height`),!0;if(!c)return!1;var l=t.hasRowSpan(r.columns);return t.getMaxCellHeight(r.columns)>o?(l&&console.log(`The content of row ${t.index} will not be drawn correctly since drawing rows with a height larger than the page height and has cells with rowspans is not supported.`),!0):!(l||r.settings.rowPageBreak===`avoid`)}function K(e,t,n,r,i,a,o){var s=J(e,t,r,a);if(n.canEntireRowFit(s,o))q(e,t,n,a,o);else if(he(e,n,s,t)){var c=me(n,s,t,e);q(e,t,n,a,o),Y(e,t,i,a,o),K(e,t,c,r,i,a,o)}else Y(e,t,i,a,o),K(e,t,n,r,i,a,o)}function q(t,n,r,i,a){i.x=n.settings.margin.left;for(var o=0,s=a;o`u`)return console.error(`Cannot run autoTableHtmlToJson in non browser environment`),null;var r=v(new n(this),e,window,t,!1),i=r.head,a=r.body;return{columns:i[0]?.map(function(e){return e.content})||[],rows:a,data:a}}}function Z(e,t){H(e,P(e,C(e,t)))}try{if(typeof window<`u`&&window){var Q=window,$=Q.jsPDF||Q.jspdf?.jsPDF;$&&ve($)}}catch(e){console.error(`Could not apply autoTable plugin`,e)}export{Z as autoTable,Z as default};