function q(e,t,r,i,n){i=i||{};var a=1.15,s=n.internal.scaleFactor,h=n.internal.getFontSize()/s,f=n.getLineHeightFactor?n.getLineHeightFactor():a,o=h*f,l=/\r\n|\r|\n/g,g="",u=1;if((i.valign==="middle"||i.valign==="bottom"||i.halign==="center"||i.halign==="right")&&(g=typeof e=="string"?e.split(l):e,u=g.length||1),r+=h*(2-a),i.valign==="middle"?r-=u/2*o:i.valign==="bottom"&&(r-=u*o),i.halign==="center"||i.halign==="right"){var v=h;if(i.halign==="center"&&(v*=.5),g&&u>=1){for(var d=0;d0,i=t||t===0;return r&&i?"DF":r?"S":i?"F":null}function F(e,t){var r,i,n,a;if(e=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.length===1?e=e[0]:e=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:(r=e.left)!==null&&r!==void 0?r:t,top:(i=e.top)!==null&&i!==void 0?i:t,right:(n=e.right)!==null&&n!==void 0?n:t,bottom:(a=e.bottom)!==null&&a!==void 0?a:t}):(typeof e!="number"&&(e=t),{top:e,right:e,bottom:e,left:e})}function Q(e,t){var r=F(t.settings.margin,0);return e.pageSize().width-(r.left+r.right)}function ot(e,t,r,i,n){var a={},s=1.3333333333333333,h=b(t,function(c){return n.getComputedStyle(c).backgroundColor});h!=null&&(a.fillColor=h);var f=b(t,function(c){return n.getComputedStyle(c).color});f!=null&&(a.textColor=f);var o=ht(i,r);o&&(a.cellPadding=o);var l="borderTopColor",g=s*r,u=i.borderTopWidth;if(i.borderBottomWidth===u&&i.borderRightWidth===u&&i.borderLeftWidth===u){var v=(parseFloat(u)||0)/g;v&&(a.lineWidth=v)}else a.lineWidth={top:(parseFloat(i.borderTopWidth)||0)/g,right:(parseFloat(i.borderRightWidth)||0)/g,bottom:(parseFloat(i.borderBottomWidth)||0)/g,left:(parseFloat(i.borderLeftWidth)||0)/g},a.lineWidth.top||(a.lineWidth.right?l="borderRightColor":a.lineWidth.bottom?l="borderBottomColor":a.lineWidth.left&&(l="borderLeftColor"));var d=b(t,function(c){return n.getComputedStyle(c)[l]});d!=null&&(a.lineColor=d);var m=["left","right","center","justify"];m.indexOf(i.textAlign)!==-1&&(a.halign=i.textAlign),m=["middle","bottom","top"],m.indexOf(i.verticalAlign)!==-1&&(a.valign=i.verticalAlign);var p=parseInt(i.fontSize||"");isNaN(p)||(a.fontSize=p/s);var y=st(i);y&&(a.fontStyle=y);var x=(i.fontFamily||"").toLowerCase();return e.indexOf(x)!==-1&&(a.font=x),a}function st(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 b(e,t){var r=X(e,t);if(!r)return null;var i=r.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d*))?\)$/);if(!i||!Array.isArray(i))return null;var n=[parseInt(i[1]),parseInt(i[2]),parseInt(i[3])],a=parseInt(i[4]);return a===0||isNaN(n[0])||isNaN(n[1])||isNaN(n[2])?null:n}function X(e,t){var r=t(e);return r==="rgba(0, 0, 0, 0)"||r==="transparent"||r==="initial"||r==="inherit"?e.parentElement==null?null:X(e.parentElement,t):r}function ht(e,t){var r=[e.paddingTop,e.paddingRight,e.paddingBottom,e.paddingLeft],i=96/(72/t),n=(parseInt(e.lineHeight)-parseInt(e.fontSize))/t/2,a=r.map(function(h){return parseInt(h||"0")/i}),s=F(a,0);return n>s.top&&(s.top=n),n>s.bottom&&(s.bottom=n),s}function Z(e,t,r,i,n){var a,s;i===void 0&&(i=!1),n===void 0&&(n=!1);var h;typeof t=="string"?h=r.document.querySelector(t):h=t;var f=Object.keys(e.getFontList()),o=e.scaleFactor(),l=[],g=[],u=[];if(!h)return console.error("Html table could not be found with input: ",t),{head:l,body:g,foot:u};for(var v=0;v0&&(n||g.display!=="none"))return s}function lt(e){var t=e.cloneNode(!0);return t.innerHTML=t.innerHTML.replace(/\n/g,"").replace(/ +/g," "),t.innerHTML=t.innerHTML.split(//).map(function(r){return r.trim()}).join(` `),t.innerText||t.textContent||""}function gt(e,t,r){for(var i=0,n=[e,t,r];i0?"_".concat(f):"");var l={dataKey:o};n.push(l)}}),n}var A=function(){function e(t,r,i){this.table=r,this.pageNumber=r.pageNumber,this.settings=r.settings,this.cursor=i,this.doc=t.getDocument()}return e}(),ct=function(e){G(t,e);function t(r,i,n,a,s,h){var f=e.call(this,r,i,h)||this;return f.cell=n,f.row=a,f.column=s,f.section=a.section,f}return t}(A),wt=function(){function e(t,r){this.pageNumber=1,this.id=t.id,this.settings=t.settings,this.styles=t.styles,this.hooks=t.hooks,this.columns=r.columns,this.head=r.head,this.body=r.body,this.foot=r.foot}return e.prototype.getHeadHeight=function(t){return this.head.reduce(function(r,i){return r+i.getMaxCellHeight(t)},0)},e.prototype.getFootHeight=function(t){return this.foot.reduce(function(r,i){return r+i.getMaxCellHeight(t)},0)},e.prototype.allRows=function(){return this.head.concat(this.body).concat(this.foot)},e.prototype.callCellHooks=function(t,r,i,n,a,s){for(var h=0,f=r;h1:!1}).length>0},e.prototype.canEntireRowFit=function(t,r){return this.getMaxCellHeight(r)<=t},e.prototype.getMinimumRowHeight=function(t,r){var i=this;return t.reduce(function(n,a){var s=i.cells[a.index];if(!s)return 0;var h=r.getLineHeight(s.styles.fontSize),f=s.padding("vertical"),o=f+h;return o>n?o:n},0)},e}(),tt=function(){function e(t,r,i){var 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=r,this.section=i,this.raw=t;var a=t;t!=null&&typeof t=="object"&&!Array.isArray(t)?(this.rowSpan=t.rowSpan||1,this.colSpan=t.colSpan||1,a=(n=t.content)!==null&&n!==void 0?n:t,t._element&&(this.raw=t._element)):(this.rowSpan=1,this.colSpan=1);var s=a!=null?""+a:"",h=/\r\n|\r|\n/g;this.text=s.split(h)}return e.prototype.getTextPos=function(){var t;if(this.styles.valign==="top")t=this.y+this.padding("top");else if(this.styles.valign==="bottom")t=this.y+this.height-this.padding("bottom");else{var r=this.height-this.padding("vertical");t=this.y+r/2+this.padding("top")}var i;if(this.styles.halign==="right")i=this.x+this.width-this.padding("right");else if(this.styles.halign==="center"){var n=this.width-this.padding("horizontal");i=this.x+n/2+this.padding("left")}else i=this.x+this.padding("left");return{x:i,y:t}},e.prototype.getContentHeight=function(t,r){r===void 0&&(r=1.15);var i=Array.isArray(this.text)?this.text.length:1,n=this.styles.fontSize/t*r,a=i*n+this.padding("vertical");return Math.max(a,this.styles.minCellHeight)},e.prototype.padding=function(t){var r=F(this.styles.cellPadding,0);return t==="vertical"?r.top+r.bottom:t==="horizontal"?r.left+r.right:r[t]},e}(),St=function(){function e(t,r,i){this.wrappedWidth=0,this.minReadableWidth=0,this.minWidth=0,this.width=0,this.dataKey=t,this.raw=r,this.index=i}return e.prototype.getMaxCustomCellWidth=function(t){for(var r=0,i=0,n=t.allRows();i.1/e.scaleFactor()&&(n=n<1?n:Math.round(n),console.log("Of the table content, ".concat(n," units width could not fit page"))),Ht(t),Dt(t,e),Pt(t)}function Ct(e,t){var r=e.scaleFactor(),i=t.settings.horizontalPageBreak,n=Q(e,t);t.allRows().forEach(function(a){for(var s=0,h=t.columns;sn?(o.minWidth=n,o.wrappedWidth=n):(o.minWidth=o.contentWidth,o.wrappedWidth=o.contentWidth);else{var v=10/r;o.minWidth=o.styles.minCellWidth||v,o.wrappedWidth=o.contentWidth,o.minWidth>o.wrappedWidth&&(o.wrappedWidth=o.minWidth)}}}}),t.allRows().forEach(function(a){for(var s=0,h=t.columns;s1&&!f.minWidth&&(f.minWidth=o.minWidth),o.colSpan>1&&!f.wrappedWidth&&(f.wrappedWidth=o.minWidth))}})}function j(e,t,r){for(var i=t,n=e.reduce(function(v,d){return v+d.wrappedWidth},0),a=0;ar(v):!0});u.length&&(t=j(u,t,r))}return t}function Pt(e){for(var t={},r=1,i=e.allRows(),n=0;n1)r--,delete a.cells[f.index];else if(o)o.cell.height+=a.height,r=o.cell.colSpan,delete a.cells[f.index],o.left--,o.left<=1&&delete t[f.index];else{var l=a.cells[f.index];if(!l)continue;if(l.height=a.height,l.rowSpan>1){var g=i.length-n,u=l.rowSpan>g?g:l.rowSpan;t[f.index]={cell:l,left:u,row:a}}}}}function Ht(e){for(var t=e.allRows(),r=0;r1&&e.columns[h+1])a+=f.width,delete i.cells[f.index];else if(n){var o=n;delete i.cells[f.index],n=null,o.width=f.width+a}else{var o=i.cells[f.index];if(!o)continue;if(s=o.colSpan,a=0,o.colSpan>1){n=o,a+=f.width;continue}o.width=f.width+a}}}function Dt(e,t){for(var r={count:0,height:0},i=0,n=e.allRows();i1&&r.count*r.height0&&r.height>u&&(u=r.height),u>a.height&&(a.height=u)}}r.count--}}function N(e,t,r,i,n){return e.map(function(a){return Wt(a,t,r,i,n)})}function Wt(e,t,r,i,n){var a=1e4*i.scaleFactor();if(t=Math.ceil(t*a)/a,t>=D(e,r,i))return e;for(;t0?r:null}function bt(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 kt(e){return e.map(function(t,r){var i,n;return typeof t=="object"?n=(i=t.dataKey)!==null&&i!==void 0?i:r:n=r,new St(n,t,r)})}function Tt(e,t,r,i,n,a,s){var h=at(i),f;e==="head"?f=n.headStyles:e==="body"?f=n.bodyStyles:e==="foot"&&(f=n.footStyles);var o=w({},h.table,h[e],n.styles,f),l=n.columnStyles[t.dataKey]||n.columnStyles[t.index]||{},g=e==="body"?l:{},u=e==="body"&&r%2===0?w({},h.alternateRow,n.alternateRowStyles):{},v=nt(a),d=w({},v,o,u,g);return w(d,s)}function Rt(e,t,r){var i;r===void 0&&(r={});var n=Q(e,t),a=new Map,s=[],h=[],f=[];Array.isArray(t.settings.horizontalPageBreakRepeat)?f=t.settings.horizontalPageBreakRepeat:(typeof t.settings.horizontalPageBreakRepeat=="string"||typeof t.settings.horizontalPageBreakRepeat=="number")&&(f=[t.settings.horizontalPageBreakRepeat]),f.forEach(function(u){var v=t.columns.find(function(d){return d.dataKey===u||d.index===u});v&&!a.has(v.index)&&(a.set(v.index,!0),s.push(v.index),h.push(t.columns[v.index]),n-=v.wrappedWidth)});for(var o=!0,l=(i=r==null?void 0:r.start)!==null&&i!==void 0?i:0;l=g)o=!1,s.push(l),h.push(t.columns[l]),n-=g;else break;l++}return{colIndexes:s,columns:h,lastIndex:l-1}}function zt(e,t){for(var r=[],i=0;il.pageSize().height)&&(it(l),a.y=n.top),t.callWillDrawPageHooks(l,a);var g=w({},a);t.startPageNumber=l.pageNumber(),r.horizontalPageBreak?At(l,t,g,a):(l.applyStyles(l.userStyles),(r.showHead==="firstPage"||r.showHead==="everyPage")&&t.head.forEach(function(u){return S(l,t,u,a,t.columns)}),l.applyStyles(l.userStyles),t.body.forEach(function(u,v){var d=v===t.body.length-1;W(l,t,u,d,g,a,t.columns)}),l.applyStyles(l.userStyles),(r.showFoot==="lastPage"||r.showFoot==="everyPage")&&t.foot.forEach(function(u){return S(l,t,u,a,t.columns)})),U(l,t,g,a),t.callEndPageHooks(l,a),t.finalY=a.y,e.lastAutoTable=t,l.applyStyles(l.userStyles)}function At(e,t,r,i){var n=zt(e,t),a=t.settings;if(a.horizontalPageBreakBehaviour==="afterAllRows")n.forEach(function(o,l){e.applyStyles(e.userStyles),l>0?H(e,t,r,i,o.columns,!0):Y(e,t,i,o.columns),jt(e,t,r,i,o.columns),T(e,t,i,o.columns)});else for(var s=-1,h=n[0],f=function(){var o=s;if(h){e.applyStyles(e.userStyles);var l=h.columns;s>=0?H(e,t,r,i,l,!0):Y(e,t,i,l),o=I(e,t,s+1,i,l),T(e,t,i,l)}var g=o-s;n.slice(1).forEach(function(u){e.applyStyles(e.userStyles),H(e,t,r,i,u.columns,!0),I(e,t,s+1,i,u.columns,g),T(e,t,i,u.columns)}),s=o};sg&&(l.text=o.text.splice(g,o.text.length));var u=i.scaleFactor(),v=i.getLineHeightFactor();o.contentHeight=o.getContentHeight(u,v),o.contentHeight>=t&&(o.contentHeight=t,l.styles.minCellHeight-=t),o.contentHeight>e.height&&(e.height=o.contentHeight),l.contentHeight=l.getContentHeight(u,v),l.contentHeight>a&&(a=l.contentHeight),n[f.index]=l}}var d=new V(e.raw,-1,e.section,n,!0);d.height=a;for(var m=0,p=r.columns;mh)return console.log("Will not be able to print row ".concat(t.index," correctly since it's minimum height is larger than page height")),!0;if(!o)return!1;var l=t.hasRowSpan(i.columns),g=t.getMaxCellHeight(i.columns)>h;return g?(l&&console.log("The content of row ".concat(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||i.settings.rowPageBreak==="avoid")}function W(e,t,r,i,n,a,s){var h=et(e,t,i,a);if(r.canEntireRowFit(h,s))S(e,t,r,a,s);else if(Et(e,r,h,t)){var f=Lt(r,h,t,e);S(e,t,r,a,s),H(e,t,n,a,s),W(e,t,f,i,n,a,s)}else H(e,t,n,a,s),W(e,t,r,i,n,a,s)}function S(e,t,r,i,n){i.x=t.settings.margin.left;for(var a=0,s=n;a"u")return console.error("Cannot run autoTableHtmlToJson in non browser environment"),null;var n=new P(this),a=Z(n,t,window,r,!1),s=a.head,h=a.body,f=((i=s[0])===null||i===void 0?void 0:i.map(function(o){return o.content}))||[];return{columns:f,rows:h,data:h}}}var R;function Yt(e,t){var r=B(e,t),i=L(e,r);E(e,i)}function It(e,t){var r=B(e,t);return L(e,r)}function Kt(e,t){E(e,t)}try{if(typeof window<"u"&&window){var K=window,_=K.jsPDF||((R=K.jspdf)===null||R===void 0?void 0:R.jsPDF);_&&Ot(_)}}catch(e){console.error("Could not apply autoTable plugin",e)}export{tt as Cell,ct as CellHookData,St as Column,A as HookData,V as Row,wt as Table,It as __createTable,Kt as __drawTable,Ot as applyPlugin,Yt as autoTable,Yt as default};