diff --git a/dist/index.js b/dist/index.js index dab1f62..109b1a1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8,7 +8,7 @@ if (! jSuites && typeof(require) === 'function') { global.jspreadsheet = factory(); }(this, (function () { -var jspreadsheet;(function(){var __webpack_modules__={463:function(e){var t;e.exports=(function(){var e={765:function(e,t){var o;o=function(e){e.version="1.0.2";var t=Math;function o(e,t){for(var o=0,n=0;or)l=n(o,r,a(o),p(o),-1);else{for(var i=!1,s=0,u=0,c=1,f=0,d=2/o,b=2*t.floor((r+t.floor(t.sqrt(40*r)))/2);b>0;b--)f=b*d*c-s,s=c,c=f,t.abs(c)>1e10&&(c*=1e-10,s*=1e-10,l*=1e-10,u*=1e-10),i&&(u+=c),i=!i,b==r&&(l=s);l/=u=2*u-c}return l}}(),v=(l=.636619772,i=[-2957821389,7062834065,-512359803.6,10879881.29,-86327.92757,228.4622733].reverse(),s=[40076544269,745249964.8,7189466.438,47447.2647,226.1030244,1].reverse(),a=[1,-.001098628627,2734510407e-14,-2073370639e-15,2.093887211e-7].reverse(),u=[-.01562499995,.0001430488765,-6911147651e-15,7.621095161e-7,-9.34945152e-8].reverse(),c=[-4900604943e3,127527439e4,-51534381390,734926455.1,-4237922.726,8511.937935].reverse(),f=[249958057e5,424441966400,3733650367,22459040.02,102042.605,354.9632885,1].reverse(),d=[1,.00183105,-3516396496e-14,2457520174e-15,-2.40337019e-7].reverse(),p=[.04687499995,-.0002002690873,8449199096e-15,-8.8228987e-7,1.05787412e-7].reverse(),r((function(e){var n=0,r=0,c=0,f=e*e,d=e-.785398164;return e<8?n=(r=o(i,f))/(c=o(s,f))+l*m(e,0)*t.log(e):(r=o(a,f=64/f),c=o(u,f),n=t.sqrt(l/e)*(t.sin(d)*r+t.cos(d)*c*8/e)),n}),(function(e){var n=0,r=0,i=0,s=e*e,a=e-2.356194491;return e<8?n=(r=e*o(c,s))/(i=o(f,s))+l*(m(e,1)*t.log(e)-1/e):(r=o(d,s=64/s),i=o(p,s),n=t.sqrt(l/e)*(t.sin(a)*r+t.cos(a)*i*8/e)),n}),0,1,-1)),y=(b=[1,3.5156229,3.0899424,1.2067492,.2659732,.0360768,.0045813].reverse(),j=[.39894228,.01328592,.00225319,-.00157565,.00916281,-.02057706,.02635537,-.01647633,.00392377].reverse(),h=[.5,.87890594,.51498869,.15084934,.02658733,.00301532,32411e-8].reverse(),g=[.39894228,-.03988024,-.00362018,.00163801,-.01031555,.02282967,-.02895312,.01787654,-.00420059].reverse(),function e(n,r){if(0===(r=Math.round(r)))return function(e){return e<=3.75?o(b,e*e/14.0625):t.exp(t.abs(e))/t.sqrt(t.abs(e))*o(j,3.75/t.abs(e))}(n);if(1===r)return function(e){return e<3.75?e*o(h,e*e/14.0625):(e<0?-1:1)*t.exp(t.abs(e))/t.sqrt(t.abs(e))*o(g,3.75/t.abs(e))}(n);if(r<0)return NaN;if(0===t.abs(n))return 0;if(n==1/0)return 1/0;var l,i=0,s=2/t.abs(n),a=0,u=1,c=0;for(l=2*t.round((r+t.round(t.sqrt(40*r)))/2);l>0;l--)c=l*s*u+a,a=u,u=c,t.abs(u)>1e10&&(u*=1e-10,a*=1e-10,i*=1e-10),l==r&&(i=a);return i*=e(n,0)/u,n<0&&r%2?-i:i}),C=function(){var e=[-.57721566,.4227842,.23069756,.0348859,.00262698,1075e-7,74e-7].reverse(),n=[1.25331414,-.07832358,.02189568,-.01062446,.00587872,-.0025154,53208e-8].reverse(),l=[1,.15443144,-.67278579,-.18156897,-.01919402,-.00110404,-4686e-8].reverse(),i=[1.25331414,.23498619,-.0365562,.01504268,-.00780353,.00325614,-68245e-8].reverse();return r((function(r){return r<=2?-t.log(r/2)*y(r,0)+o(e,r*r/4):t.exp(-r)/t.sqrt(r)*o(n,2/r)}),(function(e){return e<=2?t.log(e/2)*y(e,1)+1/e*o(l,e*e/4):t.exp(-e)/t.sqrt(e)*o(i,2/e)}),0,2,1)}();e.besselj=m,e.bessely=v,e.besseli=y,e.besselk=C},"undefined"==typeof DO_NOT_EXPORT_BESSEL?o(t):o({})},162:function(e){var t;e.exports=(t=function(e,t){var o=Array.prototype.concat,n=Array.prototype.slice,r=Object.prototype.toString;function l(t,o){var n=t>o?t:o;return e.pow(10,17-~~(e.log(n>0?n:-n)*e.LOG10E))}var i=Array.isArray||function(e){return"[object Array]"===r.call(e)};function s(e){return"[object Function]"===r.call(e)}function a(e){return"number"==typeof e&&e-e==0}function u(){return new u._init(arguments)}function c(){return 0}function f(){return 1}function d(e,t){return e===t?1:0}u.fn=u.prototype,u._init=function(e){if(i(e[0]))if(i(e[0][0])){s(e[1])&&(e[0]=u.map(e[0],e[1]));for(var t=0;t=0;t--,n++)o[n]=[e[n][t]];return o},u.transpose=function(e){var t,o,n,r,l,s=[];for(i(e[0])||(e=[e]),o=e.length,n=e[0].length,l=0;l0&&(s[n][0]=e[n][0]),a=1;ao&&n>0)return[];if(n>0)for(r=e;ro;r+=n)l.push(r);return l},u.slice=function(){function e(e,o,n,r){var l,i=[],s=e.length;if(o===t&&n===t&&r===t)return u.copy(e);if(r=r||1,(o=(o=o||0)>=0?o:s+o)===(n=(n=n||e.length)>=0?n:s+n)||0===r)return[];if(on&&r>0)return[];if(r>0)for(l=o;ln;l+=r)i.push(e[l]);return i}return function(t,o){var n,r;return a((o=o||{}).row)?a(o.col)?t[o.row][o.col]:e(u.rowa(t,o.row),(n=o.col||{}).start,n.end,n.step):a(o.col)?e(u.cola(t,o.col),(r=o.row||{}).start,r.end,r.step):(r=o.row||{},n=o.col||{},e(t,r.start,r.end,r.step).map((function(t){return e(t,n.start,n.end,n.step)})))}}(),u.sliceAssign=function(o,n,r){var l,i;if(a(n.row)){if(a(n.col))return o[n.row][n.col]=r;n.col=n.col||{},n.col.start=n.col.start||0,n.col.end=n.col.end||o[0].length,n.col.step=n.col.step||1,l=u.arange(n.col.start,e.min(o.length,n.col.end),n.col.step);var s=n.row;return l.forEach((function(e,t){o[s][e]=r[t]})),o}if(a(n.col)){n.row=n.row||{},n.row.start=n.row.start||0,n.row.end=n.row.end||o.length,n.row.step=n.row.step||1,i=u.arange(n.row.start,e.min(o[0].length,n.row.end),n.row.step);var c=n.col;return i.forEach((function(e,t){o[e][c]=r[t]})),o}return r[0].length===t&&(r=[r]),n.row.start=n.row.start||0,n.row.end=n.row.end||o.length,n.row.step=n.row.step||1,n.col.start=n.col.start||0,n.col.end=n.col.end||o[0].length,n.col.step=n.col.step||1,i=u.arange(n.row.start,e.min(o.length,n.row.end),n.row.step),l=u.arange(n.col.start,e.min(o[0].length,n.col.end),n.col.step),i.forEach((function(e,t){l.forEach((function(n,l){o[e][n]=r[t][l]}))})),o},u.diagonal=function(e){var t=u.zeros(e.length,e.length);return e.forEach((function(e,o){t[o][o]=e})),t},u.copy=function(e){return e.map((function(e){return a(e)?e:e.map((function(e){return e}))}))};var p=u.prototype;return p.length=0,p.push=Array.prototype.push,p.sort=Array.prototype.sort,p.splice=Array.prototype.splice,p.slice=Array.prototype.slice,p.toArray=function(){return this.length>1?n.call(this):n.call(this)[0]},p.map=function(e,t){return u(u.map(this,e,t))},p.cumreduce=function(e,t){return u(u.cumreduce(this,e,t))},p.alter=function(e){return u.alter(this,e),this},function(e){for(var t=0;t=0;)t+=e[o];return t},e.sumsqrd=function(e){for(var t=0,o=e.length;--o>=0;)t+=e[o]*e[o];return t},e.sumsqerr=function(t){for(var o,n=e.mean(t),r=0,l=t.length;--l>=0;)r+=(o=t[l]-n)*o;return r},e.sumrow=function(e){for(var t=0,o=e.length;--o>=0;)t+=e[o];return t},e.product=function(e){for(var t=1,o=e.length;--o>=0;)t*=e[o];return t},e.min=function(e){for(var t=e[0],o=0;++ot&&(t=e[o]);return t},e.unique=function(e){for(var t={},o=[],n=0;ni?(a=[r[t]],i=l,s=0):l===i&&(a.push(r[t]),s++),l=1);return 0===s?a[0]:a},e.range=function(t){return e.max(t)-e.min(t)},e.variance=function(t,o){return e.sumsqerr(t)/(t.length-(o?1:0))},e.pooledvariance=function(t){return t.reduce((function(t,o){return t+e.sumsqerr(o)}),0)/(t.reduce((function(e,t){return e+t.length}),0)-t.length)},e.deviation=function(t){for(var o=e.mean(t),n=t.length,r=new Array(n),l=0;l=0;l--)r.push(t.abs(o[l]-n));return e.mean(r)},e.meddev=function(o){for(var n=e.median(o),r=[],l=o.length-1;l>=0;l--)r.push(t.abs(o[l]-n));return e.median(r)},e.coeffvar=function(t){return e.stdev(t)/e.mean(t)},e.quartiles=function(e){var o=e.length,r=e.slice().sort(n);return[r[t.round(o/4)-1],r[t.round(o/2)-1],r[t.round(3*o/4)-1]]},e.quantiles=function(e,o,l,i){var s,a,u,c,f,d=e.slice().sort(n),p=[o.length],b=e.length;for(void 0===l&&(l=3/8),void 0===i&&(i=3/8),s=0;s1){for(a=!0===n?this:this.transpose();s1){for("sumrow"!==t&&(a=!0===n?this:this.transpose());s1){for(s=s.transpose();i=0;s--)i*=n,i+=u[s];if(l=i/o+.5*t.log(r)+(o-.5)*t.log(o)-o,e<=7)for(s=1;s<=a;s++)l-=t.log(o-1),o-=1;return l},e.gammafn=function(e){var o,n,r,l,i=[-1.716185138865495,24.76565080557592,-379.80425647094563,629.3311553128184,866.9662027904133,-31451.272968848367,-36144.413418691176,66456.14382024054],s=[-30.8402300119739,315.35062697960416,-1015.1563674902192,-3107.771671572311,22538.11842098015,4755.846277527881,-134659.9598649693,-115132.2596755535],a=!1,u=0,c=0,f=0,d=e;if(e>171.6243769536076)return 1/0;if(d<=0){if(!(l=d%1+36e-17))return 1/0;a=(1&d?-1:1)*t.PI/t.sin(t.PI*l),d=1-d}for(r=d,n=d<1?d++:(d-=u=(0|d)-1)-1,o=0;o<8;++o)f=(f+i[o])*n,c=c*n+s[o];if(l=f/c+1,rd)for(o=0;o=1?o:1/o)+.4*o+17);if(n<0||o<=0)return NaN;if(n170||n>170?t.exp(e.combinationln(o,n)):e.factorial(o)/e.factorial(n)/e.factorial(o-n)},e.combinationln=function(t,o){return e.factorialln(t)-e.factorialln(o)-e.factorialln(t-o)},e.permutation=function(t,o){return e.factorial(t)/e.factorial(t-o)},e.betafn=function(o,n){if(!(o<=0||n<=0))return o+n>170?t.exp(e.betaln(o,n)):e.gammafn(o)*e.gammafn(n)/e.gammafn(o+n)},e.betaln=function(t,o){return e.gammaln(t)+e.gammaln(o)-e.gammaln(t+o)},e.betacf=function(e,o,n){var r,l,i,s,a=1e-30,u=1,c=o+n,f=o+1,d=o-1,p=1,b=1-c*e/f;for(t.abs(b)=1)return t.max(100,n+100*t.sqrt(n));if(o<=0)return 0;for(n>1?(a=t.log(f),u=t.exp(f*(a-1)-d),s=o<.5?o:1-o,r=(2.30753+.27061*(l=t.sqrt(-2*t.log(s))))/(1+l*(.99229+.04481*l))-l,o<.5&&(r=-r),r=t.max(.001,n*t.pow(1-1/(9*n)-r/(3*t.sqrt(n)),3))):r=o<(l=1-n*(.253+.12*n))?t.pow(o/l,1/n):1-t.log(1-(o-l)/(1-l));c<12;c++){if(r<=0)return 0;if((r-=l=(i=(e.lowRegGamma(n,r)-o)/(l=n>1?u*t.exp(-(r-f)+f*(t.log(r)-a)):t.exp(-r+f*t.log(r)-d)))/(1-.5*t.min(1,i*((n-1)/r-1))))<=0&&(r=.5*(r+l)),t.abs(l)<1e-8*r)break}return r},e.erf=function(e){var o,n,r,l,i=[-1.3026537197817094,.6419697923564902,.019476473204185836,-.00956151478680863,-.000946595344482036,.000366839497852761,42523324806907e-18,-20278578112534e-18,-1624290004647e-18,130365583558e-17,1.5626441722e-8,-8.5238095915e-8,6.529054439e-9,5.059343495e-9,-9.91364156e-10,-2.27365122e-10,96467911e-18,2394038e-18,-6886027e-18,894487e-18,313092e-18,-112708e-18,381e-18,7106e-18,-1523e-18,-94e-18,121e-18,-28e-18],s=i.length-1,a=!1,u=0,c=0;for(e<0&&(e=-e,a=!0),n=4*(o=2/(2+e))-2;s>0;s--)r=u,u=n*u-c+i[s],c=r;return l=o*t.exp(-e*e+.5*(i[0]+n*u)-c),a?l-1:1-l},e.erfc=function(t){return 1-e.erf(t)},e.erfcinv=function(o){var n,r,l,i,s=0;if(o>=2)return-100;if(o<=0)return 100;for(i=o<1?o:2-o,n=-.70711*((2.30753+.27061*(l=t.sqrt(-2*t.log(i/2))))/(1+l*(.99229+.04481*l))-l);s<2;s++)n+=(r=e.erfc(n)-i)/(1.1283791670955126*t.exp(-n*n)-n*r);return o<1?n:-n},e.ibetainv=function(o,n,r){var l,i,s,a,u,c,f,d,p,b,j=n-1,h=r-1,g=0;if(o<=0)return 0;if(o>=1)return 1;for(n>=1&&r>=1?(s=o<.5?o:1-o,c=(2.30753+.27061*(a=t.sqrt(-2*t.log(s))))/(1+a*(.99229+.04481*a))-a,o<.5&&(c=-c),f=(c*c-3)/6,d=2/(1/(2*n-1)+1/(2*r-1)),p=c*t.sqrt(f+d)/d-(1/(2*r-1)-1/(2*n-1))*(f+5/6-2/(3*d)),c=n/(n+r*t.exp(2*p))):(l=t.log(n/(n+r)),i=t.log(r/(n+r)),c=o<(a=t.exp(n*l)/n)/(p=a+(u=t.exp(r*i)/r))?t.pow(n*p*o,1/n):1-t.pow(r*p*(1-o),1/r)),b=-e.gammaln(n)-e.gammaln(r)+e.gammaln(n+r);g<10;g++){if(0===c||1===c)return c;if((c-=a=(u=(e.ibeta(c,n,r)-o)/(a=t.exp(j*t.log(c)+h*t.log(1-c)+b)))/(1-.5*t.min(1,u*(j/c-h/(1-c)))))<=0&&(c=.5*(c+a)),c>=1&&(c=.5*(c+a+1)),t.abs(a)<1e-8*c&&g>0)break}return c},e.ibeta=function(o,n,r){var l=0===o||1===o?0:t.exp(e.gammaln(n+r)-e.gammaln(n)-e.gammaln(r)+n*t.log(o)+r*t.log(1-o));return!(o<0||o>1)&&(o<(n+1)/(n+r+2)?l*e.betacf(o,n,r)/n:1-l*e.betacf(1-o,r,n)/r)},e.randn=function(o,n){var r,l,i,s,a;if(n||(n=o),o)return e.create(o,n,(function(){return e.randn()}));do{r=e._random_fn(),l=1.7156*(e._random_fn()-.5),a=(i=r-.449871)*i+(s=t.abs(l)+.386595)*(.196*s-.25472*i)}while(a>.27597&&(a>.27846||l*l>-4*t.log(r)*r*r));return l/r},e.randg=function(o,n,r){var l,i,s,a,u,c,f=o;if(r||(r=n),o||(o=1),n)return(c=e.zeros(n,r)).alter((function(){return e.randg(o)})),c;o<1&&(o+=1),l=o-1/3,i=1/t.sqrt(9*l);do{do{a=1+i*(u=e.randn())}while(a<=0);a*=a*a,s=e._random_fn()}while(s>1-.331*t.pow(u,4)&&t.log(s)>.5*u*u+l*(1-a+t.log(a)));if(o==f)return l*a;do{s=e._random_fn()}while(0===s);return t.pow(s,1/f)*l*a},function(t){for(var o=0;or;)f=a,s=u+(l=-(o+c)*(o+n+c)*e/(o+2*c)/(o+2*c+1))*s,a=(i=a+l*i)+(l=(c+=1)*(n-c)*e/(o+2*c-1)/(o+2*c))*a,i/=u=s+l*u,s/=u,a/=u,u=1;return a/o}function n(o,n,r){var l=[.9815606342467192,.9041172563704749,.7699026741943047,.5873179542866175,.3678314989981802,.1252334085114689],i=[.04717533638651183,.10693932599531843,.16007832854334622,.20316742672306592,.2334925365383548,.24914704581340277],s=.5*o;if(s>=8)return 1;var a,u=2*e.normal.cdf(s,0,1,1,0)-1;u=u>=t.exp(-50/r)?t.pow(u,r):0;for(var c=s,f=(8-s)/(a=o>3?2:3),d=c+f,p=0,b=r-1,j=1;j<=a;j++){for(var h=0,g=.5*(d+c),m=.5*(d-c),v=1;v<=12;v++){var y,C=g+m*(660)break;var w=2*e.normal.cdf(C,0,1,1,0)*.5-2*e.normal.cdf(C,o,1,1,0)*.5;w>=t.exp(-30/b)&&(h+=w=i[y-1]*t.exp(-.5*x)*t.pow(w,b))}p+=h*=2*m*r/t.sqrt(2*t.PI),c=d,d+=f}return(u+=p)<=t.exp(-30/n)?0:(u=t.pow(u,n))>=1?1:u}!function(t){for(var o=0;o1||o<0?0:1==n&&1==r?1:n<512&&r<512?t.pow(o,n-1)*t.pow(1-o,r-1)/e.betafn(n,r):t.exp((n-1)*t.log(o)+(r-1)*t.log(1-o)-e.betaln(n,r))},cdf:function(t,o,n){return t>1||t<0?1*(t>1):e.ibeta(t,o,n)},inv:function(t,o,n){return e.ibetainv(t,o,n)},mean:function(e,t){return e/(e+t)},median:function(t,o){return e.ibetainv(.5,t,o)},mode:function(e,t){return(e-1)/(e+t-2)},sample:function(t,o){var n=e.randg(t);return n/(n+e.randg(o))},variance:function(e,o){return e*o/(t.pow(e+o,2)*(e+o+1))}}),e.extend(e.centralF,{pdf:function(o,n,r){var l;return o<0?0:n<=2?0===o&&n<2?1/0:0===o&&2===n?1:1/e.betafn(n/2,r/2)*t.pow(n/r,n/2)*t.pow(o,n/2-1)*t.pow(1+n/r*o,-(n+r)/2):(l=n*o/(r+o*n),n*(r/(r+o*n))/2*e.binomial.pdf((n-2)/2,(n+r-2)/2,l))},cdf:function(t,o,n){return t<0?0:e.ibeta(o*t/(o*t+n),o/2,n/2)},inv:function(t,o,n){return n/(o*(1/e.ibetainv(t,o/2,n/2)-1))},mean:function(e,t){return t>2?t/(t-2):void 0},mode:function(e,t){return e>2?t*(e-2)/(e*(t+2)):void 0},sample:function(t,o){return 2*e.randg(t/2)/t/(2*e.randg(o/2)/o)},variance:function(e,t){if(!(t<=4))return 2*t*t*(e+t-2)/(e*(t-2)*(t-2)*(t-4))}}),e.extend(e.cauchy,{pdf:function(e,o,n){return n<0?0:n/(t.pow(e-o,2)+t.pow(n,2))/t.PI},cdf:function(e,o,n){return t.atan((e-o)/n)/t.PI+.5},inv:function(e,o,n){return o+n*t.tan(t.PI*(e-.5))},median:function(e){return e},mode:function(e){return e},sample:function(o,n){return e.randn()*t.sqrt(1/(2*e.randg(.5)))*n+o}}),e.extend(e.chisquare,{pdf:function(o,n){return o<0?0:0===o&&2===n?.5:t.exp((n/2-1)*t.log(o)-o/2-n/2*t.log(2)-e.gammaln(n/2))},cdf:function(t,o){return t<0?0:e.lowRegGamma(o/2,t/2)},inv:function(t,o){return 2*e.gammapinv(t,.5*o)},mean:function(e){return e},median:function(e){return e*t.pow(1-2/(9*e),3)},mode:function(e){return e-2>0?e-2:0},sample:function(t){return 2*e.randg(t/2)},variance:function(e){return 2*e}}),e.extend(e.exponential,{pdf:function(e,o){return e<0?0:o*t.exp(-o*e)},cdf:function(e,o){return e<0?0:1-t.exp(-o*e)},inv:function(e,o){return-t.log(1-e)/o},mean:function(e){return 1/e},median:function(e){return 1/e*t.log(2)},mode:function(){return 0},sample:function(o){return-1/o*t.log(e._random_fn())},variance:function(e){return t.pow(e,-2)}}),e.extend(e.gamma,{pdf:function(o,n,r){return o<0?0:0===o&&1===n?1/r:t.exp((n-1)*t.log(o)-o/r-e.gammaln(n)-n*t.log(r))},cdf:function(t,o,n){return t<0?0:e.lowRegGamma(o,t/n)},inv:function(t,o,n){return e.gammapinv(t,o)*n},mean:function(e,t){return e*t},mode:function(e,t){if(e>1)return(e-1)*t},sample:function(t,o){return e.randg(t)*o},variance:function(e,t){return e*t*t}}),e.extend(e.invgamma,{pdf:function(o,n,r){return o<=0?0:t.exp(-(n+1)*t.log(o)-r/o-e.gammaln(n)+n*t.log(r))},cdf:function(t,o,n){return t<=0?0:1-e.lowRegGamma(o,n/t)},inv:function(t,o,n){return n/e.gammapinv(1-t,o)},mean:function(e,t){return e>1?t/(e-1):void 0},mode:function(e,t){return t/(e+1)},sample:function(t,o){return o/e.randg(t)},variance:function(e,t){if(!(e<=2))return t*t/((e-1)*(e-1)*(e-2))}}),e.extend(e.kumaraswamy,{pdf:function(e,o,n){return 0===e&&1===o?n:1===e&&1===n?o:t.exp(t.log(o)+t.log(n)+(o-1)*t.log(e)+(n-1)*t.log(1-t.pow(e,o)))},cdf:function(e,o,n){return e<0?0:e>1?1:1-t.pow(1-t.pow(e,o),n)},inv:function(e,o,n){return t.pow(1-t.pow(1-e,1/n),1/o)},mean:function(t,o){return o*e.gammafn(1+1/t)*e.gammafn(o)/e.gammafn(1+1/t+o)},median:function(e,o){return t.pow(1-t.pow(2,-1/o),1/e)},mode:function(e,o){if(e>=1&&o>=1&&1!==e&&1!==o)return t.pow((e-1)/(e*o-1),1/e)},variance:function(){throw new Error("variance not yet implemented")}}),e.extend(e.lognormal,{pdf:function(e,o,n){return e<=0?0:t.exp(-t.log(e)-.5*t.log(2*t.PI)-t.log(n)-t.pow(t.log(e)-o,2)/(2*n*n))},cdf:function(o,n,r){return o<0?0:.5+.5*e.erf((t.log(o)-n)/t.sqrt(2*r*r))},inv:function(o,n,r){return t.exp(-1.4142135623730951*r*e.erfcinv(2*o)+n)},mean:function(e,o){return t.exp(e+o*o/2)},median:function(e){return t.exp(e)},mode:function(e,o){return t.exp(e-o*o)},sample:function(o,n){return t.exp(e.randn()*n+o)},variance:function(e,o){return(t.exp(o*o)-1)*t.exp(2*e+o*o)}}),e.extend(e.noncentralt,{pdf:function(o,n,r){return t.abs(r)<1e-14?e.studentt.pdf(o,n):t.abs(o)<1e-14?t.exp(e.gammaln((n+1)/2)-r*r/2-.5*t.log(t.PI*n)-e.gammaln(n/2)):n/o*(e.noncentralt.cdf(o*t.sqrt(1+2/n),n+2,r)-e.noncentralt.cdf(o,n,r))},cdf:function(o,n,r){var l=1e-14;if(t.abs(r)l||a>l;)u=a,f>0&&(d*=r*r/(2*f),p*=r*r/(2*(f+.5))),s+=.5*(a=d*e.beta.cdf(c,f+.5,n/2)+p*e.beta.cdf(c,f+1,n/2)),f++;return i?1-s:s}}),e.extend(e.normal,{pdf:function(e,o,n){return t.exp(-.5*t.log(2*t.PI)-t.log(n)-t.pow(e-o,2)/(2*n*n))},cdf:function(o,n,r){return.5*(1+e.erf((o-n)/t.sqrt(2*r*r)))},inv:function(t,o,n){return-1.4142135623730951*n*e.erfcinv(2*t)+o},mean:function(e){return e},median:function(e){return e},mode:function(e){return e},sample:function(t,o){return e.randn()*o+t},variance:function(e,t){return t*t}}),e.extend(e.pareto,{pdf:function(e,o,n){return e1e100?1e100:n,1/(t.sqrt(n)*e.betafn(.5,n/2))*t.pow(1+o*o/n,-(n+1)/2)},cdf:function(o,n){var r=n/2;return e.ibeta((o+t.sqrt(o*o+n))/(2*t.sqrt(o*o+n)),r,r)},inv:function(o,n){var r=e.ibetainv(2*t.min(o,1-o),.5*n,.5);return r=t.sqrt(n*(1-r)/r),o>.5?r:-r},mean:function(e){return e>1?0:void 0},median:function(){return 0},mode:function(){return 0},sample:function(o){return e.randn()*t.sqrt(o/(2*e.randg(o/2)))},variance:function(e){return e>2?e/(e-2):e>1?1/0:void 0}}),e.extend(e.weibull,{pdf:function(e,o,n){return e<0||o<0||n<0?0:n/o*t.pow(e/o,n-1)*t.exp(-t.pow(e/o,n))},cdf:function(e,o,n){return e<0?0:1-t.exp(-t.pow(e/o,n))},inv:function(e,o,n){return o*t.pow(-t.log(1-e),1/n)},mean:function(t,o){return t*e.gammafn(1+1/o)},median:function(e,o){return e*t.pow(t.log(2),1/o)},mode:function(e,o){return o<=1?0:e*t.pow((o-1)/o,1/o)},sample:function(o,n){return o*t.pow(-t.log(e._random_fn()),1/n)},variance:function(o,n){return o*o*e.gammafn(1+2/n)-t.pow(e.weibull.mean(o,n),2)}}),e.extend(e.uniform,{pdf:function(e,t,o){return eo?0:1/(o-t)},cdf:function(e,t,o){return e=r)return 1;if(l<0||l>1||r<=0)return NaN;var a=l,u=(n=t.floor(n))+1,c=r-n,f=u+c,d=t.exp(e.gammaln(f)-e.gammaln(c)-e.gammaln(u)+u*t.log(a)+c*t.log(1-a));return i=a<(u+1)/(f+2)?d*o(a,u,c,s):1-d*o(1-a,c,u,s),t.round(1/s*(1-i))/(1/s)}}),e.extend(e.negbin,{pdf:function(o,n,r){return o===o>>>0&&(o<0?0:e.combination(o+n-1,n-1)*t.pow(1-r,o)*t.pow(r,n))},cdf:function(t,o,n){var r=0,l=0;if(t<0)return 0;for(;l<=t;l++)r+=e.negbin.pdf(l,o,n);return r}}),e.extend(e.hypgeom,{pdf:function(o,n,r,l){if(o!=o|0)return!1;if(o<0||ol||o>r)return 0;if(2*r>n)return 2*l>n?e.hypgeom.pdf(n-r-l+o,n,n-r,n-l):e.hypgeom.pdf(l-o,n,n-r,l);if(2*l>n)return e.hypgeom.pdf(r-o,n,r,n-l);if(r1&&s=l||o>=r)return 1;if(2*r>n)return 2*l>n?e.hypgeom.cdf(n-r-l+o,n,n-r,n-l):1-e.hypgeom.cdf(l-o-1,n,n-r,l);if(2*l>n)return 1-e.hypgeom.cdf(r-o-1,n,r,n-l);if(r1&&al);return r-1},sampleLarge:function(o){var n,r,l,i,s,a,u,c,f,d,p=o;for(i=t.sqrt(p),s=t.log(p),a=.02483*(u=.931+2.53*i)-.059,c=1.1239+1.1328/(u-3.4),f=.9277-3.6224/(u-2);;){if(r=t.random()-.5,l=t.random(),d=.5-t.abs(r),n=t.floor((2*a/d+u)*r+p+.43),d>=.07&&l<=f)return n;if(!(n<0||d<.013&&l>d)&&t.log(l)+t.log(c)-t.log(a/(d*d)+u)<=n*s-p-e.loggam(n+1))return n}},sample:function(e){return e<10?this.sampleSmall(e):this.sampleLarge(e)}}),e.extend(e.triangular,{pdf:function(e,t,o,n){return o<=t||no?NaN:eo?0:en?NaN:e<=o?0:e>=n?1:e<=r?t.pow(e-o,2)/((n-o)*(r-o)):1-t.pow(n-e,2)/((n-o)*(n-r))},inv:function(e,o,n,r){return n<=o||rn?NaN:e<=(r-o)/(n-o)?o+(n-o)*t.sqrt(e*((r-o)/(n-o))):o+(n-o)*(1-t.sqrt((1-e)*(1-(r-o)/(n-o))))},mean:function(e,t,o){return(e+t+o)/3},median:function(e,o,n){return n<=(e+o)/2?o-t.sqrt((o-e)*(o-n))/t.sqrt(2):n>(e+o)/2?e+t.sqrt((o-e)*(n-e))/t.sqrt(2):void 0},mode:function(e,t,o){return o},sample:function(o,n,r){var l=e._random_fn();return l<(r-o)/(n-o)?o+t.sqrt(l*(n-o)*(r-o)):n-t.sqrt((1-l)*(n-o)*(n-r))},variance:function(e,t,o){return(e*e+t*t+o*o-e*t-e*o-t*o)/18}}),e.extend(e.arcsine,{pdf:function(e,o,n){return n<=o?NaN:e<=o||e>=n?0:2/t.PI*t.pow(t.pow(n-o,2)-t.pow(2*e-o-n,2),-.5)},cdf:function(e,o,n){return e25e3)return n(o,1,i);var u,c=.5*l,f=c*t.log(l)-l*t.log(2)-e.gammaln(c),d=c-1,p=.25*l;u=l<=100?1:l<=800?.5:l<=5e3?.25:.125,f+=t.log(u);for(var b=0,j=1;j<=50;j++){for(var h=0,g=(2*j-1)*u,m=1;m<=16;m++){var v,y;8=-30&&(h+=n(8=1&&h<=1e-14)break;b+=h}if(h>1e-14)throw new Error("tukey.cdf failed to converge");return b>1&&(b=1),b},inv:function(o,n,r){if(r<2||n<2)return NaN;if(o<0||o>1)return NaN;if(0===o)return 0;if(1===o)return 1/0;var l,i=function(e,o,n){var r=.5-.5*e,l=t.sqrt(t.log(1/(r*r))),i=l+((((-453642210148e-16*l-.204231210125)*l-.342242088547)*l-1)*l+.322232421088)/((((.0038560700634*l+.10353775285)*l+.531103462366)*l+.588581570495)*l+.099348462606);n<120&&(i+=(i*i*i+i)/n/4);var s=.8832-.2368*i;return n<120&&(s+=-1.214/n+1.208*i/n),i*(s*t.log(o-1)+1.4142)}(o,n,r),s=e.tukey.cdf(i,n,r)-o;l=s>0?t.max(0,i-1):i+1;for(var a,u=e.tukey.cdf(l,n,r)-o,c=1;c<50;c++)if(a=l-u*(l-i)/(u-s),s=u,i=l,a<0&&(a=0,u=-o),u=e.tukey.cdf(a,n,r)-o,l=a,t.abs(l-i)<1e-4)return a;throw new Error("tukey.inv failed to converge")}})}(t,Math),function(e,t){var o,n,r=Array.prototype.push,l=e.utils.isArray;function i(t){return l(t)||t instanceof e}e.extend({add:function(t,o){return i(o)?(i(o[0])||(o=[o]),e.map(t,(function(e,t,n){return e+o[t][n]}))):e.map(t,(function(e){return e+o}))},subtract:function(t,o){return i(o)?(i(o[0])||(o=[o]),e.map(t,(function(e,t,n){return e-o[t][n]||0}))):e.map(t,(function(e){return e-o}))},divide:function(t,o){return i(o)?(i(o[0])||(o=[o]),e.multiply(t,e.inv(o))):e.map(t,(function(e){return e/o}))},multiply:function(t,o){var n,r,l,s,a,u,c,f;if(void 0===t.length&&void 0===o.length)return t*o;if(a=t.length,u=t[0].length,c=e.zeros(a,l=i(o)?o[0].length:u),f=0,i(o)){for(;fn&&(r[l-1][i-1]=t[l][i])}var s=n%2?-1:1;o+=e(r)*t[0][n]*s}return o},gauss_elimination:function(o,n){var r,l,i,s,a=0,u=0,c=o.length,f=o[0].length,d=1,p=0,b=[];for(r=(o=e.aug(o,n))[0].length,a=0;a=0;a--){for(p=0,u=a+1;u<=c-1;u++)p+=b[u]*o[a][u];b[a]=(o[a][r-1]-p)/o[a][a]}return b},gauss_jordan:function(o,n){var r,l,i,s=e.aug(o,n),a=s.length,u=s[0].length,c=0;for(l=0;lt.abs(s[f][l])&&(f=i);var d=s[l];for(s[l]=s[f],s[f]=d,i=l+1;i=0;l--){for(c=s[l][l],i=0;il-1;r--)s[i][r]-=s[l][r]*s[i][l]/c;for(s[l][l]/=c,r=a;rf?(p[c][f]=o[c][f],b[c][f]=j[c][f]=0):cl;)i=u,u=e.add(e.multiply(a,i),s),c++;return u},gauss_seidel:function(o,n,r,l){for(var i,s,a,u,c,f=0,d=o.length,p=[],b=[],j=[];fi?(p[f][i]=o[f][i],b[f][i]=j[f][i]=0):fl;)s=c,c=e.add(e.multiply(u,s),a),f+=1;return c},SOR:function(o,n,r,l,i){for(var s,a,u,c,f,d=0,p=o.length,b=[],j=[],h=[];ds?(b[d][s]=o[d][s],j[d][s]=h[d][s]=0):dl;)a=f,f=e.add(e.multiply(c,a),u),d++;return f},householder:function(o){for(var n,r,l,i,s=o.length,a=o[0].length,u=0,c=[],f=[];u0?-1:1)*t.sqrt(n),r=t.sqrt((n*n-o[u+1][u]*n)/2),(c=e.zeros(s,1))[u+1][0]=(o[u+1][u]-n)/(2*r),l=u+2;l0?t.PI/4:-t.PI/4:t.atan(2*o[l][i]/(o[l][l]-o[i][i]))/2,(u=e.identity(f,f))[l][l]=t.cos(a),u[l][i]=-t.sin(a),u[i][l]=t.sin(a),u[i][i]=t.cos(a),d=e.multiply(d,u),o=e.multiply(e.multiply(e.inv(u),o),u),c=0,n=1;n.001&&(c=1)}for(n=0;n=f;)i=l(e,n+r),s=l(e,n),p[d]=(o[i]-2*o[s]+o[2*s-i])/(r*r),r/=2,d++;for(u=p.length,a=1;1!=u;){for(c=0;cn);r++);return o[r-=1]+(n-t[r])*d[r]+e.sq(n-t[r])*l[r]+(n-t[r])*e.sq(n-t[r])*p[r]},gauss_quadrature:function(){throw new Error("gauss_quadrature not yet implemented")},PCA:function(t){var o,n,r,l,i,s=t.length,a=t[0].length,u=0,c=[],f=[],d=[],p=[],b=[],j=[],h=[];for(u=0;u1||n>1||e<=0||n<=0)throw new Error("Proportions should be greater than 0 and less than 1");var l=(e*o+n*r)/(o+r);return(e-n)/t.sqrt(l*(1-l)*(1/o+1/r))}e.extend({zscore:function(){var t=o.call(arguments);return n(t[1])?(t[0]-t[1])/t[2]:(t[0]-e.mean(t[1]))/e.stdev(t[1],t[2])},ztest:function(){var n,l=o.call(arguments);return r(l[1])?(n=e.zscore(l[0],l[1],l[3]),1===l[2]?e.normal.cdf(-t.abs(n),0,1):2*e.normal.cdf(-t.abs(n),0,1)):l.length>2?(n=e.zscore(l[0],l[1],l[2]),1===l[3]?e.normal.cdf(-t.abs(n),0,1):2*e.normal.cdf(-t.abs(n),0,1)):(n=l[0],1===l[1]?e.normal.cdf(-t.abs(n),0,1):2*e.normal.cdf(-t.abs(n),0,1))}}),e.extend(e.fn,{zscore:function(e,t){return(e-this.mean())/this.stdev(t)},ztest:function(o,n,r){var l=t.abs(this.zscore(o,r));return 1===n?e.normal.cdf(-l,0,1):2*e.normal.cdf(-l,0,1)}}),e.extend({tscore:function(){var n=o.call(arguments);return 4===n.length?(n[0]-n[1])/(n[2]/t.sqrt(n[3])):(n[0]-e.mean(n[1]))/(e.stdev(n[1],!0)/t.sqrt(n[1].length))},ttest:function(){var r,l=o.call(arguments);return 5===l.length?(r=t.abs(e.tscore(l[0],l[1],l[2],l[3])),1===l[4]?e.studentt.cdf(-r,l[3]-1):2*e.studentt.cdf(-r,l[3]-1)):n(l[1])?(r=t.abs(l[0]),1==l[2]?e.studentt.cdf(-r,l[1]-1):2*e.studentt.cdf(-r,l[1]-1)):(r=t.abs(e.tscore(l[0],l[1])),1==l[2]?e.studentt.cdf(-r,l[1].length-1):2*e.studentt.cdf(-r,l[1].length-1))}}),e.extend(e.fn,{tscore:function(e){return(e-this.mean())/(this.stdev(!0)/t.sqrt(this.cols()))},ttest:function(o,n){return 1===n?1-e.studentt.cdf(t.abs(this.tscore(o)),this.cols()-1):2*e.studentt.cdf(-t.abs(this.tscore(o)),this.cols()-1)}}),e.extend({anovafscore:function(){var n,r,l,i,s,a,u,c,f=o.call(arguments);if(1===f.length){for(s=new Array(f[0].length),u=0;u.5?1-n:n)})),c=t.studentt.inv(.975,o.df_resid),f=o.coef.map((function(e,t){var o=c*s[t];return[e-o,e+o]}));return{se:s,t:a,p:u,sigmaHat:i,interval95:f}}(r),i=function(e){var o,n,r,l=e.R2/e.df_model/((1-e.R2)/e.df_resid);return{F_statistic:l,pvalue:1-(o=l,n=e.df_model,r=e.df_resid,t.beta.cdf(o/(r/n+o),n/2,r/2))}}(r),s=1-(1-r.R2)*((r.nobs-1)/r.df_resid);return r.t=l,r.f=i,r.adjust_R2=s,r}}}(),t.extend({buildxmatrix:function(){for(var e=new Array(arguments.length),o=0;o1){for(i=[],n=0;nt+"."+e))],i.splice(i.indexOf(t),1))}}if(i.length<1)e[l]=n[l];else for(let o=0;o0?c+=e+" = "+t.get(r)+";\n":c+="var "+e+" = "+n+";\n"}))}else{let e=Object.keys(t);if(e.length){let o,n={};for(let t=0;t0){let e=e.split(".");n[e[0]]={}}o=Object.keys(n);for(let e=0;e0?c+=o+" = "+t[e[n]]+";\n":c+="var "+o+" = "+t[e[n]]+";\n"}}}let d=(e=function(e,t){let o="",n=0,r=["=","!",">","<"];for(let t=0;t0&&"="===e[t]&&-1===r.indexOf(e[t-1])&&-1===r.indexOf(e[t+1])&&(o+="="));return o=o.replace(/\^/g,"**"),o=o.replace(/<>/g,"!="),o=o.replace(/&/g,"+"),o=o.replace(/\$/g,""),o}(e=(e=e.replace(/\$/g,"")).replace(/!/g,"."))).match(/(('.*?'!)|(\w*!))?(\$?[A-Z]+\$?[0-9]*):(\$?[A-Z]+\$?[0-9]*)?/g);d&&d.length&&(e=s(d,e));let p=new Function(c+"; return "+e)();return null===p&&(p=0),p};return u.getColumnNameFromCoords=function(e,t){return n="",(o=parseInt(e))>701?(n+=String.fromCharCode(64+parseInt(o/676)),n+=String.fromCharCode(64+parseInt(o%676/26))):o>25&&(n+=String.fromCharCode(64+parseInt(o/26))),n+String.fromCharCode(65+o%26)+(parseInt(t)+1);var o,n},u.getCoordsFromColumnName=function(e){var t=/^[a-zA-Z]+/.exec(e);if(t){for(var o=0,n=0;n0&&r--,[o,r]}},u.getRangeFromTokens=function(e){e=e.filter((function(e){return"#REF!"!=e}));for(var t="",o="",n=0;n=0?t=".":e[n].indexOf("!")>=0&&(t="!"),t&&(o=e[n].split(t),e[n]=o[1],o=o[0]+t);return e.sort((function(e,t){var o=Helpers.getCoordsFromColumnName(e),n=Helpers.getCoordsFromColumnName(t);return o[1]>n[1]?1:o[1]n[0]?1:o[0]0){var t=e.split(".");e=t[1],t=t[0]+"."}else e.indexOf("!")>0?(t=e.split("!"),e=t[1],t=t[0]+"!"):t="";e=e.split(":");var o=u.getCoordsFromColumnName(e[0]),n=u.getCoordsFromColumnName(e[1]);if(o[0]<=n[0])var r=o[0],l=n[0];else r=n[0],l=o[0];if(null===o[1]&&null==n[1])for(var i=null,s=null,a=Object.keys(vars),c=0;cs)&&(s=f[1])}else o[1]<=n[1]?(i=o[1],s=n[1]):(i=n[1],s=o[1]);for(var d=[],p=i;p<=s;p++){var b=[];for(c=r;c<=l;c++)b.push(t+u.getColumnNameFromCoords(c,p));d.push(b)}return d},u.setFormula=function(t){let o=Object.keys(t);for(let n=0;n{t.push(e)})),t}function h(e,t){let o=-1;const n=e.length;for(;++oArray.isArray(e)))&&0!==e.length||(e=[[...e]]),e.map(((t,o)=>{t.map(((t,n)=>{t||(e[o][n]=0)}))}));const o=e.reduce(((t,o,n)=>o.length>e[t].length?n:t),0),n=e[o].length;return e.map((e=>[...e,...Array(n-e.length).fill(t||0)]))}function v(){let e;if(1===arguments.length){const o=arguments[0];e=null!=(t=o)&&"number"==typeof t.length&&"string"!=typeof t?j.apply(null,arguments):[o]}else e=Array.from(arguments);for(var t;!C(e);)e=y(e);return e}function y(e){return e&&e.reduce?e.reduce(((e,t)=>{const o=Array.isArray(e),n=Array.isArray(t);return o&&n?e.concat(t):o?(e.push(t),e):n?[e].concat(t):[e,t]})):[e]}function C(e){if(!e)return!1;for(let t=0;te.map((e=>e[o])))):s}function A(e,t){let o=null;return h(e,((e,n)=>{if(e[0]===t)return o=n,!1})),null==o?s:o}function E(){for(let e=0;e"number"==typeof e))}function S(e){if("boolean"==typeof e)return e;if(e instanceof Error)return e;if("number"==typeof e)return 0!==e;if("string"==typeof e){const t=e.toUpperCase();if("TRUE"===t)return!0;if("FALSE"===t)return!1}return e instanceof Date&&!isNaN(e)||s}function D(e){if(!isNaN(e)){if(e instanceof Date)return new Date(e);const t=parseFloat(e);return t<0||t>=2958466?c:function(e){e<60&&(e+=1);const t=Math.floor(e-25569),o=new Date(86400*t*1e3),n=e-Math.floor(e)+1e-7;let r=Math.floor(86400*n);const l=r%60;r-=l;const i=Math.floor(r/3600),s=Math.floor(r/60)%60;let a=o.getUTCDate(),u=o.getUTCMonth();return e>=60&&e<61&&(a=29,u=1),new Date(o.getUTCFullYear(),u,a,i,s,l)}(t)}return"string"!=typeof e||(e=/(\d{4})-(\d\d?)-(\d\d?)$/.test(e)?new Date(e+"T00:00:00.000"):new Date(e),isNaN(e))?s:e}function T(e){let t,o=e.length;for(;o--;){if(t=D(e[o]),t===s)return t;e[o]=t}return e}function F(e){return e instanceof Error?e:null==e?0:("boolean"==typeof e&&(e=+e),isNaN(e)||""===e?s:parseFloat(e))}function L(e){let t,o;if(!e||0===(t=e.length))return s;for(;t--;){if(e[t]instanceof Error)return e[t];if(o=F(e[t]),o instanceof Error)return o;e[t]=o}return e}function R(e){return e instanceof Error?e:null==e?"":e.toString()}function O(){let e=arguments.length;for(;e--;)if("string"==typeof arguments[e])return!0;return!1}function k(e){return null!=e}const H="=",B=[">",">=","<","<=","=","<>"],P="operator",_="literal",V=[P,_],U=P,q=_;function z(e,t){if(-1===V.indexOf(t))throw new Error("Unsupported token type: "+t);return{value:e,type:t}}function Y(e){return function(e){let t="";const o=[];for(let n=0;n=0?o.push(z(r,U)):t+=r}return t.length>0&&o.push(z(function(e){return"string"!=typeof e||/^\d+(\.\d+)?$/.test(e)&&(e=-1===e.indexOf(".")?parseInt(e,10):parseFloat(e)),e}(t),q)),o.length>0&&o[0].type!==U&&o.unshift(z(H,U)),o}(function(e){const t=e.length,o=[];let n=0,r="",l="";for(;n":case"<":case"=":l+=t,r.length>0&&(o.push(r),r="");break;default:l.length>0&&(o.push(l),l=""),r+=t}n++}return r.length>0&&o.push(r),l.length>0&&o.push(l),o}(e))}const W=function(e){const t=[];let o;for(let n=0;n":o=e[0]>e[1];break;case">=":o=e[0]>=e[1];break;case"<":o=e[0]":o=e[0]!=e[1]}return o}(t,o)},X={};function G(e){return[s,a,i,c,u,l].indexOf(e)>=0||"number"==typeof e&&(isNaN(e)||!isFinite(e))}function K(e){return G(e)||e===f}function $(e){return!0===e||!1===e}function J(e){return"number"==typeof e&&!isNaN(e)&&isFinite(e)}function Q(e){return"string"==typeof e}function Z(){const e=[];for(let t=0;te&&(i=!0)}return r}function te(){const e=v(arguments).filter(k);if(0===e.length)return i;const t=E.apply(void 0,e);if(t)return t;const o=N(e),n=o.length;let r,l=0,s=0;for(let e=0;e{switch(e){case l:return 1;case i:return 2;case s:return 3;case a:return 4;case u:return 5;case c:return 6;case f:return 7;case p:return 8}return f};const ne={DIST:function(e,t,o,r,l,i){return arguments.length<4?s:(l=void 0===l?0:l,i=void 0===i?1:i,M(e=F(e),t=F(t),o=F(o),l=F(l),i=F(i))?s:(e=(e-l)/(i-l),r?n.beta.cdf(e,t,o):n.beta.pdf(e,t,o)))},INV:(e,t,o,r,l)=>(r=void 0===r?0:r,l=void 0===l?1:l,M(e=F(e),t=F(t),o=F(o),r=F(r),l=F(l))?s:n.beta.inv(e,t,o)*(l-r)+r)},re={DIST:(e,t,o,r)=>M(e=F(e),t=F(t),o=F(o),r=F(r))?s:r?n.binomial.cdf(e,t,o):n.binomial.pdf(e,t,o)};re.DIST.RANGE=(e,t,o,n)=>{if(n=void 0===n?o:n,M(e=F(e),t=F(t),o=F(o),n=F(n)))return s;let r=0;for(let l=o;l<=n;l++)r+=Ue(e,l)*Math.pow(t,l)*Math.pow(1-t,e-l);return r},re.INV=(e,t,o)=>{if(M(e=F(e),t=F(t),o=F(o)))return s;let r=0;for(;r<=e;){if(n.binomial.cdf(r,e,t)>=o)return r;r++}};const le={DIST:(e,t,o)=>M(e=F(e),t=F(t))?s:o?n.chisquare.cdf(e,t):n.chisquare.pdf(e,t)};le.DIST.RT=(e,t)=>!e|!t?f:e<1||t>Math.pow(10,10)?c:"number"!=typeof e||"number"!=typeof t?s:1-n.chisquare.cdf(e,t),le.INV=(e,t)=>M(e=F(e),t=F(t))?s:n.chisquare.inv(e,t),le.INV.RT=(e,t)=>!e|!t?f:e<0||e>1||t<1||t>Math.pow(10,10)?c:"number"!=typeof e||"number"!=typeof t?s:n.chisquare.inv(1-e,t),le.TEST=function(e,t){if(2!==arguments.length)return f;if(!(e instanceof Array&&t instanceof Array))return s;if(e.length!==t.length)return s;if(e[0]&&t[0]&&e[0].length!==t[0].length)return s;const o=e.length;let n,r,l;for(r=0;r=2;)o=o*e/n,n-=2;let r=o,l=t;for(;r>1e-10*o;)l+=2,r=r*e/l,o+=r;return 1-o}(u,a))/1e6};const ie={};function se(){return N(v(arguments)).length}function ae(){const e=v(arguments);return e.length-ue(e)}function ue(){const e=v(arguments);let t,o=0;for(let n=0;nM(e=F(e),t=F(t),o=F(o))?s:n.normalci(1,e,t,o)[1]-1,ie.T=(e,t,o)=>M(e=F(e),t=F(t),o=F(o))?s:n.tci(1,e,t,o)[1]-1;const ce={P:(e,t)=>{if(M(e=L(v(e)),t=L(v(t))))return s;const o=n.mean(e),r=n.mean(t);let l=0;const i=e.length;for(let n=0;nM(e=L(v(e)),t=L(v(t)))?s:n.covariance(e,t)},fe={DIST:(e,t,o)=>M(e=F(e),t=F(t))?s:o?n.exponential.cdf(e,t):n.exponential.pdf(e,t)},de={};function pe(e,t,o){if(M(e=F(e),t=L(v(t)),o=L(v(o))))return s;const r=n.mean(o),l=n.mean(t),i=o.length;let a=0,u=0;for(let e=0;eM(e=F(e),t=F(t),o=F(o))?s:r?n.centralF.cdf(e,t,o):n.centralF.pdf(e,t,o),de.DIST.RT=function(e,t,o){return 3!==arguments.length?f:e<0||t<1||o<1?c:"number"!=typeof e||"number"!=typeof t||"number"!=typeof o?s:1-n.centralF.cdf(e,t,o)},de.INV=(e,t,o)=>M(e=F(e),t=F(t),o=F(o))?s:e<=0||e>1?c:n.centralF.inv(e,t,o),de.INV.RT=function(e,t,o){return 3!==arguments.length?f:e<0||e>1||t<1||t>Math.pow(10,10)||o<1||o>Math.pow(10,10)?c:"number"!=typeof e||"number"!=typeof t||"number"!=typeof o?s:n.centralF.inv(1-e,t,o)},de.TEST=(e,t)=>{if(!e||!t)return f;if(!(e instanceof Array&&t instanceof Array))return f;if(e.length<2||t.length<2)return i;const o=(e,t)=>{let o=0;for(let n=0;n1||t<=0||o<=0?c:"number"!=typeof e||"number"!=typeof t||"number"!=typeof o?s:n.gamma.inv(e,t,o)},je.PRECISE=function(e){return 1!==arguments.length?f:e<=0?c:"number"!=typeof e?s:n.gammaln(e)};const he={};function ge(e,t){return M(e=L(v(e)),t=F(t))?e:t<0||e.lengtht-e))[t-1]}function me(e,t){if(M(e=L(v(e)),t=L(v(t))))return s;const o=n.mean(e),r=n.mean(t),l=t.length;let i=0,a=0;for(let n=0;n{if(M(e=F(e),t=F(t),o=F(o),n=F(n)))return s;function l(e,t,o,n){return Ue(o,e)*Ue(n-o,t-e)/Ue(n,t)}return r?function(e,t,o,n){let r=0;for(let i=0;i<=e;i++)r+=l(i,t,o,n);return r}(e,t,o,n):l(e,t,o,n)};const ve={};function ye(){const e=v(arguments),t=E.apply(void 0,e);if(t)return t;const o=N(e);return 0===o.length?0:Math.max.apply(Math,o)}function Ce(){const e=v(arguments),t=E.apply(void 0,e);if(t)return t;const o=g(e);let r=n.median(o);return isNaN(r)&&(r=c),r}function xe(){const e=v(arguments),t=E.apply(void 0,e);if(t)return t;const o=N(e);return 0===o.length?0:Math.min.apply(Math,o)}ve.DIST=(e,t,o,r)=>M(e=F(e),t=F(t),o=F(o))?s:r?n.lognormal.cdf(e,t,o):n.lognormal.pdf(e,t,o),ve.INV=(e,t,o)=>M(e=F(e),t=F(t),o=F(o))?s:n.lognormal.inv(e,t,o);const we={MULT:function(){const e=L(v(arguments));if(e instanceof Error)return e;const t=e.length,o={};let n,r=[],l=0;for(let i=0;il&&(l=o[n],r=[]),o[n]===l&&(r[r.length]=n);return r},SNGL:function(){const e=L(v(arguments));return e instanceof Error?e:we.MULT(e).sort(((e,t)=>e-t))[0]}},Ae={DIST:(e,t,o,r)=>M(e=F(e),t=F(t),o=F(o))?s:r?n.negbin.cdf(e,t,o):n.negbin.pdf(e,t,o)},Ee={};function Me(e,t){if(M(t=L(v(t)),e=L(v(e))))return s;const o=n.mean(e),r=n.mean(t),l=e.length;let i=0,a=0,u=0;for(let n=0;nM(e=F(e),t=F(t),o=F(o))?s:o<=0?c:r?n.normal.cdf(e,t,o):n.normal.pdf(e,t,o),Ee.INV=(e,t,o)=>M(e=F(e),t=F(t),o=F(o))?s:n.normal.inv(e,t,o),Ee.S={},Ee.S.DIST=(e,t)=>(e=F(e))instanceof Error?s:t?n.normal.cdf(e,0,1):n.normal.pdf(e,0,1),Ee.S.INV=e=>(e=F(e))instanceof Error?s:n.normal.inv(e,0,1);const Ie={EXC:(e,t)=>{if(M(e=L(v(e)),t=F(t)))return s;const o=(e=e.sort(((e,t)=>e-t))).length;if(t<1/(o+1)||t>1-1/(o+1))return c;const n=t*(o+1)-1,r=Math.floor(n);return I(n===r?e[n]:e[r]+(n-r)*(e[r+1]-e[r]))},INC:(e,t)=>{if(M(e=L(v(e)),t=F(t)))return s;const o=t*((e=e.sort(((e,t)=>e-t))).length-1),n=Math.floor(o);return I(o===n?e[o]:e[n]+(o-n)*(e[n+1]-e[n]))}},Ne={EXC:(e,t,o)=>{if(o=void 0===o?3:o,M(e=L(v(e)),t=F(t),o=F(o)))return s;e=e.sort(((e,t)=>e-t));const n=Z.apply(null,e),r=e.length,l=n.length,i=Math.pow(10,o);let a=0,u=!1,c=0;for(;!u&&c=n[c]&&(t{if(o=void 0===o?3:o,M(e=L(v(e)),t=F(t),o=F(o)))return s;e=e.sort(((e,t)=>e-t));const n=Z.apply(null,e),r=e.length,l=n.length,i=Math.pow(10,o);let a=0,u=!1,c=0;for(;!u&&c=n[c]&&(tM(e=F(e),t=F(t))?s:o?n.poisson.cdf(e,t):n.poisson.pdf(e,t)},De={EXC:(e,t)=>{if(M(e=L(v(e)),t=F(t)))return s;switch(t){case 1:return Ie.EXC(e,.25);case 2:return Ie.EXC(e,.5);case 3:return Ie.EXC(e,.75);default:return c}},INC:(e,t)=>{if(M(e=L(v(e)),t=F(t)))return s;switch(t){case 1:return Ie.INC(e,.25);case 2:return Ie.INC(e,.5);case 3:return Ie.INC(e,.75);default:return c}}},Te={};function Fe(){const e=L(v(arguments));if(e instanceof Error)return e;const t=n.mean(e),o=e.length;let r=0;for(let n=0;ne-t))[t-1]}Te.AVG=(e,t,o)=>{if(M(e=F(e),t=L(v(t))))return s;const n=(o=o||!1)?(e,t)=>e-t:(e,t)=>t-e,r=(t=(t=v(t)).sort(n)).length;let l=0;for(let o=0;o1?(2*t.indexOf(e)+l+1)/2:t.indexOf(e)+1},Te.EQ=(e,t,o)=>{if(M(e=F(e),t=L(v(t))))return s;const n=(o=o||!1)?(e,t)=>e-t:(e,t)=>t-e;return(t=t.sort(n)).indexOf(e)+1},Fe.P=function(){const e=L(v(arguments));if(e instanceof Error)return e;const t=n.mean(e),o=e.length;let r=0,l=0;for(let n=0;n1!==o&&2!==o?c:1===o?Oe.DIST.RT(e,t):Oe.DIST["2T"](e,t)};Oe.DIST["2T"]=function(e,t){return 2!==arguments.length?f:e<0||t<1?c:"number"!=typeof e||"number"!=typeof t?s:2*(1-n.studentt.cdf(e,t))},Oe.DIST.RT=function(e,t){return 2!==arguments.length?f:e<0||t<1?c:"number"!=typeof e||"number"!=typeof t?s:1-n.studentt.cdf(e,t)},Oe.INV=(e,t)=>M(e=F(e),t=F(t))?s:n.studentt.inv(e,t),Oe.INV["2T"]=(e,t)=>(e=F(e),t=F(t),e<=0||e>1||t<1?c:M(e,t)?s:Math.abs(n.studentt.inv(e/2,t))),Oe.TEST=(e,t)=>{if(M(e=L(v(e)),t=L(v(t))))return s;const o=n.mean(e),r=n.mean(t);let l,i=0,a=0;for(l=0;lM(e=F(e),t=F(t),o=F(o))?s:n?1-Math.exp(-Math.pow(e/o,t)):Math.pow(e,t-1)*Math.exp(-Math.pow(e/o,t))*t/Math.pow(o,t)},_e={};function Ve(e,t,o){const n=E(e=F(e),t=F(t),o=F(o));if(n)return n;if(0===t)return 0;t=Math.abs(t);const r=-Math.floor(Math.log(t)/Math.log(10));return e>=0?Ke(Math.ceil(e/t)*t,r):0===o?-Ke(Math.floor(Math.abs(e)/t)*t,r):-Ke(Math.ceil(Math.abs(e)/t)*t,r)}function Ue(e,t){return E(e=F(e),t=F(t))||(e{if(M(e=L(v(e)),t=F(t)))return s;o=o||Re.S(e);const n=e.length;return 1-Ee.S.DIST((te(e)-t)/(o/Math.sqrt(n)),!0)},Ve.MATH=Ve,Ve.PRECISE=Ve;const qe=[];function ze(e){if((e=F(e))instanceof Error)return e;const t=Math.floor(e);return 0===t||1===t?1:(qe[t]>0||(qe[t]=ze(t-1)*t),qe[t])}function Ye(e,t){const o=E(e=F(e),t=F(t));if(o)return o;if(0===t)return 0;if(!(e>=0&&t>0||e<=0&&t<0))return c;t=Math.abs(t);const n=-Math.floor(Math.log(t)/Math.log(10));return e>=0?Ke(Math.floor(e/t)*t,n):-Ke(Math.ceil(Math.abs(e)/t),n)}Ye.MATH=(e,t,o)=>{if(t instanceof Error)return t;t=void 0===t?0:t;const n=E(e=F(e),t=F(t),o=F(o));if(n)return n;if(0===t)return 0;t=t?Math.abs(t):1;const r=-Math.floor(Math.log(t)/Math.log(10));return e>=0?Ke(Math.floor(e/t)*t,r):0===o||void 0===o?-Ke(Math.ceil(Math.abs(e)/t)*t,r):-Ke(Math.floor(Math.abs(e)/t)*t,r)},Ye.PRECISE=Ye.MATH;const We={CEILING:Ve};function Xe(e,t){const o=E(e=F(e),t=F(t));if(o)return o;if(0===e&&0===t)return c;const n=Math.pow(e,t);return isNaN(n)?c:n}function Ge(){const e=v(arguments).filter((e=>null!=e));if(0===e.length)return 0;const t=L(e);if(t instanceof Error)return t;let o=1;for(let e=0;e{if(e instanceof Error)return!1;if(t instanceof Error)e=t;else if("number"==typeof t)e+=t;else if("string"==typeof t){const o=parseFloat(t);!isNaN(o)&&(e+=o)}else if(Array.isArray(t)){const o=$e.apply(null,t);o instanceof Error?e=o:e+=o}})),e}var Je=Object.freeze({__proto__:null,ADD:function(e,t){return 2!==arguments.length?f:E(e=F(e),t=F(t))||e+t},DIVIDE:function(e,t){return 2!==arguments.length?f:E(e=F(e),t=F(t))||(0===t?i:e/t)},EQ:function(e,t){return 2!==arguments.length?f:e instanceof Error?e:t instanceof Error?t:(null===e&&(e=void 0),null===t&&(t=void 0),e===t)},GT:function(e,t){return 2!==arguments.length?f:e instanceof Error?e:t instanceof Error?t:(O(e,t)?(e=R(e),t=R(t)):(e=F(e),t=F(t)),E(e,t)||e>t)},GTE:function(e,t){return 2!==arguments.length?f:(O(e,t)?(e=R(e),t=R(t)):(e=F(e),t=F(t)),E(e,t)||e>=t)},LT:function(e,t){return 2!==arguments.length?f:(O(e,t)?(e=R(e),t=R(t)):(e=F(e),t=F(t)),E(e,t)||er||s===r&&a{const o=e.getFullYear(),n=new Date(o,2,1);if(ut(o)&&e=n)return!0;const r=t.getFullYear(),l=new Date(r,2,1);return ut(r)&&t>=l&&es||r===s&&n>=i))return(l===a&&ut(l)||o(e,t)||1===s&&29===i)&&(u=366),ct(e,t)/u;const c=a-l+1,f=(new Date(a+1,0,1)-new Date(l,0,1))/1e3/60/60/24/c;return ct(e,t)/f}case 2:return ct(e,t)/360;case 3:return ct(e,t)/365;case 4:return(i+30*s+360*a-(n+30*r+360*l))/360}}function dt(e){const t=e>-22038912e5?2:1;return Math.ceil((e-Qe)/864e5)+t}function pt(e){return 0===(e=F(e))?s:e instanceof Error?e:String.fromCharCode(e)}function bt(e){if(M(e))return e;let t=(e=e||"").charCodeAt(0);return isNaN(t)&&(t=s),t}function jt(){const e=v(arguments),t=E.apply(void 0,e);if(t)return t;let o=0;for(;(o=e.indexOf(!0))>-1;)e[o]="TRUE";let n=0;for(;(n=e.indexOf(!1))>-1;)e[n]="FALSE";return e.join("")}st.INTL=(e,t,o,n)=>{if((e=D(e))instanceof Error)return e;if((t=D(t))instanceof Error)return t;let r=!1;const l=[],i=[1,2,3,4,5,6,0],a=new RegExp("^[0|1]{7}$");if(void 0===o)o=tt[1];else if("string"==typeof o&&a.test(o)){r=!0,o=o.split("");for(let e=0;e0?f.getUTCDay():f.getDay();let t=r?l.includes(e):e===o[0]||e===o[1];for(let e=0;e{if((e=D(e))instanceof Error)return e;if((t=F(t))instanceof Error)return t;if(t<0)return c;if(!((o=void 0===o?tt[1]:tt[o])instanceof Array))return s;void 0===n?n=[]:n instanceof Array||(n=[n]);for(let e=0;e0?"+":"";return e.toString()+n+(1===t?o:t.toString()+o)}}function wt(e,t){return t=void 0===t?0:t,M(e=F(e),t=F(t))?s:n.erf(e)}function At(e){return isNaN(e)?s:n.erfc(e)}function Et(e){const t=Tt(e),o=Mt(e);return M(t,o)?s:Math.sqrt(Math.pow(t,2)+Math.pow(o,2))}function Mt(e){if(void 0===e||!0===e||!1===e)return s;if(0===e||"0"===e)return 0;if(["i","j"].indexOf(e)>=0)return 1;let t=(e=(e+="").replace("+i","+1i").replace("-i","-1i").replace("+j","+1j").replace("-j","-1j")).indexOf("+"),o=e.indexOf("-");0===t&&(t=e.indexOf("+",1)),0===o&&(o=e.indexOf("-",1));const n=e.substring(e.length-1,e.length),r="i"===n||"j"===n;return t>=0||o>=0?r?t>=0?isNaN(e.substring(0,t))||isNaN(e.substring(t+1,e.length-1))?c:Number(e.substring(t+1,e.length-1)):isNaN(e.substring(0,o))||isNaN(e.substring(o+1,e.length-1))?c:-Number(e.substring(o+1,e.length-1)):c:r?isNaN(e.substring(0,e.length-1))?c:e.substring(0,e.length-1):isNaN(e)?c:0}function It(e){const t=Tt(e),o=Mt(e);return M(t,o)?s:0===t&&0===o?i:0===t&&o>0?Math.PI/2:0===t&&o<0?-Math.PI/2:0===o&&t>0?0:0===o&&t<0?-Math.PI:t>0?Math.atan(o/t):t<0&&o>=0?Math.atan(o/t)+Math.PI:Math.atan(o/t)-Math.PI}function Nt(e){const t=Tt(e),o=Mt(e);if(M(t,o))return s;let n=e.substring(e.length-1);return n="i"===n||"j"===n?n:"i",xt(Math.cos(t)*(Math.exp(o)+Math.exp(-o))/2,-Math.sin(t)*(Math.exp(o)-Math.exp(-o))/2,n)}function St(e){const t=Tt(e),o=Mt(e);if(M(t,o))return s;let n=e.substring(e.length-1);return n="i"===n||"j"===n?n:"i",xt(Math.cos(o)*(Math.exp(t)+Math.exp(-t))/2,Math.sin(o)*(Math.exp(t)-Math.exp(-t))/2,n)}function Dt(e,t){const o=Tt(e),n=Mt(e),r=Tt(t),l=Mt(t);if(M(o,n,r,l))return s;const i=e.substring(e.length-1),a=t.substring(t.length-1);let u="i";if(("j"===i||"j"===a)&&(u="j"),0===r&&0===l)return c;const f=r*r+l*l;return xt((o*r+n*l)/f,(n*r-o*l)/f,u)}function Tt(e){if(void 0===e||!0===e||!1===e)return s;if(0===e||"0"===e)return 0;if(["i","+i","1i","+1i","-i","-1i","j","+j","1j","+1j","-j","-1j"].indexOf(e)>=0)return 0;let t=(e+="").indexOf("+"),o=e.indexOf("-");0===t&&(t=e.indexOf("+",1)),0===o&&(o=e.indexOf("-",1));const n=e.substring(e.length-1,e.length),r="i"===n||"j"===n;return t>=0||o>=0?r?t>=0?isNaN(e.substring(0,t))||isNaN(e.substring(t+1,e.length-1))?c:Number(e.substring(0,t)):isNaN(e.substring(0,o))||isNaN(e.substring(o+1,e.length-1))?c:Number(e.substring(0,o)):c:r?isNaN(e.substring(0,e.length-1))?c:0:isNaN(e)?c:e}function Ft(e){const t=Tt(e),o=Mt(e);if(M(t,o))return s;let n=e.substring(e.length-1);return n="i"===n||"j"===n?n:"i",xt(Math.sin(t)*(Math.exp(o)+Math.exp(-o))/2,Math.cos(t)*(Math.exp(o)-Math.exp(-o))/2,n)}function Lt(e){const t=Tt(e),o=Mt(e);if(M(t,o))return s;let n=e.substring(e.length-1);return n="i"===n||"j"===n?n:"i",xt(Math.cos(o)*(Math.exp(t)-Math.exp(-t))/2,Math.sin(o)*(Math.exp(t)+Math.exp(-t))/2,n)}wt.PRECISE=()=>{throw new Error("ERF.PRECISE is not implemented")},At.PRECISE=()=>{throw new Error("ERFC.PRECISE is not implemented")};const Rt=ne.DIST,Ot=ne.INV,kt=re.DIST,Ht=Ve.MATH,Bt=Ve.PRECISE,Pt=le.DIST,_t=le.DIST.RT,Vt=le.INV,Ut=le.INV.RT,qt=le.TEST,zt=ce.P,Yt=ce.P,Wt=ce.S,Xt=re.INV,Gt=At.PRECISE,Kt=wt.PRECISE,$t=fe.DIST,Jt=de.DIST,Qt=de.DIST.RT,Zt=de.INV,eo=de.INV.RT,to=Ye.MATH,oo=Ye.PRECISE,no=de.TEST,ro=be.DIST,lo=be.INV,io=je.PRECISE,so=he.DIST,ao=ve.INV,uo=ve.DIST,co=ve.INV,fo=we.MULT,po=we.SNGL,bo=Ae.DIST,jo=st.INTL,ho=Ee.DIST,go=Ee.INV,mo=Ee.S.DIST,vo=Ee.S.INV,yo=Ie.EXC,Co=Ie.INC,xo=Ne.EXC,wo=Ne.INC,Ao=Se.DIST,Eo=De.EXC,Mo=De.INC,Io=Te.AVG,No=Te.EQ,So=Fe.P,Do=Re.P,To=Re.S,Fo=Oe.DIST,Lo=Oe.DIST.RT,Ro=Oe.INV,Oo=Oe.TEST,ko=ke.P,Ho=ke.S,Bo=Pe.DIST,Po=at.INTL,_o=_e.TEST;function Vo(e){const t=[];return h(e,(e=>{e&&t.push(e)})),t}function Uo(e,t){const o={};for(let t=1;tn&&(n=t[e].length);for(let r=1;r{t+={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1}[e]})),t},t.ASC=function(){throw new Error("ASC is not implemented")},t.ASIN=function(e){if((e=F(e))instanceof Error)return e;let t=Math.asin(e);return isNaN(t)&&(t=c),t},t.ASINH=function(e){return(e=F(e))instanceof Error?e:Math.log(e+Math.sqrt(e*e+1))},t.ATAN=function(e){return(e=F(e))instanceof Error?e:Math.atan(e)},t.ATAN2=function(e,t){return E(e=F(e),t=F(t))||Math.atan2(e,t)},t.ATANH=function(e){if((e=F(e))instanceof Error)return e;let t=Math.log((1+e)/(1-e))/2;return isNaN(t)&&(t=c),t},t.AVEDEV=function(){const e=v(arguments).filter(k);if(0===e.length)return c;const t=L(e);return t instanceof Error?t:n.sum(n(t).subtract(n.mean(t)).abs()[0])/t.length},t.AVERAGE=te,t.AVERAGEA=oe,t.AVERAGEIF=function(e,t,o){if(arguments.length<=1)return f;if(o=L(v(o=o||e).filter(k)),e=v(e),o instanceof Error)return o;let n=0,r=0;const l=void 0===t||"*"===t,i=l?null:Y(t+"");for(let t=0;t=n.length?mt("0",t-n.length)+n:c},t.BIN2OCT=function(e,t){if(!Ct(e))return c;const o=e.toString();if(10===o.length&&"1"===o.substring(0,1))return(1073741312+parseInt(o.substring(1),2)).toString(8);const n=parseInt(e,2).toString(8);return void 0===t?n:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=n.length?mt("0",t-n.length)+n:c},t.BINOM=re,t.BINOMDIST=kt,t.BITAND=function(e,t){return M(e=F(e),t=F(t))?s:e<0||t<0||Math.floor(e)!==e||Math.floor(t)!==t||e>0xffffffffffff||t>0xffffffffffff?c:e&t},t.BITLSHIFT=function(e,t){return M(e=F(e),t=F(t))?s:e<0||Math.floor(e)!==e||e>0xffffffffffff||Math.abs(t)>53?c:t>=0?e<>-t},t.BITOR=function(e,t){return M(e=F(e),t=F(t))?s:e<0||t<0||Math.floor(e)!==e||Math.floor(t)!==t||e>0xffffffffffff||t>0xffffffffffff?c:e|t},t.BITRSHIFT=function(e,t){return M(e=F(e),t=F(t))?s:e<0||Math.floor(e)!==e||e>0xffffffffffff||Math.abs(t)>53?c:t>=0?e>>t:e<<-t},t.BITXOR=function(e,t){return M(e=F(e),t=F(t))?s:e<0||t<0||Math.floor(e)!==e||Math.floor(t)!==t||e>0xffffffffffff||t>0xffffffffffff?c:e^t},t.CEILING=Ve,t.CEILINGMATH=Ht,t.CEILINGPRECISE=Bt,t.CELL=function(){throw new Error("CELL is not implemented")},t.CHAR=pt,t.CHIDIST=Pt,t.CHIDISTRT=_t,t.CHIINV=Vt,t.CHIINVRT=Ut,t.CHISQ=le,t.CHITEST=qt,t.CHOOSE=function(){if(arguments.length<2)return f;const e=arguments[0];return e<1||e>254||arguments.length=0)&&(s=n[e]),(n[e][1]===c||i.indexOf(c)>=0)&&(a=n[e]);if(null===s){const e=r[t.substring(0,2)];let o=l[t.substring(0,1)];"da"===t.substring(0,2)&&(o=["dekao",10,"da"]),e?(d=e[2],u=t.substring(2)):o&&(d=o[1],u=t.substring(o[2].length));for(let e=0;e=0)&&(s=n[e])}if(null===a){const e=r[o.substring(0,2)];let t=l[o.substring(0,1)];"da"===o.substring(0,2)&&(t=["dekao",10,"da"]),e?(p=e[2],c=o.substring(2)):t&&(p=t[1],c=o.substring(t[2].length));for(let e=0;e=0)&&(a=n[e])}return null===s||null===a||s[3]!==a[3]?f:e*s[6]*d/(a[6]*p)},t.CORREL=function(e,t){return M(e=L(v(e)),t=L(v(t)))?s:n.corrcoeff(e,t)},t.COS=function(e){return(e=F(e))instanceof Error?e:Math.cos(e)},t.COSH=function(e){return(e=F(e))instanceof Error?e:(Math.exp(e)+Math.exp(-e))/2},t.COT=function(e){return(e=F(e))instanceof Error?e:0===e?i:1/Math.tan(e)},t.COTH=function(e){if((e=F(e))instanceof Error)return e;if(0===e)return i;const t=Math.exp(2*e);return(t+1)/(t-1)},t.COUNT=se,t.COUNTA=ae,t.COUNTBLANK=ue,t.COUNTIF=function(e,t){if(e=v(e),void 0===t||"*"===t)return e.length;let o=0;const n=Y(t+"");for(let t=0;tr)return c;if(0!==l&&1!==l)return c;const i=Go(e,t,o,0,l);let a=0;1===n&&(0===l&&(a=-o),n++);for(let t=n;t<=r;t++)a+=1===l?Yo(e,t-2,i,o,1)-i:Yo(e,t-1,i,o,0);return a*=e,a},t.CUMPRINC=function(e,t,o,n,r,l){if(M(e=F(e),t=F(t),o=F(o)))return s;if(e<=0||t<=0||o<=0)return c;if(n<1||r<1||n>r)return c;if(0!==l&&1!==l)return c;const i=Go(e,t,o,0,l);let a=0;1===n&&(a=0===l?i+o*e:i,n++);for(let t=n;t<=r;t++)a+=l>0?i-(Yo(e,t-2,i,o,1)-i)*e:i-Yo(e,t-1,i,o,0)*e;return a},t.DATE=function(e,t,o){let n;return M(e=F(e),t=F(t),o=F(o))?n=s:(n=new Date(e,t-1,o),n.getFullYear()<0&&(n=c)),n},t.DATEDIF=ot,t.DATEVALUE=function(e){if("string"!=typeof e)return s;const t=Date.parse(e);return isNaN(t)?s:new Date(e)},t.DAVERAGE=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);let l=0;return h(n,(e=>{l+=r[e]})),0===n.length?i:l/n.length},t.DAY=function(e){const t=D(e);return t instanceof Error?t:t.getDate()},t.DAYS=rt,t.DAYS360=lt,t.DB=function(e,t,o,n,r){if(r=void 0===r?12:r,M(e=F(e),t=F(t),o=F(o),n=F(n),r=F(r)))return s;if(e<0||t<0||o<0||n<0)return c;if(-1===[1,2,3,4,5,6,7,8,9,10,11,12].indexOf(r))return c;if(n>o)return c;if(t>=e)return 0;const l=(1-Math.pow(t/e,1/o)).toFixed(3),i=e*l*r/12;let a=i,u=0;const f=n===o?o-1:n;for(let t=2;t<=f;t++)u=(e-a)*l,a+=u;return 1===n?i:n===o?(e-a)*l:u},t.DBCS=function(){throw new Error("DBCS is not implemented")},t.DCOUNT=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);const l=[];return h(n,(e=>{l.push(r[e])})),se(l)},t.DCOUNTA=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);const l=[];return h(n,(e=>{l.push(r[e])})),ae(l)},t.DDB=function(e,t,o,n,r){if(r=void 0===r?2:r,M(e=F(e),t=F(t),o=F(o),n=F(n),r=F(r)))return s;if(e<0||t<0||o<0||n<0||r<=0)return c;if(n>o)return c;if(t>=e)return 0;let l=0,i=0;for(let s=1;s<=n;s++)i=Math.min(r/o*(e-l),e-t-l),l+=i;return i},t.DEC2BIN=function(e,t){if((e=F(e))instanceof Error)return e;if(!/^-?[0-9]{1,3}$/.test(e)||e<-512||e>511)return c;if(e<0)return"1"+mt("0",9-(512+e).toString(2).length)+(512+e).toString(2);const o=parseInt(e,10).toString(2);return void 0===t?o:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=o.length?mt("0",t-o.length)+o:c},t.DEC2HEX=function(e,t){if((e=F(e))instanceof Error)return e;if(!/^-?[0-9]{1,12}$/.test(e)||e<-549755813888||e>549755813887)return c;if(e<0)return(1099511627776+e).toString(16);const o=parseInt(e,10).toString(16);return void 0===t?o:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=o.length?mt("0",t-o.length)+o:c},t.DEC2OCT=function(e,t){if((e=F(e))instanceof Error)return e;if(!/^-?[0-9]{1,9}$/.test(e)||e<-536870912||e>536870911)return c;if(e<0)return(1073741824+e).toString(8);const o=parseInt(e,10).toString(8);return void 0===t?o:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=o.length?mt("0",t-o.length)+o:c},t.DECIMAL=function(e,t){return arguments.length<1?s:E(e=F(e),t=F(t))||(0===t?c:parseInt(e,t))},t.DEGREES=function(e){return(e=F(e))instanceof Error?e:180*e/Math.PI},t.DELTA=function(e,t){return t=void 0===t?0:t,M(e=F(e),t=F(t))?s:e===t?1:0},t.DEVSQ=function(){const e=L(v(arguments));if(e instanceof Error)return e;const t=n.mean(e);let o=0;for(let n=0;n1?c:r[n[0]]},t.DISC=function(e,t,o,n,r){if(M(e=D(e),t=D(t),o=F(o),n=F(n),r=(r=F(r))||0))return s;if(o<=0||n<=0)return c;if(e>=t)return s;let l,i;switch(r){case 0:l=360,i=lt(e,t,!1);break;case 1:case 3:l=365,i=ot(e,t,"D");break;case 2:l=360,i=ot(e,t,"D");break;case 4:l=360,i=lt(e,t,!0);break;default:return c}return(n-o)/n*l/i},t.DMAX=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);let l=r[n[0]];return h(n,(e=>{l{l>r[e]&&(l=r[e])})),l},t.DOLLAR=function(e,t=2){if(e=F(e),isNaN(e))return s;const o={style:"currency",currency:"USD",minimumFractionDigits:t>=0?t:0,maximumFractionDigits:t>=0?t:0},n=(e=Ke(e,t)).toLocaleString("en-US",o);return e<0?"$("+n.slice(2)+")":n},t.DOLLARDE=function(e,t){if(M(e=F(e),t=F(t)))return s;if(t<0)return c;if(t>=0&&t<1)return i;t=parseInt(t,10);let o=parseInt(e,10);o+=e%1*Math.pow(10,Math.ceil(Math.log(t)/Math.LN10))/t;const n=Math.pow(10,Math.ceil(Math.log(t)/Math.LN2)+1);return o=Math.round(o*n)/n,o},t.DOLLARFR=function(e,t){if(M(e=F(e),t=F(t)))return s;if(t<0)return c;if(t>=0&&t<1)return i;t=parseInt(t,10);let o=parseInt(e,10);return o+=e%1*Math.pow(10,-Math.ceil(Math.log(t)/Math.LN10))*t,o},t.DPRODUCT=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);let l=[];h(n,(e=>{l.push(r[e])})),l=Vo(l);let i=1;return h(l,(e=>{i*=e})),i},t.DSTDEV=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);let l=[];return h(n,(e=>{l.push(r[e])})),l=Vo(l),Re.S(l)},t.DSTDEVP=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);let l=[];return h(n,(e=>{l.push(r[e])})),l=Vo(l),Re.P(l)},t.DSUM=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);const l=[];return h(n,(e=>{l.push(r[e])})),$e(l)},t.DURATION=function(){throw new Error("DURATION is not implemented")},t.DVAR=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);const l=[];return h(n,(e=>{l.push(r[e])})),ke.S(l)},t.DVARP=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);const l=[];return h(n,(e=>{l.push(r[e])})),ke.P(l)},t.EDATE=function(e,t){return(e=D(e))instanceof Error?e:isNaN(t)?s:(t=parseInt(t,10),e.setMonth(e.getMonth()+t),e)},t.EFFECT=function(e,t){return M(e=F(e),t=F(t))?s:e<=0||t<1?c:(t=parseInt(t,10),Math.pow(1+e/t,t)-1)},t.EOMONTH=function(e,t){return(e=D(e))instanceof Error?e:isNaN(t)?s:(t=parseInt(t,10),new Date(e.getFullYear(),e.getMonth()+t+1,0))},t.ERF=wt,t.ERFC=At,t.ERFCPRECISE=Gt,t.ERFPRECISE=Kt,t.ERROR=X,t.EVEN=function(e){return(e=F(e))instanceof Error?e:Ve(e,-2,-1)},t.EXACT=function(e,t){return 2!==arguments.length?f:E(e,t)||(e=R(e))===R(t)},t.EXP=function(e){return arguments.length<1?f:arguments.length>1?d:(e=F(e))instanceof Error?e:e=Math.exp(e)},t.EXPON=fe,t.EXPONDIST=$t,t.F=de,t.FACT=ze,t.FACTDOUBLE=function e(t){if((t=F(t))instanceof Error)return t;const o=Math.floor(t);return o<=0?1:o*e(o-2)},t.FALSE=function(){return!1},t.FDIST=Jt,t.FDISTRT=Qt,t.FIND=function(e,t,o){if(arguments.length<2)return f;e=R(e),o=void 0===o?0:o;const n=(t=R(t)).indexOf(e,o-1);return-1===n?s:n+1},t.FINV=Zt,t.FINVRT=eo,t.FISHER=function(e){return(e=F(e))instanceof Error?e:Math.log((1+e)/(1-e))/2},t.FISHERINV=function(e){if((e=F(e))instanceof Error)return e;const t=Math.exp(2*e);return(t-1)/(t+1)},t.FIXED=gt,t.FLOOR=Ye,t.FLOORMATH=to,t.FLOORPRECISE=oo,t.FORECAST=pe,t.FREQUENCY=function(e,t){if(M(e=L(v(e)),t=L(v(t))))return s;const o=e.length,n=t.length,r=[];for(let l=0;l<=n;l++){r[l]=0;for(let i=0;it[l-1]&&e[i]<=t[l]&&(r[l]+=1):l===n&&e[i]>t[n-1]&&(r[n]+=1)}return r},t.FTEST=no,t.FV=Yo,t.FVSCHEDULE=function(e,t){if(M(e=F(e),t=L(v(t))))return s;const o=t.length;let n=e;for(let e=0;er?n%=r:r%=n;n+=r}return n},t.GEOMEAN=function(){const e=L(v(arguments));return e instanceof Error?e:n.geomean(e)},t.GESTEP=function(e,t){return M(t=t||0,e=F(e))?e:e>=t?1:0},t.GROWTH=function(e,t,o,n){if((e=L(e))instanceof Error)return e;let r;if(void 0===t)for(t=[],r=1;r<=e.length;r++)t.push(r);if(void 0===o)for(o=[],r=1;r<=e.length;r++)o.push(r);if(M(t=L(t),o=L(o)))return s;void 0===n&&(n=!0);const l=e.length;let i,a,u=0,c=0,f=0,d=0;for(r=0;r511)return c;if(o)return"1"+mt("0",9-(512+n).toString(2).length)+(512+n).toString(2);const r=n.toString(2);return void 0===t?r:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=r.length?mt("0",t-r.length)+r:c},t.HEX2DEC=function(e){if(!/^[0-9A-Fa-f]{1,10}$/.test(e))return c;const t=parseInt(e,16);return t>=549755813888?t-1099511627776:t},t.HEX2OCT=function(e,t){if(!/^[0-9A-Fa-f]{1,10}$/.test(e))return c;const o=parseInt(e,16);if(o>536870911&&o<0xffe0000000)return c;if(o>=0xffe0000000)return(o-0xffc0000000).toString(8);const n=o.toString(8);return void 0===t?n:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=n.length?mt("0",t-n.length)+n:c},t.HLOOKUP=function(e,t,o,n){return ee(e,w(t),o,n)},t.HOUR=function(e){return(e=D(e))instanceof Error?e:e.getHours()},t.HYPGEOM=he,t.HYPGEOMDIST=so,t.IF=function(e,t,o){return e instanceof Error?e:(null==(t=!(arguments.length>=2)||t)&&(t=0),null==(o=3===arguments.length&&o)&&(o=0),e?t:o)},t.IFERROR=function(e,t){return K(e)?t:e},t.IFNA=function(e,t){return e===f?t:e},t.IFS=function(){for(let e=0;e0&&!Array.isArray(e[0]);return r&&!o?(o=t,t=1):(o=o||1,t=t||1),o<0||t<0?s:r&&1===t&&o<=e.length?e[o-1]:t<=e.length&&o<=e[t-1].length?e[t-1][o-1]:a},t.INFO=function(){throw new Error("INFO is not implemented")},t.INT=function(e){return(e=F(e))instanceof Error?e:Math.floor(e)},t.INTERCEPT=function(e,t){return M(e=L(e),t=L(t))?s:e.length!==t.length?f:pe(0,e,t)},t.INTRATE=function(){throw new Error("INTRATE is not implemented")},t.IPMT=Wo,t.IRR=function(e,t){if(t=t||0,M(e=L(v(e)),t=F(t)))return s;const o=(e,t,o)=>{const n=o+1;let r=e[0];for(let o=1;o{const n=o+1;let r=0;for(let o=1;o0&&(l=!0),e[t]<0&&(i=!0);if(!l||!i)return c;let a,u,f,d=t=void 0===t?.1:t,p=!0;do{f=o(e,r,d),a=d-f/n(e,r,d),u=Math.abs(a-d),d=a,p=u>1e-10&&Math.abs(f)>1e-10}while(p);return d},t.ISBLANK=function(e){return null===e},t.ISERR=G,t.ISERROR=K,t.ISEVEN=function(e){return!(1&Math.floor(Math.abs(e)))},t.ISFORMULA=function(){throw new Error("ISFORMULA is not implemented")},t.ISLOGICAL=$,t.ISNA=function(e){return e===f},t.ISNONTEXT=function(e){return"string"!=typeof e},t.ISNUMBER=J,t.ISO=We,t.ISODD=function(e){return!!(1&Math.floor(Math.abs(e)))},t.ISOWEEKNUM=it,t.ISPMT=function(e,t,o,n){return M(e=F(e),t=F(t),o=F(o),n=F(n))?s:n*e*(t/o-1)},t.ISREF=function(){throw new Error("ISREF is not implemented")},t.ISTEXT=Q,t.KURT=function(){const e=L(v(arguments));if(e instanceof Error)return e;const t=n.mean(e),o=e.length;let r=0;for(let n=0;n1;){if(n%2){for(t=3,o=Math.floor(Math.sqrt(n));t<=o&&n%t;t+=2);r=t<=o?t:n}else r=2;for(n/=r,l*=r,t=e.length;t;e[--t]%r==0&&1==(e[t]/=r)&&e.splice(t,1));}}return l},t.LEFT=function(e,t){return E(e,t)||(e=R(e),(t=F(t=void 0===t?1:t))instanceof Error||"string"!=typeof e?s:e.substring(0,t))},t.LEN=function(e){return 0===arguments.length?d:e instanceof Error?e:Array.isArray(e)?s:R(e).length},t.LINEST=me,t.LN=function(e){return(e=F(e))instanceof Error?e:0===e?c:Math.log(e)},t.LOG=function(e,t){return E(e=F(e),t=F(t))||(0===e||0===t?c:Math.log(e)/Math.log(t))},t.LOG10=function(e){return(e=F(e))instanceof Error?e:0===e?c:Math.log(e)/Math.log(10)},t.LOGEST=function(e,t){if(M(e=L(v(e)),t=L(v(t))))return s;if(e.length!==t.length)return s;for(let t=0;te)return r}return r},t.LOWER=function(e){return 1!==arguments.length?s:M(e=R(e))?e:e.toLowerCase()},t.MATCH=function(e,t,o){if(!e||!t)return f;if(2===arguments.length&&(o=1),!((t=v(t))instanceof Array))return f;if(-1!==o&&0!==o&&1!==o)return f;let n,r;for(let l=0;lr&&(n=l+1,r=t[l]):(n=l+1,r=t[l]))}else if(0===o){if("string"==typeof e&&"string"==typeof t[l]){const o=e.toLowerCase().replace(/\?/g,".").replace(/\*/g,".*").replace(/~/g,"\\");if(new RegExp("^"+o+"$").test(t[l].toLowerCase()))return l+1}else if(t[l]===e)return l+1}else if(-1===o){if(t[l]===e)return l+1;t[l]>e&&(r?t[l]null==e?0:e)),0===o.length?0:Math.max.apply(Math,o)},t.MDURATION=function(){throw new Error("MDURATION is not implemented")},t.MEDIAN=Ce,t.MID=function(e,t,o){if(null==t)return s;if(M(t=F(t),o=F(o))||"string"!=typeof e)return o;const n=t-1,r=n+o;return e.substring(n,r)},t.MIN=xe,t.MINA=function(){const e=v(arguments),t=E.apply(void 0,e);if(t)return t;let o=g(e);return o=o.map((e=>null==e?0:e)),0===o.length?0:Math.min.apply(Math,o)},t.MINUTE=function(e){return(e=D(e))instanceof Error?e:e.getMinutes()},t.MIRR=function(e,t,o){if(M(e=L(v(e)),t=F(t),o=F(o)))return s;const n=e.length,r=[],l=[];for(let t=0;t!e.length))||t.some((e=>!e.length))||y(e).some((e=>"number"!=typeof e))||y(t).some((e=>"number"!=typeof e))||e[0].length!==t.length?s:Array(e.length).fill(0).map((()=>Array(t[0].length).fill(0))).map(((o,n)=>o.map(((o,r)=>e[n].reduce(((e,o,n)=>e+o*t[n][r]),0)))))},t.MOD=function(e,t){const o=E(e=F(e),t=F(t));if(o)return o;if(0===t)return i;let n=Math.abs(e%t);return n=e<0?t-n:n,t>0?n:-n},t.MODE=we,t.MODEMULT=fo,t.MODESNGL=po,t.MONTH=function(e){return(e=D(e))instanceof Error?e:e.getMonth()+1},t.MROUND=function(e,t){return E(e=F(e),t=F(t))||(e*t==0?0:e*t<0?c:Math.round(e/t)*t)},t.MULTINOMIAL=function(){const e=L(v(arguments));if(e instanceof Error)return e;let t=0,o=1;for(let n=0;n1?f:!(e=parseInt(e))||e<=0?s:Array(e).fill(0).map((()=>Array(e).fill(0))).map(((e,t)=>(e[t]=1,e)))},t.N=function(e){return J(e)?e:e instanceof Date?e.getTime():!0===e?1:!1===e?0:K(e)?e:0},t.NA=function(){return f},t.NEGBINOM=Ae,t.NEGBINOMDIST=bo,t.NETWORKDAYS=st,t.NETWORKDAYSINTL=jo,t.NOMINAL=function(e,t){return M(e=F(e),t=F(t))?s:e<=0||t<1?c:(t=parseInt(t,10),(Math.pow(e+1,1/t)-1)*t)},t.NORM=Ee,t.NORMDIST=ho,t.NORMINV=go,t.NORMSDIST=mo,t.NORMSINV=vo,t.NOT=function(e){return"string"==typeof e?s:e instanceof Error?e:!e},t.NOW=function(){return new Date},t.NPER=function(e,t,o,n,r){if(r=void 0===r?0:r,n=void 0===n?0:n,M(e=F(e),t=F(t),o=F(o),n=F(n),r=F(r)))return s;if(0===e)return-(o+n)/t;{const l=t*(1+e*r)-n*e,i=o*e+t*(1+e*r);return Math.log(l/i)/Math.log(1+e)}},t.NPV=Xo,t.NUMBERVALUE=function(e,t,o){return"number"==typeof(e=k(e)?e:"")?e:"string"!=typeof e?f:(t=void 0===t?".":t,o=void 0===o?",":o,Number(e.replace(t,".").replace(o,"")))},t.OCT2BIN=function(e,t){if(!/^[0-7]{1,10}$/.test(e))return c;const o=!(10!==e.length||"7"!==e.substring(0,1)),n=o?parseInt(e,8)-1073741824:parseInt(e,8);if(n<-512||n>511)return c;if(o)return"1"+mt("0",9-(512+n).toString(2).length)+(512+n).toString(2);const r=n.toString(2);return void 0===t?r:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=r.length?mt("0",t-r.length)+r:c},t.OCT2DEC=function(e){if(!/^[0-7]{1,10}$/.test(e))return c;const t=parseInt(e,8);return t>=536870912?t-1073741824:t},t.OCT2HEX=function(e,t){if(!/^[0-7]{1,10}$/.test(e))return c;const o=parseInt(e,8);if(o>=536870912)return"ff"+(o+3221225472).toString(16);const n=o.toString(16);return void 0===t?n:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=n.length?mt("0",t-n.length)+n:c},t.ODD=function(e){if((e=F(e))instanceof Error)return e;let t=Math.ceil(Math.abs(e));return t=1&t?t:t+1,e>=0?t:-t},t.ODDFPRICE=function(){throw new Error("ODDFPRICE is not implemented")},t.ODDFYIELD=function(){throw new Error("ODDFYIELD is not implemented")},t.ODDLPRICE=function(){throw new Error("ODDLPRICE is not implemented")},t.ODDLYIELD=function(){throw new Error("ODDLYIELD is not implemented")},t.OR=function(){const e=v(arguments);let t=s;for(let o=0;o=t)return s;let l,i;switch(r){case 0:l=360,i=lt(e,t,!1);break;case 1:case 3:l=365,i=ot(e,t,"D");break;case 2:l=360,i=ot(e,t,"D");break;case 4:l=360,i=lt(e,t,!0);break;default:return c}return n-o*n*i/l},t.PRICEMAT=function(){throw new Error("PRICEMAT is not implemented")},t.PROB=function(e,t,o,n){if(void 0===o)return 0;if(n=void 0===n?o:n,M(e=L(v(e)),t=L(v(t)),o=F(o),n=F(n)))return s;if(o===n)return e.indexOf(o)>=0?t[e.indexOf(o)]:0;const r=e.sort(((e,t)=>e-t)),l=r.length;let i=0;for(let s=0;s=o&&r[s]<=n&&(i+=t[e.indexOf(r[s])]);return i},t.PRODUCT=Ge,t.PRONETIC=function(){throw new Error("PRONETIC is not implemented")},t.PROPER=function(e){return M(e)?e:isNaN(e)&&"number"==typeof e?s:(e=R(e)).replace(/\w\S*/g,(e=>e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()))},t.PV=function(e,t,o,n,r){return n=n||0,r=r||0,M(e=F(e),t=F(t),o=F(o),n=F(n),r=F(r))?s:0===e?-o*t-n:((1-Math.pow(1+e,t))/e*o*(1+e*r)-n)/Math.pow(1+e,t)},t.QUARTILE=De,t.QUARTILEEXC=Eo,t.QUARTILEINC=Mo,t.QUOTIENT=function(e,t){return E(e=F(e),t=F(t))||parseInt(e/t,10)},t.RADIANS=function(e){return(e=F(e))instanceof Error?e:e*Math.PI/180},t.RAND=function(){return Math.random()},t.RANDBETWEEN=function(e,t){return E(e=F(e),t=F(t))||e+Math.ceil((t-e+1)*Math.random())-1},t.RANK=Te,t.RANKAVG=Io,t.RANKEQ=No,t.RATE=function(e,t,o,n,r,l){if(l=void 0===l?.01:l,n=void 0===n?0:n,r=void 0===r?0:r,M(e=F(e),t=F(t),o=F(o),n=F(n),r=F(r),l=F(l)))return s;const i=1e-10;let a=l;r=r?1:0;for(let l=0;l<20;l++){if(a<=-1)return c;let l,s,u;if(Math.abs(a)0?1:-1)*Math.floor(Math.abs(e)*Math.pow(10,t))/Math.pow(10,t)},t.ROUNDUP=function(e,t){return E(e=F(e),t=F(t))||(e>0?1:-1)*Math.ceil(Math.abs(e)*Math.pow(10,t))/Math.pow(10,t)},t.ROW=function(e,t){return 2!==arguments.length?f:t<0?c:e instanceof Array&&"number"==typeof t?0!==e.length?n.row(e,t):void 0:s},t.ROWS=function(e){return 1!==arguments.length?f:e instanceof Array?0===e.length?0:n.rows(e):s},t.RRI=function(e,t,o){return M(e=F(e),t=F(t),o=F(o))?s:0===e||0===t?c:Math.pow(o/t,1/e)-1},t.RSQ=function(e,t){return M(e=L(v(e)),t=L(v(t)))?s:Math.pow(Me(e,t),2)},t.SEARCH=function(e,t,o){let n;return"string"!=typeof e||"string"!=typeof t?s:(o=void 0===o?0:o,n=t.toLowerCase().indexOf(e.toLowerCase(),o-1)+1,0===n?s:n)},t.SEC=function(e){return(e=F(e))instanceof Error?e:1/Math.cos(e)},t.SECH=function(e){return(e=F(e))instanceof Error?e:2/(Math.exp(e)+Math.exp(-e))},t.SECOND=function(e){return(e=D(e))instanceof Error?e:e.getSeconds()},t.SERIESSUM=function(e,t,o,n){if(M(e=F(e),t=F(t),o=F(o),n=L(n)))return s;let r=n[0]*Math.pow(e,t);for(let l=1;le.sort(((e,n)=>(e=R(e[t-1]),n=R(n[t-1]),1===o?en?o:-1*o))),l=m(e),i=n?w(l):l;return t>=1&&t<=i[0].length?n?w(r(i)):r(i):s},t.SQRT=function(e){return(e=F(e))instanceof Error?e:e<0?c:Math.sqrt(e)},t.SQRTPI=function(e){return(e=F(e))instanceof Error?e:Math.sqrt(e*Math.PI)},t.STANDARDIZE=function(e,t,o){return M(e=F(e),t=F(t),o=F(o))?s:(e-t)/o},t.STDEV=Re,t.STDEVA=function(){const e=He.apply(this,arguments);return Math.sqrt(e)},t.STDEVP=Do,t.STDEVPA=function(){const e=Be.apply(this,arguments);let t=Math.sqrt(e);return isNaN(t)&&(t=c),t},t.STDEVS=To,t.STEYX=function(e,t){if(M(e=L(v(e)),t=L(v(t))))return s;const o=n.mean(t),r=n.mean(e),l=t.length;let i=0,a=0,u=0;for(let n=0;n-1&&e.indexOf(t,r)>-1;)if(r=e.indexOf(t,r+1),l++,r>-1&&l===n)return e.substring(0,r)+o+e.substring(r+t.length);return e}}return e},t.SUBTOTAL=function(e,t){if((e=F(e))instanceof Error)return e;switch(e){case 1:case 101:return te(t);case 2:case 102:return se(t);case 3:case 103:return ae(t);case 4:case 104:return ye(t);case 5:case 105:return xe(t);case 6:case 106:return Ge(t);case 7:case 107:return Re.S(t);case 8:case 108:return Re.P(t);case 9:case 109:return $e(t);case 10:case 110:return ke.S(t);case 11:case 111:return ke.P(t)}},t.SUM=$e,t.SUMIF=function(e,t,o){if(e=v(e),o=o?v(o):e,e instanceof Error)return e;if(null==t||t instanceof Error)return 0;let n=0;const r="*"===t,l=r?null:Y(t+"");for(let t=0;t0){const t=arguments[0],o=arguments.length-1,n=Math.floor(o/2);let r=!1;const l=o%2!=0,i=o%2==0?null:arguments[arguments.length-1];if(n)for(let o=0;oo?c:(e-t)*(o-(n=parseInt(n,10))+1)*2/(o*(o+1))},t.T=function(e){return e instanceof Error||"string"==typeof e?e:""},t.TAN=function(e){return(e=F(e))instanceof Error?e:Math.tan(e)},t.TANH=function(e){if((e=F(e))instanceof Error)return e;const t=Math.exp(2*e);return(t-1)/(t+1)},t.TBILLEQ=function(e,t,o){return M(e=D(e),t=D(t),o=F(o))?s:o<=0||e>t||t-e>31536e6?c:365*o/(360-o*lt(e,t,!1))},t.TBILLPRICE=function(e,t,o){return M(e=D(e),t=D(t),o=F(o))?s:o<=0||e>t||t-e>31536e6?c:100*(1-o*lt(e,t,!1)/360)},t.TBILLYIELD=function(e,t,o){return M(e=D(e),t=D(t),o=F(o))?s:o<=0||e>t||t-e>31536e6?c:360*(100-o)/(o*lt(e,t,!1))},t.TDIST=Fo,t.TDISTRT=Lo,t.TEXT=function(e,t){if(void 0===e||e instanceof Error||t instanceof Error)return f;if(null==t)return"";if("number"==typeof t)return String(t);if("string"!=typeof t)return s;const o=t.startsWith("$")?"$":"",n=t.endsWith("%");return n&&(e*=100),e=(e=gt(e,(t=t.replace(/%/g,"").replace(/\$/g,"")).split(".")[1].match(/0/g).length,!t.includes(","))).startsWith("-")?"-"+o+(e=e.replace("-","")):o+e,n&&(e+="%"),e},t.TEXTJOIN=function(e,t,...o){if("boolean"!=typeof t&&(t=S(t)),arguments.length<3)return f;e=null!=e?e:"";let n=v(o),r=t?n.filter((e=>e)):n;if(Array.isArray(e)){e=v(e);let t=r.map((e=>[e])),o=0;for(let n=0;n{i.push(r*e+l)})),i},t.TRIM=function(e){return(e=R(e))instanceof Error?e:e.replace(/\s+/g," ").trim()},t.TRIMMEAN=function(e,t){if(M(e=L(v(e)),t=F(t)))return s;const o=Ye(e.length*t,2)/2;return n.mean((l=(l=o)||1,(r=x(e.sort(((e,t)=>e-t)),o))&&"function"==typeof r.slice?r.slice(0,r.length-l):r));var r,l},t.TRUE=function(){return!0},t.TRUNC=function(e,t){return E(e=F(e),t=F(t))||(e>0?1:-1)*Math.floor(Math.abs(e)*Math.pow(10,t))/Math.pow(10,t)},t.TTEST=Oo,t.TYPE=function(e){return J(e)?1:Q(e)?2:$(e)?4:K(e)?16:Array.isArray(e)?64:void 0},t.UNICHAR=vt,t.UNICODE=yt,t.UNIQUE=Z,t.UPPER=function(e){return(e=R(e))instanceof Error?e:e.toUpperCase()},t.VALUE=function(e){const t=E(e);if(t)return t;if("number"==typeof e)return e;if(k(e)||(e=""),"string"!=typeof e)return s;const o=/(%)$/.test(e)||/^(%)/.test(e);if(""===(e=(e=(e=e.replace(/^[^0-9-]{0,3}/,"")).replace(/[^0-9]{0,3}$/,"")).replace(/[ ,]/g,"")))return 0;let n=Number(e);return isNaN(n)?s:(n=n||0,o&&(n*=.01),n)},t.VAR=ke,t.VARA=He,t.VARP=ko,t.VARPA=Be,t.VARS=Ho,t.VDB=function(){throw new Error("VDB is not implemented")},t.VLOOKUP=ee,t.WEEKDAY=function(e,t){if((e=D(e))instanceof Error)return e;void 0===t&&(t=1);const o=e.getDay();return et[t][o]},t.WEEKNUM=function(e,t){if((e=D(e))instanceof Error)return e;if(void 0===t&&(t=1),21===t)return it(e);const o=Ze[t];let n=new Date(e.getFullYear(),0,1);const r=n.getDay(){const n=o+1;let r=e[0];for(let o=1;o{const n=o+1;let r=0;for(let o=1;o0&&(l=!0),e[t]<0&&(i=!0);if(!l||!i)return c;let a,u,f,d=o=o||.1,p=!0;do{f=n(e,t,d),a=d-f/r(e,t,d),u=Math.abs(a-d),d=a,p=u>1e-10&&Math.abs(f)>1e-10}while(p);return d},t.XNPV=function(e,t,o){if(M(e=F(e),t=L(v(t)),o=T(v(o))))return s;let n=0;for(let r=0;re&&(e=t.length)}obj.options.minDimensions[0]>e&&(e=obj.options.minDimensions[0]);for(var o=[],n=0;n0&&obj.options.paginationOptions&&obj.options.paginationOptions.length>0){obj.paginationDropdown=document.createElement("select"),obj.paginationDropdown.classList.add("jexcel_pagination_dropdown"),obj.paginationDropdown.onchange=function(){obj.options.pagination=parseInt(this.value),obj.page(0)};for(var n=0;n0)if(obj.options.nestedHeaders[0]&&obj.options.nestedHeaders[0][0])for(var s=0;sr?i:r,u=s>l?s:l;for(t=0;t=c&&t0&&r++}return o},obj.getJsonRow=function(e){for(var t=obj.options.data[e],o=obj.options.columns.length,n={},r=0;r200)&&(n.style.whiteSpace="pre-wrap"),e>0&&1==this.options.textOverflow&&(o||n.innerHTML?obj.records[t][e-1].style.overflow="hidden":e==obj.options.columns.length-1&&(n.style.overflow="hidden")),n},obj.createCellHeader=function(e){var t=obj.options.columns[e].width?obj.options.columns[e].width:obj.options.defaultColWidth,o=obj.options.columns[e].align?obj.options.columns[e].align:obj.options.defaultColAlign;obj.headers[e]=document.createElement("td"),obj.options.stripHTML?obj.headers[e].textContent=obj.options.columns[e].title?obj.options.columns[e].title:jexcel.getColumnName(e):obj.headers[e].innerHTML=obj.options.columns[e].title?obj.options.columns[e].title:jexcel.getColumnName(e),obj.headers[e].setAttribute("data-x",e),obj.headers[e].style.textAlign=o,obj.options.columns[e].title&&obj.headers[e].setAttribute("title",obj.headers[e].innerText),obj.options.columns[e].id&&obj.headers[e].setAttribute("id",obj.options.columns[e].id),obj.colgroup[e]=document.createElement("col"),obj.colgroup[e].setAttribute("width",t),"hidden"==obj.options.columns[e].type&&(obj.headers[e].style.display="none",obj.colgroup[e].style.display="none")},obj.updateNestedHeader=function(e,t,o){obj.options.nestedHeaders[t][e].title&&(obj.options.nestedHeaders[t][e].title=o,obj.options.nestedHeaders[t].element.children[e+1].textContent=o)},obj.createNestedHeader=function(e){var t=document.createElement("tr");t.classList.add("jexcel_nested");var o=document.createElement("td");t.appendChild(o),e.element=t;for(var n=0,r=0;r1?obj.records[u[1]][u[0]].setAttribute("colspan",t):t=1,o>1?obj.records[u[1]][u[0]].setAttribute("rowspan",o):o=1,obj.options.mergeCells[e]=[t,o,[]],obj.records[u[1]][u[0]].setAttribute("data-merged","true"),obj.records[u[1]][u[0]].style.overflow="hidden";for(var d=[],p=u[1];p0||s>0)&&(obj.records[n[1]+i][n[0]+s]=r[2][l],obj.records[n[1]+i][n[0]+s].style.display="",t&&t[l]&&obj.updateCell(n[0]+s,n[1]+i,t[l]),l++);obj.updateSelection(obj.records[n[1]][n[0]],obj.records[n[1]+i-1][n[0]+s-1]),o||delete obj.options.mergeCells[e]}},obj.destroyMerged=function(e){if(obj.options.mergeCells){obj.options.mergeCells;for(var t=Object.keys(obj.options.mergeCells),o=0;o1?i-1:0);null==t?s<=e&&a>=e&&o.push(n[r]):t?s=e&&o.push(n[r]):s<=e&&a>e&&o.push(n[r])}return o},obj.isRowMerged=function(e,t){var o=[];if(obj.options.mergeCells)for(var n=Object.keys(obj.options.mergeCells),r=0;r1?i-1:0);null==t?s<=e&&a>=e&&o.push(n[r]):t?s=e&&o.push(n[r]):s<=e&&a>e&&o.push(n[r])}return o},obj.openFilter=function(e){if(obj.options.filters){e=parseInt(e),obj.resetSelection();var t=[];if("checkbox"==obj.options.columns[e].type)t.push({id:"true",name:"True"}),t.push({id:"false",name:"False"});else{for(var o=[],n=!1,r=0;r0&&(obj.records[n][r-1].style.overflow="hidden");var l=function(t){var o=e.getBoundingClientRect(),l=document.createElement(t);return l.style.width=o.width+"px",l.style.height=o.height-2+"px",l.style.minHeight=o.height-2+"px",e.classList.add("editor"),e.innerHTML="",e.appendChild(l),obj.dispatch("oncreateeditor",el,e,r,n,l),l};if(1==e.classList.contains("readonly"));else if(obj.edition=[obj.records[n][r],obj.records[n][r].innerHTML,r,n],obj.options.columns[r].editor)obj.options.columns[r].editor.openEditor(e,el,t,o);else if("hidden"==obj.options.columns[r].type);else if("checkbox"==obj.options.columns[r].type||"radio"==obj.options.columns[r].type){var i=!e.children[0].checked;obj.setValue(e,i),obj.edition=null}else if("dropdown"==obj.options.columns[r].type||"autocomplete"==obj.options.columns[r].type){if(i=obj.options.data[n][r],obj.options.columns[r].multiple&&!Array.isArray(i)&&(i=i.split(";")),"function"==typeof obj.options.columns[r].filter)var s=obj.options.columns[r].filter(el,e,r,n,obj.options.columns[r].source);else s=obj.options.columns[r].source;for(var a=[],u=0;u0)for(var s=0;s200)?obj.records[t][e].style.whiteSpace="pre-wrap":obj.records[t][e].style.whiteSpace="";e>0&&(obj.records[t][e-1].style.overflow=o?"hidden":""),obj.dispatch("onchange",el,obj.records[t]&&obj.records[t][e]?obj.records[t][e]:null,e,t,o,c.oldValue)}else var c={x:e,y:t,col:e,row:t};return c},obj.copyData=function(e,t){var o=obj.getData(!0,!0),n=obj.selectedContainer,r=parseInt(e.getAttribute("data-x")),l=parseInt(e.getAttribute("data-y")),i=parseInt(t.getAttribute("data-x")),s=parseInt(t.getAttribute("data-y")),a=[],u=!1;if(n[0]==r){if(l=obj.selectedCell[1]&&t<=obj.selectedCell[3]||o>=obj.selectedCell[1]&&o<=obj.selectedCell[3]))return void obj.resetSelection()}else if(obj.selectedCell&&(t>=obj.selectedCell[0]&&t<=obj.selectedCell[2]||o>=obj.selectedCell[0]&&o<=obj.selectedCell[2]))return void obj.resetSelection()},obj.resetSelection=function(e){if(obj.highlighted.length){u=1;for(var t=0;t0?o+(r-1):o,s=l>0?n+(l-1):n;else i=o,s=n;for(var a=o;a<=i;a++)obj.headers[a]&&obj.headers[a].classList.remove("selected");for(a=n;a<=s;a++)obj.rows[a]&&obj.rows[a].classList.remove("selected")}}else var u=0;return obj.highlighted=[],obj.selectedCell=null,obj.corner.style.top="-2000px",obj.corner.style.left="-2000px",1==e&&1==u&&obj.dispatch("onblur",el),u},obj.updateSelection=function(e,t,o){var n=e.getAttribute("data-x"),r=e.getAttribute("data-y");if(t)var l=t.getAttribute("data-x"),i=t.getAttribute("data-y");else l=n,i=r;obj.updateSelectionFromCoords(n,r,l,i,o)},obj.updateSelectionFromCoords=function(e,t,o,n,r){var l=obj.resetSelection();if(null==t&&(t=0,n=obj.rows.length-1),null==o&&(o=e),null==n&&(n=t),e>=obj.headers.length&&(e=obj.headers.length-1),t>=obj.rows.length&&(t=obj.rows.length-1),o>=obj.headers.length&&(o=obj.headers.length-1),n>=obj.rows.length&&(n=obj.rows.length-1),obj.selectedCell=[e,t,o,n],null!=e){if(obj.records[t][e]&&obj.records[t][e].classList.add("highlight-selected"),parseInt(e)1&&(ds&&(s=d+b-1)),j&&(pu&&(u=p+j-1))}var h=null,g=null,m=null,v=null;for(f=a;f<=u;f++)"none"!=obj.rows[f].style.display&&(null==m&&(m=f),v=f);for(c=i;c<=s;c++){for(f=a;f<=u;f++)"none"!=obj.rows[f].style.display&&"none"!=obj.records[f][c].style.display&&(obj.records[f][c].classList.add("highlight"),obj.highlighted.push(obj.records[f][c]));"hidden"!=obj.options.columns[c].type&&(null==h&&(h=c),g=c)}for(h||(h=0),g||(g=0),c=h;c<=g;c++)"hidden"!=obj.options.columns[c].type&&obj.colgroup[c].style&&"none"!=obj.colgroup[c].style.display&&(obj.records[m]&&obj.records[m][c]&&obj.records[m][c].classList.add("highlight-top"),obj.records[v]&&obj.records[v][c]&&obj.records[v][c].classList.add("highlight-bottom"),obj.headers[c].classList.add("selected"));for(f=m;f<=v;f++)obj.rows[f]&&"none"!=obj.rows[f].style.display&&(obj.records[f][h].classList.add("highlight-left"),obj.records[f][g].classList.add("highlight-right"),obj.rows[f].classList.add("selected"));obj.selectedContainer=[h,m,g,v]}0==l&&(obj.dispatch("onfocus",el),obj.removeCopyingSelection()),obj.dispatch("onselection",el,h,m,g,v,r),obj.updateCornerPosition()},obj.removeCopySelection=function(){for(var e=0;e0)var i=parseInt(r)+1,s=parseInt(e);else i=parseInt(e),s=parseInt(o)-1;if(t-l>0)var a=parseInt(l)+1,u=parseInt(t);else a=parseInt(t),u=parseInt(n)-1;s-i<=u-a?(i=parseInt(o),s=parseInt(r)):(a=parseInt(n),u=parseInt(l));for(var c=a;c<=u;c++)for(var f=i;f<=s;f++)obj.records[c][f]&&"none"!=obj.rows[c].style.display&&"none"!=obj.records[c][f].style.display&&(obj.records[c][f].classList.add("selection"),obj.records[a][f].classList.add("selection-top"),obj.records[u][f].classList.add("selection-bottom"),obj.records[c][i].classList.add("selection-left"),obj.records[c][s].classList.add("selection-right"),obj.selection.push(obj.records[c][f]))}},obj.updateCornerPosition=function(){if(obj.highlighted.length){var e=obj.highlighted[obj.highlighted.length-1],t=e.getAttribute("data-x"),o=obj.content.getBoundingClientRect(),n=o.left,r=o.top,l=e.getBoundingClientRect(),i=l.left,s=l.top,a=l.width,u=l.height,c=i-n+obj.content.scrollLeft+a-4,f=s-r+obj.content.scrollTop+u-4;if(obj.corner.style.top=f+"px",obj.corner.style.left=c+"px",obj.options.freezeColumns){var d=obj.getFreezeWidth();t>obj.options.freezeColumns-1&&i-n+aobj.content.scrollTop+30&&dobj.content.scrollLeft+p&&f0&&("object"==typeof e&&(e=e.getAttribute("data-y")),o||(o=obj.rows[e].getAttribute("height"))||(o=obj.rows[e].getBoundingClientRect().height),t=parseInt(t),obj.rows[e].style.height=t+"px",obj.options.rows[e]||(obj.options.rows[e]={}),obj.options.rows[e].height=t,obj.setHistory({action:"setHeight",row:e,oldValue:o,newValue:t}),obj.dispatch("onresizerow",el,e,t,o),obj.updateCornerPosition())},obj.getHeight=function(e){if(void 0===e)for(var t=[],o=0;o=0){if(Object.keys(obj.options.mergeCells).length>0){if(!confirm(obj.options.text.thisActionWillDestroyAnyExistingMergedCellsAreYouSure))return!1;obj.destroyMerged()}t=null==t?obj.headers[e].classList.contains("arrow-down")?1:0:t?1:0;var o=[];if("number"==obj.options.columns[e].type||"numeric"==obj.options.columns[e].type||"percentage"==obj.options.columns[e].type||"autonumber"==obj.options.columns[e].type||"color"==obj.options.columns[e].type)for(var n=0;nr?-1:nr?1:n0)obj.page(0);else if(1==obj.options.lazyLoading)obj.loadPage(0);else for(o=0;o0){if(e>t)var n=1;else n=0;if(obj.isRowMerged(e).length||obj.isRowMerged(t,n).length){if(!confirm(obj.options.text.thisActionWillDestroyAnyExistingMergedCellsAreYouSure))return!1;obj.destroyMerged()}}if(1==obj.options.search){if(obj.results&&obj.results.length!=obj.rows.length){if(!confirm(obj.options.text.thisActionWillClearYourSearchResultsAreYouSure))return!1;obj.resetSearch()}obj.results=null}o||(Array.prototype.indexOf.call(obj.tbody.children,obj.rows[t])>=0?e>t?obj.tbody.insertBefore(obj.rows[e],obj.rows[t]):obj.tbody.insertBefore(obj.rows[e],obj.rows[t].nextSibling):obj.tbody.removeChild(obj.rows[e])),obj.rows.splice(t,0,obj.rows.splice(e,1)[0]),obj.records.splice(t,0,obj.records.splice(e,1)[0]),obj.options.data.splice(t,0,obj.options.data.splice(e,1)[0]),obj.options.pagination>0&&obj.tbody.children.length!=obj.options.pagination&&obj.page(obj.pageNumber),obj.setHistory({action:"moveRow",oldValue:e,newValue:t}),obj.updateTableReferences(),obj.dispatch("onmoverow",el,e,t)},obj.insertRow=function(e,t,o){if(1==obj.options.allowInsertRow){var n=[];if(e>0)var r=e;else r=1,e&&(n=e);o=!!o;var l=obj.options.data.length-1;if((null==t||t>=parseInt(l)||t<0)&&(t=l),!1===obj.dispatch("onbeforeinsertrow",el,t,r,o))return!1;if(Object.keys(obj.options.mergeCells).length>0&&obj.isRowMerged(t,o).length){if(!confirm(obj.options.text.thisActionWillDestroyAnyExistingMergedCellsAreYouSure))return!1;obj.destroyMerged()}if(1==obj.options.search){if(obj.results&&obj.results.length!=obj.rows.length){if(!confirm(obj.options.text.thisActionWillClearYourSearchResultsAreYouSure))return!1;obj.resetSearch()}obj.results=null}for(var i=o?t:t+1,s=obj.records.splice(i),a=obj.options.data.splice(i),u=obj.rows.splice(i),c=[],f=[],d=[],p=i;p=0&&obj.tbody.insertBefore(j,u[0]):Array.prototype.indexOf.call(obj.tbody.children,obj.rows[t])>=0&&obj.tbody.appendChild(j),c.push(obj.records[p]),f.push(obj.options.data[p]),d.push(j)}Array.prototype.push.apply(obj.records,s),Array.prototype.push.apply(obj.options.data,a),Array.prototype.push.apply(obj.rows,u),obj.options.pagination>0&&obj.page(obj.pageNumber),obj.setHistory({action:"insertRow",rowNumber:t,numOfRows:r,insertBefore:o,rowRecords:c,rowData:f,rowNode:d}),obj.updateTableReferences(),obj.dispatch("oninsertrow",el,t,r,c,o)}},obj.deleteRow=function(e,t){if(1==obj.options.allowDeleteRow)if(1==obj.options.allowDeletingAllRows||obj.options.data.length>1){if(null==e){var o=obj.getSelectedRows();o[0]?(e=parseInt(o[0].getAttribute("data-y")),t=o.length):(e=obj.options.data.length-1,t=1)}var n=obj.options.data.length-1;if((null==e||e>n||e<0)&&(e=n),t||(t=1),e+t>=obj.options.data.length&&(t=obj.options.data.length-e),!1===obj.dispatch("onbeforedeleterow",el,e,t))return!1;if(parseInt(e)>-1){var r=!1;if(Object.keys(obj.options.mergeCells).length>0)for(var l=e;l=0&&(obj.rows[l].className="",obj.rows[l].parentNode.removeChild(obj.rows[l]));var i=obj.records.splice(e,t),s=obj.options.data.splice(e,t),a=obj.rows.splice(e,t);obj.options.pagination>0&&obj.tbody.children.length!=obj.options.pagination&&obj.page(obj.pageNumber),obj.conditionalSelectionUpdate(1,e,e+t-1),obj.setHistory({action:"deleteRow",rowNumber:e,numOfRows:t,insertBefore:1,rowRecords:i,rowData:s,rowNode:a}),obj.updateTableReferences(),obj.dispatch("ondeleterow",el,e,t,i)}}else console.error("Jspreadsheet: It is not possible to delete the last row")},obj.moveColumn=function(e,t){if(Object.keys(obj.options.mergeCells).length>0){if(e>t)var o=1;else o=0;if(obj.isColMerged(e).length||obj.isColMerged(t,o).length){if(!confirm(obj.options.text.thisActionWillDestroyAnyExistingMergedCellsAreYouSure))return!1;obj.destroyMerged()}}if((e=parseInt(e))>(t=parseInt(t))){obj.headerContainer.insertBefore(obj.headers[e],obj.headers[t]),obj.colgroupContainer.insertBefore(obj.colgroup[e],obj.colgroup[t]);for(var n=0;n0)var l=e;else l=1,e&&(r=e);o=!!o;var i=obj.options.columns.length-1;if((null==t||t>=parseInt(i)||t<0)&&(t=i),!1===obj.dispatch("onbeforeinsertcolumn",el,t,l,o))return!1;if(Object.keys(obj.options.mergeCells).length>0&&obj.isColMerged(t,o).length){if(!confirm(obj.options.text.thisActionWillDestroyAnyExistingMergedCellsAreYouSure))return!1;obj.destroyMerged()}n||(n=[]);for(var s=0;s0)if(obj.options.nestedHeaders[0]&&obj.options.nestedHeaders[0][0])for(g=0;g1){if(null==e){var o=obj.getSelectedColumns(!0);o.length?(e=parseInt(o[0]),t=parseInt(o.length)):(e=obj.headers.length-1,t=1)}var n=obj.options.data[0].length-1;if((null==e||e>n||e<0)&&(e=n),t||(t=1),t>obj.options.data[0].length-e&&(t=obj.options.data[0].length-e),!1===obj.dispatch("onbeforedeletecolumn",el,e,t))return!1;if(parseInt(e)>-1){var r=!1;if(Object.keys(obj.options.mergeCells).length>0)for(var l=e;l0)if(obj.options.nestedHeaders[0]&&obj.options.nestedHeaders[0][0])for(var p=0;p0){for(var e=0,t=obj.rows.length-1;t>=0;t--){for(var o=!1,n=0;n0&&obj.insertRow(obj.options.minSpareRows-e)}if(obj.options.minSpareCols>0){var r=0;for(n=obj.headers.length-1;n>=0;n--){for(o=!1,t=0;t0&&obj.insertColumn(obj.options.minSpareCols-r)}if("function"==typeof obj.options.updateTable){for(obj.options.detachForUpdates&&el.removeChild(obj.content),t=0;te+1&&(obj.filter.children[e+1].style.display="");for(var t=0;te+1&&(obj.filter.children[e+1].style.display="none");for(var t=0;t0)if(chainLoopProtection[n])obj.records[t][e].innerHTML="#ERROR",obj.formula[n]="";else{chainLoopProtection[n]=!0;for(var r=0;r-1)return console.error("Self Reference detected"),"#ERROR";var formulaExpressions={};if(tokens)for(var i=0;i0&&obj.up.visible(1,t?0:1):(obj.selectedCell[1]>0&&obj.up.visible(0,t?0:1),obj.selectedCell[2]=obj.selectedCell[0],obj.selectedCell[3]=obj.selectedCell[1]),obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]),1==obj.options.lazyLoading)if(0==obj.selectedCell[1]||0==obj.selectedCell[3])obj.loadPage(0),obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]);else if(obj.loadValidation())obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]);else{var o=parseInt(obj.tbody.firstChild.getAttribute("data-y"));obj.selectedCell[1]-o<30&&(obj.loadUp(),obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]))}else if(obj.options.pagination>0){var n=obj.whichPage(obj.selectedCell[3]);n!=obj.pageNumber&&obj.page(n)}obj.updateScroll(1)},obj.up.visible=function(e,t){if(0==e)var o=parseInt(obj.selectedCell[0]),n=parseInt(obj.selectedCell[1]);else o=parseInt(obj.selectedCell[2]),n=parseInt(obj.selectedCell[3]);if(0==t){for(var r=0;r=0;o--)if("none"!=obj.records[o][e].style.display&&"none"!=obj.rows[o].style.display){if(obj.records[o][e].getAttribute("data-merged")&&obj.records[o][e]==obj.records[t][e])continue;t=o;break}return t},obj.down=function(e,t){if(e?obj.selectedCell[3]0){var o=obj.whichPage(obj.selectedCell[3]);o!=obj.pageNumber&&obj.page(o)}obj.updateScroll(3)},obj.down.visible=function(e,t){if(0==e)var o=parseInt(obj.selectedCell[0]),n=parseInt(obj.selectedCell[1]);else o=parseInt(obj.selectedCell[2]),n=parseInt(obj.selectedCell[3]);if(0==t){for(var r=obj.rows.length-1;r>n;r--)if("none"!=obj.records[r][o].style.display&&"none"!=obj.rows[r].style.display){n=r;break}}else n=obj.down.get(o,n);0==e?(obj.selectedCell[0]=o,obj.selectedCell[1]=n):(obj.selectedCell[2]=o,obj.selectedCell[3]=n)},obj.down.get=function(e,t){e=parseInt(e);for(var o=(t=parseInt(t))+1;oo;r--)if("none"!=obj.records[n][r].style.display){o=r;break}}else o=obj.right.get(o,n);0==e?(obj.selectedCell[0]=o,obj.selectedCell[1]=n):(obj.selectedCell[2]=o,obj.selectedCell[3]=n)},obj.right.get=function(e,t){e=parseInt(e),t=parseInt(t);for(var o=e+1;o0&&obj.left.visible(1,t?0:1):(obj.selectedCell[0]>0&&obj.left.visible(0,t?0:1),obj.selectedCell[2]=obj.selectedCell[0],obj.selectedCell[3]=obj.selectedCell[1]),obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]),obj.updateScroll(0)},obj.left.visible=function(e,t){if(0==e)var o=parseInt(obj.selectedCell[0]),n=parseInt(obj.selectedCell[1]);else o=parseInt(obj.selectedCell[2]),n=parseInt(obj.selectedCell[3]);if(0==t){for(var r=0;r=0;o--)if("none"!=obj.records[t][o].style.display){if(obj.records[t][o].getAttribute("data-merged")&&obj.records[t][o]==obj.records[t][e])continue;e=o;break}return e},obj.first=function(e,t){if(e?t?obj.selectedCell[3]=0:obj.left.visible(1,0):(t?obj.selectedCell[1]=0:obj.left.visible(0,0),obj.selectedCell[2]=obj.selectedCell[0],obj.selectedCell[3]=obj.selectedCell[1]),1!=obj.options.lazyLoading||0!=obj.selectedCell[1]&&0!=obj.selectedCell[3]){if(obj.options.pagination>0){var o=obj.whichPage(obj.selectedCell[3]);o!=obj.pageNumber&&obj.page(o)}}else obj.loadPage(0);obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]),obj.updateScroll(1)},obj.last=function(e,t){if(e?t?obj.selectedCell[3]=obj.records.length-1:obj.right.visible(1,0):(t?obj.selectedCell[1]=obj.records.length-1:obj.right.visible(0,0),obj.selectedCell[2]=obj.selectedCell[0],obj.selectedCell[3]=obj.selectedCell[1]),1!=obj.options.lazyLoading||obj.selectedCell[1]!=obj.records.length-1&&obj.selectedCell[3]!=obj.records.length-1){if(obj.options.pagination>0){var o=obj.whichPage(obj.selectedCell[3]);o!=obj.pageNumber&&obj.page(o)}}else obj.loadPage(-1);obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]),obj.updateScroll(3)},obj.selectAll=function(){obj.selectedCell||(obj.selectedCell=[]),obj.selectedCell[0]=0,obj.selectedCell[1]=0,obj.selectedCell[2]=obj.headers.length-1,obj.selectedCell[3]=obj.records.length-1,obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3])},obj.loadPage=function(e){if(1!=obj.options.search&&1!=obj.options.filters||!obj.results)t=obj.rows;else var t=obj.results;var o=100;null!=e&&-1!=e||(e=Math.ceil(t.length/o)-1);var n=e*o,r=e*o+o;r>t.length&&(r=t.length),(n=r-100)<0&&(n=0);for(var l=n;lo&&obj.tbody.removeChild(obj.tbody.firstChild)},obj.loadUp=function(){if(1!=obj.options.search&&1!=obj.options.filters||!obj.results)e=obj.rows;else var e=obj.results;var t=0;if(e.length>100){var o=parseInt(obj.tbody.firstChild.getAttribute("data-y"));if(1!=obj.options.search&&1!=obj.options.filters||!obj.results||(o=e.indexOf(o)),o>0)for(var n=0;n<30;n++)(o-=1)>-1&&(1!=obj.options.search&&1!=obj.options.filters||!obj.results?obj.tbody.insertBefore(obj.rows[o],obj.tbody.firstChild):obj.tbody.insertBefore(obj.rows[e[o]],obj.tbody.firstChild),obj.tbody.children.length>100&&(obj.tbody.removeChild(obj.tbody.lastChild),t=1))}return t},obj.loadDown=function(){if(1!=obj.options.search&&1!=obj.options.filters||!obj.results)e=obj.rows;else var e=obj.results;var t=0;if(e.length>100){var o=parseInt(obj.tbody.lastChild.getAttribute("data-y"));if(1!=obj.options.search&&1!=obj.options.filters||!obj.results||(o=e.indexOf(o)),o100&&(obj.tbody.removeChild(obj.tbody.firstChild),t=1)),o+=1}return t},obj.loadValidation=function(){if(obj.selectedCell){var e=parseInt(obj.tbody.firstChild.getAttribute("data-y"))/100,t=parseInt(obj.selectedCell[3]/100),o=parseInt(obj.rows.length/100);if(e!=t&&t<=o&&!Array.prototype.indexOf.call(obj.tbody.children,obj.rows[obj.selectedCell[3]]))return obj.loadPage(t),!0}return!1},obj.resetSearch=function(){obj.searchInput.value="",obj.search(""),obj.results=null},obj.search=function(e){if(obj.options.filters&&obj.resetFilters(),obj.resetSelection(),obj.pageNumber=0,obj.results=[],e){var t=function(e){-1==obj.results.indexOf(e)&&obj.results.push(e)},o=e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");o=new RegExp(o,"i"),obj.options.data.forEach((function(e,n){if(function(e,t,o){for(var n=0;n=0||(""+obj.records[o][n].innerHTML).toLowerCase().search(t)>=0)return!0;return!1}(e,o,n)){var r=obj.isRowMerged(n);if(r.length)for(var l=0;l0?obj.options.pagination:obj.results?obj.results.length:obj.rows.length;obj.tbody.firstChild;)obj.tbody.removeChild(obj.tbody.firstChild);for(var o=0;o-1?(t0&&obj.updatePagination(),obj.updateCornerPosition(),e},obj.whichPage=function(e){return 1!=obj.options.search&&1!=obj.options.filters||!obj.results||(e=obj.results.indexOf(e)),Math.ceil((parseInt(e)+1)/parseInt(obj.options.pagination))-1},obj.page=function(e){var t=obj.pageNumber;if(1!=obj.options.search&&1!=obj.options.filters||!obj.results)o=obj.rows;else var o=obj.results;var n=parseInt(obj.options.pagination);null!=e&&-1!=e||(e=Math.ceil(o.length/n)-1),obj.pageNumber=e;var r=e*n,l=e*n+n;for(l>o.length&&(l=o.length),r<0&&(r=0);obj.tbody.firstChild;)obj.tbody.removeChild(obj.tbody.firstChild);for(var i=r;i0&&obj.updatePagination(),obj.updateCornerPosition(),obj.dispatch("onchangepage",el,e,t)},obj.updatePagination=function(){if(obj.pagination.children[0].innerHTML="",obj.pagination.children[1].innerHTML="",obj.options.pagination){if(1!=obj.options.search&&1!=obj.options.filters||!obj.results)e=obj.rows.length;else var e=obj.results.length;if(e){var t=Math.ceil(e/obj.options.pagination);if(obj.pageNumber<6)var o=1,n=t<10?t:10;else t-obj.pageNumber<5?(n=t,(o=t-9)<1&&(o=1)):(o=obj.pageNumber-4,n=obj.pageNumber+5);o>1&&((l=document.createElement("div")).className="jexcel_page",l.innerHTML="<",l.title=1,obj.pagination.children[1].appendChild(l));for(var r=o;r<=n;r++){var l;(l=document.createElement("div")).className="jexcel_page",l.innerHTML=r,obj.pagination.children[1].appendChild(l),obj.pageNumber==r-1&&l.classList.add("jexcel_page_selected")}n",l.title=t,obj.pagination.children[1].appendChild(l)),obj.pagination.children[0].innerHTML=function(e){var t=Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,(function(e,o){return void 0!==t[o]?t[o]:e}))}(obj.options.text.showingPage,obj.pageNumber+1,t)}else obj.pagination.children[0].innerHTML=obj.options.text.noRecordsFound}},obj.download=function(e){if(0==obj.options.allowExport)console.error("Export not allowed");else{var t="";t+=obj.copy(!1,obj.options.csvDelimiter,!0,e,!0);var o=new Blob(["\ufeff"+t],{type:"text/csv;charset=utf-8;"});if(window.navigator&&window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(o,obj.options.csvFileName+".csv");else{var n=document.createElement("a"),r=URL.createObjectURL(o);n.href=r,n.setAttribute("download",obj.options.csvFileName+".csv"),document.body.appendChild(n),n.click(),n.parentNode.removeChild(n)}}},obj.setHistory=function(e){if(1!=obj.ignoreHistory){var t=++obj.historyIndex;obj.history=obj.history=obj.history.slice(0,t+1),obj.history[t]=e}},obj.copy=function(e,t,o,n,r){t||(t="\t");for(var l=new RegExp(t,"ig"),i=[],s=[],a=[],u=[],c=[],f=obj.options.data[0].length,d=obj.options.data.length,p="",b=!1,j="",h="",g=0,m=0,v=0,y=0,C=!0,x=0;x0)for(p=obj.options.nestedHeaders[0]&&obj.options.nestedHeaders[0][0]?obj.options.nestedHeaders:[obj.options.nestedHeaders],x=0;x1&Number.isInteger(s/o[0].length)){f=null,p=s/o[0].length;var d=o.map((function(e,t){var o=Array.apply(null,{length:p*e.length}).map((function(t,o){return e[o%e.length]}));return o}));o=d}if(a>1&Number.isInteger(a/o.length)){f=null;var p=a/o.length;d=Array.apply(null,{length:p*o.length}).map((function(e,t){return o[t%o.length]})),o=d}if(null!=e&&null!=t&&o){for(var b=0,j=0,h=[],g={},m={},v=0,y=parseInt(e),C=parseInt(t),x=null;x=o[j];){for(b=0,y=parseInt(e);null!=x[b];){var w=obj.updateCell(y,C,x[b]);if(h.push(w),obj.updateFormulaChain(y,C,h),f&&f[v]){var A=jexcel.getColumnNameFromId([y,C]);g[A]=f[v],m[A]=obj.getStyle(A),obj.records[C][y].setAttribute("style",f[v]),v++}if(null!=x[++b]){if(y>=obj.headers.length-1){if(1!=obj.options.allowInsertColumn)break;obj.insertColumn()}y=obj.right.get(y,C)}}if(j++,o[j]){if(C>=obj.rows.length-1){if(1!=obj.options.allowInsertRow)break;obj.insertRow()}C=obj.down.get(e,C)}}obj.updateSelectionFromCoords(e,t,y,C),obj.setHistory({action:"setValue",records:h,selection:obj.selectedCell,newStyle:g,oldStyle:m}),obj.updateTable(),obj.dispatch("onpaste",el,o),obj.onafterchanges(el,h)}obj.removeCopyingSelection()},obj.removeCopyingSelection=function(){for(var e=document.querySelectorAll(".jexcel .copying"),t=0;t0&&obj.page(obj.pageNumber),obj.updateTableReferences()},obj.historyProcessColumn=function(e,t){var o=t.insertBefore?t.columnNumber:t.columnNumber+1;if(1==e){var n=t.numOfColumns;obj.options.columns.splice(o,n);for(var r=o;r0)if(obj.options.nestedHeaders[0]&&obj.options.nestedHeaders[0][0])for(l=0;l=0){var n=obj.history[obj.historyIndex--];if("insertRow"==n.action)obj.historyProcessRow(1,n);else if("deleteRow"==n.action)obj.historyProcessRow(0,n);else if("insertColumn"==n.action)obj.historyProcessColumn(1,n);else if("deleteColumn"==n.action)obj.historyProcessColumn(0,n);else if("moveRow"==n.action)obj.moveRow(n.newValue,n.oldValue);else if("moveColumn"==n.action)obj.moveColumn(n.newValue,n.oldValue);else if("setMerge"==n.action)obj.removeMerge(n.column,n.data);else if("setStyle"==n.action)obj.setStyle(n.oldValue,null,null,1);else if("setWidth"==n.action)obj.setWidth(n.column,n.oldValue);else if("setHeight"==n.action)obj.setHeight(n.row,n.oldValue);else if("setHeader"==n.action)obj.setHeader(n.column,n.oldValue);else if("setComments"==n.action)obj.setComments(n.column,n.oldValue[0],n.oldValue[1]);else if("orderBy"==n.action){for(var r=[],l=0;l0?o.join("; "):""},obj.parseCSV=function(e,t){9==(e=e.replace(/\r?\n$|\r$|\n$/g,"")).charCodeAt(e.length-1)&&(e+="\0"),t=t||",";for(var o=[],n=!1,r=0,l=0,i=0;i0)for(var o=t.shift(),n=0;n0&&obj.content.scrollLeft!=scrollLeft&&obj.updateFreezePosition(),1!=obj.options.lazyLoading&&1!=obj.options.tableOverflow||obj.edition&&"jdropdown"!=e.target.className.substr(0,9)&&obj.closeEditor(obj.edition[0],!0)},obj.wheelControls=function(e){1==obj.options.lazyLoading&&null==jexcel.timeControlLoading&&(jexcel.timeControlLoading=setTimeout((function(){obj.content.scrollTop+obj.content.clientHeight>=obj.content.scrollHeight-10?obj.loadDown()&&(obj.content.scrollTop+obj.content.clientHeight>obj.content.scrollHeight-10&&(obj.content.scrollTop=obj.content.scrollTop-obj.content.clientHeight),obj.updateCornerPosition()):obj.content.scrollTop<=obj.content.clientHeight&&obj.loadUp()&&(obj.content.scrollTop<10&&(obj.content.scrollTop=obj.content.scrollTop+obj.content.clientHeight),obj.updateCornerPosition()),jexcel.timeControlLoading=null}),100))},obj.getFreezeWidth=function(){var e=0;if(obj.options.freezeColumns>0)for(var t=0;t50)for(var t=0;t0&&"hidden"!==obj.options.columns[t-1].type&&(e+=parseInt(obj.options.columns[t-1].width)),obj.headers[t].classList.add("jexcel_freezed"),obj.headers[t].style.left=e+"px";for(var o=0;o0?obj.records[o][t-1].style.width:0)-51+"px";obj.records[o][t].classList.add("jexcel_freezed"),obj.records[o][t].style.left=n}}else for(t=0;t200)&&e.altKey){var t=jexcel.current.edition[0].children[0],o=jexcel.current.edition[0].children[0].value,n=t.selectionStart;o=o.slice(0,n)+"\n"+o.slice(n),t.value=o,t.focus(),t.selectionStart=n+1,t.selectionEnd=n+1}else jexcel.current.edition[0].children[0].blur();else 9==e.which&&(["calendar","html"].includes(jexcel.current.options.columns[jexcel.current.edition[2]].type)?jexcel.current.closeEditor(jexcel.current.edition[0],!0):jexcel.current.edition[0].children[0].blur());if(!jexcel.current.edition&&jexcel.current.selectedCell)if(37==e.which)jexcel.current.left(e.shiftKey,e.ctrlKey),e.preventDefault();else if(39==e.which)jexcel.current.right(e.shiftKey,e.ctrlKey),e.preventDefault();else if(38==e.which)jexcel.current.up(e.shiftKey,e.ctrlKey),e.preventDefault();else if(40==e.which)jexcel.current.down(e.shiftKey,e.ctrlKey),e.preventDefault();else if(36==e.which)jexcel.current.first(e.shiftKey,e.ctrlKey),e.preventDefault();else if(35==e.which)jexcel.current.last(e.shiftKey,e.ctrlKey),e.preventDefault();else if(46==e.which||8==e.which)1==jexcel.current.options.editable&&(jexcel.current.selectedRow?1==jexcel.current.options.allowDeleteRow&&confirm(jexcel.current.options.text.areYouSureToDeleteTheSelectedRows)&&jexcel.current.deleteRow():jexcel.current.selectedHeader?1==jexcel.current.options.allowDeleteColumn&&confirm(jexcel.current.options.text.areYouSureToDeleteTheSelectedColumns)&&jexcel.current.deleteColumn():jexcel.current.setValue(jexcel.current.highlighted,""));else if(13==e.which)e.shiftKey?jexcel.current.up():(1==jexcel.current.options.allowInsertRow&&1==jexcel.current.options.allowManualInsertRow&&jexcel.current.selectedCell[1]==jexcel.current.options.data.length-1&&jexcel.current.insertRow(),jexcel.current.down()),e.preventDefault();else if(9==e.which)e.shiftKey?jexcel.current.left():(1==jexcel.current.options.allowInsertColumn&&1==jexcel.current.options.allowManualInsertColumn&&jexcel.current.selectedCell[0]==jexcel.current.options.data[0].length-1&&jexcel.current.insertColumn(),jexcel.current.right()),e.preventDefault();else if(!e.ctrlKey&&!e.metaKey||e.shiftKey){if(jexcel.current.selectedCell&&1==jexcel.current.options.editable){var r=jexcel.current.selectedCell[1],l=jexcel.current.selectedCell[0];"readonly"!=jexcel.current.options.columns[l].type&&(32==e.keyCode?(e.preventDefault(),"checkbox"==jexcel.current.options.columns[l].type||"radio"==jexcel.current.options.columns[l].type?jexcel.current.setCheckRadioValue():jexcel.current.openEditor(jexcel.current.records[r][l],!0)):113==e.keyCode?jexcel.current.openEditor(jexcel.current.records[r][l],!1):(8==e.keyCode||e.keyCode>=48&&e.keyCode<=57||e.keyCode>=96&&e.keyCode<=111||e.keyCode>=187&&e.keyCode<=190||(String.fromCharCode(e.keyCode)==e.key||String.fromCharCode(e.keyCode).toLowerCase()==e.key.toLowerCase())&&jexcel.validLetter(String.fromCharCode(e.keyCode)))&&(jexcel.current.openEditor(jexcel.current.records[r][l],!0),"calendar"==jexcel.current.options.columns[l].type&&e.preventDefault()))}}else 65==e.which?(jexcel.current.selectAll(),e.preventDefault()):83==e.which?(jexcel.current.download(),e.preventDefault()):89==e.which?(jexcel.current.redo(),e.preventDefault()):90==e.which?(jexcel.current.undo(),e.preventDefault()):67==e.which?(jexcel.current.copy(!0),e.preventDefault()):88==e.which?(1==jexcel.current.options.editable?jexcel.cutControls():jexcel.copyControls(),e.preventDefault()):86==e.which&&jexcel.pasteControls();else e.target.classList.contains("jexcel_search")&&(jexcel.timeControl&&clearTimeout(jexcel.timeControl),jexcel.timeControl=setTimeout((function(){jexcel.current.search(e.target.value)}),200))}},jexcel.isMouseAction=!1,jexcel.mouseDownControls=function(e){if((e=e||window.event).buttons)var t=e.buttons;else t=e.button?e.button:e.which;var o=jexcel.getElement(e.target);if(o[0]?jexcel.current!=o[0].jexcel&&(jexcel.current&&(jexcel.current.edition&&jexcel.current.closeEditor(jexcel.current.edition[0],!0),jexcel.current.resetSelection()),jexcel.current=o[0].jexcel):jexcel.current&&(jexcel.current.edition&&jexcel.current.closeEditor(jexcel.current.edition[0],!0),jexcel.current.resetSelection(!0),jexcel.current=null),jexcel.current&&1==t){if(e.target.classList.contains("jexcel_selectall"))jexcel.current&&jexcel.current.selectAll();else if(e.target.classList.contains("jexcel_corner"))1==jexcel.current.options.editable&&(jexcel.current.selectedCorner=!0);else{if(1==o[1]){if(p=e.target.getAttribute("data-x")){var n=e.target.getBoundingClientRect();if(1==jexcel.current.options.columnResize&&n.width-e.offsetX<6){jexcel.current.resizing={mousePosition:e.pageX,column:p,width:n.width},jexcel.current.headers[p].classList.add("resizing");for(var r=0;r"==e.target.textContent?jexcel.current.page(e.target.getAttribute("title")-1):jexcel.current.page(e.target.textContent-1))}jexcel.current.edition?jexcel.isMouseAction=!1:jexcel.isMouseAction=!0}else jexcel.isMouseAction=!1},jexcel.mouseUpControls=function(e){if(jexcel.current)if(jexcel.current.resizing){if(jexcel.current.resizing.column){var t=jexcel.current.colgroup[jexcel.current.resizing.column].getAttribute("width"),o=jexcel.current.getSelectedColumns();if(o.length>1){for(var n=[],r=0;r0&&(jexcel.current.copyData(jexcel.current.selection[0],jexcel.current.selection[jexcel.current.selection.length-1]),jexcel.current.removeCopySelection()));jexcel.timeControl&&(clearTimeout(jexcel.timeControl),jexcel.timeControl=null),jexcel.isMouseAction=!1},jexcel.mouseMoveControls=function(e){if((e=e||window.event).buttons)var t=e.buttons;else t=e.button?e.button:e.which;if(t||(jexcel.isMouseAction=!1),jexcel.current)if(1==jexcel.isMouseAction){if(jexcel.current.resizing)if(jexcel.current.resizing.column){var o=e.pageX-jexcel.current.resizing.mousePosition;if(jexcel.current.resizing.width+o>0){var n=jexcel.current.resizing.width+o;jexcel.current.colgroup[jexcel.current.resizing.column].setAttribute("width",n),jexcel.current.updateCornerPosition()}}else{var r=e.pageY-jexcel.current.resizing.mousePosition;if(jexcel.current.resizing.height+r>0){var l=jexcel.current.resizing.height+r;jexcel.current.rows[jexcel.current.resizing.row].setAttribute("height",l),jexcel.current.updateCornerPosition()}}else if(jexcel.current.dragging)if(jexcel.current.dragging.column){var i=e.target.getAttribute("data-x");if(i)if(jexcel.current.isColMerged(i).length)console.error("Jspreadsheet: This column is part of a merged cell.");else{for(var s=0;se.offsetX?(jexcel.current.dragging.columne.offsetY?e.target.parentNode.nextSibling:e.target.parentNode;jexcel.current.dragging.element!=u&&(e.target.parentNode.parentNode.insertBefore(jexcel.current.dragging.element,u),jexcel.current.dragging.destination=Array.prototype.indexOf.call(jexcel.current.dragging.element.parentNode.children,jexcel.current.dragging.element))}}}else{var c=e.target.getAttribute("data-x"),f=e.target.getAttribute("data-y"),d=e.target.getBoundingClientRect();jexcel.current.cursor&&(jexcel.current.cursor.style.cursor="",jexcel.current.cursor=null),e.target.parentNode.parentNode&&e.target.parentNode.parentNode.className&&(e.target.parentNode.parentNode.classList.contains("resizable")&&(e.target&&c&&!f&&d.width-(e.clientX-d.left)<6?(jexcel.current.cursor=e.target,jexcel.current.cursor.style.cursor="col-resize"):e.target&&!c&&f&&d.height-(e.clientY-d.top)<6&&(jexcel.current.cursor=e.target,jexcel.current.cursor.style.cursor="row-resize")),e.target.parentNode.parentNode.classList.contains("draggable")&&(e.target&&!c&&f&&d.width-(e.clientX-d.left)<6||e.target&&c&&!f&&d.height-(e.clientY-d.top)<6)&&(jexcel.current.cursor=e.target,jexcel.current.cursor.style.cursor="move"))}},jexcel.mouseOverControls=function(e){if((e=e||window.event).buttons)var t=e.buttons;else t=e.button?e.button:e.which;if(t||(jexcel.isMouseAction=!1),jexcel.current&&1==jexcel.isMouseAction){var o=jexcel.getElement(e.target);if(o[0]){if(jexcel.current!=o[0].jexcel&&jexcel.current)return!1;var n=e.target.getAttribute("data-x"),r=e.target.getAttribute("data-y");if(jexcel.current.resizing||jexcel.current.dragging);else{if(1==o[1]&&jexcel.current.selectedHeader){n=e.target.getAttribute("data-x");var l=jexcel.current.selectedHeader,i=n;jexcel.current.updateSelectionFromCoords(l,0,i,jexcel.current.options.data.length-1)}2==o[1]&&(e.target.classList.contains("jexcel_row")?jexcel.current.selectedRow&&(l=jexcel.current.selectedRow,i=r,jexcel.current.updateSelectionFromCoords(0,l,jexcel.current.options.data[0].length-1,i)):jexcel.current.edition||n&&r&&(jexcel.current.selectedCorner?jexcel.current.updateCopySelection(n,r):jexcel.current.selectedCell&&jexcel.current.updateSelectionFromCoords(jexcel.current.selectedCell[0],jexcel.current.selectedCell[1],n,r)))}}}jexcel.timeControl&&(clearTimeout(jexcel.timeControl),jexcel.timeControl=null)},jexcel.doubleClickControls=function(e){if(jexcel.current)if(e.target.classList.contains("jexcel_corner")){if(jexcel.current.highlighted.length>0){var t=jexcel.current.highlighted[0].getAttribute("data-x"),o=parseInt(jexcel.current.highlighted[jexcel.current.highlighted.length-1].getAttribute("data-y"))+1,n=jexcel.current.highlighted[jexcel.current.highlighted.length-1].getAttribute("data-x"),r=jexcel.current.records.length-1;jexcel.current.copyData(jexcel.current.records[o][t],jexcel.current.records[r][n])}}else if(e.target.classList.contains("jexcel_column_filter")){var l=e.target.getAttribute("data-x");jexcel.current.openFilter(l)}else{var i=jexcel.getElement(e.target);if(1==i[1]&&1==jexcel.current.options.columnSorting&&(l=e.target.getAttribute("data-x"))&&jexcel.current.orderBy(l),2==i[1]&&1==jexcel.current.options.editable&&!jexcel.current.edition){var s=function(e){if(e.parentNode){var t=e.getAttribute("data-x"),o=e.getAttribute("data-y");return t&&o?e:s(e.parentNode)}},a=s(e.target);a&&a.classList.contains("highlight")&&jexcel.current.openEditor(a)}}},jexcel.copyControls=function(e){jexcel.current&&jexcel.copyControls.enabled&&(jexcel.current.edition||jexcel.current.copy(!0))},jexcel.cutControls=function(e){jexcel.current&&(jexcel.current.edition||(jexcel.current.copy(!0),1==jexcel.current.options.editable&&jexcel.current.setValue(jexcel.current.highlighted,"")))},jexcel.pasteControls=function(e){jexcel.current&&jexcel.current.selectedCell&&(jexcel.current.edition||1==jexcel.current.options.editable&&(e&&e.clipboardData?(jexcel.current.paste(jexcel.current.selectedCell[0],jexcel.current.selectedCell[1],e.clipboardData.getData("text")),e.preventDefault()):window.clipboardData&&jexcel.current.paste(jexcel.current.selectedCell[0],jexcel.current.selectedCell[1],window.clipboardData.getData("text"))))},jexcel.contextMenuControls=function(e){if("buttons"in(e=e||window.event)?e.buttons:e.which||e.button,jexcel.current)if(jexcel.current.edition)e.preventDefault();else if(jexcel.current.options.contextMenu&&(jexcel.current.contextMenu.contextmenu.close(),jexcel.current)){var t=e.target.getAttribute("data-x"),o=e.target.getAttribute("data-y");if(t||o){(tparseInt(jexcel.current.selectedCell[2])||oparseInt(jexcel.current.selectedCell[3]))&&jexcel.current.updateSelectionFromCoords(t,o,t,o);var n=jexcel.current.options.contextMenu(jexcel.current,t,o,e);jexcel.current.contextMenu.contextmenu.open(e,n),e.preventDefault()}}},jexcel.touchStartControls=function(e){var t=jexcel.getElement(e.target);if(t[0]?jexcel.current!=t[0].jexcel&&(jexcel.current&&jexcel.current.resetSelection(),jexcel.current=t[0].jexcel):jexcel.current&&(jexcel.current.resetSelection(),jexcel.current=null),jexcel.current&&!jexcel.current.edition){var o=e.target.getAttribute("data-x"),n=e.target.getAttribute("data-y");o&&n&&(jexcel.current.updateSelectionFromCoords(o,n),jexcel.timeControl=setTimeout((function(){"color"==jexcel.current.options.columns[o].type?jexcel.tmpElement=null:jexcel.tmpElement=e.target,jexcel.current.openEditor(e.target,!1,e)}),500))}},jexcel.touchEndControls=function(e){jexcel.timeControl&&(clearTimeout(jexcel.timeControl),jexcel.timeControl=null,jexcel.tmpElement&&"INPUT"==jexcel.tmpElement.children[0].tagName&&jexcel.tmpElement.children[0].focus(),jexcel.tmpElement=null)},jexcel.tabs=function(e,t){var o=[];if(e.classList.contains("jexcel_tabs"))r=e.children[0],l=e.children[1];else{e.innerHTML="",e.classList.add("jexcel_tabs"),e.jexcel=[];var n=document.createElement("div"),r=e.appendChild(n),l=(n=document.createElement("div"),e.appendChild(n))}for(var i=[],s=[],a=0;a0)for(n.mergeCells=[],r=0;r0&&(n.style[d[r]]=p.style),p.s&&p.s.fgColor&&(n.style[d[r]]&&(n.style[d[r]]+=";"),n.style[d[r]]+="background-color:#"+p.s.fgColor.rgb)}for(var j=n.columns,h=0;h<=f;h++)for(r=0;r<=c;r++)n.data[h]||(n.data[h]=[]),n.data[h][r]||j0&&l--,e=1==t?[n,l]:n+"-"+l}return e},jexcel.getColumnNameFromId=function(e){return Array.isArray(e)||(e=e.split("-")),jexcel.getColumnName(parseInt(e[0]))+(parseInt(e[1])+1)},jexcel.getElement=function(e){var t=0,o=0;return function e(n){n.className&&n.classList.contains("jexcel_container")&&(o=n),"THEAD"==n.tagName?t=1:"TBODY"==n.tagName&&(t=2),n.parentNode&&(o||e(n.parentNode))}(e),[o,t]},jexcel.doubleDigitFormat=function(e){return 1==(e=""+e).length&&(e="0"+e),e},jexcel.createFromTable=function(e,t){if("TABLE"==e.tagName){t||(t={}),t.columns=[],t.data=[];var o=e.querySelectorAll("colgroup > col");if(o.length)for(var n=0;n50?o.width:50;t.columns[n]||(t.columns[n]={}),e.getAttribute("data-celltype")?t.columns[n].type=e.getAttribute("data-celltype"):t.columns[n].type="text",t.columns[n].width=r+"px",t.columns[n].title=e.innerHTML,t.columns[n].align=e.style.textAlign||"center",(o=e.getAttribute("name"))&&(t.columns[n].name=o),(o=e.getAttribute("id"))&&(t.columns[n].id=o),(o=e.getAttribute("data-mask"))&&(t.columns[n].mask=o)},i=[],s=e.querySelectorAll(":scope > thead > tr");if(s.length){for(var a=0;a tr, :scope > tbody > tr");for(a=0;a0&&(t.nestedHeaders=i),Object.keys(b).length>0&&(t.style=b),Object.keys(d).length>0&&(t.mergeCells=d),Object.keys(p).length>0&&(t.rows=p),Object.keys(j).length>0&&(t.classes=j),(h=e.querySelectorAll("tfoot tr")).length){var w=[];for(a=0;a0&&(t.footers=w)}if(1==t.parseTableAutoCellType){var E=[];for(n=0;n25&&(M=!1),10==g.length&&"-"==g.substr(4,1)&&"-"==g.substr(7,1)||(I=!1);var N=Object.keys(E[n]).length;I?t.columns[n].type="calendar":1==M&&N>1&&N<=parseInt(.1*t.data.length)&&(t.columns[n].type="dropdown",t.columns[n].source=Object.keys(E[n]))}}return t}console.log("Element is not a table")},jexcel.helpers=(component={getCaretIndex:function(e){if(this.config.root)var t=this.config.root;else t=window;var o=0,n=t.getSelection();if(n&&0!==n.rangeCount){var r=n.getRangeAt(0),l=r.cloneRange();l.selectNodeContents(e),l.setEnd(r.endContainer,r.endOffset),o=l.toString().length}return o},invert:function(e){for(var t=[],o=Object.keys(e),n=0;n0;)t=(o-1)%26,n=String.fromCharCode(65+t).toString()+n,o=parseInt((o-t)/26);return n},getColumnNameFromCoords:function(e,t){return component.getColumnName(parseInt(e))+(parseInt(t)+1)},getCoordsFromColumnName:function(e){var t=/^[a-zA-Z]+/.exec(e);if(t){for(var o=0,n=0;n0&&r--,[o,r]}},createFromTable:function(){},injectArray:function(e,t,o){return e.slice(0,t).concat(o).concat(e.slice(t))},parseCSV:function(e,t){t=t||",";for(var o=0,n=0,r=[[]],l=0,i=null,s=!1,a=!1,u=0;ul&&(l=o)}for(var f=0;fr)l=n(o,r,a(o),p(o),-1);else{for(var i=!1,s=0,u=0,c=1,f=0,d=2/o,b=2*t.floor((r+t.floor(t.sqrt(40*r)))/2);b>0;b--)f=b*d*c-s,s=c,c=f,t.abs(c)>1e10&&(c*=1e-10,s*=1e-10,l*=1e-10,u*=1e-10),i&&(u+=c),i=!i,b==r&&(l=s);l/=u=2*u-c}return l}}(),v=(l=.636619772,i=[-2957821389,7062834065,-512359803.6,10879881.29,-86327.92757,228.4622733].reverse(),s=[40076544269,745249964.8,7189466.438,47447.2647,226.1030244,1].reverse(),a=[1,-.001098628627,2734510407e-14,-2073370639e-15,2.093887211e-7].reverse(),u=[-.01562499995,.0001430488765,-6911147651e-15,7.621095161e-7,-9.34945152e-8].reverse(),c=[-4900604943e3,127527439e4,-51534381390,734926455.1,-4237922.726,8511.937935].reverse(),f=[249958057e5,424441966400,3733650367,22459040.02,102042.605,354.9632885,1].reverse(),d=[1,.00183105,-3516396496e-14,2457520174e-15,-2.40337019e-7].reverse(),p=[.04687499995,-.0002002690873,8449199096e-15,-8.8228987e-7,1.05787412e-7].reverse(),r((function(e){var n=0,r=0,c=0,f=e*e,d=e-.785398164;return e<8?n=(r=o(i,f))/(c=o(s,f))+l*m(e,0)*t.log(e):(r=o(a,f=64/f),c=o(u,f),n=t.sqrt(l/e)*(t.sin(d)*r+t.cos(d)*c*8/e)),n}),(function(e){var n=0,r=0,i=0,s=e*e,a=e-2.356194491;return e<8?n=(r=e*o(c,s))/(i=o(f,s))+l*(m(e,1)*t.log(e)-1/e):(r=o(d,s=64/s),i=o(p,s),n=t.sqrt(l/e)*(t.sin(a)*r+t.cos(a)*i*8/e)),n}),0,1,-1)),y=(b=[1,3.5156229,3.0899424,1.2067492,.2659732,.0360768,.0045813].reverse(),j=[.39894228,.01328592,.00225319,-.00157565,.00916281,-.02057706,.02635537,-.01647633,.00392377].reverse(),h=[.5,.87890594,.51498869,.15084934,.02658733,.00301532,32411e-8].reverse(),g=[.39894228,-.03988024,-.00362018,.00163801,-.01031555,.02282967,-.02895312,.01787654,-.00420059].reverse(),function e(n,r){if(0===(r=Math.round(r)))return function(e){return e<=3.75?o(b,e*e/14.0625):t.exp(t.abs(e))/t.sqrt(t.abs(e))*o(j,3.75/t.abs(e))}(n);if(1===r)return function(e){return e<3.75?e*o(h,e*e/14.0625):(e<0?-1:1)*t.exp(t.abs(e))/t.sqrt(t.abs(e))*o(g,3.75/t.abs(e))}(n);if(r<0)return NaN;if(0===t.abs(n))return 0;if(n==1/0)return 1/0;var l,i=0,s=2/t.abs(n),a=0,u=1,c=0;for(l=2*t.round((r+t.round(t.sqrt(40*r)))/2);l>0;l--)c=l*s*u+a,a=u,u=c,t.abs(u)>1e10&&(u*=1e-10,a*=1e-10,i*=1e-10),l==r&&(i=a);return i*=e(n,0)/u,n<0&&r%2?-i:i}),C=function(){var e=[-.57721566,.4227842,.23069756,.0348859,.00262698,1075e-7,74e-7].reverse(),n=[1.25331414,-.07832358,.02189568,-.01062446,.00587872,-.0025154,53208e-8].reverse(),l=[1,.15443144,-.67278579,-.18156897,-.01919402,-.00110404,-4686e-8].reverse(),i=[1.25331414,.23498619,-.0365562,.01504268,-.00780353,.00325614,-68245e-8].reverse();return r((function(r){return r<=2?-t.log(r/2)*y(r,0)+o(e,r*r/4):t.exp(-r)/t.sqrt(r)*o(n,2/r)}),(function(e){return e<=2?t.log(e/2)*y(e,1)+1/e*o(l,e*e/4):t.exp(-e)/t.sqrt(e)*o(i,2/e)}),0,2,1)}();e.besselj=m,e.bessely=v,e.besseli=y,e.besselk=C},"undefined"==typeof DO_NOT_EXPORT_BESSEL?o(t):o({})},162:function(e){var t;e.exports=(t=function(e,t){var o=Array.prototype.concat,n=Array.prototype.slice,r=Object.prototype.toString;function l(t,o){var n=t>o?t:o;return e.pow(10,17-~~(e.log(n>0?n:-n)*e.LOG10E))}var i=Array.isArray||function(e){return"[object Array]"===r.call(e)};function s(e){return"[object Function]"===r.call(e)}function a(e){return"number"==typeof e&&e-e==0}function u(){return new u._init(arguments)}function c(){return 0}function f(){return 1}function d(e,t){return e===t?1:0}u.fn=u.prototype,u._init=function(e){if(i(e[0]))if(i(e[0][0])){s(e[1])&&(e[0]=u.map(e[0],e[1]));for(var t=0;t=0;t--,n++)o[n]=[e[n][t]];return o},u.transpose=function(e){var t,o,n,r,l,s=[];for(i(e[0])||(e=[e]),o=e.length,n=e[0].length,l=0;l0&&(s[n][0]=e[n][0]),a=1;ao&&n>0)return[];if(n>0)for(r=e;ro;r+=n)l.push(r);return l},u.slice=function(){function e(e,o,n,r){var l,i=[],s=e.length;if(o===t&&n===t&&r===t)return u.copy(e);if(r=r||1,(o=(o=o||0)>=0?o:s+o)===(n=(n=n||e.length)>=0?n:s+n)||0===r)return[];if(on&&r>0)return[];if(r>0)for(l=o;ln;l+=r)i.push(e[l]);return i}return function(t,o){var n,r;return a((o=o||{}).row)?a(o.col)?t[o.row][o.col]:e(u.rowa(t,o.row),(n=o.col||{}).start,n.end,n.step):a(o.col)?e(u.cola(t,o.col),(r=o.row||{}).start,r.end,r.step):(r=o.row||{},n=o.col||{},e(t,r.start,r.end,r.step).map((function(t){return e(t,n.start,n.end,n.step)})))}}(),u.sliceAssign=function(o,n,r){var l,i;if(a(n.row)){if(a(n.col))return o[n.row][n.col]=r;n.col=n.col||{},n.col.start=n.col.start||0,n.col.end=n.col.end||o[0].length,n.col.step=n.col.step||1,l=u.arange(n.col.start,e.min(o.length,n.col.end),n.col.step);var s=n.row;return l.forEach((function(e,t){o[s][e]=r[t]})),o}if(a(n.col)){n.row=n.row||{},n.row.start=n.row.start||0,n.row.end=n.row.end||o.length,n.row.step=n.row.step||1,i=u.arange(n.row.start,e.min(o[0].length,n.row.end),n.row.step);var c=n.col;return i.forEach((function(e,t){o[e][c]=r[t]})),o}return r[0].length===t&&(r=[r]),n.row.start=n.row.start||0,n.row.end=n.row.end||o.length,n.row.step=n.row.step||1,n.col.start=n.col.start||0,n.col.end=n.col.end||o[0].length,n.col.step=n.col.step||1,i=u.arange(n.row.start,e.min(o.length,n.row.end),n.row.step),l=u.arange(n.col.start,e.min(o[0].length,n.col.end),n.col.step),i.forEach((function(e,t){l.forEach((function(n,l){o[e][n]=r[t][l]}))})),o},u.diagonal=function(e){var t=u.zeros(e.length,e.length);return e.forEach((function(e,o){t[o][o]=e})),t},u.copy=function(e){return e.map((function(e){return a(e)?e:e.map((function(e){return e}))}))};var p=u.prototype;return p.length=0,p.push=Array.prototype.push,p.sort=Array.prototype.sort,p.splice=Array.prototype.splice,p.slice=Array.prototype.slice,p.toArray=function(){return this.length>1?n.call(this):n.call(this)[0]},p.map=function(e,t){return u(u.map(this,e,t))},p.cumreduce=function(e,t){return u(u.cumreduce(this,e,t))},p.alter=function(e){return u.alter(this,e),this},function(e){for(var t=0;t=0;)t+=e[o];return t},e.sumsqrd=function(e){for(var t=0,o=e.length;--o>=0;)t+=e[o]*e[o];return t},e.sumsqerr=function(t){for(var o,n=e.mean(t),r=0,l=t.length;--l>=0;)r+=(o=t[l]-n)*o;return r},e.sumrow=function(e){for(var t=0,o=e.length;--o>=0;)t+=e[o];return t},e.product=function(e){for(var t=1,o=e.length;--o>=0;)t*=e[o];return t},e.min=function(e){for(var t=e[0],o=0;++ot&&(t=e[o]);return t},e.unique=function(e){for(var t={},o=[],n=0;ni?(a=[r[t]],i=l,s=0):l===i&&(a.push(r[t]),s++),l=1);return 0===s?a[0]:a},e.range=function(t){return e.max(t)-e.min(t)},e.variance=function(t,o){return e.sumsqerr(t)/(t.length-(o?1:0))},e.pooledvariance=function(t){return t.reduce((function(t,o){return t+e.sumsqerr(o)}),0)/(t.reduce((function(e,t){return e+t.length}),0)-t.length)},e.deviation=function(t){for(var o=e.mean(t),n=t.length,r=new Array(n),l=0;l=0;l--)r.push(t.abs(o[l]-n));return e.mean(r)},e.meddev=function(o){for(var n=e.median(o),r=[],l=o.length-1;l>=0;l--)r.push(t.abs(o[l]-n));return e.median(r)},e.coeffvar=function(t){return e.stdev(t)/e.mean(t)},e.quartiles=function(e){var o=e.length,r=e.slice().sort(n);return[r[t.round(o/4)-1],r[t.round(o/2)-1],r[t.round(3*o/4)-1]]},e.quantiles=function(e,o,l,i){var s,a,u,c,f,d=e.slice().sort(n),p=[o.length],b=e.length;for(void 0===l&&(l=3/8),void 0===i&&(i=3/8),s=0;s1){for(a=!0===n?this:this.transpose();s1){for("sumrow"!==t&&(a=!0===n?this:this.transpose());s1){for(s=s.transpose();i=0;s--)i*=n,i+=u[s];if(l=i/o+.5*t.log(r)+(o-.5)*t.log(o)-o,e<=7)for(s=1;s<=a;s++)l-=t.log(o-1),o-=1;return l},e.gammafn=function(e){var o,n,r,l,i=[-1.716185138865495,24.76565080557592,-379.80425647094563,629.3311553128184,866.9662027904133,-31451.272968848367,-36144.413418691176,66456.14382024054],s=[-30.8402300119739,315.35062697960416,-1015.1563674902192,-3107.771671572311,22538.11842098015,4755.846277527881,-134659.9598649693,-115132.2596755535],a=!1,u=0,c=0,f=0,d=e;if(e>171.6243769536076)return 1/0;if(d<=0){if(!(l=d%1+36e-17))return 1/0;a=(1&d?-1:1)*t.PI/t.sin(t.PI*l),d=1-d}for(r=d,n=d<1?d++:(d-=u=(0|d)-1)-1,o=0;o<8;++o)f=(f+i[o])*n,c=c*n+s[o];if(l=f/c+1,rd)for(o=0;o=1?o:1/o)+.4*o+17);if(n<0||o<=0)return NaN;if(n170||n>170?t.exp(e.combinationln(o,n)):e.factorial(o)/e.factorial(n)/e.factorial(o-n)},e.combinationln=function(t,o){return e.factorialln(t)-e.factorialln(o)-e.factorialln(t-o)},e.permutation=function(t,o){return e.factorial(t)/e.factorial(t-o)},e.betafn=function(o,n){if(!(o<=0||n<=0))return o+n>170?t.exp(e.betaln(o,n)):e.gammafn(o)*e.gammafn(n)/e.gammafn(o+n)},e.betaln=function(t,o){return e.gammaln(t)+e.gammaln(o)-e.gammaln(t+o)},e.betacf=function(e,o,n){var r,l,i,s,a=1e-30,u=1,c=o+n,f=o+1,d=o-1,p=1,b=1-c*e/f;for(t.abs(b)=1)return t.max(100,n+100*t.sqrt(n));if(o<=0)return 0;for(n>1?(a=t.log(f),u=t.exp(f*(a-1)-d),s=o<.5?o:1-o,r=(2.30753+.27061*(l=t.sqrt(-2*t.log(s))))/(1+l*(.99229+.04481*l))-l,o<.5&&(r=-r),r=t.max(.001,n*t.pow(1-1/(9*n)-r/(3*t.sqrt(n)),3))):r=o<(l=1-n*(.253+.12*n))?t.pow(o/l,1/n):1-t.log(1-(o-l)/(1-l));c<12;c++){if(r<=0)return 0;if((r-=l=(i=(e.lowRegGamma(n,r)-o)/(l=n>1?u*t.exp(-(r-f)+f*(t.log(r)-a)):t.exp(-r+f*t.log(r)-d)))/(1-.5*t.min(1,i*((n-1)/r-1))))<=0&&(r=.5*(r+l)),t.abs(l)<1e-8*r)break}return r},e.erf=function(e){var o,n,r,l,i=[-1.3026537197817094,.6419697923564902,.019476473204185836,-.00956151478680863,-.000946595344482036,.000366839497852761,42523324806907e-18,-20278578112534e-18,-1624290004647e-18,130365583558e-17,1.5626441722e-8,-8.5238095915e-8,6.529054439e-9,5.059343495e-9,-9.91364156e-10,-2.27365122e-10,96467911e-18,2394038e-18,-6886027e-18,894487e-18,313092e-18,-112708e-18,381e-18,7106e-18,-1523e-18,-94e-18,121e-18,-28e-18],s=i.length-1,a=!1,u=0,c=0;for(e<0&&(e=-e,a=!0),n=4*(o=2/(2+e))-2;s>0;s--)r=u,u=n*u-c+i[s],c=r;return l=o*t.exp(-e*e+.5*(i[0]+n*u)-c),a?l-1:1-l},e.erfc=function(t){return 1-e.erf(t)},e.erfcinv=function(o){var n,r,l,i,s=0;if(o>=2)return-100;if(o<=0)return 100;for(i=o<1?o:2-o,n=-.70711*((2.30753+.27061*(l=t.sqrt(-2*t.log(i/2))))/(1+l*(.99229+.04481*l))-l);s<2;s++)n+=(r=e.erfc(n)-i)/(1.1283791670955126*t.exp(-n*n)-n*r);return o<1?n:-n},e.ibetainv=function(o,n,r){var l,i,s,a,u,c,f,d,p,b,j=n-1,h=r-1,g=0;if(o<=0)return 0;if(o>=1)return 1;for(n>=1&&r>=1?(s=o<.5?o:1-o,c=(2.30753+.27061*(a=t.sqrt(-2*t.log(s))))/(1+a*(.99229+.04481*a))-a,o<.5&&(c=-c),f=(c*c-3)/6,d=2/(1/(2*n-1)+1/(2*r-1)),p=c*t.sqrt(f+d)/d-(1/(2*r-1)-1/(2*n-1))*(f+5/6-2/(3*d)),c=n/(n+r*t.exp(2*p))):(l=t.log(n/(n+r)),i=t.log(r/(n+r)),c=o<(a=t.exp(n*l)/n)/(p=a+(u=t.exp(r*i)/r))?t.pow(n*p*o,1/n):1-t.pow(r*p*(1-o),1/r)),b=-e.gammaln(n)-e.gammaln(r)+e.gammaln(n+r);g<10;g++){if(0===c||1===c)return c;if((c-=a=(u=(e.ibeta(c,n,r)-o)/(a=t.exp(j*t.log(c)+h*t.log(1-c)+b)))/(1-.5*t.min(1,u*(j/c-h/(1-c)))))<=0&&(c=.5*(c+a)),c>=1&&(c=.5*(c+a+1)),t.abs(a)<1e-8*c&&g>0)break}return c},e.ibeta=function(o,n,r){var l=0===o||1===o?0:t.exp(e.gammaln(n+r)-e.gammaln(n)-e.gammaln(r)+n*t.log(o)+r*t.log(1-o));return!(o<0||o>1)&&(o<(n+1)/(n+r+2)?l*e.betacf(o,n,r)/n:1-l*e.betacf(1-o,r,n)/r)},e.randn=function(o,n){var r,l,i,s,a;if(n||(n=o),o)return e.create(o,n,(function(){return e.randn()}));do{r=e._random_fn(),l=1.7156*(e._random_fn()-.5),a=(i=r-.449871)*i+(s=t.abs(l)+.386595)*(.196*s-.25472*i)}while(a>.27597&&(a>.27846||l*l>-4*t.log(r)*r*r));return l/r},e.randg=function(o,n,r){var l,i,s,a,u,c,f=o;if(r||(r=n),o||(o=1),n)return(c=e.zeros(n,r)).alter((function(){return e.randg(o)})),c;o<1&&(o+=1),l=o-1/3,i=1/t.sqrt(9*l);do{do{a=1+i*(u=e.randn())}while(a<=0);a*=a*a,s=e._random_fn()}while(s>1-.331*t.pow(u,4)&&t.log(s)>.5*u*u+l*(1-a+t.log(a)));if(o==f)return l*a;do{s=e._random_fn()}while(0===s);return t.pow(s,1/f)*l*a},function(t){for(var o=0;or;)f=a,s=u+(l=-(o+c)*(o+n+c)*e/(o+2*c)/(o+2*c+1))*s,a=(i=a+l*i)+(l=(c+=1)*(n-c)*e/(o+2*c-1)/(o+2*c))*a,i/=u=s+l*u,s/=u,a/=u,u=1;return a/o}function n(o,n,r){var l=[.9815606342467192,.9041172563704749,.7699026741943047,.5873179542866175,.3678314989981802,.1252334085114689],i=[.04717533638651183,.10693932599531843,.16007832854334622,.20316742672306592,.2334925365383548,.24914704581340277],s=.5*o;if(s>=8)return 1;var a,u=2*e.normal.cdf(s,0,1,1,0)-1;u=u>=t.exp(-50/r)?t.pow(u,r):0;for(var c=s,f=(8-s)/(a=o>3?2:3),d=c+f,p=0,b=r-1,j=1;j<=a;j++){for(var h=0,g=.5*(d+c),m=.5*(d-c),v=1;v<=12;v++){var y,C=g+m*(660)break;var w=2*e.normal.cdf(C,0,1,1,0)*.5-2*e.normal.cdf(C,o,1,1,0)*.5;w>=t.exp(-30/b)&&(h+=w=i[y-1]*t.exp(-.5*x)*t.pow(w,b))}p+=h*=2*m*r/t.sqrt(2*t.PI),c=d,d+=f}return(u+=p)<=t.exp(-30/n)?0:(u=t.pow(u,n))>=1?1:u}!function(t){for(var o=0;o1||o<0?0:1==n&&1==r?1:n<512&&r<512?t.pow(o,n-1)*t.pow(1-o,r-1)/e.betafn(n,r):t.exp((n-1)*t.log(o)+(r-1)*t.log(1-o)-e.betaln(n,r))},cdf:function(t,o,n){return t>1||t<0?1*(t>1):e.ibeta(t,o,n)},inv:function(t,o,n){return e.ibetainv(t,o,n)},mean:function(e,t){return e/(e+t)},median:function(t,o){return e.ibetainv(.5,t,o)},mode:function(e,t){return(e-1)/(e+t-2)},sample:function(t,o){var n=e.randg(t);return n/(n+e.randg(o))},variance:function(e,o){return e*o/(t.pow(e+o,2)*(e+o+1))}}),e.extend(e.centralF,{pdf:function(o,n,r){var l;return o<0?0:n<=2?0===o&&n<2?1/0:0===o&&2===n?1:1/e.betafn(n/2,r/2)*t.pow(n/r,n/2)*t.pow(o,n/2-1)*t.pow(1+n/r*o,-(n+r)/2):(l=n*o/(r+o*n),n*(r/(r+o*n))/2*e.binomial.pdf((n-2)/2,(n+r-2)/2,l))},cdf:function(t,o,n){return t<0?0:e.ibeta(o*t/(o*t+n),o/2,n/2)},inv:function(t,o,n){return n/(o*(1/e.ibetainv(t,o/2,n/2)-1))},mean:function(e,t){return t>2?t/(t-2):void 0},mode:function(e,t){return e>2?t*(e-2)/(e*(t+2)):void 0},sample:function(t,o){return 2*e.randg(t/2)/t/(2*e.randg(o/2)/o)},variance:function(e,t){if(!(t<=4))return 2*t*t*(e+t-2)/(e*(t-2)*(t-2)*(t-4))}}),e.extend(e.cauchy,{pdf:function(e,o,n){return n<0?0:n/(t.pow(e-o,2)+t.pow(n,2))/t.PI},cdf:function(e,o,n){return t.atan((e-o)/n)/t.PI+.5},inv:function(e,o,n){return o+n*t.tan(t.PI*(e-.5))},median:function(e){return e},mode:function(e){return e},sample:function(o,n){return e.randn()*t.sqrt(1/(2*e.randg(.5)))*n+o}}),e.extend(e.chisquare,{pdf:function(o,n){return o<0?0:0===o&&2===n?.5:t.exp((n/2-1)*t.log(o)-o/2-n/2*t.log(2)-e.gammaln(n/2))},cdf:function(t,o){return t<0?0:e.lowRegGamma(o/2,t/2)},inv:function(t,o){return 2*e.gammapinv(t,.5*o)},mean:function(e){return e},median:function(e){return e*t.pow(1-2/(9*e),3)},mode:function(e){return e-2>0?e-2:0},sample:function(t){return 2*e.randg(t/2)},variance:function(e){return 2*e}}),e.extend(e.exponential,{pdf:function(e,o){return e<0?0:o*t.exp(-o*e)},cdf:function(e,o){return e<0?0:1-t.exp(-o*e)},inv:function(e,o){return-t.log(1-e)/o},mean:function(e){return 1/e},median:function(e){return 1/e*t.log(2)},mode:function(){return 0},sample:function(o){return-1/o*t.log(e._random_fn())},variance:function(e){return t.pow(e,-2)}}),e.extend(e.gamma,{pdf:function(o,n,r){return o<0?0:0===o&&1===n?1/r:t.exp((n-1)*t.log(o)-o/r-e.gammaln(n)-n*t.log(r))},cdf:function(t,o,n){return t<0?0:e.lowRegGamma(o,t/n)},inv:function(t,o,n){return e.gammapinv(t,o)*n},mean:function(e,t){return e*t},mode:function(e,t){if(e>1)return(e-1)*t},sample:function(t,o){return e.randg(t)*o},variance:function(e,t){return e*t*t}}),e.extend(e.invgamma,{pdf:function(o,n,r){return o<=0?0:t.exp(-(n+1)*t.log(o)-r/o-e.gammaln(n)+n*t.log(r))},cdf:function(t,o,n){return t<=0?0:1-e.lowRegGamma(o,n/t)},inv:function(t,o,n){return n/e.gammapinv(1-t,o)},mean:function(e,t){return e>1?t/(e-1):void 0},mode:function(e,t){return t/(e+1)},sample:function(t,o){return o/e.randg(t)},variance:function(e,t){if(!(e<=2))return t*t/((e-1)*(e-1)*(e-2))}}),e.extend(e.kumaraswamy,{pdf:function(e,o,n){return 0===e&&1===o?n:1===e&&1===n?o:t.exp(t.log(o)+t.log(n)+(o-1)*t.log(e)+(n-1)*t.log(1-t.pow(e,o)))},cdf:function(e,o,n){return e<0?0:e>1?1:1-t.pow(1-t.pow(e,o),n)},inv:function(e,o,n){return t.pow(1-t.pow(1-e,1/n),1/o)},mean:function(t,o){return o*e.gammafn(1+1/t)*e.gammafn(o)/e.gammafn(1+1/t+o)},median:function(e,o){return t.pow(1-t.pow(2,-1/o),1/e)},mode:function(e,o){if(e>=1&&o>=1&&1!==e&&1!==o)return t.pow((e-1)/(e*o-1),1/e)},variance:function(){throw new Error("variance not yet implemented")}}),e.extend(e.lognormal,{pdf:function(e,o,n){return e<=0?0:t.exp(-t.log(e)-.5*t.log(2*t.PI)-t.log(n)-t.pow(t.log(e)-o,2)/(2*n*n))},cdf:function(o,n,r){return o<0?0:.5+.5*e.erf((t.log(o)-n)/t.sqrt(2*r*r))},inv:function(o,n,r){return t.exp(-1.4142135623730951*r*e.erfcinv(2*o)+n)},mean:function(e,o){return t.exp(e+o*o/2)},median:function(e){return t.exp(e)},mode:function(e,o){return t.exp(e-o*o)},sample:function(o,n){return t.exp(e.randn()*n+o)},variance:function(e,o){return(t.exp(o*o)-1)*t.exp(2*e+o*o)}}),e.extend(e.noncentralt,{pdf:function(o,n,r){return t.abs(r)<1e-14?e.studentt.pdf(o,n):t.abs(o)<1e-14?t.exp(e.gammaln((n+1)/2)-r*r/2-.5*t.log(t.PI*n)-e.gammaln(n/2)):n/o*(e.noncentralt.cdf(o*t.sqrt(1+2/n),n+2,r)-e.noncentralt.cdf(o,n,r))},cdf:function(o,n,r){var l=1e-14;if(t.abs(r)l||a>l;)u=a,f>0&&(d*=r*r/(2*f),p*=r*r/(2*(f+.5))),s+=.5*(a=d*e.beta.cdf(c,f+.5,n/2)+p*e.beta.cdf(c,f+1,n/2)),f++;return i?1-s:s}}),e.extend(e.normal,{pdf:function(e,o,n){return t.exp(-.5*t.log(2*t.PI)-t.log(n)-t.pow(e-o,2)/(2*n*n))},cdf:function(o,n,r){return.5*(1+e.erf((o-n)/t.sqrt(2*r*r)))},inv:function(t,o,n){return-1.4142135623730951*n*e.erfcinv(2*t)+o},mean:function(e){return e},median:function(e){return e},mode:function(e){return e},sample:function(t,o){return e.randn()*o+t},variance:function(e,t){return t*t}}),e.extend(e.pareto,{pdf:function(e,o,n){return e1e100?1e100:n,1/(t.sqrt(n)*e.betafn(.5,n/2))*t.pow(1+o*o/n,-(n+1)/2)},cdf:function(o,n){var r=n/2;return e.ibeta((o+t.sqrt(o*o+n))/(2*t.sqrt(o*o+n)),r,r)},inv:function(o,n){var r=e.ibetainv(2*t.min(o,1-o),.5*n,.5);return r=t.sqrt(n*(1-r)/r),o>.5?r:-r},mean:function(e){return e>1?0:void 0},median:function(){return 0},mode:function(){return 0},sample:function(o){return e.randn()*t.sqrt(o/(2*e.randg(o/2)))},variance:function(e){return e>2?e/(e-2):e>1?1/0:void 0}}),e.extend(e.weibull,{pdf:function(e,o,n){return e<0||o<0||n<0?0:n/o*t.pow(e/o,n-1)*t.exp(-t.pow(e/o,n))},cdf:function(e,o,n){return e<0?0:1-t.exp(-t.pow(e/o,n))},inv:function(e,o,n){return o*t.pow(-t.log(1-e),1/n)},mean:function(t,o){return t*e.gammafn(1+1/o)},median:function(e,o){return e*t.pow(t.log(2),1/o)},mode:function(e,o){return o<=1?0:e*t.pow((o-1)/o,1/o)},sample:function(o,n){return o*t.pow(-t.log(e._random_fn()),1/n)},variance:function(o,n){return o*o*e.gammafn(1+2/n)-t.pow(e.weibull.mean(o,n),2)}}),e.extend(e.uniform,{pdf:function(e,t,o){return eo?0:1/(o-t)},cdf:function(e,t,o){return e=r)return 1;if(l<0||l>1||r<=0)return NaN;var a=l,u=(n=t.floor(n))+1,c=r-n,f=u+c,d=t.exp(e.gammaln(f)-e.gammaln(c)-e.gammaln(u)+u*t.log(a)+c*t.log(1-a));return i=a<(u+1)/(f+2)?d*o(a,u,c,s):1-d*o(1-a,c,u,s),t.round(1/s*(1-i))/(1/s)}}),e.extend(e.negbin,{pdf:function(o,n,r){return o===o>>>0&&(o<0?0:e.combination(o+n-1,n-1)*t.pow(1-r,o)*t.pow(r,n))},cdf:function(t,o,n){var r=0,l=0;if(t<0)return 0;for(;l<=t;l++)r+=e.negbin.pdf(l,o,n);return r}}),e.extend(e.hypgeom,{pdf:function(o,n,r,l){if(o!=o|0)return!1;if(o<0||ol||o>r)return 0;if(2*r>n)return 2*l>n?e.hypgeom.pdf(n-r-l+o,n,n-r,n-l):e.hypgeom.pdf(l-o,n,n-r,l);if(2*l>n)return e.hypgeom.pdf(r-o,n,r,n-l);if(r1&&s=l||o>=r)return 1;if(2*r>n)return 2*l>n?e.hypgeom.cdf(n-r-l+o,n,n-r,n-l):1-e.hypgeom.cdf(l-o-1,n,n-r,l);if(2*l>n)return 1-e.hypgeom.cdf(r-o-1,n,r,n-l);if(r1&&al);return r-1},sampleLarge:function(o){var n,r,l,i,s,a,u,c,f,d,p=o;for(i=t.sqrt(p),s=t.log(p),a=.02483*(u=.931+2.53*i)-.059,c=1.1239+1.1328/(u-3.4),f=.9277-3.6224/(u-2);;){if(r=t.random()-.5,l=t.random(),d=.5-t.abs(r),n=t.floor((2*a/d+u)*r+p+.43),d>=.07&&l<=f)return n;if(!(n<0||d<.013&&l>d)&&t.log(l)+t.log(c)-t.log(a/(d*d)+u)<=n*s-p-e.loggam(n+1))return n}},sample:function(e){return e<10?this.sampleSmall(e):this.sampleLarge(e)}}),e.extend(e.triangular,{pdf:function(e,t,o,n){return o<=t||no?NaN:eo?0:en?NaN:e<=o?0:e>=n?1:e<=r?t.pow(e-o,2)/((n-o)*(r-o)):1-t.pow(n-e,2)/((n-o)*(n-r))},inv:function(e,o,n,r){return n<=o||rn?NaN:e<=(r-o)/(n-o)?o+(n-o)*t.sqrt(e*((r-o)/(n-o))):o+(n-o)*(1-t.sqrt((1-e)*(1-(r-o)/(n-o))))},mean:function(e,t,o){return(e+t+o)/3},median:function(e,o,n){return n<=(e+o)/2?o-t.sqrt((o-e)*(o-n))/t.sqrt(2):n>(e+o)/2?e+t.sqrt((o-e)*(n-e))/t.sqrt(2):void 0},mode:function(e,t,o){return o},sample:function(o,n,r){var l=e._random_fn();return l<(r-o)/(n-o)?o+t.sqrt(l*(n-o)*(r-o)):n-t.sqrt((1-l)*(n-o)*(n-r))},variance:function(e,t,o){return(e*e+t*t+o*o-e*t-e*o-t*o)/18}}),e.extend(e.arcsine,{pdf:function(e,o,n){return n<=o?NaN:e<=o||e>=n?0:2/t.PI*t.pow(t.pow(n-o,2)-t.pow(2*e-o-n,2),-.5)},cdf:function(e,o,n){return e25e3)return n(o,1,i);var u,c=.5*l,f=c*t.log(l)-l*t.log(2)-e.gammaln(c),d=c-1,p=.25*l;u=l<=100?1:l<=800?.5:l<=5e3?.25:.125,f+=t.log(u);for(var b=0,j=1;j<=50;j++){for(var h=0,g=(2*j-1)*u,m=1;m<=16;m++){var v,y;8=-30&&(h+=n(8=1&&h<=1e-14)break;b+=h}if(h>1e-14)throw new Error("tukey.cdf failed to converge");return b>1&&(b=1),b},inv:function(o,n,r){if(r<2||n<2)return NaN;if(o<0||o>1)return NaN;if(0===o)return 0;if(1===o)return 1/0;var l,i=function(e,o,n){var r=.5-.5*e,l=t.sqrt(t.log(1/(r*r))),i=l+((((-453642210148e-16*l-.204231210125)*l-.342242088547)*l-1)*l+.322232421088)/((((.0038560700634*l+.10353775285)*l+.531103462366)*l+.588581570495)*l+.099348462606);n<120&&(i+=(i*i*i+i)/n/4);var s=.8832-.2368*i;return n<120&&(s+=-1.214/n+1.208*i/n),i*(s*t.log(o-1)+1.4142)}(o,n,r),s=e.tukey.cdf(i,n,r)-o;l=s>0?t.max(0,i-1):i+1;for(var a,u=e.tukey.cdf(l,n,r)-o,c=1;c<50;c++)if(a=l-u*(l-i)/(u-s),s=u,i=l,a<0&&(a=0,u=-o),u=e.tukey.cdf(a,n,r)-o,l=a,t.abs(l-i)<1e-4)return a;throw new Error("tukey.inv failed to converge")}})}(t,Math),function(e,t){var o,n,r=Array.prototype.push,l=e.utils.isArray;function i(t){return l(t)||t instanceof e}e.extend({add:function(t,o){return i(o)?(i(o[0])||(o=[o]),e.map(t,(function(e,t,n){return e+o[t][n]}))):e.map(t,(function(e){return e+o}))},subtract:function(t,o){return i(o)?(i(o[0])||(o=[o]),e.map(t,(function(e,t,n){return e-o[t][n]||0}))):e.map(t,(function(e){return e-o}))},divide:function(t,o){return i(o)?(i(o[0])||(o=[o]),e.multiply(t,e.inv(o))):e.map(t,(function(e){return e/o}))},multiply:function(t,o){var n,r,l,s,a,u,c,f;if(void 0===t.length&&void 0===o.length)return t*o;if(a=t.length,u=t[0].length,c=e.zeros(a,l=i(o)?o[0].length:u),f=0,i(o)){for(;fn&&(r[l-1][i-1]=t[l][i])}var s=n%2?-1:1;o+=e(r)*t[0][n]*s}return o},gauss_elimination:function(o,n){var r,l,i,s,a=0,u=0,c=o.length,f=o[0].length,d=1,p=0,b=[];for(r=(o=e.aug(o,n))[0].length,a=0;a=0;a--){for(p=0,u=a+1;u<=c-1;u++)p+=b[u]*o[a][u];b[a]=(o[a][r-1]-p)/o[a][a]}return b},gauss_jordan:function(o,n){var r,l,i,s=e.aug(o,n),a=s.length,u=s[0].length,c=0;for(l=0;lt.abs(s[f][l])&&(f=i);var d=s[l];for(s[l]=s[f],s[f]=d,i=l+1;i=0;l--){for(c=s[l][l],i=0;il-1;r--)s[i][r]-=s[l][r]*s[i][l]/c;for(s[l][l]/=c,r=a;rf?(p[c][f]=o[c][f],b[c][f]=j[c][f]=0):cl;)i=u,u=e.add(e.multiply(a,i),s),c++;return u},gauss_seidel:function(o,n,r,l){for(var i,s,a,u,c,f=0,d=o.length,p=[],b=[],j=[];fi?(p[f][i]=o[f][i],b[f][i]=j[f][i]=0):fl;)s=c,c=e.add(e.multiply(u,s),a),f+=1;return c},SOR:function(o,n,r,l,i){for(var s,a,u,c,f,d=0,p=o.length,b=[],j=[],h=[];ds?(b[d][s]=o[d][s],j[d][s]=h[d][s]=0):dl;)a=f,f=e.add(e.multiply(c,a),u),d++;return f},householder:function(o){for(var n,r,l,i,s=o.length,a=o[0].length,u=0,c=[],f=[];u0?-1:1)*t.sqrt(n),r=t.sqrt((n*n-o[u+1][u]*n)/2),(c=e.zeros(s,1))[u+1][0]=(o[u+1][u]-n)/(2*r),l=u+2;l0?t.PI/4:-t.PI/4:t.atan(2*o[l][i]/(o[l][l]-o[i][i]))/2,(u=e.identity(f,f))[l][l]=t.cos(a),u[l][i]=-t.sin(a),u[i][l]=t.sin(a),u[i][i]=t.cos(a),d=e.multiply(d,u),o=e.multiply(e.multiply(e.inv(u),o),u),c=0,n=1;n.001&&(c=1)}for(n=0;n=f;)i=l(e,n+r),s=l(e,n),p[d]=(o[i]-2*o[s]+o[2*s-i])/(r*r),r/=2,d++;for(u=p.length,a=1;1!=u;){for(c=0;cn);r++);return o[r-=1]+(n-t[r])*d[r]+e.sq(n-t[r])*l[r]+(n-t[r])*e.sq(n-t[r])*p[r]},gauss_quadrature:function(){throw new Error("gauss_quadrature not yet implemented")},PCA:function(t){var o,n,r,l,i,s=t.length,a=t[0].length,u=0,c=[],f=[],d=[],p=[],b=[],j=[],h=[];for(u=0;u1||n>1||e<=0||n<=0)throw new Error("Proportions should be greater than 0 and less than 1");var l=(e*o+n*r)/(o+r);return(e-n)/t.sqrt(l*(1-l)*(1/o+1/r))}e.extend({zscore:function(){var t=o.call(arguments);return n(t[1])?(t[0]-t[1])/t[2]:(t[0]-e.mean(t[1]))/e.stdev(t[1],t[2])},ztest:function(){var n,l=o.call(arguments);return r(l[1])?(n=e.zscore(l[0],l[1],l[3]),1===l[2]?e.normal.cdf(-t.abs(n),0,1):2*e.normal.cdf(-t.abs(n),0,1)):l.length>2?(n=e.zscore(l[0],l[1],l[2]),1===l[3]?e.normal.cdf(-t.abs(n),0,1):2*e.normal.cdf(-t.abs(n),0,1)):(n=l[0],1===l[1]?e.normal.cdf(-t.abs(n),0,1):2*e.normal.cdf(-t.abs(n),0,1))}}),e.extend(e.fn,{zscore:function(e,t){return(e-this.mean())/this.stdev(t)},ztest:function(o,n,r){var l=t.abs(this.zscore(o,r));return 1===n?e.normal.cdf(-l,0,1):2*e.normal.cdf(-l,0,1)}}),e.extend({tscore:function(){var n=o.call(arguments);return 4===n.length?(n[0]-n[1])/(n[2]/t.sqrt(n[3])):(n[0]-e.mean(n[1]))/(e.stdev(n[1],!0)/t.sqrt(n[1].length))},ttest:function(){var r,l=o.call(arguments);return 5===l.length?(r=t.abs(e.tscore(l[0],l[1],l[2],l[3])),1===l[4]?e.studentt.cdf(-r,l[3]-1):2*e.studentt.cdf(-r,l[3]-1)):n(l[1])?(r=t.abs(l[0]),1==l[2]?e.studentt.cdf(-r,l[1]-1):2*e.studentt.cdf(-r,l[1]-1)):(r=t.abs(e.tscore(l[0],l[1])),1==l[2]?e.studentt.cdf(-r,l[1].length-1):2*e.studentt.cdf(-r,l[1].length-1))}}),e.extend(e.fn,{tscore:function(e){return(e-this.mean())/(this.stdev(!0)/t.sqrt(this.cols()))},ttest:function(o,n){return 1===n?1-e.studentt.cdf(t.abs(this.tscore(o)),this.cols()-1):2*e.studentt.cdf(-t.abs(this.tscore(o)),this.cols()-1)}}),e.extend({anovafscore:function(){var n,r,l,i,s,a,u,c,f=o.call(arguments);if(1===f.length){for(s=new Array(f[0].length),u=0;u.5?1-n:n)})),c=t.studentt.inv(.975,o.df_resid),f=o.coef.map((function(e,t){var o=c*s[t];return[e-o,e+o]}));return{se:s,t:a,p:u,sigmaHat:i,interval95:f}}(r),i=function(e){var o,n,r,l=e.R2/e.df_model/((1-e.R2)/e.df_resid);return{F_statistic:l,pvalue:1-(o=l,n=e.df_model,r=e.df_resid,t.beta.cdf(o/(r/n+o),n/2,r/2))}}(r),s=1-(1-r.R2)*((r.nobs-1)/r.df_resid);return r.t=l,r.f=i,r.adjust_R2=s,r}}}(),t.extend({buildxmatrix:function(){for(var e=new Array(arguments.length),o=0;o1){for(i=[],n=0;nt+"."+e))],i.splice(i.indexOf(t),1))}}if(i.length<1)e[l]=n[l];else for(let o=0;o0?c+=e+" = "+t.get(r)+";\n":c+="var "+e+" = "+n+";\n"}))}else{let e=Object.keys(t);if(e.length){let o,n={};for(let t=0;t0){let e=e.split(".");n[e[0]]={}}o=Object.keys(n);for(let e=0;e0?c+=o+" = "+t[e[n]]+";\n":c+="var "+o+" = "+t[e[n]]+";\n"}}}let d=(e=function(e,t){let o="",n=0,r=["=","!",">","<"];for(let t=0;t0&&"="===e[t]&&-1===r.indexOf(e[t-1])&&-1===r.indexOf(e[t+1])&&(o+="="));return o=o.replace(/\^/g,"**"),o=o.replace(/<>/g,"!="),o=o.replace(/&/g,"+"),o=o.replace(/\$/g,""),o}(e=(e=e.replace(/\$/g,"")).replace(/!/g,"."))).match(/(('.*?'!)|(\w*!))?(\$?[A-Z]+\$?[0-9]*):(\$?[A-Z]+\$?[0-9]*)?/g);d&&d.length&&(e=s(d,e));let p=new Function(c+"; return "+e)();return null===p&&(p=0),p};return u.getColumnNameFromCoords=function(e,t){return n="",(o=parseInt(e))>701?(n+=String.fromCharCode(64+parseInt(o/676)),n+=String.fromCharCode(64+parseInt(o%676/26))):o>25&&(n+=String.fromCharCode(64+parseInt(o/26))),n+String.fromCharCode(65+o%26)+(parseInt(t)+1);var o,n},u.getCoordsFromColumnName=function(e){var t=/^[a-zA-Z]+/.exec(e);if(t){for(var o=0,n=0;n0&&r--,[o,r]}},u.getRangeFromTokens=function(e){e=e.filter((function(e){return"#REF!"!=e}));for(var t="",o="",n=0;n=0?t=".":e[n].indexOf("!")>=0&&(t="!"),t&&(o=e[n].split(t),e[n]=o[1],o=o[0]+t);return e.sort((function(e,t){var o=Helpers.getCoordsFromColumnName(e),n=Helpers.getCoordsFromColumnName(t);return o[1]>n[1]?1:o[1]n[0]?1:o[0]0){var t=e.split(".");e=t[1],t=t[0]+"."}else e.indexOf("!")>0?(t=e.split("!"),e=t[1],t=t[0]+"!"):t="";e=e.split(":");var o=u.getCoordsFromColumnName(e[0]),n=u.getCoordsFromColumnName(e[1]);if(o[0]<=n[0])var r=o[0],l=n[0];else r=n[0],l=o[0];if(null===o[1]&&null==n[1])for(var i=null,s=null,a=Object.keys(vars),c=0;cs)&&(s=f[1])}else o[1]<=n[1]?(i=o[1],s=n[1]):(i=n[1],s=o[1]);for(var d=[],p=i;p<=s;p++){var b=[];for(c=r;c<=l;c++)b.push(t+u.getColumnNameFromCoords(c,p));d.push(b)}return d},u.setFormula=function(t){let o=Object.keys(t);for(let n=0;n{t.push(e)})),t}function h(e,t){let o=-1;const n=e.length;for(;++oArray.isArray(e)))&&0!==e.length||(e=[[...e]]),e.map(((t,o)=>{t.map(((t,n)=>{t||(e[o][n]=0)}))}));const o=e.reduce(((t,o,n)=>o.length>e[t].length?n:t),0),n=e[o].length;return e.map((e=>[...e,...Array(n-e.length).fill(t||0)]))}function v(){let e;if(1===arguments.length){const o=arguments[0];e=null!=(t=o)&&"number"==typeof t.length&&"string"!=typeof t?j.apply(null,arguments):[o]}else e=Array.from(arguments);for(var t;!C(e);)e=y(e);return e}function y(e){return e&&e.reduce?e.reduce(((e,t)=>{const o=Array.isArray(e),n=Array.isArray(t);return o&&n?e.concat(t):o?(e.push(t),e):n?[e].concat(t):[e,t]})):[e]}function C(e){if(!e)return!1;for(let t=0;te.map((e=>e[o])))):s}function A(e,t){let o=null;return h(e,((e,n)=>{if(e[0]===t)return o=n,!1})),null==o?s:o}function E(){for(let e=0;e"number"==typeof e))}function S(e){if("boolean"==typeof e)return e;if(e instanceof Error)return e;if("number"==typeof e)return 0!==e;if("string"==typeof e){const t=e.toUpperCase();if("TRUE"===t)return!0;if("FALSE"===t)return!1}return e instanceof Date&&!isNaN(e)||s}function D(e){if(!isNaN(e)){if(e instanceof Date)return new Date(e);const t=parseFloat(e);return t<0||t>=2958466?c:function(e){e<60&&(e+=1);const t=Math.floor(e-25569),o=new Date(86400*t*1e3),n=e-Math.floor(e)+1e-7;let r=Math.floor(86400*n);const l=r%60;r-=l;const i=Math.floor(r/3600),s=Math.floor(r/60)%60;let a=o.getUTCDate(),u=o.getUTCMonth();return e>=60&&e<61&&(a=29,u=1),new Date(o.getUTCFullYear(),u,a,i,s,l)}(t)}return"string"!=typeof e||(e=/(\d{4})-(\d\d?)-(\d\d?)$/.test(e)?new Date(e+"T00:00:00.000"):new Date(e),isNaN(e))?s:e}function T(e){let t,o=e.length;for(;o--;){if(t=D(e[o]),t===s)return t;e[o]=t}return e}function F(e){return e instanceof Error?e:null==e?0:("boolean"==typeof e&&(e=+e),isNaN(e)||""===e?s:parseFloat(e))}function L(e){let t,o;if(!e||0===(t=e.length))return s;for(;t--;){if(e[t]instanceof Error)return e[t];if(o=F(e[t]),o instanceof Error)return o;e[t]=o}return e}function R(e){return e instanceof Error?e:null==e?"":e.toString()}function O(){let e=arguments.length;for(;e--;)if("string"==typeof arguments[e])return!0;return!1}function k(e){return null!=e}const H="=",B=[">",">=","<","<=","=","<>"],P="operator",_="literal",V=[P,_],U=P,q=_;function z(e,t){if(-1===V.indexOf(t))throw new Error("Unsupported token type: "+t);return{value:e,type:t}}function Y(e){return function(e){let t="";const o=[];for(let n=0;n=0?o.push(z(r,U)):t+=r}return t.length>0&&o.push(z(function(e){return"string"!=typeof e||/^\d+(\.\d+)?$/.test(e)&&(e=-1===e.indexOf(".")?parseInt(e,10):parseFloat(e)),e}(t),q)),o.length>0&&o[0].type!==U&&o.unshift(z(H,U)),o}(function(e){const t=e.length,o=[];let n=0,r="",l="";for(;n":case"<":case"=":l+=t,r.length>0&&(o.push(r),r="");break;default:l.length>0&&(o.push(l),l=""),r+=t}n++}return r.length>0&&o.push(r),l.length>0&&o.push(l),o}(e))}const W=function(e){const t=[];let o;for(let n=0;n":o=e[0]>e[1];break;case">=":o=e[0]>=e[1];break;case"<":o=e[0]":o=e[0]!=e[1]}return o}(t,o)},X={};function G(e){return[s,a,i,c,u,l].indexOf(e)>=0||"number"==typeof e&&(isNaN(e)||!isFinite(e))}function K(e){return G(e)||e===f}function $(e){return!0===e||!1===e}function J(e){return"number"==typeof e&&!isNaN(e)&&isFinite(e)}function Q(e){return"string"==typeof e}function Z(){const e=[];for(let t=0;te&&(i=!0)}return r}function te(){const e=v(arguments).filter(k);if(0===e.length)return i;const t=E.apply(void 0,e);if(t)return t;const o=N(e),n=o.length;let r,l=0,s=0;for(let e=0;e{switch(e){case l:return 1;case i:return 2;case s:return 3;case a:return 4;case u:return 5;case c:return 6;case f:return 7;case p:return 8}return f};const ne={DIST:function(e,t,o,r,l,i){return arguments.length<4?s:(l=void 0===l?0:l,i=void 0===i?1:i,M(e=F(e),t=F(t),o=F(o),l=F(l),i=F(i))?s:(e=(e-l)/(i-l),r?n.beta.cdf(e,t,o):n.beta.pdf(e,t,o)))},INV:(e,t,o,r,l)=>(r=void 0===r?0:r,l=void 0===l?1:l,M(e=F(e),t=F(t),o=F(o),r=F(r),l=F(l))?s:n.beta.inv(e,t,o)*(l-r)+r)},re={DIST:(e,t,o,r)=>M(e=F(e),t=F(t),o=F(o),r=F(r))?s:r?n.binomial.cdf(e,t,o):n.binomial.pdf(e,t,o)};re.DIST.RANGE=(e,t,o,n)=>{if(n=void 0===n?o:n,M(e=F(e),t=F(t),o=F(o),n=F(n)))return s;let r=0;for(let l=o;l<=n;l++)r+=Ue(e,l)*Math.pow(t,l)*Math.pow(1-t,e-l);return r},re.INV=(e,t,o)=>{if(M(e=F(e),t=F(t),o=F(o)))return s;let r=0;for(;r<=e;){if(n.binomial.cdf(r,e,t)>=o)return r;r++}};const le={DIST:(e,t,o)=>M(e=F(e),t=F(t))?s:o?n.chisquare.cdf(e,t):n.chisquare.pdf(e,t)};le.DIST.RT=(e,t)=>!e|!t?f:e<1||t>Math.pow(10,10)?c:"number"!=typeof e||"number"!=typeof t?s:1-n.chisquare.cdf(e,t),le.INV=(e,t)=>M(e=F(e),t=F(t))?s:n.chisquare.inv(e,t),le.INV.RT=(e,t)=>!e|!t?f:e<0||e>1||t<1||t>Math.pow(10,10)?c:"number"!=typeof e||"number"!=typeof t?s:n.chisquare.inv(1-e,t),le.TEST=function(e,t){if(2!==arguments.length)return f;if(!(e instanceof Array&&t instanceof Array))return s;if(e.length!==t.length)return s;if(e[0]&&t[0]&&e[0].length!==t[0].length)return s;const o=e.length;let n,r,l;for(r=0;r=2;)o=o*e/n,n-=2;let r=o,l=t;for(;r>1e-10*o;)l+=2,r=r*e/l,o+=r;return 1-o}(u,a))/1e6};const ie={};function se(){return N(v(arguments)).length}function ae(){const e=v(arguments);return e.length-ue(e)}function ue(){const e=v(arguments);let t,o=0;for(let n=0;nM(e=F(e),t=F(t),o=F(o))?s:n.normalci(1,e,t,o)[1]-1,ie.T=(e,t,o)=>M(e=F(e),t=F(t),o=F(o))?s:n.tci(1,e,t,o)[1]-1;const ce={P:(e,t)=>{if(M(e=L(v(e)),t=L(v(t))))return s;const o=n.mean(e),r=n.mean(t);let l=0;const i=e.length;for(let n=0;nM(e=L(v(e)),t=L(v(t)))?s:n.covariance(e,t)},fe={DIST:(e,t,o)=>M(e=F(e),t=F(t))?s:o?n.exponential.cdf(e,t):n.exponential.pdf(e,t)},de={};function pe(e,t,o){if(M(e=F(e),t=L(v(t)),o=L(v(o))))return s;const r=n.mean(o),l=n.mean(t),i=o.length;let a=0,u=0;for(let e=0;eM(e=F(e),t=F(t),o=F(o))?s:r?n.centralF.cdf(e,t,o):n.centralF.pdf(e,t,o),de.DIST.RT=function(e,t,o){return 3!==arguments.length?f:e<0||t<1||o<1?c:"number"!=typeof e||"number"!=typeof t||"number"!=typeof o?s:1-n.centralF.cdf(e,t,o)},de.INV=(e,t,o)=>M(e=F(e),t=F(t),o=F(o))?s:e<=0||e>1?c:n.centralF.inv(e,t,o),de.INV.RT=function(e,t,o){return 3!==arguments.length?f:e<0||e>1||t<1||t>Math.pow(10,10)||o<1||o>Math.pow(10,10)?c:"number"!=typeof e||"number"!=typeof t||"number"!=typeof o?s:n.centralF.inv(1-e,t,o)},de.TEST=(e,t)=>{if(!e||!t)return f;if(!(e instanceof Array&&t instanceof Array))return f;if(e.length<2||t.length<2)return i;const o=(e,t)=>{let o=0;for(let n=0;n1||t<=0||o<=0?c:"number"!=typeof e||"number"!=typeof t||"number"!=typeof o?s:n.gamma.inv(e,t,o)},je.PRECISE=function(e){return 1!==arguments.length?f:e<=0?c:"number"!=typeof e?s:n.gammaln(e)};const he={};function ge(e,t){return M(e=L(v(e)),t=F(t))?e:t<0||e.lengtht-e))[t-1]}function me(e,t){if(M(e=L(v(e)),t=L(v(t))))return s;const o=n.mean(e),r=n.mean(t),l=t.length;let i=0,a=0;for(let n=0;n{if(M(e=F(e),t=F(t),o=F(o),n=F(n)))return s;function l(e,t,o,n){return Ue(o,e)*Ue(n-o,t-e)/Ue(n,t)}return r?function(e,t,o,n){let r=0;for(let i=0;i<=e;i++)r+=l(i,t,o,n);return r}(e,t,o,n):l(e,t,o,n)};const ve={};function ye(){const e=v(arguments),t=E.apply(void 0,e);if(t)return t;const o=N(e);return 0===o.length?0:Math.max.apply(Math,o)}function Ce(){const e=v(arguments),t=E.apply(void 0,e);if(t)return t;const o=g(e);let r=n.median(o);return isNaN(r)&&(r=c),r}function xe(){const e=v(arguments),t=E.apply(void 0,e);if(t)return t;const o=N(e);return 0===o.length?0:Math.min.apply(Math,o)}ve.DIST=(e,t,o,r)=>M(e=F(e),t=F(t),o=F(o))?s:r?n.lognormal.cdf(e,t,o):n.lognormal.pdf(e,t,o),ve.INV=(e,t,o)=>M(e=F(e),t=F(t),o=F(o))?s:n.lognormal.inv(e,t,o);const we={MULT:function(){const e=L(v(arguments));if(e instanceof Error)return e;const t=e.length,o={};let n,r=[],l=0;for(let i=0;il&&(l=o[n],r=[]),o[n]===l&&(r[r.length]=n);return r},SNGL:function(){const e=L(v(arguments));return e instanceof Error?e:we.MULT(e).sort(((e,t)=>e-t))[0]}},Ae={DIST:(e,t,o,r)=>M(e=F(e),t=F(t),o=F(o))?s:r?n.negbin.cdf(e,t,o):n.negbin.pdf(e,t,o)},Ee={};function Me(e,t){if(M(t=L(v(t)),e=L(v(e))))return s;const o=n.mean(e),r=n.mean(t),l=e.length;let i=0,a=0,u=0;for(let n=0;nM(e=F(e),t=F(t),o=F(o))?s:o<=0?c:r?n.normal.cdf(e,t,o):n.normal.pdf(e,t,o),Ee.INV=(e,t,o)=>M(e=F(e),t=F(t),o=F(o))?s:n.normal.inv(e,t,o),Ee.S={},Ee.S.DIST=(e,t)=>(e=F(e))instanceof Error?s:t?n.normal.cdf(e,0,1):n.normal.pdf(e,0,1),Ee.S.INV=e=>(e=F(e))instanceof Error?s:n.normal.inv(e,0,1);const Ie={EXC:(e,t)=>{if(M(e=L(v(e)),t=F(t)))return s;const o=(e=e.sort(((e,t)=>e-t))).length;if(t<1/(o+1)||t>1-1/(o+1))return c;const n=t*(o+1)-1,r=Math.floor(n);return I(n===r?e[n]:e[r]+(n-r)*(e[r+1]-e[r]))},INC:(e,t)=>{if(M(e=L(v(e)),t=F(t)))return s;const o=t*((e=e.sort(((e,t)=>e-t))).length-1),n=Math.floor(o);return I(o===n?e[o]:e[n]+(o-n)*(e[n+1]-e[n]))}},Ne={EXC:(e,t,o)=>{if(o=void 0===o?3:o,M(e=L(v(e)),t=F(t),o=F(o)))return s;e=e.sort(((e,t)=>e-t));const n=Z.apply(null,e),r=e.length,l=n.length,i=Math.pow(10,o);let a=0,u=!1,c=0;for(;!u&&c=n[c]&&(t{if(o=void 0===o?3:o,M(e=L(v(e)),t=F(t),o=F(o)))return s;e=e.sort(((e,t)=>e-t));const n=Z.apply(null,e),r=e.length,l=n.length,i=Math.pow(10,o);let a=0,u=!1,c=0;for(;!u&&c=n[c]&&(tM(e=F(e),t=F(t))?s:o?n.poisson.cdf(e,t):n.poisson.pdf(e,t)},De={EXC:(e,t)=>{if(M(e=L(v(e)),t=F(t)))return s;switch(t){case 1:return Ie.EXC(e,.25);case 2:return Ie.EXC(e,.5);case 3:return Ie.EXC(e,.75);default:return c}},INC:(e,t)=>{if(M(e=L(v(e)),t=F(t)))return s;switch(t){case 1:return Ie.INC(e,.25);case 2:return Ie.INC(e,.5);case 3:return Ie.INC(e,.75);default:return c}}},Te={};function Fe(){const e=L(v(arguments));if(e instanceof Error)return e;const t=n.mean(e),o=e.length;let r=0;for(let n=0;ne-t))[t-1]}Te.AVG=(e,t,o)=>{if(M(e=F(e),t=L(v(t))))return s;const n=(o=o||!1)?(e,t)=>e-t:(e,t)=>t-e,r=(t=(t=v(t)).sort(n)).length;let l=0;for(let o=0;o1?(2*t.indexOf(e)+l+1)/2:t.indexOf(e)+1},Te.EQ=(e,t,o)=>{if(M(e=F(e),t=L(v(t))))return s;const n=(o=o||!1)?(e,t)=>e-t:(e,t)=>t-e;return(t=t.sort(n)).indexOf(e)+1},Fe.P=function(){const e=L(v(arguments));if(e instanceof Error)return e;const t=n.mean(e),o=e.length;let r=0,l=0;for(let n=0;n1!==o&&2!==o?c:1===o?Oe.DIST.RT(e,t):Oe.DIST["2T"](e,t)};Oe.DIST["2T"]=function(e,t){return 2!==arguments.length?f:e<0||t<1?c:"number"!=typeof e||"number"!=typeof t?s:2*(1-n.studentt.cdf(e,t))},Oe.DIST.RT=function(e,t){return 2!==arguments.length?f:e<0||t<1?c:"number"!=typeof e||"number"!=typeof t?s:1-n.studentt.cdf(e,t)},Oe.INV=(e,t)=>M(e=F(e),t=F(t))?s:n.studentt.inv(e,t),Oe.INV["2T"]=(e,t)=>(e=F(e),t=F(t),e<=0||e>1||t<1?c:M(e,t)?s:Math.abs(n.studentt.inv(e/2,t))),Oe.TEST=(e,t)=>{if(M(e=L(v(e)),t=L(v(t))))return s;const o=n.mean(e),r=n.mean(t);let l,i=0,a=0;for(l=0;lM(e=F(e),t=F(t),o=F(o))?s:n?1-Math.exp(-Math.pow(e/o,t)):Math.pow(e,t-1)*Math.exp(-Math.pow(e/o,t))*t/Math.pow(o,t)},_e={};function Ve(e,t,o){const n=E(e=F(e),t=F(t),o=F(o));if(n)return n;if(0===t)return 0;t=Math.abs(t);const r=-Math.floor(Math.log(t)/Math.log(10));return e>=0?Ke(Math.ceil(e/t)*t,r):0===o?-Ke(Math.floor(Math.abs(e)/t)*t,r):-Ke(Math.ceil(Math.abs(e)/t)*t,r)}function Ue(e,t){return E(e=F(e),t=F(t))||(e{if(M(e=L(v(e)),t=F(t)))return s;o=o||Re.S(e);const n=e.length;return 1-Ee.S.DIST((te(e)-t)/(o/Math.sqrt(n)),!0)},Ve.MATH=Ve,Ve.PRECISE=Ve;const qe=[];function ze(e){if((e=F(e))instanceof Error)return e;const t=Math.floor(e);return 0===t||1===t?1:(qe[t]>0||(qe[t]=ze(t-1)*t),qe[t])}function Ye(e,t){const o=E(e=F(e),t=F(t));if(o)return o;if(0===t)return 0;if(!(e>=0&&t>0||e<=0&&t<0))return c;t=Math.abs(t);const n=-Math.floor(Math.log(t)/Math.log(10));return e>=0?Ke(Math.floor(e/t)*t,n):-Ke(Math.ceil(Math.abs(e)/t),n)}Ye.MATH=(e,t,o)=>{if(t instanceof Error)return t;t=void 0===t?0:t;const n=E(e=F(e),t=F(t),o=F(o));if(n)return n;if(0===t)return 0;t=t?Math.abs(t):1;const r=-Math.floor(Math.log(t)/Math.log(10));return e>=0?Ke(Math.floor(e/t)*t,r):0===o||void 0===o?-Ke(Math.ceil(Math.abs(e)/t)*t,r):-Ke(Math.floor(Math.abs(e)/t)*t,r)},Ye.PRECISE=Ye.MATH;const We={CEILING:Ve};function Xe(e,t){const o=E(e=F(e),t=F(t));if(o)return o;if(0===e&&0===t)return c;const n=Math.pow(e,t);return isNaN(n)?c:n}function Ge(){const e=v(arguments).filter((e=>null!=e));if(0===e.length)return 0;const t=L(e);if(t instanceof Error)return t;let o=1;for(let e=0;e{if(e instanceof Error)return!1;if(t instanceof Error)e=t;else if("number"==typeof t)e+=t;else if("string"==typeof t){const o=parseFloat(t);!isNaN(o)&&(e+=o)}else if(Array.isArray(t)){const o=$e.apply(null,t);o instanceof Error?e=o:e+=o}})),e}var Je=Object.freeze({__proto__:null,ADD:function(e,t){return 2!==arguments.length?f:E(e=F(e),t=F(t))||e+t},DIVIDE:function(e,t){return 2!==arguments.length?f:E(e=F(e),t=F(t))||(0===t?i:e/t)},EQ:function(e,t){return 2!==arguments.length?f:e instanceof Error?e:t instanceof Error?t:(null===e&&(e=void 0),null===t&&(t=void 0),e===t)},GT:function(e,t){return 2!==arguments.length?f:e instanceof Error?e:t instanceof Error?t:(O(e,t)?(e=R(e),t=R(t)):(e=F(e),t=F(t)),E(e,t)||e>t)},GTE:function(e,t){return 2!==arguments.length?f:(O(e,t)?(e=R(e),t=R(t)):(e=F(e),t=F(t)),E(e,t)||e>=t)},LT:function(e,t){return 2!==arguments.length?f:(O(e,t)?(e=R(e),t=R(t)):(e=F(e),t=F(t)),E(e,t)||er||s===r&&a{const o=e.getFullYear(),n=new Date(o,2,1);if(ut(o)&&e=n)return!0;const r=t.getFullYear(),l=new Date(r,2,1);return ut(r)&&t>=l&&es||r===s&&n>=i))return(l===a&&ut(l)||o(e,t)||1===s&&29===i)&&(u=366),ct(e,t)/u;const c=a-l+1,f=(new Date(a+1,0,1)-new Date(l,0,1))/1e3/60/60/24/c;return ct(e,t)/f}case 2:return ct(e,t)/360;case 3:return ct(e,t)/365;case 4:return(i+30*s+360*a-(n+30*r+360*l))/360}}function dt(e){const t=e>-22038912e5?2:1;return Math.ceil((e-Qe)/864e5)+t}function pt(e){return 0===(e=F(e))?s:e instanceof Error?e:String.fromCharCode(e)}function bt(e){if(M(e))return e;let t=(e=e||"").charCodeAt(0);return isNaN(t)&&(t=s),t}function jt(){const e=v(arguments),t=E.apply(void 0,e);if(t)return t;let o=0;for(;(o=e.indexOf(!0))>-1;)e[o]="TRUE";let n=0;for(;(n=e.indexOf(!1))>-1;)e[n]="FALSE";return e.join("")}st.INTL=(e,t,o,n)=>{if((e=D(e))instanceof Error)return e;if((t=D(t))instanceof Error)return t;let r=!1;const l=[],i=[1,2,3,4,5,6,0],a=new RegExp("^[0|1]{7}$");if(void 0===o)o=tt[1];else if("string"==typeof o&&a.test(o)){r=!0,o=o.split("");for(let e=0;e0?f.getUTCDay():f.getDay();let t=r?l.includes(e):e===o[0]||e===o[1];for(let e=0;e{if((e=D(e))instanceof Error)return e;if((t=F(t))instanceof Error)return t;if(t<0)return c;if(!((o=void 0===o?tt[1]:tt[o])instanceof Array))return s;void 0===n?n=[]:n instanceof Array||(n=[n]);for(let e=0;e0?"+":"";return e.toString()+n+(1===t?o:t.toString()+o)}}function wt(e,t){return t=void 0===t?0:t,M(e=F(e),t=F(t))?s:n.erf(e)}function At(e){return isNaN(e)?s:n.erfc(e)}function Et(e){const t=Tt(e),o=Mt(e);return M(t,o)?s:Math.sqrt(Math.pow(t,2)+Math.pow(o,2))}function Mt(e){if(void 0===e||!0===e||!1===e)return s;if(0===e||"0"===e)return 0;if(["i","j"].indexOf(e)>=0)return 1;let t=(e=(e+="").replace("+i","+1i").replace("-i","-1i").replace("+j","+1j").replace("-j","-1j")).indexOf("+"),o=e.indexOf("-");0===t&&(t=e.indexOf("+",1)),0===o&&(o=e.indexOf("-",1));const n=e.substring(e.length-1,e.length),r="i"===n||"j"===n;return t>=0||o>=0?r?t>=0?isNaN(e.substring(0,t))||isNaN(e.substring(t+1,e.length-1))?c:Number(e.substring(t+1,e.length-1)):isNaN(e.substring(0,o))||isNaN(e.substring(o+1,e.length-1))?c:-Number(e.substring(o+1,e.length-1)):c:r?isNaN(e.substring(0,e.length-1))?c:e.substring(0,e.length-1):isNaN(e)?c:0}function It(e){const t=Tt(e),o=Mt(e);return M(t,o)?s:0===t&&0===o?i:0===t&&o>0?Math.PI/2:0===t&&o<0?-Math.PI/2:0===o&&t>0?0:0===o&&t<0?-Math.PI:t>0?Math.atan(o/t):t<0&&o>=0?Math.atan(o/t)+Math.PI:Math.atan(o/t)-Math.PI}function Nt(e){const t=Tt(e),o=Mt(e);if(M(t,o))return s;let n=e.substring(e.length-1);return n="i"===n||"j"===n?n:"i",xt(Math.cos(t)*(Math.exp(o)+Math.exp(-o))/2,-Math.sin(t)*(Math.exp(o)-Math.exp(-o))/2,n)}function St(e){const t=Tt(e),o=Mt(e);if(M(t,o))return s;let n=e.substring(e.length-1);return n="i"===n||"j"===n?n:"i",xt(Math.cos(o)*(Math.exp(t)+Math.exp(-t))/2,Math.sin(o)*(Math.exp(t)-Math.exp(-t))/2,n)}function Dt(e,t){const o=Tt(e),n=Mt(e),r=Tt(t),l=Mt(t);if(M(o,n,r,l))return s;const i=e.substring(e.length-1),a=t.substring(t.length-1);let u="i";if(("j"===i||"j"===a)&&(u="j"),0===r&&0===l)return c;const f=r*r+l*l;return xt((o*r+n*l)/f,(n*r-o*l)/f,u)}function Tt(e){if(void 0===e||!0===e||!1===e)return s;if(0===e||"0"===e)return 0;if(["i","+i","1i","+1i","-i","-1i","j","+j","1j","+1j","-j","-1j"].indexOf(e)>=0)return 0;let t=(e+="").indexOf("+"),o=e.indexOf("-");0===t&&(t=e.indexOf("+",1)),0===o&&(o=e.indexOf("-",1));const n=e.substring(e.length-1,e.length),r="i"===n||"j"===n;return t>=0||o>=0?r?t>=0?isNaN(e.substring(0,t))||isNaN(e.substring(t+1,e.length-1))?c:Number(e.substring(0,t)):isNaN(e.substring(0,o))||isNaN(e.substring(o+1,e.length-1))?c:Number(e.substring(0,o)):c:r?isNaN(e.substring(0,e.length-1))?c:0:isNaN(e)?c:e}function Ft(e){const t=Tt(e),o=Mt(e);if(M(t,o))return s;let n=e.substring(e.length-1);return n="i"===n||"j"===n?n:"i",xt(Math.sin(t)*(Math.exp(o)+Math.exp(-o))/2,Math.cos(t)*(Math.exp(o)-Math.exp(-o))/2,n)}function Lt(e){const t=Tt(e),o=Mt(e);if(M(t,o))return s;let n=e.substring(e.length-1);return n="i"===n||"j"===n?n:"i",xt(Math.cos(o)*(Math.exp(t)-Math.exp(-t))/2,Math.sin(o)*(Math.exp(t)+Math.exp(-t))/2,n)}wt.PRECISE=()=>{throw new Error("ERF.PRECISE is not implemented")},At.PRECISE=()=>{throw new Error("ERFC.PRECISE is not implemented")};const Rt=ne.DIST,Ot=ne.INV,kt=re.DIST,Ht=Ve.MATH,Bt=Ve.PRECISE,Pt=le.DIST,_t=le.DIST.RT,Vt=le.INV,Ut=le.INV.RT,qt=le.TEST,zt=ce.P,Yt=ce.P,Wt=ce.S,Xt=re.INV,Gt=At.PRECISE,Kt=wt.PRECISE,$t=fe.DIST,Jt=de.DIST,Qt=de.DIST.RT,Zt=de.INV,eo=de.INV.RT,to=Ye.MATH,oo=Ye.PRECISE,no=de.TEST,ro=be.DIST,lo=be.INV,io=je.PRECISE,so=he.DIST,ao=ve.INV,uo=ve.DIST,co=ve.INV,fo=we.MULT,po=we.SNGL,bo=Ae.DIST,jo=st.INTL,ho=Ee.DIST,go=Ee.INV,mo=Ee.S.DIST,vo=Ee.S.INV,yo=Ie.EXC,Co=Ie.INC,xo=Ne.EXC,wo=Ne.INC,Ao=Se.DIST,Eo=De.EXC,Mo=De.INC,Io=Te.AVG,No=Te.EQ,So=Fe.P,Do=Re.P,To=Re.S,Fo=Oe.DIST,Lo=Oe.DIST.RT,Ro=Oe.INV,Oo=Oe.TEST,ko=ke.P,Ho=ke.S,Bo=Pe.DIST,Po=at.INTL,_o=_e.TEST;function Vo(e){const t=[];return h(e,(e=>{e&&t.push(e)})),t}function Uo(e,t){const o={};for(let t=1;tn&&(n=t[e].length);for(let r=1;r{t+={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1}[e]})),t},t.ASC=function(){throw new Error("ASC is not implemented")},t.ASIN=function(e){if((e=F(e))instanceof Error)return e;let t=Math.asin(e);return isNaN(t)&&(t=c),t},t.ASINH=function(e){return(e=F(e))instanceof Error?e:Math.log(e+Math.sqrt(e*e+1))},t.ATAN=function(e){return(e=F(e))instanceof Error?e:Math.atan(e)},t.ATAN2=function(e,t){return E(e=F(e),t=F(t))||Math.atan2(e,t)},t.ATANH=function(e){if((e=F(e))instanceof Error)return e;let t=Math.log((1+e)/(1-e))/2;return isNaN(t)&&(t=c),t},t.AVEDEV=function(){const e=v(arguments).filter(k);if(0===e.length)return c;const t=L(e);return t instanceof Error?t:n.sum(n(t).subtract(n.mean(t)).abs()[0])/t.length},t.AVERAGE=te,t.AVERAGEA=oe,t.AVERAGEIF=function(e,t,o){if(arguments.length<=1)return f;if(o=L(v(o=o||e).filter(k)),e=v(e),o instanceof Error)return o;let n=0,r=0;const l=void 0===t||"*"===t,i=l?null:Y(t+"");for(let t=0;t=n.length?mt("0",t-n.length)+n:c},t.BIN2OCT=function(e,t){if(!Ct(e))return c;const o=e.toString();if(10===o.length&&"1"===o.substring(0,1))return(1073741312+parseInt(o.substring(1),2)).toString(8);const n=parseInt(e,2).toString(8);return void 0===t?n:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=n.length?mt("0",t-n.length)+n:c},t.BINOM=re,t.BINOMDIST=kt,t.BITAND=function(e,t){return M(e=F(e),t=F(t))?s:e<0||t<0||Math.floor(e)!==e||Math.floor(t)!==t||e>0xffffffffffff||t>0xffffffffffff?c:e&t},t.BITLSHIFT=function(e,t){return M(e=F(e),t=F(t))?s:e<0||Math.floor(e)!==e||e>0xffffffffffff||Math.abs(t)>53?c:t>=0?e<>-t},t.BITOR=function(e,t){return M(e=F(e),t=F(t))?s:e<0||t<0||Math.floor(e)!==e||Math.floor(t)!==t||e>0xffffffffffff||t>0xffffffffffff?c:e|t},t.BITRSHIFT=function(e,t){return M(e=F(e),t=F(t))?s:e<0||Math.floor(e)!==e||e>0xffffffffffff||Math.abs(t)>53?c:t>=0?e>>t:e<<-t},t.BITXOR=function(e,t){return M(e=F(e),t=F(t))?s:e<0||t<0||Math.floor(e)!==e||Math.floor(t)!==t||e>0xffffffffffff||t>0xffffffffffff?c:e^t},t.CEILING=Ve,t.CEILINGMATH=Ht,t.CEILINGPRECISE=Bt,t.CELL=function(){throw new Error("CELL is not implemented")},t.CHAR=pt,t.CHIDIST=Pt,t.CHIDISTRT=_t,t.CHIINV=Vt,t.CHIINVRT=Ut,t.CHISQ=le,t.CHITEST=qt,t.CHOOSE=function(){if(arguments.length<2)return f;const e=arguments[0];return e<1||e>254||arguments.length=0)&&(s=n[e]),(n[e][1]===c||i.indexOf(c)>=0)&&(a=n[e]);if(null===s){const e=r[t.substring(0,2)];let o=l[t.substring(0,1)];"da"===t.substring(0,2)&&(o=["dekao",10,"da"]),e?(d=e[2],u=t.substring(2)):o&&(d=o[1],u=t.substring(o[2].length));for(let e=0;e=0)&&(s=n[e])}if(null===a){const e=r[o.substring(0,2)];let t=l[o.substring(0,1)];"da"===o.substring(0,2)&&(t=["dekao",10,"da"]),e?(p=e[2],c=o.substring(2)):t&&(p=t[1],c=o.substring(t[2].length));for(let e=0;e=0)&&(a=n[e])}return null===s||null===a||s[3]!==a[3]?f:e*s[6]*d/(a[6]*p)},t.CORREL=function(e,t){return M(e=L(v(e)),t=L(v(t)))?s:n.corrcoeff(e,t)},t.COS=function(e){return(e=F(e))instanceof Error?e:Math.cos(e)},t.COSH=function(e){return(e=F(e))instanceof Error?e:(Math.exp(e)+Math.exp(-e))/2},t.COT=function(e){return(e=F(e))instanceof Error?e:0===e?i:1/Math.tan(e)},t.COTH=function(e){if((e=F(e))instanceof Error)return e;if(0===e)return i;const t=Math.exp(2*e);return(t+1)/(t-1)},t.COUNT=se,t.COUNTA=ae,t.COUNTBLANK=ue,t.COUNTIF=function(e,t){if(e=v(e),void 0===t||"*"===t)return e.length;let o=0;const n=Y(t+"");for(let t=0;tr)return c;if(0!==l&&1!==l)return c;const i=Go(e,t,o,0,l);let a=0;1===n&&(0===l&&(a=-o),n++);for(let t=n;t<=r;t++)a+=1===l?Yo(e,t-2,i,o,1)-i:Yo(e,t-1,i,o,0);return a*=e,a},t.CUMPRINC=function(e,t,o,n,r,l){if(M(e=F(e),t=F(t),o=F(o)))return s;if(e<=0||t<=0||o<=0)return c;if(n<1||r<1||n>r)return c;if(0!==l&&1!==l)return c;const i=Go(e,t,o,0,l);let a=0;1===n&&(a=0===l?i+o*e:i,n++);for(let t=n;t<=r;t++)a+=l>0?i-(Yo(e,t-2,i,o,1)-i)*e:i-Yo(e,t-1,i,o,0)*e;return a},t.DATE=function(e,t,o){let n;return M(e=F(e),t=F(t),o=F(o))?n=s:(n=new Date(e,t-1,o),n.getFullYear()<0&&(n=c)),n},t.DATEDIF=ot,t.DATEVALUE=function(e){if("string"!=typeof e)return s;const t=Date.parse(e);return isNaN(t)?s:new Date(e)},t.DAVERAGE=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);let l=0;return h(n,(e=>{l+=r[e]})),0===n.length?i:l/n.length},t.DAY=function(e){const t=D(e);return t instanceof Error?t:t.getDate()},t.DAYS=rt,t.DAYS360=lt,t.DB=function(e,t,o,n,r){if(r=void 0===r?12:r,M(e=F(e),t=F(t),o=F(o),n=F(n),r=F(r)))return s;if(e<0||t<0||o<0||n<0)return c;if(-1===[1,2,3,4,5,6,7,8,9,10,11,12].indexOf(r))return c;if(n>o)return c;if(t>=e)return 0;const l=(1-Math.pow(t/e,1/o)).toFixed(3),i=e*l*r/12;let a=i,u=0;const f=n===o?o-1:n;for(let t=2;t<=f;t++)u=(e-a)*l,a+=u;return 1===n?i:n===o?(e-a)*l:u},t.DBCS=function(){throw new Error("DBCS is not implemented")},t.DCOUNT=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);const l=[];return h(n,(e=>{l.push(r[e])})),se(l)},t.DCOUNTA=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);const l=[];return h(n,(e=>{l.push(r[e])})),ae(l)},t.DDB=function(e,t,o,n,r){if(r=void 0===r?2:r,M(e=F(e),t=F(t),o=F(o),n=F(n),r=F(r)))return s;if(e<0||t<0||o<0||n<0||r<=0)return c;if(n>o)return c;if(t>=e)return 0;let l=0,i=0;for(let s=1;s<=n;s++)i=Math.min(r/o*(e-l),e-t-l),l+=i;return i},t.DEC2BIN=function(e,t){if((e=F(e))instanceof Error)return e;if(!/^-?[0-9]{1,3}$/.test(e)||e<-512||e>511)return c;if(e<0)return"1"+mt("0",9-(512+e).toString(2).length)+(512+e).toString(2);const o=parseInt(e,10).toString(2);return void 0===t?o:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=o.length?mt("0",t-o.length)+o:c},t.DEC2HEX=function(e,t){if((e=F(e))instanceof Error)return e;if(!/^-?[0-9]{1,12}$/.test(e)||e<-549755813888||e>549755813887)return c;if(e<0)return(1099511627776+e).toString(16);const o=parseInt(e,10).toString(16);return void 0===t?o:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=o.length?mt("0",t-o.length)+o:c},t.DEC2OCT=function(e,t){if((e=F(e))instanceof Error)return e;if(!/^-?[0-9]{1,9}$/.test(e)||e<-536870912||e>536870911)return c;if(e<0)return(1073741824+e).toString(8);const o=parseInt(e,10).toString(8);return void 0===t?o:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=o.length?mt("0",t-o.length)+o:c},t.DECIMAL=function(e,t){return arguments.length<1?s:E(e=F(e),t=F(t))||(0===t?c:parseInt(e,t))},t.DEGREES=function(e){return(e=F(e))instanceof Error?e:180*e/Math.PI},t.DELTA=function(e,t){return t=void 0===t?0:t,M(e=F(e),t=F(t))?s:e===t?1:0},t.DEVSQ=function(){const e=L(v(arguments));if(e instanceof Error)return e;const t=n.mean(e);let o=0;for(let n=0;n1?c:r[n[0]]},t.DISC=function(e,t,o,n,r){if(M(e=D(e),t=D(t),o=F(o),n=F(n),r=(r=F(r))||0))return s;if(o<=0||n<=0)return c;if(e>=t)return s;let l,i;switch(r){case 0:l=360,i=lt(e,t,!1);break;case 1:case 3:l=365,i=ot(e,t,"D");break;case 2:l=360,i=ot(e,t,"D");break;case 4:l=360,i=lt(e,t,!0);break;default:return c}return(n-o)/n*l/i},t.DMAX=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);let l=r[n[0]];return h(n,(e=>{l{l>r[e]&&(l=r[e])})),l},t.DOLLAR=function(e,t=2){if(e=F(e),isNaN(e))return s;const o={style:"currency",currency:"USD",minimumFractionDigits:t>=0?t:0,maximumFractionDigits:t>=0?t:0},n=(e=Ke(e,t)).toLocaleString("en-US",o);return e<0?"$("+n.slice(2)+")":n},t.DOLLARDE=function(e,t){if(M(e=F(e),t=F(t)))return s;if(t<0)return c;if(t>=0&&t<1)return i;t=parseInt(t,10);let o=parseInt(e,10);o+=e%1*Math.pow(10,Math.ceil(Math.log(t)/Math.LN10))/t;const n=Math.pow(10,Math.ceil(Math.log(t)/Math.LN2)+1);return o=Math.round(o*n)/n,o},t.DOLLARFR=function(e,t){if(M(e=F(e),t=F(t)))return s;if(t<0)return c;if(t>=0&&t<1)return i;t=parseInt(t,10);let o=parseInt(e,10);return o+=e%1*Math.pow(10,-Math.ceil(Math.log(t)/Math.LN10))*t,o},t.DPRODUCT=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);let l=[];h(n,(e=>{l.push(r[e])})),l=Vo(l);let i=1;return h(l,(e=>{i*=e})),i},t.DSTDEV=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);let l=[];return h(n,(e=>{l.push(r[e])})),l=Vo(l),Re.S(l)},t.DSTDEVP=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);let l=[];return h(n,(e=>{l.push(r[e])})),l=Vo(l),Re.P(l)},t.DSUM=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);const l=[];return h(n,(e=>{l.push(r[e])})),$e(l)},t.DURATION=function(){throw new Error("DURATION is not implemented")},t.DVAR=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);const l=[];return h(n,(e=>{l.push(r[e])})),ke.S(l)},t.DVARP=function(e,t,o){if(isNaN(t)&&"string"!=typeof t)return s;const n=Uo(e,o);let r=[];if("string"==typeof t){const o=A(e,t);r=x(e[o])}else r=x(e[t]);const l=[];return h(n,(e=>{l.push(r[e])})),ke.P(l)},t.EDATE=function(e,t){return(e=D(e))instanceof Error?e:isNaN(t)?s:(t=parseInt(t,10),e.setMonth(e.getMonth()+t),e)},t.EFFECT=function(e,t){return M(e=F(e),t=F(t))?s:e<=0||t<1?c:(t=parseInt(t,10),Math.pow(1+e/t,t)-1)},t.EOMONTH=function(e,t){return(e=D(e))instanceof Error?e:isNaN(t)?s:(t=parseInt(t,10),new Date(e.getFullYear(),e.getMonth()+t+1,0))},t.ERF=wt,t.ERFC=At,t.ERFCPRECISE=Gt,t.ERFPRECISE=Kt,t.ERROR=X,t.EVEN=function(e){return(e=F(e))instanceof Error?e:Ve(e,-2,-1)},t.EXACT=function(e,t){return 2!==arguments.length?f:E(e,t)||(e=R(e))===R(t)},t.EXP=function(e){return arguments.length<1?f:arguments.length>1?d:(e=F(e))instanceof Error?e:e=Math.exp(e)},t.EXPON=fe,t.EXPONDIST=$t,t.F=de,t.FACT=ze,t.FACTDOUBLE=function e(t){if((t=F(t))instanceof Error)return t;const o=Math.floor(t);return o<=0?1:o*e(o-2)},t.FALSE=function(){return!1},t.FDIST=Jt,t.FDISTRT=Qt,t.FIND=function(e,t,o){if(arguments.length<2)return f;e=R(e),o=void 0===o?0:o;const n=(t=R(t)).indexOf(e,o-1);return-1===n?s:n+1},t.FINV=Zt,t.FINVRT=eo,t.FISHER=function(e){return(e=F(e))instanceof Error?e:Math.log((1+e)/(1-e))/2},t.FISHERINV=function(e){if((e=F(e))instanceof Error)return e;const t=Math.exp(2*e);return(t-1)/(t+1)},t.FIXED=gt,t.FLOOR=Ye,t.FLOORMATH=to,t.FLOORPRECISE=oo,t.FORECAST=pe,t.FREQUENCY=function(e,t){if(M(e=L(v(e)),t=L(v(t))))return s;const o=e.length,n=t.length,r=[];for(let l=0;l<=n;l++){r[l]=0;for(let i=0;it[l-1]&&e[i]<=t[l]&&(r[l]+=1):l===n&&e[i]>t[n-1]&&(r[n]+=1)}return r},t.FTEST=no,t.FV=Yo,t.FVSCHEDULE=function(e,t){if(M(e=F(e),t=L(v(t))))return s;const o=t.length;let n=e;for(let e=0;er?n%=r:r%=n;n+=r}return n},t.GEOMEAN=function(){const e=L(v(arguments));return e instanceof Error?e:n.geomean(e)},t.GESTEP=function(e,t){return M(t=t||0,e=F(e))?e:e>=t?1:0},t.GROWTH=function(e,t,o,n){if((e=L(e))instanceof Error)return e;let r;if(void 0===t)for(t=[],r=1;r<=e.length;r++)t.push(r);if(void 0===o)for(o=[],r=1;r<=e.length;r++)o.push(r);if(M(t=L(t),o=L(o)))return s;void 0===n&&(n=!0);const l=e.length;let i,a,u=0,c=0,f=0,d=0;for(r=0;r511)return c;if(o)return"1"+mt("0",9-(512+n).toString(2).length)+(512+n).toString(2);const r=n.toString(2);return void 0===t?r:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=r.length?mt("0",t-r.length)+r:c},t.HEX2DEC=function(e){if(!/^[0-9A-Fa-f]{1,10}$/.test(e))return c;const t=parseInt(e,16);return t>=549755813888?t-1099511627776:t},t.HEX2OCT=function(e,t){if(!/^[0-9A-Fa-f]{1,10}$/.test(e))return c;const o=parseInt(e,16);if(o>536870911&&o<0xffe0000000)return c;if(o>=0xffe0000000)return(o-0xffc0000000).toString(8);const n=o.toString(8);return void 0===t?n:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=n.length?mt("0",t-n.length)+n:c},t.HLOOKUP=function(e,t,o,n){return ee(e,w(t),o,n)},t.HOUR=function(e){return(e=D(e))instanceof Error?e:e.getHours()},t.HYPGEOM=he,t.HYPGEOMDIST=so,t.IF=function(e,t,o){return e instanceof Error?e:(null==(t=!(arguments.length>=2)||t)&&(t=0),null==(o=3===arguments.length&&o)&&(o=0),e?t:o)},t.IFERROR=function(e,t){return K(e)?t:e},t.IFNA=function(e,t){return e===f?t:e},t.IFS=function(){for(let e=0;e0&&!Array.isArray(e[0]);return r&&!o?(o=t,t=1):(o=o||1,t=t||1),o<0||t<0?s:r&&1===t&&o<=e.length?e[o-1]:t<=e.length&&o<=e[t-1].length?e[t-1][o-1]:a},t.INFO=function(){throw new Error("INFO is not implemented")},t.INT=function(e){return(e=F(e))instanceof Error?e:Math.floor(e)},t.INTERCEPT=function(e,t){return M(e=L(e),t=L(t))?s:e.length!==t.length?f:pe(0,e,t)},t.INTRATE=function(){throw new Error("INTRATE is not implemented")},t.IPMT=Wo,t.IRR=function(e,t){if(t=t||0,M(e=L(v(e)),t=F(t)))return s;const o=(e,t,o)=>{const n=o+1;let r=e[0];for(let o=1;o{const n=o+1;let r=0;for(let o=1;o0&&(l=!0),e[t]<0&&(i=!0);if(!l||!i)return c;let a,u,f,d=t=void 0===t?.1:t,p=!0;do{f=o(e,r,d),a=d-f/n(e,r,d),u=Math.abs(a-d),d=a,p=u>1e-10&&Math.abs(f)>1e-10}while(p);return d},t.ISBLANK=function(e){return null===e},t.ISERR=G,t.ISERROR=K,t.ISEVEN=function(e){return!(1&Math.floor(Math.abs(e)))},t.ISFORMULA=function(){throw new Error("ISFORMULA is not implemented")},t.ISLOGICAL=$,t.ISNA=function(e){return e===f},t.ISNONTEXT=function(e){return"string"!=typeof e},t.ISNUMBER=J,t.ISO=We,t.ISODD=function(e){return!!(1&Math.floor(Math.abs(e)))},t.ISOWEEKNUM=it,t.ISPMT=function(e,t,o,n){return M(e=F(e),t=F(t),o=F(o),n=F(n))?s:n*e*(t/o-1)},t.ISREF=function(){throw new Error("ISREF is not implemented")},t.ISTEXT=Q,t.KURT=function(){const e=L(v(arguments));if(e instanceof Error)return e;const t=n.mean(e),o=e.length;let r=0;for(let n=0;n1;){if(n%2){for(t=3,o=Math.floor(Math.sqrt(n));t<=o&&n%t;t+=2);r=t<=o?t:n}else r=2;for(n/=r,l*=r,t=e.length;t;e[--t]%r==0&&1==(e[t]/=r)&&e.splice(t,1));}}return l},t.LEFT=function(e,t){return E(e,t)||(e=R(e),(t=F(t=void 0===t?1:t))instanceof Error||"string"!=typeof e?s:e.substring(0,t))},t.LEN=function(e){return 0===arguments.length?d:e instanceof Error?e:Array.isArray(e)?s:R(e).length},t.LINEST=me,t.LN=function(e){return(e=F(e))instanceof Error?e:0===e?c:Math.log(e)},t.LOG=function(e,t){return E(e=F(e),t=F(t))||(0===e||0===t?c:Math.log(e)/Math.log(t))},t.LOG10=function(e){return(e=F(e))instanceof Error?e:0===e?c:Math.log(e)/Math.log(10)},t.LOGEST=function(e,t){if(M(e=L(v(e)),t=L(v(t))))return s;if(e.length!==t.length)return s;for(let t=0;te)return r}return r},t.LOWER=function(e){return 1!==arguments.length?s:M(e=R(e))?e:e.toLowerCase()},t.MATCH=function(e,t,o){if(!e||!t)return f;if(2===arguments.length&&(o=1),!((t=v(t))instanceof Array))return f;if(-1!==o&&0!==o&&1!==o)return f;let n,r;for(let l=0;lr&&(n=l+1,r=t[l]):(n=l+1,r=t[l]))}else if(0===o){if("string"==typeof e&&"string"==typeof t[l]){const o=e.toLowerCase().replace(/\?/g,".").replace(/\*/g,".*").replace(/~/g,"\\");if(new RegExp("^"+o+"$").test(t[l].toLowerCase()))return l+1}else if(t[l]===e)return l+1}else if(-1===o){if(t[l]===e)return l+1;t[l]>e&&(r?t[l]null==e?0:e)),0===o.length?0:Math.max.apply(Math,o)},t.MDURATION=function(){throw new Error("MDURATION is not implemented")},t.MEDIAN=Ce,t.MID=function(e,t,o){if(null==t)return s;if(M(t=F(t),o=F(o))||"string"!=typeof e)return o;const n=t-1,r=n+o;return e.substring(n,r)},t.MIN=xe,t.MINA=function(){const e=v(arguments),t=E.apply(void 0,e);if(t)return t;let o=g(e);return o=o.map((e=>null==e?0:e)),0===o.length?0:Math.min.apply(Math,o)},t.MINUTE=function(e){return(e=D(e))instanceof Error?e:e.getMinutes()},t.MIRR=function(e,t,o){if(M(e=L(v(e)),t=F(t),o=F(o)))return s;const n=e.length,r=[],l=[];for(let t=0;t!e.length))||t.some((e=>!e.length))||y(e).some((e=>"number"!=typeof e))||y(t).some((e=>"number"!=typeof e))||e[0].length!==t.length?s:Array(e.length).fill(0).map((()=>Array(t[0].length).fill(0))).map(((o,n)=>o.map(((o,r)=>e[n].reduce(((e,o,n)=>e+o*t[n][r]),0)))))},t.MOD=function(e,t){const o=E(e=F(e),t=F(t));if(o)return o;if(0===t)return i;let n=Math.abs(e%t);return n=e<0?t-n:n,t>0?n:-n},t.MODE=we,t.MODEMULT=fo,t.MODESNGL=po,t.MONTH=function(e){return(e=D(e))instanceof Error?e:e.getMonth()+1},t.MROUND=function(e,t){return E(e=F(e),t=F(t))||(e*t==0?0:e*t<0?c:Math.round(e/t)*t)},t.MULTINOMIAL=function(){const e=L(v(arguments));if(e instanceof Error)return e;let t=0,o=1;for(let n=0;n1?f:!(e=parseInt(e))||e<=0?s:Array(e).fill(0).map((()=>Array(e).fill(0))).map(((e,t)=>(e[t]=1,e)))},t.N=function(e){return J(e)?e:e instanceof Date?e.getTime():!0===e?1:!1===e?0:K(e)?e:0},t.NA=function(){return f},t.NEGBINOM=Ae,t.NEGBINOMDIST=bo,t.NETWORKDAYS=st,t.NETWORKDAYSINTL=jo,t.NOMINAL=function(e,t){return M(e=F(e),t=F(t))?s:e<=0||t<1?c:(t=parseInt(t,10),(Math.pow(e+1,1/t)-1)*t)},t.NORM=Ee,t.NORMDIST=ho,t.NORMINV=go,t.NORMSDIST=mo,t.NORMSINV=vo,t.NOT=function(e){return"string"==typeof e?s:e instanceof Error?e:!e},t.NOW=function(){return new Date},t.NPER=function(e,t,o,n,r){if(r=void 0===r?0:r,n=void 0===n?0:n,M(e=F(e),t=F(t),o=F(o),n=F(n),r=F(r)))return s;if(0===e)return-(o+n)/t;{const l=t*(1+e*r)-n*e,i=o*e+t*(1+e*r);return Math.log(l/i)/Math.log(1+e)}},t.NPV=Xo,t.NUMBERVALUE=function(e,t,o){return"number"==typeof(e=k(e)?e:"")?e:"string"!=typeof e?f:(t=void 0===t?".":t,o=void 0===o?",":o,Number(e.replace(t,".").replace(o,"")))},t.OCT2BIN=function(e,t){if(!/^[0-7]{1,10}$/.test(e))return c;const o=!(10!==e.length||"7"!==e.substring(0,1)),n=o?parseInt(e,8)-1073741824:parseInt(e,8);if(n<-512||n>511)return c;if(o)return"1"+mt("0",9-(512+n).toString(2).length)+(512+n).toString(2);const r=n.toString(2);return void 0===t?r:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=r.length?mt("0",t-r.length)+r:c},t.OCT2DEC=function(e){if(!/^[0-7]{1,10}$/.test(e))return c;const t=parseInt(e,8);return t>=536870912?t-1073741824:t},t.OCT2HEX=function(e,t){if(!/^[0-7]{1,10}$/.test(e))return c;const o=parseInt(e,8);if(o>=536870912)return"ff"+(o+3221225472).toString(16);const n=o.toString(16);return void 0===t?n:isNaN(t)?s:t<0?c:(t=Math.floor(t))>=n.length?mt("0",t-n.length)+n:c},t.ODD=function(e){if((e=F(e))instanceof Error)return e;let t=Math.ceil(Math.abs(e));return t=1&t?t:t+1,e>=0?t:-t},t.ODDFPRICE=function(){throw new Error("ODDFPRICE is not implemented")},t.ODDFYIELD=function(){throw new Error("ODDFYIELD is not implemented")},t.ODDLPRICE=function(){throw new Error("ODDLPRICE is not implemented")},t.ODDLYIELD=function(){throw new Error("ODDLYIELD is not implemented")},t.OR=function(){const e=v(arguments);let t=s;for(let o=0;o=t)return s;let l,i;switch(r){case 0:l=360,i=lt(e,t,!1);break;case 1:case 3:l=365,i=ot(e,t,"D");break;case 2:l=360,i=ot(e,t,"D");break;case 4:l=360,i=lt(e,t,!0);break;default:return c}return n-o*n*i/l},t.PRICEMAT=function(){throw new Error("PRICEMAT is not implemented")},t.PROB=function(e,t,o,n){if(void 0===o)return 0;if(n=void 0===n?o:n,M(e=L(v(e)),t=L(v(t)),o=F(o),n=F(n)))return s;if(o===n)return e.indexOf(o)>=0?t[e.indexOf(o)]:0;const r=e.sort(((e,t)=>e-t)),l=r.length;let i=0;for(let s=0;s=o&&r[s]<=n&&(i+=t[e.indexOf(r[s])]);return i},t.PRODUCT=Ge,t.PRONETIC=function(){throw new Error("PRONETIC is not implemented")},t.PROPER=function(e){return M(e)?e:isNaN(e)&&"number"==typeof e?s:(e=R(e)).replace(/\w\S*/g,(e=>e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()))},t.PV=function(e,t,o,n,r){return n=n||0,r=r||0,M(e=F(e),t=F(t),o=F(o),n=F(n),r=F(r))?s:0===e?-o*t-n:((1-Math.pow(1+e,t))/e*o*(1+e*r)-n)/Math.pow(1+e,t)},t.QUARTILE=De,t.QUARTILEEXC=Eo,t.QUARTILEINC=Mo,t.QUOTIENT=function(e,t){return E(e=F(e),t=F(t))||parseInt(e/t,10)},t.RADIANS=function(e){return(e=F(e))instanceof Error?e:e*Math.PI/180},t.RAND=function(){return Math.random()},t.RANDBETWEEN=function(e,t){return E(e=F(e),t=F(t))||e+Math.ceil((t-e+1)*Math.random())-1},t.RANK=Te,t.RANKAVG=Io,t.RANKEQ=No,t.RATE=function(e,t,o,n,r,l){if(l=void 0===l?.01:l,n=void 0===n?0:n,r=void 0===r?0:r,M(e=F(e),t=F(t),o=F(o),n=F(n),r=F(r),l=F(l)))return s;const i=1e-10;let a=l;r=r?1:0;for(let l=0;l<20;l++){if(a<=-1)return c;let l,s,u;if(Math.abs(a)0?1:-1)*Math.floor(Math.abs(e)*Math.pow(10,t))/Math.pow(10,t)},t.ROUNDUP=function(e,t){return E(e=F(e),t=F(t))||(e>0?1:-1)*Math.ceil(Math.abs(e)*Math.pow(10,t))/Math.pow(10,t)},t.ROW=function(e,t){return 2!==arguments.length?f:t<0?c:e instanceof Array&&"number"==typeof t?0!==e.length?n.row(e,t):void 0:s},t.ROWS=function(e){return 1!==arguments.length?f:e instanceof Array?0===e.length?0:n.rows(e):s},t.RRI=function(e,t,o){return M(e=F(e),t=F(t),o=F(o))?s:0===e||0===t?c:Math.pow(o/t,1/e)-1},t.RSQ=function(e,t){return M(e=L(v(e)),t=L(v(t)))?s:Math.pow(Me(e,t),2)},t.SEARCH=function(e,t,o){let n;return"string"!=typeof e||"string"!=typeof t?s:(o=void 0===o?0:o,n=t.toLowerCase().indexOf(e.toLowerCase(),o-1)+1,0===n?s:n)},t.SEC=function(e){return(e=F(e))instanceof Error?e:1/Math.cos(e)},t.SECH=function(e){return(e=F(e))instanceof Error?e:2/(Math.exp(e)+Math.exp(-e))},t.SECOND=function(e){return(e=D(e))instanceof Error?e:e.getSeconds()},t.SERIESSUM=function(e,t,o,n){if(M(e=F(e),t=F(t),o=F(o),n=L(n)))return s;let r=n[0]*Math.pow(e,t);for(let l=1;le.sort(((e,n)=>(e=R(e[t-1]),n=R(n[t-1]),1===o?en?o:-1*o))),l=m(e),i=n?w(l):l;return t>=1&&t<=i[0].length?n?w(r(i)):r(i):s},t.SQRT=function(e){return(e=F(e))instanceof Error?e:e<0?c:Math.sqrt(e)},t.SQRTPI=function(e){return(e=F(e))instanceof Error?e:Math.sqrt(e*Math.PI)},t.STANDARDIZE=function(e,t,o){return M(e=F(e),t=F(t),o=F(o))?s:(e-t)/o},t.STDEV=Re,t.STDEVA=function(){const e=He.apply(this,arguments);return Math.sqrt(e)},t.STDEVP=Do,t.STDEVPA=function(){const e=Be.apply(this,arguments);let t=Math.sqrt(e);return isNaN(t)&&(t=c),t},t.STDEVS=To,t.STEYX=function(e,t){if(M(e=L(v(e)),t=L(v(t))))return s;const o=n.mean(t),r=n.mean(e),l=t.length;let i=0,a=0,u=0;for(let n=0;n-1&&e.indexOf(t,r)>-1;)if(r=e.indexOf(t,r+1),l++,r>-1&&l===n)return e.substring(0,r)+o+e.substring(r+t.length);return e}}return e},t.SUBTOTAL=function(e,t){if((e=F(e))instanceof Error)return e;switch(e){case 1:case 101:return te(t);case 2:case 102:return se(t);case 3:case 103:return ae(t);case 4:case 104:return ye(t);case 5:case 105:return xe(t);case 6:case 106:return Ge(t);case 7:case 107:return Re.S(t);case 8:case 108:return Re.P(t);case 9:case 109:return $e(t);case 10:case 110:return ke.S(t);case 11:case 111:return ke.P(t)}},t.SUM=$e,t.SUMIF=function(e,t,o){if(e=v(e),o=o?v(o):e,e instanceof Error)return e;if(null==t||t instanceof Error)return 0;let n=0;const r="*"===t,l=r?null:Y(t+"");for(let t=0;t0){const t=arguments[0],o=arguments.length-1,n=Math.floor(o/2);let r=!1;const l=o%2!=0,i=o%2==0?null:arguments[arguments.length-1];if(n)for(let o=0;oo?c:(e-t)*(o-(n=parseInt(n,10))+1)*2/(o*(o+1))},t.T=function(e){return e instanceof Error||"string"==typeof e?e:""},t.TAN=function(e){return(e=F(e))instanceof Error?e:Math.tan(e)},t.TANH=function(e){if((e=F(e))instanceof Error)return e;const t=Math.exp(2*e);return(t-1)/(t+1)},t.TBILLEQ=function(e,t,o){return M(e=D(e),t=D(t),o=F(o))?s:o<=0||e>t||t-e>31536e6?c:365*o/(360-o*lt(e,t,!1))},t.TBILLPRICE=function(e,t,o){return M(e=D(e),t=D(t),o=F(o))?s:o<=0||e>t||t-e>31536e6?c:100*(1-o*lt(e,t,!1)/360)},t.TBILLYIELD=function(e,t,o){return M(e=D(e),t=D(t),o=F(o))?s:o<=0||e>t||t-e>31536e6?c:360*(100-o)/(o*lt(e,t,!1))},t.TDIST=Fo,t.TDISTRT=Lo,t.TEXT=function(e,t){if(void 0===e||e instanceof Error||t instanceof Error)return f;if(null==t)return"";if("number"==typeof t)return String(t);if("string"!=typeof t)return s;const o=t.startsWith("$")?"$":"",n=t.endsWith("%");return n&&(e*=100),e=(e=gt(e,(t=t.replace(/%/g,"").replace(/\$/g,"")).split(".")[1].match(/0/g).length,!t.includes(","))).startsWith("-")?"-"+o+(e=e.replace("-","")):o+e,n&&(e+="%"),e},t.TEXTJOIN=function(e,t,...o){if("boolean"!=typeof t&&(t=S(t)),arguments.length<3)return f;e=null!=e?e:"";let n=v(o),r=t?n.filter((e=>e)):n;if(Array.isArray(e)){e=v(e);let t=r.map((e=>[e])),o=0;for(let n=0;n{i.push(r*e+l)})),i},t.TRIM=function(e){return(e=R(e))instanceof Error?e:e.replace(/\s+/g," ").trim()},t.TRIMMEAN=function(e,t){if(M(e=L(v(e)),t=F(t)))return s;const o=Ye(e.length*t,2)/2;return n.mean((l=(l=o)||1,(r=x(e.sort(((e,t)=>e-t)),o))&&"function"==typeof r.slice?r.slice(0,r.length-l):r));var r,l},t.TRUE=function(){return!0},t.TRUNC=function(e,t){return E(e=F(e),t=F(t))||(e>0?1:-1)*Math.floor(Math.abs(e)*Math.pow(10,t))/Math.pow(10,t)},t.TTEST=Oo,t.TYPE=function(e){return J(e)?1:Q(e)?2:$(e)?4:K(e)?16:Array.isArray(e)?64:void 0},t.UNICHAR=vt,t.UNICODE=yt,t.UNIQUE=Z,t.UPPER=function(e){return(e=R(e))instanceof Error?e:e.toUpperCase()},t.VALUE=function(e){const t=E(e);if(t)return t;if("number"==typeof e)return e;if(k(e)||(e=""),"string"!=typeof e)return s;const o=/(%)$/.test(e)||/^(%)/.test(e);if(""===(e=(e=(e=e.replace(/^[^0-9-]{0,3}/,"")).replace(/[^0-9]{0,3}$/,"")).replace(/[ ,]/g,"")))return 0;let n=Number(e);return isNaN(n)?s:(n=n||0,o&&(n*=.01),n)},t.VAR=ke,t.VARA=He,t.VARP=ko,t.VARPA=Be,t.VARS=Ho,t.VDB=function(){throw new Error("VDB is not implemented")},t.VLOOKUP=ee,t.WEEKDAY=function(e,t){if((e=D(e))instanceof Error)return e;void 0===t&&(t=1);const o=e.getDay();return et[t][o]},t.WEEKNUM=function(e,t){if((e=D(e))instanceof Error)return e;if(void 0===t&&(t=1),21===t)return it(e);const o=Ze[t];let n=new Date(e.getFullYear(),0,1);const r=n.getDay(){const n=o+1;let r=e[0];for(let o=1;o{const n=o+1;let r=0;for(let o=1;o0&&(l=!0),e[t]<0&&(i=!0);if(!l||!i)return c;let a,u,f,d=o=o||.1,p=!0;do{f=n(e,t,d),a=d-f/r(e,t,d),u=Math.abs(a-d),d=a,p=u>1e-10&&Math.abs(f)>1e-10}while(p);return d},t.XNPV=function(e,t,o){if(M(e=F(e),t=L(v(t)),o=T(v(o))))return s;let n=0;for(let r=0;re&&(e=t.length)}obj.options.minDimensions[0]>e&&(e=obj.options.minDimensions[0]);for(var o=[],n=0;n0&&obj.options.paginationOptions&&obj.options.paginationOptions.length>0){obj.paginationDropdown=document.createElement("select"),obj.paginationDropdown.classList.add("jexcel_pagination_dropdown"),obj.paginationDropdown.onchange=function(){obj.options.pagination=parseInt(this.value),obj.page(0)};for(var n=0;n0)if(obj.options.nestedHeaders[0]&&obj.options.nestedHeaders[0][0])for(var s=0;sr?i:r,u=s>l?s:l;for(t=0;t=c&&t0&&r++}return o},obj.getJsonRow=function(e){for(var t=obj.options.data[e],o=obj.options.columns.length,n={},r=0;r200)&&(n.style.whiteSpace="pre-wrap"),e>0&&1==this.options.textOverflow&&(o||n.innerHTML?obj.records[t][e-1].style.overflow="hidden":e==obj.options.columns.length-1&&(n.style.overflow="hidden")),n},obj.createCellHeader=function(e){var t=obj.options.columns[e].width?obj.options.columns[e].width:obj.options.defaultColWidth,o=obj.options.columns[e].align?obj.options.columns[e].align:obj.options.defaultColAlign;obj.headers[e]=document.createElement("td"),obj.options.stripHTML?obj.headers[e].textContent=obj.options.columns[e].title?obj.options.columns[e].title:jexcel.getColumnName(e):obj.headers[e].innerHTML=obj.options.columns[e].title?obj.options.columns[e].title:jexcel.getColumnName(e),obj.headers[e].setAttribute("data-x",e),obj.headers[e].style.textAlign=o,obj.options.columns[e].title&&obj.headers[e].setAttribute("title",obj.headers[e].innerText),obj.options.columns[e].id&&obj.headers[e].setAttribute("id",obj.options.columns[e].id),obj.colgroup[e]=document.createElement("col"),obj.colgroup[e].setAttribute("width",t),"hidden"==obj.options.columns[e].type&&(obj.headers[e].style.display="none",obj.colgroup[e].style.display="none")},obj.updateNestedHeader=function(e,t,o){obj.options.nestedHeaders[t][e].title&&(obj.options.nestedHeaders[t][e].title=o,obj.options.nestedHeaders[t].element.children[e+1].textContent=o)},obj.createNestedHeader=function(e){var t=document.createElement("tr");t.classList.add("jexcel_nested");var o=document.createElement("td");t.appendChild(o),e.element=t;for(var n=0,r=0;r1?obj.records[u[1]][u[0]].setAttribute("colspan",t):t=1,o>1?obj.records[u[1]][u[0]].setAttribute("rowspan",o):o=1,obj.options.mergeCells[e]=[t,o,[]],obj.records[u[1]][u[0]].setAttribute("data-merged","true"),obj.records[u[1]][u[0]].style.overflow="hidden";for(var d=[],p=u[1];p0||s>0)&&(obj.records[n[1]+i][n[0]+s]=r[2][l],obj.records[n[1]+i][n[0]+s].style.display="",t&&t[l]&&obj.updateCell(n[0]+s,n[1]+i,t[l]),l++);obj.updateSelection(obj.records[n[1]][n[0]],obj.records[n[1]+i-1][n[0]+s-1]),o||delete obj.options.mergeCells[e]}},obj.destroyMerged=function(e){if(obj.options.mergeCells){obj.options.mergeCells;for(var t=Object.keys(obj.options.mergeCells),o=0;o1?i-1:0);null==t?s<=e&&a>=e&&o.push(n[r]):t?s=e&&o.push(n[r]):s<=e&&a>e&&o.push(n[r])}return o},obj.isRowMerged=function(e,t){var o=[];if(obj.options.mergeCells)for(var n=Object.keys(obj.options.mergeCells),r=0;r1?i-1:0);null==t?s<=e&&a>=e&&o.push(n[r]):t?s=e&&o.push(n[r]):s<=e&&a>e&&o.push(n[r])}return o},obj.openFilter=function(e){if(obj.options.filters){e=parseInt(e),obj.resetSelection();var t=[];if("checkbox"==obj.options.columns[e].type)t.push({id:"true",name:"True"}),t.push({id:"false",name:"False"});else{for(var o=[],n=!1,r=0;r0&&(obj.records[n][r-1].style.overflow="hidden");var l=function(t){var o=e.getBoundingClientRect(),l=document.createElement(t);return l.style.width=o.width+"px",l.style.height=o.height-2+"px",l.style.minHeight=o.height-2+"px",e.classList.add("editor"),e.innerHTML="",e.appendChild(l),obj.dispatch("oncreateeditor",el,e,r,n,l),l};if(1==e.classList.contains("readonly"));else if(obj.edition=[obj.records[n][r],obj.records[n][r].innerHTML,r,n],obj.options.columns[r].editor)obj.options.columns[r].editor.openEditor(e,el,t,o);else if("hidden"==obj.options.columns[r].type);else if("checkbox"==obj.options.columns[r].type||"radio"==obj.options.columns[r].type){var i=!e.children[0].checked;obj.setValue(e,i),obj.edition=null}else if("dropdown"==obj.options.columns[r].type||"autocomplete"==obj.options.columns[r].type){if(i=obj.options.data[n][r],obj.options.columns[r].multiple&&!Array.isArray(i)&&(i=i.split(";")),"function"==typeof obj.options.columns[r].filter)var s=obj.options.columns[r].filter(el,e,r,n,obj.options.columns[r].source);else s=obj.options.columns[r].source;for(var a=[],u=0;u0)for(var s=0;s200)?obj.records[t][e].style.whiteSpace="pre-wrap":obj.records[t][e].style.whiteSpace="";e>0&&(obj.records[t][e-1].style.overflow=o?"hidden":""),obj.dispatch("onchange",el,obj.records[t]&&obj.records[t][e]?obj.records[t][e]:null,e,t,o,c.oldValue)}else var c={x:e,y:t,col:e,row:t};return c},obj.copyData=function(e,t){var o=obj.getData(!0,!0),n=obj.selectedContainer,r=parseInt(e.getAttribute("data-x")),l=parseInt(e.getAttribute("data-y")),i=parseInt(t.getAttribute("data-x")),s=parseInt(t.getAttribute("data-y")),a=[],u=!1;if(n[0]==r){if(l=obj.selectedCell[1]&&t<=obj.selectedCell[3]||o>=obj.selectedCell[1]&&o<=obj.selectedCell[3]))return void obj.resetSelection()}else if(obj.selectedCell&&(t>=obj.selectedCell[0]&&t<=obj.selectedCell[2]||o>=obj.selectedCell[0]&&o<=obj.selectedCell[2]))return void obj.resetSelection()},obj.resetSelection=function(e){if(obj.highlighted.length){u=1;for(var t=0;t0?o+(r-1):o,s=l>0?n+(l-1):n;else i=o,s=n;for(var a=o;a<=i;a++)obj.headers[a]&&obj.headers[a].classList.remove("selected");for(a=n;a<=s;a++)obj.rows[a]&&obj.rows[a].classList.remove("selected")}}else var u=0;return obj.highlighted=[],obj.selectedCell=null,obj.corner.style.top="-2000px",obj.corner.style.left="-2000px",1==e&&1==u&&obj.dispatch("onblur",el),u},obj.updateSelection=function(e,t,o){var n=e.getAttribute("data-x"),r=e.getAttribute("data-y");if(t)var l=t.getAttribute("data-x"),i=t.getAttribute("data-y");else l=n,i=r;obj.updateSelectionFromCoords(n,r,l,i,o)},obj.updateSelectionFromCoords=function(e,t,o,n,r){var l=obj.resetSelection();if(null==t&&(t=0,n=obj.rows.length-1),null==o&&(o=e),null==n&&(n=t),e>=obj.headers.length&&(e=obj.headers.length-1),t>=obj.rows.length&&(t=obj.rows.length-1),o>=obj.headers.length&&(o=obj.headers.length-1),n>=obj.rows.length&&(n=obj.rows.length-1),obj.selectedCell=[e,t,o,n],null!=e){if(obj.records[t][e]&&obj.records[t][e].classList.add("highlight-selected"),parseInt(e)1&&(ds&&(s=d+b-1)),j&&(pu&&(u=p+j-1))}var h=null,g=null,m=null,v=null;for(f=a;f<=u;f++)"none"!=obj.rows[f].style.display&&(null==m&&(m=f),v=f);for(c=i;c<=s;c++){for(f=a;f<=u;f++)"none"!=obj.rows[f].style.display&&"none"!=obj.records[f][c].style.display&&(obj.records[f][c].classList.add("highlight"),obj.highlighted.push(obj.records[f][c]));"hidden"!=obj.options.columns[c].type&&(null==h&&(h=c),g=c)}for(h||(h=0),g||(g=0),c=h;c<=g;c++)"hidden"!=obj.options.columns[c].type&&obj.colgroup[c].style&&"none"!=obj.colgroup[c].style.display&&(obj.records[m]&&obj.records[m][c]&&obj.records[m][c].classList.add("highlight-top"),obj.records[v]&&obj.records[v][c]&&obj.records[v][c].classList.add("highlight-bottom"),obj.headers[c].classList.add("selected"));for(f=m;f<=v;f++)obj.rows[f]&&"none"!=obj.rows[f].style.display&&(obj.records[f][h].classList.add("highlight-left"),obj.records[f][g].classList.add("highlight-right"),obj.rows[f].classList.add("selected"));obj.selectedContainer=[h,m,g,v]}0==l&&(obj.dispatch("onfocus",el),obj.removeCopyingSelection()),obj.dispatch("onselection",el,h,m,g,v,r),obj.updateCornerPosition()},obj.removeCopySelection=function(){for(var e=0;e0)var i=parseInt(r)+1,s=parseInt(e);else i=parseInt(e),s=parseInt(o)-1;if(t-l>0)var a=parseInt(l)+1,u=parseInt(t);else a=parseInt(t),u=parseInt(n)-1;s-i<=u-a?(i=parseInt(o),s=parseInt(r)):(a=parseInt(n),u=parseInt(l));for(var c=a;c<=u;c++)for(var f=i;f<=s;f++)obj.records[c][f]&&"none"!=obj.rows[c].style.display&&"none"!=obj.records[c][f].style.display&&(obj.records[c][f].classList.add("selection"),obj.records[a][f].classList.add("selection-top"),obj.records[u][f].classList.add("selection-bottom"),obj.records[c][i].classList.add("selection-left"),obj.records[c][s].classList.add("selection-right"),obj.selection.push(obj.records[c][f]))}},obj.updateCornerPosition=function(){if(obj.highlighted.length){var e=obj.highlighted[obj.highlighted.length-1],t=e.getAttribute("data-x"),o=obj.content.getBoundingClientRect(),n=o.left,r=o.top,l=e.getBoundingClientRect(),i=l.left,s=l.top,a=l.width,u=l.height,c=i-n+obj.content.scrollLeft+a-4,f=s-r+obj.content.scrollTop+u-4;if(obj.corner.style.top=f+"px",obj.corner.style.left=c+"px",obj.options.freezeColumns){var d=obj.getFreezeWidth();t>obj.options.freezeColumns-1&&i-n+aobj.content.scrollTop+30&&dobj.content.scrollLeft+p&&f0&&("object"==typeof e&&(e=e.getAttribute("data-y")),o||(o=obj.rows[e].getAttribute("height"))||(o=obj.rows[e].getBoundingClientRect().height),t=parseInt(t),obj.rows[e].style.height=t+"px",obj.options.rows[e]||(obj.options.rows[e]={}),obj.options.rows[e].height=t,obj.setHistory({action:"setHeight",row:e,oldValue:o,newValue:t}),obj.dispatch("onresizerow",el,e,t,o),obj.updateCornerPosition())},obj.getHeight=function(e){if(void 0===e)for(var t=[],o=0;o=0){if(Object.keys(obj.options.mergeCells).length>0){if(!confirm(obj.options.text.thisActionWillDestroyAnyExistingMergedCellsAreYouSure))return!1;obj.destroyMerged()}t=null==t?obj.headers[e].classList.contains("arrow-down")?1:0:t?1:0;var o=[];if("number"==obj.options.columns[e].type||"numeric"==obj.options.columns[e].type||"percentage"==obj.options.columns[e].type||"autonumber"==obj.options.columns[e].type||"color"==obj.options.columns[e].type)for(var n=0;nr?-1:nr?1:n0)obj.page(0);else if(1==obj.options.lazyLoading)obj.loadPage(0);else for(o=0;o0){if(e>t)var n=1;else n=0;if(obj.isRowMerged(e).length||obj.isRowMerged(t,n).length){if(!confirm(obj.options.text.thisActionWillDestroyAnyExistingMergedCellsAreYouSure))return!1;obj.destroyMerged()}}if(1==obj.options.search){if(obj.results&&obj.results.length!=obj.rows.length){if(!confirm(obj.options.text.thisActionWillClearYourSearchResultsAreYouSure))return!1;obj.resetSearch()}obj.results=null}o||(Array.prototype.indexOf.call(obj.tbody.children,obj.rows[t])>=0?e>t?obj.tbody.insertBefore(obj.rows[e],obj.rows[t]):obj.tbody.insertBefore(obj.rows[e],obj.rows[t].nextSibling):obj.tbody.removeChild(obj.rows[e])),obj.rows.splice(t,0,obj.rows.splice(e,1)[0]),obj.records.splice(t,0,obj.records.splice(e,1)[0]),obj.options.data.splice(t,0,obj.options.data.splice(e,1)[0]),obj.options.pagination>0&&obj.tbody.children.length!=obj.options.pagination&&obj.page(obj.pageNumber),obj.setHistory({action:"moveRow",oldValue:e,newValue:t}),obj.updateTableReferences(),obj.dispatch("onmoverow",el,e,t)},obj.insertRow=function(e,t,o){if(1==obj.options.allowInsertRow){var n=[];if(e>0)var r=e;else r=1,e&&(n=e);o=!!o;var l=obj.options.data.length-1;if((null==t||t>=parseInt(l)||t<0)&&(t=l),!1===obj.dispatch("onbeforeinsertrow",el,t,r,o))return!1;if(Object.keys(obj.options.mergeCells).length>0&&obj.isRowMerged(t,o).length){if(!confirm(obj.options.text.thisActionWillDestroyAnyExistingMergedCellsAreYouSure))return!1;obj.destroyMerged()}if(1==obj.options.search){if(obj.results&&obj.results.length!=obj.rows.length){if(!confirm(obj.options.text.thisActionWillClearYourSearchResultsAreYouSure))return!1;obj.resetSearch()}obj.results=null}for(var i=o?t:t+1,s=obj.records.splice(i),a=obj.options.data.splice(i),u=obj.rows.splice(i),c=[],f=[],d=[],p=i;p=0&&obj.tbody.insertBefore(j,u[0]):Array.prototype.indexOf.call(obj.tbody.children,obj.rows[t])>=0&&obj.tbody.appendChild(j),c.push(obj.records[p]),f.push(obj.options.data[p]),d.push(j)}Array.prototype.push.apply(obj.records,s),Array.prototype.push.apply(obj.options.data,a),Array.prototype.push.apply(obj.rows,u),obj.options.pagination>0&&obj.page(obj.pageNumber),obj.setHistory({action:"insertRow",rowNumber:t,numOfRows:r,insertBefore:o,rowRecords:c,rowData:f,rowNode:d}),obj.updateTableReferences(),obj.dispatch("oninsertrow",el,t,r,c,o)}},obj.deleteRow=function(e,t){if(1==obj.options.allowDeleteRow)if(1==obj.options.allowDeletingAllRows||obj.options.data.length>1){if(null==e){var o=obj.getSelectedRows();o[0]?(e=parseInt(o[0].getAttribute("data-y")),t=o.length):(e=obj.options.data.length-1,t=1)}var n=obj.options.data.length-1;if((null==e||e>n||e<0)&&(e=n),t||(t=1),e+t>=obj.options.data.length&&(t=obj.options.data.length-e),!1===obj.dispatch("onbeforedeleterow",el,e,t))return!1;if(parseInt(e)>-1){var r=!1;if(Object.keys(obj.options.mergeCells).length>0)for(var l=e;l=0&&(obj.rows[l].className="",obj.rows[l].parentNode.removeChild(obj.rows[l]));var i=obj.records.splice(e,t),s=obj.options.data.splice(e,t),a=obj.rows.splice(e,t);obj.options.pagination>0&&obj.tbody.children.length!=obj.options.pagination&&obj.page(obj.pageNumber),obj.conditionalSelectionUpdate(1,e,e+t-1),obj.setHistory({action:"deleteRow",rowNumber:e,numOfRows:t,insertBefore:1,rowRecords:i,rowData:s,rowNode:a}),obj.updateTableReferences(),obj.dispatch("ondeleterow",el,e,t,i)}}else console.error("Jspreadsheet: It is not possible to delete the last row")},obj.moveColumn=function(e,t){if(Object.keys(obj.options.mergeCells).length>0){if(e>t)var o=1;else o=0;if(obj.isColMerged(e).length||obj.isColMerged(t,o).length){if(!confirm(obj.options.text.thisActionWillDestroyAnyExistingMergedCellsAreYouSure))return!1;obj.destroyMerged()}}if((e=parseInt(e))>(t=parseInt(t))){obj.headerContainer.insertBefore(obj.headers[e],obj.headers[t]),obj.colgroupContainer.insertBefore(obj.colgroup[e],obj.colgroup[t]);for(var n=0;n0)var l=e;else l=1,e&&(r=e);o=!!o;var i=obj.options.columns.length-1;if((null==t||t>=parseInt(i)||t<0)&&(t=i),!1===obj.dispatch("onbeforeinsertcolumn",el,t,l,o))return!1;if(Object.keys(obj.options.mergeCells).length>0&&obj.isColMerged(t,o).length){if(!confirm(obj.options.text.thisActionWillDestroyAnyExistingMergedCellsAreYouSure))return!1;obj.destroyMerged()}n||(n=[]);for(var s=0;s0)if(obj.options.nestedHeaders[0]&&obj.options.nestedHeaders[0][0])for(g=0;g1){if(null==e){var o=obj.getSelectedColumns(!0);o.length?(e=parseInt(o[0]),t=parseInt(o.length)):(e=obj.headers.length-1,t=1)}var n=obj.options.data[0].length-1;if((null==e||e>n||e<0)&&(e=n),t||(t=1),t>obj.options.data[0].length-e&&(t=obj.options.data[0].length-e),!1===obj.dispatch("onbeforedeletecolumn",el,e,t))return!1;if(parseInt(e)>-1){var r=!1;if(Object.keys(obj.options.mergeCells).length>0)for(var l=e;l0)if(obj.options.nestedHeaders[0]&&obj.options.nestedHeaders[0][0])for(var p=0;p0){for(var e=0,t=obj.rows.length-1;t>=0;t--){for(var o=!1,n=0;n0&&obj.insertRow(obj.options.minSpareRows-e)}if(obj.options.minSpareCols>0){var r=0;for(n=obj.headers.length-1;n>=0;n--){for(o=!1,t=0;t0&&obj.insertColumn(obj.options.minSpareCols-r)}if("function"==typeof obj.options.updateTable){for(obj.options.detachForUpdates&&el.removeChild(obj.content),t=0;te+1&&(obj.filter.children[e+1].style.display="");for(var t=0;te+1&&(obj.filter.children[e+1].style.display="none");for(var t=0;t0)if(chainLoopProtection[n])obj.records[t][e].innerHTML="#ERROR",obj.formula[n]="";else{chainLoopProtection[n]=!0;for(var r=0;r-1)return console.error("Self Reference detected"),"#ERROR";var formulaExpressions={};if(tokens)for(var i=0;i0&&obj.up.visible(1,t?0:1):(obj.selectedCell[1]>0&&obj.up.visible(0,t?0:1),obj.selectedCell[2]=obj.selectedCell[0],obj.selectedCell[3]=obj.selectedCell[1]),obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]),1==obj.options.lazyLoading)if(0==obj.selectedCell[1]||0==obj.selectedCell[3])obj.loadPage(0),obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]);else if(obj.loadValidation())obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]);else{var o=parseInt(obj.tbody.firstChild.getAttribute("data-y"));obj.selectedCell[1]-o<30&&(obj.loadUp(),obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]))}else if(obj.options.pagination>0){var n=obj.whichPage(obj.selectedCell[3]);n!=obj.pageNumber&&obj.page(n)}obj.updateScroll(1)},obj.up.visible=function(e,t){if(0==e)var o=parseInt(obj.selectedCell[0]),n=parseInt(obj.selectedCell[1]);else o=parseInt(obj.selectedCell[2]),n=parseInt(obj.selectedCell[3]);if(0==t){for(var r=0;r=0;o--)if("none"!=obj.records[o][e].style.display&&"none"!=obj.rows[o].style.display){if(obj.records[o][e].getAttribute("data-merged")&&obj.records[o][e]==obj.records[t][e])continue;t=o;break}return t},obj.down=function(e,t){if(e?obj.selectedCell[3]0){var o=obj.whichPage(obj.selectedCell[3]);o!=obj.pageNumber&&obj.page(o)}obj.updateScroll(3)},obj.down.visible=function(e,t){if(0==e)var o=parseInt(obj.selectedCell[0]),n=parseInt(obj.selectedCell[1]);else o=parseInt(obj.selectedCell[2]),n=parseInt(obj.selectedCell[3]);if(0==t){for(var r=obj.rows.length-1;r>n;r--)if("none"!=obj.records[r][o].style.display&&"none"!=obj.rows[r].style.display){n=r;break}}else n=obj.down.get(o,n);0==e?(obj.selectedCell[0]=o,obj.selectedCell[1]=n):(obj.selectedCell[2]=o,obj.selectedCell[3]=n)},obj.down.get=function(e,t){e=parseInt(e);for(var o=(t=parseInt(t))+1;oo;r--)if("none"!=obj.records[n][r].style.display){o=r;break}}else o=obj.right.get(o,n);0==e?(obj.selectedCell[0]=o,obj.selectedCell[1]=n):(obj.selectedCell[2]=o,obj.selectedCell[3]=n)},obj.right.get=function(e,t){e=parseInt(e),t=parseInt(t);for(var o=e+1;o0&&obj.left.visible(1,t?0:1):(obj.selectedCell[0]>0&&obj.left.visible(0,t?0:1),obj.selectedCell[2]=obj.selectedCell[0],obj.selectedCell[3]=obj.selectedCell[1]),obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]),obj.updateScroll(0)},obj.left.visible=function(e,t){if(0==e)var o=parseInt(obj.selectedCell[0]),n=parseInt(obj.selectedCell[1]);else o=parseInt(obj.selectedCell[2]),n=parseInt(obj.selectedCell[3]);if(0==t){for(var r=0;r=0;o--)if("none"!=obj.records[t][o].style.display){if(obj.records[t][o].getAttribute("data-merged")&&obj.records[t][o]==obj.records[t][e])continue;e=o;break}return e},obj.first=function(e,t){if(e?t?obj.selectedCell[3]=0:obj.left.visible(1,0):(t?obj.selectedCell[1]=0:obj.left.visible(0,0),obj.selectedCell[2]=obj.selectedCell[0],obj.selectedCell[3]=obj.selectedCell[1]),1!=obj.options.lazyLoading||0!=obj.selectedCell[1]&&0!=obj.selectedCell[3]){if(obj.options.pagination>0){var o=obj.whichPage(obj.selectedCell[3]);o!=obj.pageNumber&&obj.page(o)}}else obj.loadPage(0);obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]),obj.updateScroll(1)},obj.last=function(e,t){if(e?t?obj.selectedCell[3]=obj.records.length-1:obj.right.visible(1,0):(t?obj.selectedCell[1]=obj.records.length-1:obj.right.visible(0,0),obj.selectedCell[2]=obj.selectedCell[0],obj.selectedCell[3]=obj.selectedCell[1]),1!=obj.options.lazyLoading||obj.selectedCell[1]!=obj.records.length-1&&obj.selectedCell[3]!=obj.records.length-1){if(obj.options.pagination>0){var o=obj.whichPage(obj.selectedCell[3]);o!=obj.pageNumber&&obj.page(o)}}else obj.loadPage(-1);obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3]),obj.updateScroll(3)},obj.selectAll=function(){obj.selectedCell||(obj.selectedCell=[]),obj.selectedCell[0]=0,obj.selectedCell[1]=0,obj.selectedCell[2]=obj.headers.length-1,obj.selectedCell[3]=obj.records.length-1,obj.updateSelectionFromCoords(obj.selectedCell[0],obj.selectedCell[1],obj.selectedCell[2],obj.selectedCell[3])},obj.loadPage=function(e){if(1!=obj.options.search&&1!=obj.options.filters||!obj.results)t=obj.rows;else var t=obj.results;var o=100;null!=e&&-1!=e||(e=Math.ceil(t.length/o)-1);var n=e*o,r=e*o+o;r>t.length&&(r=t.length),(n=r-100)<0&&(n=0);for(var l=n;lo&&obj.tbody.removeChild(obj.tbody.firstChild)},obj.loadUp=function(){if(1!=obj.options.search&&1!=obj.options.filters||!obj.results)e=obj.rows;else var e=obj.results;var t=0;if(e.length>100){var o=parseInt(obj.tbody.firstChild.getAttribute("data-y"));if(1!=obj.options.search&&1!=obj.options.filters||!obj.results||(o=e.indexOf(o)),o>0)for(var n=0;n<30;n++)(o-=1)>-1&&(1!=obj.options.search&&1!=obj.options.filters||!obj.results?obj.tbody.insertBefore(obj.rows[o],obj.tbody.firstChild):obj.tbody.insertBefore(obj.rows[e[o]],obj.tbody.firstChild),obj.tbody.children.length>100&&(obj.tbody.removeChild(obj.tbody.lastChild),t=1))}return t},obj.loadDown=function(){if(1!=obj.options.search&&1!=obj.options.filters||!obj.results)e=obj.rows;else var e=obj.results;var t=0;if(e.length>100){var o=parseInt(obj.tbody.lastChild.getAttribute("data-y"));if(1!=obj.options.search&&1!=obj.options.filters||!obj.results||(o=e.indexOf(o)),o100&&(obj.tbody.removeChild(obj.tbody.firstChild),t=1)),o+=1}return t},obj.loadValidation=function(){if(obj.selectedCell){var e=parseInt(obj.tbody.firstChild.getAttribute("data-y"))/100,t=parseInt(obj.selectedCell[3]/100),o=parseInt(obj.rows.length/100);if(e!=t&&t<=o&&!Array.prototype.indexOf.call(obj.tbody.children,obj.rows[obj.selectedCell[3]]))return obj.loadPage(t),!0}return!1},obj.resetSearch=function(){obj.searchInput.value="",obj.search(""),obj.results=null},obj.search=function(e){if(obj.options.filters&&obj.resetFilters(),obj.resetSelection(),obj.pageNumber=0,obj.results=[],e){var t=function(e){-1==obj.results.indexOf(e)&&obj.results.push(e)},o=e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");o=new RegExp(o,"i"),obj.options.data.forEach((function(e,n){if(function(e,t,o){for(var n=0;n=0||(""+obj.records[o][n].innerHTML).toLowerCase().search(t)>=0)return!0;return!1}(e,o,n)){var r=obj.isRowMerged(n);if(r.length)for(var l=0;l0?obj.options.pagination:obj.results?obj.results.length:obj.rows.length;obj.tbody.firstChild;)obj.tbody.removeChild(obj.tbody.firstChild);for(var o=0;o-1?(t0&&obj.updatePagination(),obj.updateCornerPosition(),e},obj.whichPage=function(e){return 1!=obj.options.search&&1!=obj.options.filters||!obj.results||(e=obj.results.indexOf(e)),Math.ceil((parseInt(e)+1)/parseInt(obj.options.pagination))-1},obj.page=function(e){var t=obj.pageNumber;if(1!=obj.options.search&&1!=obj.options.filters||!obj.results)o=obj.rows;else var o=obj.results;var n=parseInt(obj.options.pagination);null!=e&&-1!=e||(e=Math.ceil(o.length/n)-1),obj.pageNumber=e;var r=e*n,l=e*n+n;for(l>o.length&&(l=o.length),r<0&&(r=0);obj.tbody.firstChild;)obj.tbody.removeChild(obj.tbody.firstChild);for(var i=r;i0&&obj.updatePagination(),obj.updateCornerPosition(),obj.dispatch("onchangepage",el,e,t)},obj.updatePagination=function(){if(obj.pagination.children[0].innerHTML="",obj.pagination.children[1].innerHTML="",obj.options.pagination){if(1!=obj.options.search&&1!=obj.options.filters||!obj.results)e=obj.rows.length;else var e=obj.results.length;if(e){var t=Math.ceil(e/obj.options.pagination);if(obj.pageNumber<6)var o=1,n=t<10?t:10;else t-obj.pageNumber<5?(n=t,(o=t-9)<1&&(o=1)):(o=obj.pageNumber-4,n=obj.pageNumber+5);o>1&&((l=document.createElement("div")).className="jexcel_page",l.innerHTML="<",l.title=1,obj.pagination.children[1].appendChild(l));for(var r=o;r<=n;r++){var l;(l=document.createElement("div")).className="jexcel_page",l.innerHTML=r,obj.pagination.children[1].appendChild(l),obj.pageNumber==r-1&&l.classList.add("jexcel_page_selected")}n",l.title=t,obj.pagination.children[1].appendChild(l)),obj.pagination.children[0].innerHTML=function(e){var t=Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,(function(e,o){return void 0!==t[o]?t[o]:e}))}(obj.options.text.showingPage,obj.pageNumber+1,t)}else obj.pagination.children[0].innerHTML=obj.options.text.noRecordsFound}},obj.download=function(e){if(0==obj.options.allowExport)console.error("Export not allowed");else{var t="";t+=obj.copy(!1,obj.options.csvDelimiter,!0,e,!0);var o=new Blob(["\ufeff"+t],{type:"text/csv;charset=utf-8;"});if(window.navigator&&window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(o,obj.options.csvFileName+".csv");else{var n=document.createElement("a"),r=URL.createObjectURL(o);n.href=r,n.setAttribute("download",obj.options.csvFileName+".csv"),document.body.appendChild(n),n.click(),n.parentNode.removeChild(n)}}},obj.setHistory=function(e){if(1!=obj.ignoreHistory){var t=++obj.historyIndex;obj.history=obj.history=obj.history.slice(0,t+1),obj.history[t]=e}},obj.copy=function(e,t,o,n,r){t||(t="\t");for(var l=new RegExp(t,"ig"),i=[],s=[],a=[],u=[],c=[],f=obj.options.data[0].length,d=obj.options.data.length,p="",b=!1,j="",h="",g=0,m=0,v=0,y=0,C=!0,x=0;x0)for(p=obj.options.nestedHeaders[0]&&obj.options.nestedHeaders[0][0]?obj.options.nestedHeaders:[obj.options.nestedHeaders],x=0;x1&Number.isInteger(s/o[0].length)){f=null,p=s/o[0].length;var d=o.map((function(e,t){var o=Array.apply(null,{length:p*e.length}).map((function(t,o){return e[o%e.length]}));return o}));o=d}if(a>1&Number.isInteger(a/o.length)){f=null;var p=a/o.length;d=Array.apply(null,{length:p*o.length}).map((function(e,t){return o[t%o.length]})),o=d}if(null!=e&&null!=t&&o){for(var b=0,j=0,h=[],g={},m={},v=0,y=parseInt(e),C=parseInt(t),x=null;x=o[j];){for(b=0,y=parseInt(e);null!=x[b];){var w=obj.updateCell(y,C,x[b]);if(h.push(w),obj.updateFormulaChain(y,C,h),f&&f[v]){var A=jexcel.getColumnNameFromId([y,C]);g[A]=f[v],m[A]=obj.getStyle(A),obj.records[C][y].setAttribute("style",f[v]),v++}if(null!=x[++b]){if(y>=obj.headers.length-1){if(1!=obj.options.allowInsertColumn)break;obj.insertColumn()}y=obj.right.get(y,C)}}if(j++,o[j]){if(C>=obj.rows.length-1){if(1!=obj.options.allowInsertRow)break;obj.insertRow()}C=obj.down.get(e,C)}}obj.updateSelectionFromCoords(e,t,y,C),obj.setHistory({action:"setValue",records:h,selection:obj.selectedCell,newStyle:g,oldStyle:m}),obj.updateTable(),obj.dispatch("onpaste",el,o),obj.onafterchanges(el,h)}obj.removeCopyingSelection()},obj.removeCopyingSelection=function(){for(var e=document.querySelectorAll(".jexcel .copying"),t=0;t0&&obj.page(obj.pageNumber),obj.updateTableReferences()},obj.historyProcessColumn=function(e,t){var o=t.insertBefore?t.columnNumber:t.columnNumber+1;if(1==e){var n=t.numOfColumns;obj.options.columns.splice(o,n);for(var r=o;r0)if(obj.options.nestedHeaders[0]&&obj.options.nestedHeaders[0][0])for(l=0;l=0){var n=obj.history[obj.historyIndex--];if("insertRow"==n.action)obj.historyProcessRow(1,n);else if("deleteRow"==n.action)obj.historyProcessRow(0,n);else if("insertColumn"==n.action)obj.historyProcessColumn(1,n);else if("deleteColumn"==n.action)obj.historyProcessColumn(0,n);else if("moveRow"==n.action)obj.moveRow(n.newValue,n.oldValue);else if("moveColumn"==n.action)obj.moveColumn(n.newValue,n.oldValue);else if("setMerge"==n.action)obj.removeMerge(n.column,n.data);else if("setStyle"==n.action)obj.setStyle(n.oldValue,null,null,1);else if("setWidth"==n.action)obj.setWidth(n.column,n.oldValue);else if("setHeight"==n.action)obj.setHeight(n.row,n.oldValue);else if("setHeader"==n.action)obj.setHeader(n.column,n.oldValue);else if("setComments"==n.action)obj.setComments(n.column,n.oldValue[0],n.oldValue[1]);else if("orderBy"==n.action){for(var r=[],l=0;l0?o.join("; "):""},obj.parseCSV=function(e,t){9==(e=e.replace(/\r?\n$|\r$|\n$/g,"")).charCodeAt(e.length-1)&&(e+="\0"),t=t||",";for(var o=[],n=!1,r=0,l=0,i=0;i0)for(var o=t.shift(),n=0;n0&&obj.content.scrollLeft!=scrollLeft&&obj.updateFreezePosition(),1!=obj.options.lazyLoading&&1!=obj.options.tableOverflow||obj.edition&&"jdropdown"!=e.target.className.substr(0,9)&&obj.closeEditor(obj.edition[0],!0)},obj.wheelControls=function(e){1==obj.options.lazyLoading&&null==jexcel.timeControlLoading&&(jexcel.timeControlLoading=setTimeout((function(){obj.content.scrollTop+obj.content.clientHeight>=obj.content.scrollHeight-10?obj.loadDown()&&(obj.content.scrollTop+obj.content.clientHeight>obj.content.scrollHeight-10&&(obj.content.scrollTop=obj.content.scrollTop-obj.content.clientHeight),obj.updateCornerPosition()):obj.content.scrollTop<=obj.content.clientHeight&&obj.loadUp()&&(obj.content.scrollTop<10&&(obj.content.scrollTop=obj.content.scrollTop+obj.content.clientHeight),obj.updateCornerPosition()),jexcel.timeControlLoading=null}),100))},obj.getFreezeWidth=function(){var e=0;if(obj.options.freezeColumns>0)for(var t=0;t50)for(var t=0;t0&&"hidden"!==obj.options.columns[t-1].type&&(e+=parseInt(obj.options.columns[t-1].width)),obj.headers[t].classList.add("jexcel_freezed"),obj.headers[t].style.left=e+"px";for(var o=0;o0?obj.records[o][t-1].style.width:0)-51+"px";obj.records[o][t].classList.add("jexcel_freezed"),obj.records[o][t].style.left=n}}else for(t=0;t200)&&e.altKey){var t=jexcel.current.edition[0].children[0],o=jexcel.current.edition[0].children[0].value,n=t.selectionStart;o=o.slice(0,n)+"\n"+o.slice(n),t.value=o,t.focus(),t.selectionStart=n+1,t.selectionEnd=n+1}else jexcel.current.edition[0].children[0].blur();else 9==e.which&&(["calendar","html"].includes(jexcel.current.options.columns[jexcel.current.edition[2]].type)?jexcel.current.closeEditor(jexcel.current.edition[0],!0):jexcel.current.edition[0].children[0].blur());if(!jexcel.current.edition&&jexcel.current.selectedCell)if(37==e.which)jexcel.current.left(e.shiftKey,e.ctrlKey),e.preventDefault();else if(39==e.which)jexcel.current.right(e.shiftKey,e.ctrlKey),e.preventDefault();else if(38==e.which)jexcel.current.up(e.shiftKey,e.ctrlKey),e.preventDefault();else if(40==e.which)jexcel.current.down(e.shiftKey,e.ctrlKey),e.preventDefault();else if(36==e.which)jexcel.current.first(e.shiftKey,e.ctrlKey),e.preventDefault();else if(35==e.which)jexcel.current.last(e.shiftKey,e.ctrlKey),e.preventDefault();else if(46==e.which||8==e.which)1==jexcel.current.options.editable&&(jexcel.current.selectedRow?1==jexcel.current.options.allowDeleteRow&&confirm(jexcel.current.options.text.areYouSureToDeleteTheSelectedRows)&&jexcel.current.deleteRow():jexcel.current.selectedHeader?1==jexcel.current.options.allowDeleteColumn&&confirm(jexcel.current.options.text.areYouSureToDeleteTheSelectedColumns)&&jexcel.current.deleteColumn():jexcel.current.setValue(jexcel.current.highlighted,""));else if(13==e.which)e.shiftKey?jexcel.current.up():(1==jexcel.current.options.allowInsertRow&&1==jexcel.current.options.allowManualInsertRow&&jexcel.current.selectedCell[1]==jexcel.current.options.data.length-1&&jexcel.current.insertRow(),jexcel.current.down()),e.preventDefault();else if(9==e.which)e.shiftKey?jexcel.current.left():(1==jexcel.current.options.allowInsertColumn&&1==jexcel.current.options.allowManualInsertColumn&&jexcel.current.selectedCell[0]==jexcel.current.options.data[0].length-1&&jexcel.current.insertColumn(),jexcel.current.right()),e.preventDefault();else if(!e.ctrlKey&&!e.metaKey||e.shiftKey){if(jexcel.current.selectedCell&&1==jexcel.current.options.editable){var r=jexcel.current.selectedCell[1],l=jexcel.current.selectedCell[0];"readonly"!=jexcel.current.options.columns[l].type&&(32==e.keyCode?(e.preventDefault(),"checkbox"==jexcel.current.options.columns[l].type||"radio"==jexcel.current.options.columns[l].type?jexcel.current.setCheckRadioValue():jexcel.current.openEditor(jexcel.current.records[r][l],!0)):113==e.keyCode?jexcel.current.openEditor(jexcel.current.records[r][l],!1):(8==e.keyCode||e.keyCode>=48&&e.keyCode<=57||e.keyCode>=96&&e.keyCode<=111||e.keyCode>=187&&e.keyCode<=190||(String.fromCharCode(e.keyCode)==e.key||String.fromCharCode(e.keyCode).toLowerCase()==e.key.toLowerCase())&&jexcel.validLetter(String.fromCharCode(e.keyCode)))&&(jexcel.current.openEditor(jexcel.current.records[r][l],!0),"calendar"==jexcel.current.options.columns[l].type&&e.preventDefault()))}}else 65==e.which?(jexcel.current.selectAll(),e.preventDefault()):83==e.which?(jexcel.current.download(),e.preventDefault()):89==e.which?(jexcel.current.redo(),e.preventDefault()):90==e.which?(jexcel.current.undo(),e.preventDefault()):67==e.which?(jexcel.current.copy(!0),e.preventDefault()):88==e.which?(1==jexcel.current.options.editable?jexcel.cutControls():jexcel.copyControls(),e.preventDefault()):86==e.which&&jexcel.pasteControls();else e.target.classList.contains("jexcel_search")&&(jexcel.timeControl&&clearTimeout(jexcel.timeControl),jexcel.timeControl=setTimeout((function(){jexcel.current.search(e.target.value)}),200))}},jexcel.isMouseAction=!1,jexcel.mouseDownControls=function(e){if((e=e||window.event).buttons)var t=e.buttons;else t=e.button?e.button:e.which;var o=jexcel.getElement(e.target);if(o[0]?jexcel.current!=o[0].jexcel&&(jexcel.current&&(jexcel.current.edition&&jexcel.current.closeEditor(jexcel.current.edition[0],!0),jexcel.current.resetSelection()),jexcel.current=o[0].jexcel):jexcel.current&&(jexcel.current.edition&&jexcel.current.closeEditor(jexcel.current.edition[0],!0),jexcel.current.resetSelection(!0),jexcel.current=null),jexcel.current&&1==t){if(e.target.classList.contains("jexcel_selectall"))jexcel.current&&jexcel.current.selectAll();else if(e.target.classList.contains("jexcel_corner"))1==jexcel.current.options.editable&&(jexcel.current.selectedCorner=!0);else{if(1==o[1]){if(p=e.target.getAttribute("data-x")){var n=e.target.getBoundingClientRect();if(1==jexcel.current.options.columnResize&&n.width-e.offsetX<6){jexcel.current.resizing={mousePosition:e.pageX,column:p,width:n.width},jexcel.current.headers[p].classList.add("resizing");for(var r=0;r"==e.target.textContent?jexcel.current.page(e.target.getAttribute("title")-1):jexcel.current.page(e.target.textContent-1))}jexcel.current.edition?jexcel.isMouseAction=!1:jexcel.isMouseAction=!0}else jexcel.isMouseAction=!1},jexcel.mouseUpControls=function(e){if(jexcel.current)if(jexcel.current.resizing){if(jexcel.current.resizing.column){var t=jexcel.current.colgroup[jexcel.current.resizing.column].getAttribute("width"),o=jexcel.current.getSelectedColumns();if(o.length>1){for(var n=[],r=0;r0&&(jexcel.current.copyData(jexcel.current.selection[0],jexcel.current.selection[jexcel.current.selection.length-1]),jexcel.current.removeCopySelection()));jexcel.timeControl&&(clearTimeout(jexcel.timeControl),jexcel.timeControl=null),jexcel.isMouseAction=!1},jexcel.mouseMoveControls=function(e){if((e=e||window.event).buttons)var t=e.buttons;else t=e.button?e.button:e.which;if(t||(jexcel.isMouseAction=!1),jexcel.current)if(1==jexcel.isMouseAction){if(jexcel.current.resizing)if(jexcel.current.resizing.column){var o=e.pageX-jexcel.current.resizing.mousePosition;if(jexcel.current.resizing.width+o>0){var n=jexcel.current.resizing.width+o;jexcel.current.colgroup[jexcel.current.resizing.column].setAttribute("width",n),jexcel.current.updateCornerPosition()}}else{var r=e.pageY-jexcel.current.resizing.mousePosition;if(jexcel.current.resizing.height+r>0){var l=jexcel.current.resizing.height+r;jexcel.current.rows[jexcel.current.resizing.row].setAttribute("height",l),jexcel.current.updateCornerPosition()}}else if(jexcel.current.dragging)if(jexcel.current.dragging.column){var i=e.target.getAttribute("data-x");if(i)if(jexcel.current.isColMerged(i).length)console.error("Jspreadsheet: This column is part of a merged cell.");else{for(var s=0;se.offsetX?(jexcel.current.dragging.columne.offsetY?e.target.parentNode.nextSibling:e.target.parentNode;jexcel.current.dragging.element!=u&&(e.target.parentNode.parentNode.insertBefore(jexcel.current.dragging.element,u),jexcel.current.dragging.destination=Array.prototype.indexOf.call(jexcel.current.dragging.element.parentNode.children,jexcel.current.dragging.element))}}}else{var c=e.target.getAttribute("data-x"),f=e.target.getAttribute("data-y"),d=e.target.getBoundingClientRect();jexcel.current.cursor&&(jexcel.current.cursor.style.cursor="",jexcel.current.cursor=null),e.target.parentNode.parentNode&&e.target.parentNode.parentNode.className&&(e.target.parentNode.parentNode.classList.contains("resizable")&&(e.target&&c&&!f&&d.width-(e.clientX-d.left)<6?(jexcel.current.cursor=e.target,jexcel.current.cursor.style.cursor="col-resize"):e.target&&!c&&f&&d.height-(e.clientY-d.top)<6&&(jexcel.current.cursor=e.target,jexcel.current.cursor.style.cursor="row-resize")),e.target.parentNode.parentNode.classList.contains("draggable")&&(e.target&&!c&&f&&d.width-(e.clientX-d.left)<6||e.target&&c&&!f&&d.height-(e.clientY-d.top)<6)&&(jexcel.current.cursor=e.target,jexcel.current.cursor.style.cursor="move"))}},jexcel.mouseOverControls=function(e){if((e=e||window.event).buttons)var t=e.buttons;else t=e.button?e.button:e.which;if(t||(jexcel.isMouseAction=!1),jexcel.current&&1==jexcel.isMouseAction){var o=jexcel.getElement(e.target);if(o[0]){if(jexcel.current!=o[0].jexcel&&jexcel.current)return!1;var n=e.target.getAttribute("data-x"),r=e.target.getAttribute("data-y");if(jexcel.current.resizing||jexcel.current.dragging);else{if(1==o[1]&&jexcel.current.selectedHeader){n=e.target.getAttribute("data-x");var l=jexcel.current.selectedHeader,i=n;jexcel.current.updateSelectionFromCoords(l,0,i,jexcel.current.options.data.length-1)}2==o[1]&&(e.target.classList.contains("jexcel_row")?jexcel.current.selectedRow&&(l=jexcel.current.selectedRow,i=r,jexcel.current.updateSelectionFromCoords(0,l,jexcel.current.options.data[0].length-1,i)):jexcel.current.edition||n&&r&&(jexcel.current.selectedCorner?jexcel.current.updateCopySelection(n,r):jexcel.current.selectedCell&&jexcel.current.updateSelectionFromCoords(jexcel.current.selectedCell[0],jexcel.current.selectedCell[1],n,r)))}}}jexcel.timeControl&&(clearTimeout(jexcel.timeControl),jexcel.timeControl=null)},jexcel.doubleClickControls=function(e){if(jexcel.current)if(e.target.classList.contains("jexcel_corner")){if(jexcel.current.highlighted.length>0){var t=jexcel.current.highlighted[0].getAttribute("data-x"),o=parseInt(jexcel.current.highlighted[jexcel.current.highlighted.length-1].getAttribute("data-y"))+1,n=jexcel.current.highlighted[jexcel.current.highlighted.length-1].getAttribute("data-x"),r=jexcel.current.records.length-1;jexcel.current.copyData(jexcel.current.records[o][t],jexcel.current.records[r][n])}}else if(e.target.classList.contains("jexcel_column_filter")){var l=e.target.getAttribute("data-x");jexcel.current.openFilter(l)}else{var i=jexcel.getElement(e.target);if(1==i[1]&&1==jexcel.current.options.columnSorting&&(l=e.target.getAttribute("data-x"))&&jexcel.current.orderBy(l),2==i[1]&&1==jexcel.current.options.editable&&!jexcel.current.edition){var s=function(e){if(e.parentNode){var t=e.getAttribute("data-x"),o=e.getAttribute("data-y");return t&&o?e:s(e.parentNode)}},a=s(e.target);a&&a.classList.contains("highlight")&&jexcel.current.openEditor(a)}}},jexcel.copyControls=function(e){jexcel.current&&jexcel.copyControls.enabled&&(jexcel.current.edition||jexcel.current.copy(!0))},jexcel.cutControls=function(e){jexcel.current&&(jexcel.current.edition||(jexcel.current.copy(!0),1==jexcel.current.options.editable&&jexcel.current.setValue(jexcel.current.highlighted,"")))},jexcel.pasteControls=function(e){jexcel.current&&jexcel.current.selectedCell&&(jexcel.current.edition||1==jexcel.current.options.editable&&(e&&e.clipboardData?(jexcel.current.paste(jexcel.current.selectedCell[0],jexcel.current.selectedCell[1],e.clipboardData.getData("text")),e.preventDefault()):window.clipboardData&&jexcel.current.paste(jexcel.current.selectedCell[0],jexcel.current.selectedCell[1],window.clipboardData.getData("text"))))},jexcel.contextMenuControls=function(e){if("buttons"in(e=e||window.event)?e.buttons:e.which||e.button,jexcel.current)if(jexcel.current.edition)e.preventDefault();else if(jexcel.current.options.contextMenu&&(jexcel.current.contextMenu.contextmenu.close(),jexcel.current)){var t=e.target.getAttribute("data-x"),o=e.target.getAttribute("data-y");if(t||o){(tparseInt(jexcel.current.selectedCell[2])||oparseInt(jexcel.current.selectedCell[3]))&&jexcel.current.updateSelectionFromCoords(t,o,t,o);var n=jexcel.current.options.contextMenu(jexcel.current,t,o,e);jexcel.current.contextMenu.contextmenu.open(e,n),e.preventDefault()}}},jexcel.touchStartControls=function(e){var t=jexcel.getElement(e.target);if(t[0]?jexcel.current!=t[0].jexcel&&(jexcel.current&&jexcel.current.resetSelection(),jexcel.current=t[0].jexcel):jexcel.current&&(jexcel.current.resetSelection(),jexcel.current=null),jexcel.current&&!jexcel.current.edition){var o=e.target.getAttribute("data-x"),n=e.target.getAttribute("data-y");o&&n&&(jexcel.current.updateSelectionFromCoords(o,n),jexcel.timeControl=setTimeout((function(){"color"==jexcel.current.options.columns[o].type?jexcel.tmpElement=null:jexcel.tmpElement=e.target,jexcel.current.openEditor(e.target,!1,e)}),500))}},jexcel.touchEndControls=function(e){jexcel.timeControl&&(clearTimeout(jexcel.timeControl),jexcel.timeControl=null,jexcel.tmpElement&&"INPUT"==jexcel.tmpElement.children[0].tagName&&jexcel.tmpElement.children[0].focus(),jexcel.tmpElement=null)},jexcel.tabs=function(e,t){var o=[];if(e.classList.contains("jexcel_tabs"))r=e.children[0],l=e.children[1];else{e.innerHTML="",e.classList.add("jexcel_tabs"),e.jexcel=[];var n=document.createElement("div"),r=e.appendChild(n),l=(n=document.createElement("div"),e.appendChild(n))}for(var i=[],s=[],a=0;a0)for(n.mergeCells=[],r=0;r0&&(n.style[d[r]]=p.style),p.s&&p.s.fgColor&&(n.style[d[r]]&&(n.style[d[r]]+=";"),n.style[d[r]]+="background-color:#"+p.s.fgColor.rgb)}for(var j=n.columns,h=0;h<=f;h++)for(r=0;r<=c;r++)n.data[h]||(n.data[h]=[]),n.data[h][r]||j0&&l--,e=1==t?[n,l]:n+"-"+l}return e},jexcel.getColumnNameFromId=function(e){return Array.isArray(e)||(e=e.split("-")),jexcel.getColumnName(parseInt(e[0]))+(parseInt(e[1])+1)},jexcel.getElement=function(e){var t=0,o=0;return function e(n){n.className&&n.classList.contains("jexcel_container")&&(o=n),"THEAD"==n.tagName?t=1:"TBODY"==n.tagName&&(t=2),n.parentNode&&(o||e(n.parentNode))}(e),[o,t]},jexcel.doubleDigitFormat=function(e){return 1==(e=""+e).length&&(e="0"+e),e},jexcel.createFromTable=function(e,t){if("TABLE"==e.tagName){t||(t={}),t.columns=[],t.data=[];var o=e.querySelectorAll("colgroup > col");if(o.length)for(var n=0;n50?o.width:50;t.columns[n]||(t.columns[n]={}),e.getAttribute("data-celltype")?t.columns[n].type=e.getAttribute("data-celltype"):t.columns[n].type="text",t.columns[n].width=r+"px",t.columns[n].title=e.innerHTML,t.columns[n].align=e.style.textAlign||"center",(o=e.getAttribute("name"))&&(t.columns[n].name=o),(o=e.getAttribute("id"))&&(t.columns[n].id=o),(o=e.getAttribute("data-mask"))&&(t.columns[n].mask=o)},i=[],s=e.querySelectorAll(":scope > thead > tr");if(s.length){for(var a=0;a tr, :scope > tbody > tr");for(a=0;a0&&(t.nestedHeaders=i),Object.keys(b).length>0&&(t.style=b),Object.keys(d).length>0&&(t.mergeCells=d),Object.keys(p).length>0&&(t.rows=p),Object.keys(j).length>0&&(t.classes=j),(h=e.querySelectorAll("tfoot tr")).length){var w=[];for(a=0;a0&&(t.footers=w)}if(1==t.parseTableAutoCellType){var E=[];for(n=0;n25&&(M=!1),10==g.length&&"-"==g.substr(4,1)&&"-"==g.substr(7,1)||(I=!1);var N=Object.keys(E[n]).length;I?t.columns[n].type="calendar":1==M&&N>1&&N<=parseInt(.1*t.data.length)&&(t.columns[n].type="dropdown",t.columns[n].source=Object.keys(E[n]))}}return t}console.log("Element is not a table")},jexcel.helpers=(component={getCaretIndex:function(e){if(this.config.root)var t=this.config.root;else t=window;var o=0,n=t.getSelection();if(n&&0!==n.rangeCount){var r=n.getRangeAt(0),l=r.cloneRange();l.selectNodeContents(e),l.setEnd(r.endContainer,r.endOffset),o=l.toString().length}return o},invert:function(e){for(var t=[],o=Object.keys(e),n=0;n0;)t=(o-1)%26,n=String.fromCharCode(65+t).toString()+n,o=parseInt((o-t)/26);return n},getColumnNameFromCoords:function(e,t){return component.getColumnName(parseInt(e))+(parseInt(t)+1)},getCoordsFromColumnName:function(e){var t=/^[a-zA-Z]+/.exec(e);if(t){for(var o=0,n=0;n0&&r--,[o,r]}},createFromTable:function(){},injectArray:function(e,t,o){return e.slice(0,t).concat(o).concat(e.slice(t))},parseCSV:function(e,t){t=t||",";for(var o=0,n=0,r=[[]],l=0,i=null,s=!1,a=!1,u=0;ul&&(l=o)}for(var f=0;f