/*
    *
    * Wijmo Library 5.20181.462
    * http://wijmo.com/
    *
    * Copyright(c) GrapeCity, Inc.  All rights reserved.
    *
    * Licensed under the GrapeCity Commercial License.
    * sales@wijmo.com
    * wijmo.com/products/wijmo-5/license/
    *
    */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const wjcCore=require("wijmo/wijmo"),wjcXlsx=require("wijmo/wijmo.xlsx"),wjcGrid=require("wijmo/wijmo.grid"),wjcInput=require("wijmo/wijmo.input"),wjcGridXlsx=require("wijmo/wijmo.grid.xlsx"),wjcGridFilter=require("wijmo/wijmo.grid.filter"),wjcSelfRef=require("wijmo/wijmo.grid.sheet");var wjcSelf=wjcSelfRef||exports;window.wijmo=window.wijmo||{},window.wijmo.grid=window.wijmo.grid||{},window.wijmo.grid.sheet=wjcSelf;class _CalcEngine{constructor(e){this._expressionCache={},this._idChars="$:!",this._functionTable={},this._cacheSize=0,this._tableRefStart=!1,this.unknownFunction=new wjcCore.Event,this._owner=e,this._buildSymbolTable(),this._registerAggregateFunction(),this._registerMathFunction(),this._registerLogicalFunction(),this._registerTextFunction(),this._registerDateFunction(),this._registLookUpReferenceFunction(),this._registFinacialFunction()}onUnknownFunction(e,t){var o,n;if(t&&t.length>0){o=[];for(var i=0;i<t.length;i++)o[i]=t[i].evaluate(this._rowIndex,this._columnIndex)}if(n=new UnknownFunctionEventArgs(e,o),this.unknownFunction.raise(this,n),null!=n.value)return new _Expression(n.value);throw'The function "'+e+'" has not supported in FlexSheet yet.'}evaluate(e,t,o,n,i){var s;try{if(e&&e.length>1&&"="===e[0]){for(this._containsCellRef=!1,this._rowIndex=n,this._columnIndex=i,this._sheet=o||this._owner.selectedSheet,s=this._checkCache(e).evaluate(n,i,o);s instanceof _Expression;)s=s.evaluate(n,i,o);return t&&wjcCore.isPrimitive(s)?wjcCore.Globalize.format(s,t):s}return e||""}catch(e){return"Error: "+e}}addCustomFunction(e,t,o,n){var i=this;e=e.toLowerCase(),this._functionTable[e]=new _FunctionDefinition(e=>{var o,n=[];if(e&&e.length>0)for(var s=0;s<e.length;s++)o=e[s],n[s]=o instanceof _CellRangeExpression?o.cells:o.evaluate(i._rowIndex,i._columnIndex);return t.apply(i,n)},n,o)}addFunction(e,t,o,n){var i=this;e=e.toLowerCase(),this._functionTable[e]=new _FunctionDefinition(e=>{var o,n=[];if(e&&e.length>0)for(var s=0;s<e.length;s++)o=e[s],n[s]=o instanceof _CellRangeExpression?o.getValuseWithTwoDimensions():[[o.evaluate(i._rowIndex,i._columnIndex)]];return t.apply(i,n)},n,o)}_clearExpressionCache(){this._expressionCache=null,this._expressionCache={},this._cacheSize=0}_parse(e){return this._expression=e,this._expressLength=e?e.length:0,this._pointer=0,this._expressLength>0&&"="===this._expression[0]&&this._pointer++,this._parseExpression()}_buildSymbolTable(){this._tokenTable||(this._tokenTable={},this._addToken("+",_TokenID.ADD,_TokenType.ADDSUB),this._addToken("-",_TokenID.SUB,_TokenType.ADDSUB),this._addToken("(",_TokenID.OPEN,_TokenType.GROUP),this._addToken(")",_TokenID.CLOSE,_TokenType.GROUP),this._addToken("*",_TokenID.MUL,_TokenType.MULDIV),this._addToken(",",_TokenID.COMMA,_TokenType.GROUP),this._addToken(".",_TokenID.PERIOD,_TokenType.GROUP),this._addToken("/",_TokenID.DIV,_TokenType.MULDIV),this._addToken("\\",_TokenID.DIVINT,_TokenType.MULDIV),this._addToken("=",_TokenID.EQ,_TokenType.COMPARE),this._addToken(">",_TokenID.GT,_TokenType.COMPARE),this._addToken("<",_TokenID.LT,_TokenType.COMPARE),this._addToken("^",_TokenID.POWER,_TokenType.POWER),this._addToken("<>",_TokenID.NE,_TokenType.COMPARE),this._addToken(">=",_TokenID.GE,_TokenType.COMPARE),this._addToken("<=",_TokenID.LE,_TokenType.COMPARE),this._addToken("&",_TokenID.CONCAT,_TokenType.CONCAT),this._addToken("[",_TokenID.OPEN,_TokenType.SQUAREBRACKETS),this._addToken("]",_TokenID.CLOSE,_TokenType.SQUAREBRACKETS))}_registerAggregateFunction(){var e=this;e._functionTable.sum=new _FunctionDefinition((t,o)=>e._getAggregateResult(wjcCore.Aggregate.Sum,t,o)),e._functionTable.average=new _FunctionDefinition((t,o)=>e._getAggregateResult(wjcCore.Aggregate.Avg,t,o)),e._functionTable.max=new _FunctionDefinition((t,o)=>e._getAggregateResult(wjcCore.Aggregate.Max,t,o)),e._functionTable.min=new _FunctionDefinition((t,o)=>e._getAggregateResult(wjcCore.Aggregate.Min,t,o)),e._functionTable.var=new _FunctionDefinition((t,o)=>e._getAggregateResult(wjcCore.Aggregate.Var,t,o)),e._functionTable.varp=new _FunctionDefinition((t,o)=>e._getAggregateResult(wjcCore.Aggregate.VarPop,t,o)),e._functionTable.stdev=new _FunctionDefinition((t,o)=>e._getAggregateResult(wjcCore.Aggregate.Std,t,o)),e._functionTable.stdevp=new _FunctionDefinition((t,o)=>e._getAggregateResult(wjcCore.Aggregate.StdPop,t,o)),e._functionTable.count=new _FunctionDefinition((t,o)=>e._getFlexSheetAggregateResult(_FlexSheetAggregate.Count,t,o)),e._functionTable.counta=new _FunctionDefinition((t,o)=>e._getFlexSheetAggregateResult(_FlexSheetAggregate.CountA,t,o)),e._functionTable.countblank=new _FunctionDefinition((t,o)=>e._getFlexSheetAggregateResult(_FlexSheetAggregate.ConutBlank,t,o)),e._functionTable.countif=new _FunctionDefinition((t,o)=>e._getFlexSheetAggregateResult(_FlexSheetAggregate.CountIf,t,o),2,2),e._functionTable.countifs=new _FunctionDefinition((t,o)=>e._getFlexSheetAggregateResult(_FlexSheetAggregate.CountIfs,t,o),254,2),e._functionTable.sumif=new _FunctionDefinition((t,o)=>e._getFlexSheetAggregateResult(_FlexSheetAggregate.SumIf,t,o),3,2),e._functionTable.sumifs=new _FunctionDefinition((t,o)=>e._getFlexSheetAggregateResult(_FlexSheetAggregate.SumIfs,t,o),255,2),e._functionTable.rank=new _FunctionDefinition((t,o)=>e._getFlexSheetAggregateResult(_FlexSheetAggregate.Rank,t,o),3,2),e._functionTable.product=new _FunctionDefinition((t,o)=>e._getFlexSheetAggregateResult(_FlexSheetAggregate.Product,t,o),255,1),e._functionTable.subtotal=new _FunctionDefinition((t,o)=>e._handleSubtotal(t,o),255,2),e._functionTable.dcount=new _FunctionDefinition((t,o)=>e._handleDCount(t,o),3,3),e._functionTable.sumproduct=new _FunctionDefinition((t,o)=>e._getSumProduct(t,o),255,1)}_registerMathFunction(){var e=this,t=["abs","acos","asin","atan","cos","exp","ln","sin","sqrt","tan"],o=["ceiling","floor"],n=["round","rounddown","roundup"];e._functionTable.pi=new _FunctionDefinition(()=>Math.PI,0,0),e._functionTable.rand=new _FunctionDefinition(()=>Math.random(),0,0),e._functionTable.power=new _FunctionDefinition((t,o)=>Math.pow(_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o),_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o)),2,2),e._functionTable.atan2=new _FunctionDefinition((t,o)=>{var n=_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o),i=_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o);if(0===n&&0===i)throw"The x number and y number can't both be zero for the atan2 function";return Math.atan2(i,n)},2,2),e._functionTable.mod=new _FunctionDefinition((t,o)=>_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o)%_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o),2,2),e._functionTable.trunc=new _FunctionDefinition((t,o)=>{var n,i=_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o),s=2===t.length?_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o):0;return 0===s?i>=0?Math.floor(i):Math.ceil(i):(n=Math.pow(10,s),i>=0?Math.floor(i*n)/n:Math.ceil(i*n)/n)},2,1),o.forEach(t=>{e._functionTable[t]=new _FunctionDefinition((o,n)=>{var i,s,l,r=_Expression.toNumber(o[0],e._rowIndex,e._columnIndex,n),a=2===o.length?_Expression.toNumber(o[1],e._rowIndex,e._columnIndex,n):1;if(isNaN(r))throw"Invalid Number!";if(isNaN(a))throw"Invalid Significance!";if(r>0&&a<0)throw"The significance has to be positive, if the number is positive.";if(0===r||0===a)return 0;if(i=a-Math.floor(a),s=1,0!==i)for(;i<1;)s*=10,i*=10;return l="ceiling"===t?Math.ceil(r/a):Math.floor(r/a),a*s*l/s},2,1)}),n.forEach(t=>{e._functionTable[t]=new _FunctionDefinition((o,n)=>{var i,s,l,r=_Expression.toNumber(o[0],e._rowIndex,e._columnIndex,n),a=_Expression.toNumber(o[1],e._rowIndex,e._columnIndex,n);if(0===a){switch(t){case"rounddown":i=r>=0?Math.floor(r):Math.ceil(r);break;case"roundup":i=r>=0?Math.ceil(r):Math.floor(r);break;case"round":i=Math.round(r);break;default:i=Math.floor(r)}s="n0"}else if(a>0&&wjcCore.isInt(a)){switch(l=Math.pow(10,a),t){case"rounddown":i=r>=0?Math.floor(r*l)/l:Math.ceil(r*l)/l;break;case"roundup":i=r>=0?Math.ceil(r*l)/l:Math.floor(r*l)/l;break;case"round":i=Math.round(r*l)/l}s="n"+a}if(null!=i)return{value:i,format:s};throw"Invalid precision!"},2,2)}),t.forEach(t=>{e._functionTable[t]=new _FunctionDefinition((o,n)=>"ln"===t?Math.log(_Expression.toNumber(o[0],e._rowIndex,e._columnIndex,n)):Math[t](_Expression.toNumber(o[0],e._rowIndex,e._columnIndex,n)),1,1)})}_registerLogicalFunction(){var e=this;e._functionTable.and=new _FunctionDefinition((t,o)=>{var n,i=!0;for(n=0;n<t.length&&(i=i&&_Expression.toBoolean(t[n],e._rowIndex,e._columnIndex,o));n++);return i},Number.MAX_VALUE,1),e._functionTable.or=new _FunctionDefinition((t,o)=>{var n,i=!1;for(n=0;n<t.length&&!(i=i||_Expression.toBoolean(t[n],e._rowIndex,e._columnIndex,o));n++);return i},Number.MAX_VALUE,1),e._functionTable.not=new _FunctionDefinition((t,o)=>!_Expression.toBoolean(t[0],e._rowIndex,e._columnIndex,o),1,1),e._functionTable.if=new _FunctionDefinition((t,o)=>3===t.length?_Expression.toBoolean(t[0],e._rowIndex,e._columnIndex,o)?t[1].evaluate(e._rowIndex,e._columnIndex,o):t[2].evaluate(e._rowIndex,e._columnIndex,o):!!_Expression.toBoolean(t[0],e._rowIndex,e._columnIndex,o)&&t[1].evaluate(e._rowIndex,e._columnIndex,o),3,2),e._functionTable.true=new _FunctionDefinition(()=>!0,0,0),e._functionTable.false=new _FunctionDefinition(()=>!1,0,0)}_registerTextFunction(){var e=this;e._functionTable.char=new _FunctionDefinition((t,o)=>{var n,i="";for(n=0;n<t.length;n++)i+=String.fromCharCode(_Expression.toNumber(t[n],e._rowIndex,e._columnIndex,o));return i},Number.MAX_VALUE,1),e._functionTable.code=new _FunctionDefinition((t,o)=>{var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.charCodeAt(0):-1},1,1),e._functionTable.concatenate=new _FunctionDefinition((t,o)=>{var n,i="";for(n=0;n<t.length;n++)i=i.concat(_Expression.toString(t[n],e._rowIndex,e._columnIndex,o));return i},Number.MAX_VALUE,1),e._functionTable.left=new _FunctionDefinition((t,o)=>{var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o));return n&&n.length>0?n.slice(0,i):null},2,2),e._functionTable.right=new _FunctionDefinition((t,o)=>{var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o));return n&&n.length>0?n.slice(-i):null},2,2),e._functionTable.find=new _FunctionDefinition((t,o)=>{var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),s=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o),l=null!=t[2]?wjcCore.asInt(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o)):0;return null!=s&&null!=i&&(n=!isNaN(l)&&l>0&&l<s.length?s.indexOf(i,l):s.indexOf(i))>-1?n+1:-1},3,2),e._functionTable.search=new _FunctionDefinition((t,o)=>{var n,i,s,l=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),r=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o),a=null!=t[2]?wjcCore.asInt(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o)):0;return null!=r&&null!=l&&(i=new RegExp(l,"i"),!isNaN(a)&&a>0&&a<r.length?(r=r.substring(a),n=a+1):n=1,(s=r.search(i))>-1)?s+n:-1},3,2),e._functionTable.len=new _FunctionDefinition((t,o)=>{var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n?n.length:-1},1,1),e._functionTable.mid=new _FunctionDefinition((t,o)=>{var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o)),s=Math.floor(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o));return n&&n.length>0&&i>0?n.substr(i-1,s):null},3,3),e._functionTable.lower=new _FunctionDefinition((t,o)=>{var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.toLowerCase():null},1,1),e._functionTable.upper=new _FunctionDefinition((t,o)=>{var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.toUpperCase():null},1,1),e._functionTable.proper=new _FunctionDefinition((t,o)=>{var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n[0].toUpperCase()+n.substring(1).toLowerCase():null},1,1),e._functionTable.trim=new _FunctionDefinition((t,o)=>{var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.trim():null},1,1),e._functionTable.replace=new _FunctionDefinition((t,o)=>{var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),i=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o)),s=Math.floor(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o)),l=_Expression.toString(t[3],e._rowIndex,e._columnIndex,o);return n&&n.length>0&&i>0?n.substring(0,i-1)+l+n.slice(i-1+s):null},4,4),e._functionTable.substitute=new _FunctionDefinition((t,o)=>{var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),s=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o),l=_Expression.toString(t[2],e._rowIndex,e._columnIndex,o),r=4===t.length?_Expression.toNumber(t[3],e._rowIndex,e._columnIndex,o):null,a=0;if(null!=r&&r<1||isNaN(r))throw"Invalid instance number.";return i&&i.length>0&&s&&s.length>0?(n=new RegExp(s,"g"),i.replace(n,e=>(a++,null!=r?(r=Math.floor(r),a===r?l:e):l))):null},4,3),e._functionTable.rept=new _FunctionDefinition((t,o)=>{var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),s=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o)),l="";if(i&&i.length>0&&s>0)for(n=0;n<s;n++)l=l.concat(i);return l},2,2),e._functionTable.text=new _FunctionDefinition((t,o)=>{var n,i=t[0].evaluate(e._rowIndex,e._columnIndex,o),s=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o);if(!wjcCore.isPrimitive(i)&&i&&(i=i.value),wjcCore.isDate(i))s=s.replace(/\[\$\-.+\]/g,"").replace(/(\\)(.)/g,"$2").replace(/H+/g,e=>e.toLowerCase()).replace(/m+/g,e=>e.toUpperCase()).replace(/S+/g,e=>e.toLowerCase()).replace(/AM\/PM/gi,"tt").replace(/A\/P/gi,"t").replace(/\.000/g,".fff").replace(/\.00/g,".ff").replace(/\.0/g,".f").replace(/\\[\-\s,]/g,e=>e.substring(1)).replace(/Y+/g,e=>e.toLowerCase()).replace(/D+/g,e=>e.toLowerCase()).replace(/M+:?|:?M+/gi,e=>e.indexOf(":")>-1?e.toLowerCase():e).replace(/g+e/gi,e=>e.substring(0,e.length-1)+"yy");else{if(!wjcCore.isNumber(i))return i;if((n=s.match(/^(\d+)(\.\d+)?\E\+(\d+)(\.\d+)?$/))&&5===n.length)return e._parseToScientificValue(i,n[1],n[2],n[3],n[4]);/M{1,4}|d{1,4}|y{1,4}/.test(s)?i=new Date(1900,0,i-1):s&&s.indexOf("#")>-1&&(s=wjcXlsx.Workbook.fromXlsxFormat(s)[0])}if(wjcCore.isDate(i))switch(s){case"d":return i.getDate();case"M":return i.getMonth()+1;case"y":s="yy";break;case"yyy":s="yyyy"}return wjcCore.Globalize.format(i,s)},2,2),e._functionTable.value=new _FunctionDefinition((t,o)=>{var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);if((i=i.replace(/(\,\d{3})/g,e=>e.substring(1))).length>0){if(i[0]===wjcCore.culture.Globalize.numberFormat.currency.symbol)return+(i=i.substring(1));if("%"===i[i.length-1])return+(i=i.substring(0,i.length-1))/100}return n=+i,isNaN(n)?_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o):n},1,1)}_registerDateFunction(){var e=this;e._functionTable.now=new _FunctionDefinition(()=>({value:new Date,format:"M/d/yyyy h:mm"}),0,0),e._functionTable.today=new _FunctionDefinition(()=>{var e=new Date;return{value:new Date(e.getFullYear(),e.getMonth(),e.getDate()),format:"M/d/yyyy"}},0,0),e._functionTable.year=new _FunctionDefinition((t,o)=>{var n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o);return!wjcCore.isPrimitive(n)&&n?n.value:wjcCore.isDate(n)?n.getFullYear():1900},1,1),e._functionTable.month=new _FunctionDefinition((t,o)=>{var n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o);return!wjcCore.isPrimitive(n)&&n?n.value:wjcCore.isDate(n)?n.getMonth()+1:1},1,1),e._functionTable.day=new _FunctionDefinition((t,o)=>{var n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o);return!wjcCore.isPrimitive(n)&&n?n.value:wjcCore.isDate(n)?n.getDate():0},1,1),e._functionTable.hour=new _FunctionDefinition((t,o)=>{var n=t[0].evaluate(e._rowIndex,e._columnIndex,o);if(wjcCore.isNumber(n)&&!isNaN(n))return Math.floor(24*(n-Math.floor(n)));if(wjcCore.isDate(n))return n.getHours();if(n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o),!wjcCore.isPrimitive(n)&&n&&(n=n.value),wjcCore.isDate(n))return n.getHours();throw"Invalid parameter."},1,1),e._functionTable.time=new _FunctionDefinition((t,o)=>{var n=t[0].evaluate(e._rowIndex,e._columnIndex,o),i=t[1].evaluate(e._rowIndex,e._columnIndex,o),s=t[2].evaluate(e._rowIndex,e._columnIndex,o);if(wjcCore.isNumber(n)&&wjcCore.isNumber(i)&&wjcCore.isNumber(s))return n%=24,i%=60,s%=60,{value:new Date(0,0,0,n,i,s),format:"h:mm tt"};throw"Invalid parameters."},3,3),e._functionTable.date=new _FunctionDefinition((t,o)=>{var n=t[0].evaluate(e._rowIndex,e._columnIndex,o),i=t[1].evaluate(e._rowIndex,e._columnIndex,o),s=t[2].evaluate(e._rowIndex,e._columnIndex,o);if(wjcCore.isNumber(n)&&wjcCore.isNumber(i)&&wjcCore.isNumber(s))return{value:new Date(n,i-1,s),format:"M/d/yyyy"};throw"Invalid parameters."},3,3),e._functionTable.datedif=new _FunctionDefinition((t,o)=>{var n,i,s,l,r,a=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o),h=_Expression.toDate(t[1],e._rowIndex,e._columnIndex,o),d=t[2].evaluate(e._rowIndex,e._columnIndex,o);if(!wjcCore.isPrimitive(a)&&a&&(a=a.value),!wjcCore.isPrimitive(h)&&h&&(h=h.value),wjcCore.isDate(a)&&wjcCore.isDate(h)&&wjcCore.isString(d)){if(n=a.getTime(),i=h.getTime(),n>i)throw"Start date is later than end date.";switch(s=h.getDate()-a.getDate(),l=h.getMonth()-a.getMonth(),r=h.getFullYear()-a.getFullYear(),d.toUpperCase()){case"Y":return l>0?r:l<0?r-1:s>=0?r:r-1;case"M":return s>=0?12*r+l:12*r+l-1;case"D":return(i-n)/864e5;case"YM":return(l=s>=0?12*r+l:12*r+l-1)%12;case"YD":return l>0?(new Date(a.getFullYear(),h.getMonth(),h.getDate()).getTime()-a.getTime())/864e5:l<0?(new Date(a.getFullYear()+1,h.getMonth(),h.getDate()).getTime()-a.getTime())/864e5:s>=0?s:(new Date(a.getFullYear()+1,h.getMonth(),h.getDate()).getTime()-a.getTime())/864e5;case"MD":return s>=0?s:s=new Date(h.getFullYear(),h.getMonth(),0).getDate()-new Date(h.getFullYear(),h.getMonth()-1,1).getDate()+1+s;default:throw"Invalid unit."}}throw"Invalid parameters."},3,3)}_registLookUpReferenceFunction(){var e=this;e._functionTable.column=new _FunctionDefinition((t,o,n,i)=>{var s;if(null==t)return i+1;if(s=t[0],(s=e._ensureNonFunctionExpression(s))instanceof _CellRangeExpression)return s.cells.col+1;throw"Invalid Cell Reference."},1,0),e._functionTable.columns=new _FunctionDefinition((t,o)=>{var n=t[0];if((n=e._ensureNonFunctionExpression(n))instanceof _CellRangeExpression)return n.cells.columnSpan;throw"Invalid Cell Reference."},1,1),e._functionTable.row=new _FunctionDefinition((t,o,n,i)=>{var s;if(null==t)return n+1;if(s=t[0],(s=e._ensureNonFunctionExpression(s))instanceof _CellRangeExpression)return s.cells.row+1;throw"Invalid Cell Reference."},1,0),e._functionTable.rows=new _FunctionDefinition((t,o)=>{var n=t[0];if((n=e._ensureNonFunctionExpression(n))instanceof _CellRangeExpression)return n.cells.rowSpan;throw"Invalid Cell Reference."},1,1),e._functionTable.choose=new _FunctionDefinition((t,o)=>{var n=_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o);if(isNaN(n))throw"Invalid index number.";if(n<1||n>=t.length)throw"The index number is out of the list range.";return t[n].evaluate(e._rowIndex,e._columnIndex,o)},255,2),e._functionTable.index=new _FunctionDefinition((t,o)=>{var n,i=t[0],s=_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o),l=null!=t[2]?_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o):0;if(isNaN(s)||s<0)throw"Invalid Row Number.";if(isNaN(l)||l<0)throw"Invalid Column Number.";if((i=e._ensureNonFunctionExpression(i))instanceof _CellRangeExpression){if(n=i.cells,s>n.rowSpan||l>n.columnSpan)throw"Index is out of the cell range.";if(s>0&&l>0)return e._owner.getCellValue(n.topRow+s-1,n.leftCol+l-1,!0,o);if(0===s&&0===l)return i;if(0===s)return new _CellRangeExpression(new wjcGrid.CellRange(n.topRow,n.leftCol+l-1,n.bottomRow,n.leftCol+l-1),i.sheetRef,e._owner);if(0===l)return new _CellRangeExpression(new wjcGrid.CellRange(n.topRow+s-1,n.leftCol,n.topRow+s-1,n.rightCol),i.sheetRef,e._owner)}throw"Invalid Cell Reference."},4,2),e._functionTable.hlookup=new _FunctionDefinition((t,o)=>e._handleHLookup(t,o),4,3)}_registFinacialFunction(){var e=this;e._functionTable.rate=new _FunctionDefinition((t,o)=>({value:e._calculateRate(t,o),format:"p2"}),6,3)}_addToken(e,t,o){var n=new _Token(e,t,o);this._tokenTable[e]=n}_parseExpression(){return this._getToken(),this._parseCompareOrConcat()}_parseCompareOrConcat(){for(var e,t,o=this._parseAddSub();this._token.tokenType===_TokenType.COMPARE||this._token.tokenType===_TokenType.CONCAT;)e=this._token,this._getToken(),t=this._parseAddSub(),o=new _BinaryExpression(e,o,t);return o}_parseAddSub(){for(var e,t,o=this._parseMulDiv();this._token.tokenType===_TokenType.ADDSUB;)e=this._token,this._getToken(),t=this._parseMulDiv(),o=new _BinaryExpression(e,o,t);return o}_parseMulDiv(){for(var e,t,o=this._parsePower();this._token.tokenType===_TokenType.MULDIV;)e=this._token,this._getToken(),t=this._parsePower(),o=new _BinaryExpression(e,o,t);return o}_parsePower(){for(var e,t,o=this._parseUnary();this._token.tokenType===_TokenType.POWER;)e=this._token,this._getToken(),t=this._parseUnary(),o=new _BinaryExpression(e,o,t);return o}_parseUnary(){var e,t;return this._token.tokenID===_TokenID.ADD||this._token.tokenID===_TokenID.SUB?(e=this._token,this._getToken(),t=this._parseAtom(),new _UnaryExpression(e,t)):this._parseAtom()}_parseAtom(){var e,t,o,n,i,s,l,r,a,h,d,c,_,u=null;switch(this._token.tokenType){case _TokenType.LITERAL:u=new _Expression(this._token);break;case _TokenType.IDENTIFIER:if(e=this._token.value.toString().toLowerCase(),t=this._functionTable[e]){if(o=this._getParameters(),this._token.tokenType===_TokenType.GROUP&&this._token.tokenID===_TokenID.CLOSE){if(n=o?o.length:0,-1!==t.paramMin&&n<t.paramMin)throw"Too few parameters.";if(-1!==t.paramMax&&n>t.paramMax)throw"Too many parameters.";"rand"===e&&(this._containsCellRef=!0),u=new _FunctionExpression(e,t,o);break}if("true"===e||"false"===e){u=new _FunctionExpression(e,t,o,!1);break}}if(2===(h=e.split("!")).length?(c=h[0],d=h[1]):d=h[0],s=this._getDefinedName(d,c||this._sheet.name.toLowerCase())){if(s.sheetName&&s.sheetName!==this._sheet.name&&s.sheetName.toLowerCase()!==c)throw"The defined name item works in "+s.sheetName+".  It does not work in current sheet.";a=this._pointer,r=this._expressLength,l=this._expression,this._pointer=0,u=this._checkCache(s.value),this._pointer=a,this._expressLength=r,this._expression=l;break}if(c="",null!=(_=this._owner._getTable(e))){if(""===(c=_.sheet.name))throw"The Table("+e+") is not located in any sheet.";if(this._getToken(),this._token.tokenType!==_TokenType.SQUAREBRACKETS||this._token.tokenID!==_TokenID.OPEN)throw"Invalid Table Reference.";this._tableRefStart=!0,u=this._getTableReference(_,c);break}if(i=this._getCellRange(e)){this._containsCellRef=!0,u=new _CellRangeExpression(i.cellRef.cellRange,i.sheetRef,this._owner,e.indexOf(":")>-1,i.cellRef.absRow,i.cellRef.absCol,i.cellRef.absRow2,i.cellRef.absCol2);break}o=this._getParameters(),u=this.onUnknownFunction(e,o);break;case _TokenType.GROUP:if(this._token.tokenID!==_TokenID.OPEN)throw"Expression expected.";if(this._getToken(),u=this._parseCompareOrConcat(),this._token.tokenID!==_TokenID.CLOSE)throw"Unbalanced parenthesis.";break;case _TokenType.SQUAREBRACKETS:if(this._token.tokenID!==_TokenID.OPEN)throw"Table References expected.";null!=(_=this._sheet.findTable(this._rowIndex,this._columnIndex))&&(c=_.sheet.name,this._tableRefStart=!0,u=this._getTableReference(_,c,!1))}if(null===u)throw"";return this._getToken(),u}_getToken(){for(var e,t,o,n,i,s="",l="",r=new RegExp("[　-〿぀-ゟ゠-ヿ＀-ﾟ一-龯㐀-䶿]");this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;if(this._pointer>=this._expressLength)this._token=new _Token(null,_TokenID.END,_TokenType.GROUP);else{if(t=this._expression[this._pointer],n=t>="a"&&t<="z"||t>="A"&&t<="Z"||r.test(t),i=t>="0"&&t<="9"||"."==t,!n&&!i){var a=this._tokenTable[t];if(a)return this._token=a,this._pointer++,void(this._pointer<this._expressLength&&(">"===t||"<"===t)&&(a=this._tokenTable[this._expression.substring(this._pointer-1,this._pointer+1)])&&(this._token=a,this._pointer++))}if(i)this._parseDigit();else if('"'!==t){if("'"!==t||(l=this._parseSheetRef()))if("#"!==t){if(!n&&"_"!==t&&this._idChars.indexOf(t)<0&&!l)throw"Identifier expected.";for(e=1;e+this._pointer<this._expressLength;e++)if(t=this._expression[this._pointer+e],n=t>="a"&&t<="z"||t>="A"&&t<="Z"||r.test(t),i=t>="0"&&t<="9","'"!==t||":"!==o){if(o=t,!n&&!i&&"_"!==t&&this._idChars.indexOf(t)<0)break}else s=l+this._expression.substring(this._pointer,this._pointer+e),this._pointer+=e,l=this._parseSheetRef(),e=0;s+=l+this._expression.substring(this._pointer,this._pointer+e),this._pointer+=e,this._token=new _Token(s,_TokenID.ATOM,_TokenType.IDENTIFIER)}else this._parseDate()}else this._parseString()}}_getTableToken(){for(var e,t,o,n="",i=!1;this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;for("@"===(t=this._expression[this._pointer])&&(n=t,this._pointer++),"["===(t=this._expression[this._pointer])&&(i=!0),e=1;e+this._pointer<this._expressLength;e++){if(t=this._expression[this._pointer+e],i&&","===t)throw"Invalid table reference.";if("]"===t)break}o=n+this._expression.substring(this._pointer+(i?1:0),this._pointer+e),this._pointer+=e+(i?1:0),this._token=new _Token(o,_TokenID.ATOM,_TokenType.IDENTIFIER)}_parseDigit(){var e,t,o=-1,n=!1,i=!1,s=0;for(e=0;e+this._pointer<this._expressLength;e++)if((t=this._expression[this._pointer+e])>="0"&&t<="9")s=10*s+(+t-0),o>-1&&(o*=10);else if("."===t&&o<0)o=1;else{if("E"!==t&&"e"!==t||n){if("%"===t){i=!0,e++;break}break}n=!0,"+"!==(t=this._expression[this._pointer+e+1])&&"-"!==t||e++}n?s=+this._expression.substring(this._pointer,this._pointer+e):(o>1&&(s/=o),i&&(s/=100)),this._token=new _Token(s,_TokenID.ATOM,_TokenType.LITERAL),this._pointer+=e}_parseString(){var e,t,o;for(e=1;e+this._pointer<this._expressLength;e++)if('"'===(t=this._expression[this._pointer+e])){if('"'!==(e+this._pointer<this._expressLength-1?this._expression[this._pointer+e+1]:" "))break;e++}if('"'!==t)throw"Can't find final quote.";if(o=this._expression.substring(this._pointer+1,this._pointer+e),this._pointer+=e+1,"!"===this._expression[this._pointer])throw"Illegal cross sheet reference.";this._token=new _Token(o.replace('""','"'),_TokenID.ATOM,_TokenType.LITERAL)}_parseDate(){var e,t,o;for(e=1;e+this._pointer<this._expressLength&&"#"!==(t=this._expression[this._pointer+e]);e++);if("#"!==t)throw'Can\'t find final date delimiter ("#").';o=this._expression.substring(this._pointer+1,this._pointer+e),this._pointer+=e+1,this._token=new _Token(Date.parse(o),_TokenID.ATOM,_TokenType.LITERAL)}_parseSheetRef(){var e,t,o;for(e=1;e+this._pointer<this._expressLength;e++)if("'"===(t=this._expression[this._pointer+e])){if("'"!==(e+this._pointer<this._expressLength-1?this._expression[this._pointer+e+1]:" "))break;e++}if("'"!==t)throw"Can't find final quote.";return o=this._expression.substring(this._pointer+1,this._pointer+e),this._pointer+=e+1,"!"===this._expression[this._pointer]?o.replace(/\'\'/g,"'"):""}_getCellRange(e){var t,o,n,i,s;if(e&&(t=e.split(":")).length>0&&t.length<3&&(o=this._parseCell(t[0]),(i=o.cellRef?o.cellRef.cellRange:null)&&2===t.length)){if(n=this._parseCell(t[1]),s=n.cellRef.cellRange,o.sheetRef&&!n.sheetRef&&(n.sheetRef=o.sheetRef),o.sheetRef!==n.sheetRef)throw"The cell reference must be in the same sheet!";s?(i.col2=s.col,i.row2=s.row):i=null}return null==i?null:{cellRef:{cellRange:i,absRow:o.cellRef.absRow,absCol:o.cellRef.absCol,absRow2:n?n.cellRef.absRow:null,absCol2:n?n.cellRef.absCol:null},sheetRef:o.sheetRef}}_parseCellRange(e){var t,o,n=-1,i=-1,s=!1,l=!1;for(t=0;t<e.length;t++)if("$"!==(o=e[t])||s){if(!(o>="a"&&o<="z"||o>="A"&&o<="Z"))break;n<0&&(n=0),n=26*n+(o.toUpperCase().charCodeAt(0)-"A".charCodeAt(0)+1)}else s=!0;for(;t<e.length;t++)if("$"!==(o=e[t])||l){if(!(o>="0"&&o<="9"))break;i<0&&(i=0),i=10*i+(+o-0)}else l=!0;return t<e.length&&(i=n=-1),-1===i||-1===n?null:{cellRange:new wjcGrid.CellRange(i-1,n-1),absRow:l,absCol:s}}_parseCell(e){var t,o,n,i;if((o=e.lastIndexOf("!"))>0&&o<e.length-1)i=e.substring(0,o),n=e.substring(o+1);else{if(!(o<=0))return null;n=e}return t=this._parseCellRange(n),{cellRef:t,sheetRef:i}}_getParameters(){var e,t,o=this._pointer,n=this._token;if(this._getToken(),this._token.tokenType!==_TokenType.SQUAREBRACKETS||this._token.tokenID!==_TokenID.OPEN){if(this._token.tokenID!==_TokenID.OPEN)return this._pointer=o,this._token=n,null;if(o=this._pointer,this._getToken(),this._token.tokenID===_TokenID.CLOSE)return null;for(this._pointer=o,e=new Array,t=this._parseExpression(),e.push(t);this._token.tokenID===_TokenID.COMMA;)t=this._parseExpression(),e.push(t);if(this._token.tokenID!==_TokenID.CLOSE)throw"Syntax error.";return e}}_getTableReference(e,t,o=!0){var n,i,s=[],l=this._getTableParameter(),r=!1;if(null==l)throw"Invalid table reference.";for(s.push(l);this._tableRefStart&&(this._token.tokenID===_TokenID.COMMA||":"===this._token.value);){if(":"===this._token.value&&(r=!0),null==(l=this._getTableParameter()))throw"Invalid table reference.";r?(s[s.length-1]+=":"+l,r=!1):s.push(l)}if(this._token.tokenType!==_TokenType.SQUAREBRACKETS||this._token.tokenID!==_TokenID.CLOSE)throw"Unbalanced square brackets.";return this._tableRefStart=!1,n=this._getTableRange(e,s),this._containsCellRef=!0,i=new _CellRangeExpression(n,t.toLowerCase(),this._owner),i._tableParams=s,o&&(i._tableName=e.name),i}_getTableParameter(){var e;for(this._pointer;this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;return"]"===this._expression[this._pointer]?(this._tableRefStart=!1,null):(this._getTableToken(),e=this._token.value,this._getToken(),e)}_getTableRange(e,t){for(var o,n,i,s,l,r,a=0;a<t.length;a++){if(n)throw"Invalid Table Refernce.";if(o=t[a].toLowerCase(),l=null,"#"===o[0]){switch(o){case"#all":l=e.getRange();break;case"#data":l=e.getRange(TableSection.Data);break;case"#headers":l=e.getRange(TableSection.Header);break;case"#totals":l=e.getRange(TableSection.Footer);break;case"#this row":if(s=e.getRange(),!(this._rowIndex>=s.topRow&&this._rowIndex<=s.bottomRow))throw"The row is out of the table ("+e.name+") range.";l=new wjcGrid.CellRange(this._rowIndex,s.leftCol,this._rowIndex,s.rightCol);break;default:throw"Invalid Table Refernce."}if(null==l)throw"Invalid Table Refernce.";null==i?i=l:(i.row=i.topRow<l.topRow?i.topRow:l.topRow,i.row2=i.bottomRow>l.bottomRow?i.bottomRow:l.bottomRow)}else{n=!0,r=o.split(":");for(var h=0;h<r.length;h++){if(r.length>2)throw"Invalid Table Column Refernce.";if("@"===(o=r[h])[0]){if(null==(l=e.getRange(TableSection.Data,o.substring(1))))throw"Invalid Table Refernce.";if(!(this._rowIndex>=l.topRow&&this._rowIndex<=l.bottomRow))throw"The row is out of the table ("+e.name+") range.";l.row=this._rowIndex,l.row2=this._rowIndex}else if(null==(l=e.getRange(TableSection.Data,o)))throw"Invalid Table Refernce.";0===h&&(null==i?i=l:i.col=l.col),i.col2=l.col,l=null}}}return i}_getAggregateResult(e,t,o){var n,i=this._getItemList(t,o);return n=wjcCore.getAggregate(e,i.items),i.isDate&&(n={value:n=new Date(n),format:i.format||"M/d/yyyy"}),n}_getFlexSheetAggregateResult(e,t,o){var n,i,s,l;switch(e){case _FlexSheetAggregate.Count:return n=this._getItemList(t,o,!0,!1),this._countNumberCells(n.items);case _FlexSheetAggregate.CountA:return(n=this._getItemList(t,o,!1,!1)).items.length;case _FlexSheetAggregate.ConutBlank:return n=this._getItemList(t,o,!1,!0),this._countBlankCells(n.items);case _FlexSheetAggregate.Rank:if(s=_Expression.toNumber(t[0],this._rowIndex,this._columnIndex,o),l=t[2]?_Expression.toNumber(t[2],this._rowIndex,this._columnIndex,o):0,isNaN(s))throw"Invalid number.";if(isNaN(l))throw"Invalid order.";if(t[1]=this._ensureNonFunctionExpression(t[1]),t[1]instanceof _CellRangeExpression)return n=this._getItemList([t[1]],o),this._getRankOfCellRange(s,n.items,l);throw"Invalid Cell Reference.";case _FlexSheetAggregate.CountIf:if(t[0]=this._ensureNonFunctionExpression(t[0]),t[0]instanceof _CellRangeExpression)return n=this._getItemList([t[0]],o,!1),this._countCellsByCriterias([n.items],[t[1]],o);throw"Invalid Cell Reference.";case _FlexSheetAggregate.CountIfs:return this._handleCountIfs(t,o);case _FlexSheetAggregate.SumIf:if(t[0]=this._ensureNonFunctionExpression(t[0]),t[0]instanceof _CellRangeExpression)return n=this._getItemList([t[0]],o,!1),t[2]=this._ensureNonFunctionExpression(t[2]),null!=t[2]&&t[2]instanceof _CellRangeExpression&&(i=this._getItemList([t[2]],o)),this._sumCellsByCriterias([n.items],[t[1]],i?i.items:null,o);throw"Invalid Cell Reference.";case _FlexSheetAggregate.SumIfs:return this._handleSumIfs(t,o);case _FlexSheetAggregate.Product:return n=this._getItemList(t,o),this._getProductOfNumbers(n.items)}throw"Invalid aggregate type."}_getItemList(e,t,o=!0,n=!1,i=!0,s){var l,r,a,h,d,c,_,u,g,w,m=new Array;for(r=0;r<e.length;r++)if(d=e[r],(d=this._ensureNonFunctionExpression(d))instanceof _CellRangeExpression){for(h=d.getValues(i,s,t),0===r&&((g=(u=d._getSheet()||t||this._sheet).getCellStyle(d.cells.topRow,d.cells.leftCol))&&(_=g.format),_||(w=u.grid.columns[d.cells.leftCol])&&(_=w.format)),a=0;a<h.length;a++)if(l=h[a],n||null!=l&&""!==l){if(wjcCore.isString(l)&&0===l.indexOf("Error: ")){m=[0];break}null==c&&(c=l instanceof Date),l=o&&!wjcCore.isBoolean(l)?+l:l,m.push(l)}}else{if(l=d instanceof _Expression?d.evaluate(this._rowIndex,this._columnIndex,t):d,wjcCore.isPrimitive(l)||(l=l.value),!n&&(null==l||""===l))continue;if(wjcCore.isString(l)&&0===l.indexOf("Error: ")){m=[0];break}null==c&&(c=l instanceof Date),l=o?+l:l,m.push(l)}return 0===m.length&&(c=!1),{isDate:c,items:m,format:_}}_countBlankCells(e){for(var t,o=0,n=0;o<e.length;o++)(null==(t=e[o])||wjcCore.isString(t)&&""===t||wjcCore.isNumber(t)&&isNaN(t))&&n++;return n}_countNumberCells(e){for(var t,o=0,n=0;o<e.length;o++)null!=(t=e[o])&&wjcCore.isNumber(t)&&!isNaN(t)&&n++;return n}_getRankOfCellRange(e,t,o=0){var n,i=0,s=0;for(o?t.sort((e,t)=>isNaN(e)||isNaN(t)?-1:e-t):t.sort((e,t)=>isNaN(e)||isNaN(t)?1:t-e);i<t.length;i++)if(n=t[i],!isNaN(n)&&(s++,e===n))return s;throw e+" is not in the cell range."}_handleCountIfs(e,t){var o,n,i,s,l=0,r=[],a=[];if(e.length%2!=0)throw"Invalid params.";for(;l<e.length/2;l++){if(n=e[2*l],!((n=this._ensureNonFunctionExpression(n))instanceof _CellRangeExpression))throw"Invalid Cell Reference.";if(0===l){if(!n.cells)throw"Invalid Cell Reference.";i=n.cells.rowSpan,s=n.cells.columnSpan}else{if(!n.cells)throw"Invalid Cell Reference.";if(n.cells.rowSpan!==i||n.cells.columnSpan!==s)throw"The row span and column span of each cell range has to be same with each other."}o=this._getItemList([n],t,!1),r[l]=o.items,a[l]=e[2*l+1]}return this._countCellsByCriterias(r,a,t)}_countCellsByCriterias(e,t,o,n){for(var i,s,l,r,a,h=0,d=0,c=0,_=e[0].length,u=[];d<t.length;d++)"*"===(a=_Expression.toString(t[d],this._rowIndex,this._columnIndex,o))?u.push(a):u.push(this._parseRightExpr(a));for(;h<_;h++){i=!1;e:for(d=0;d<e.length;d++)if(l=e[d],r=l[h],"string"==typeof(a=u[d])){if("*"!==a&&(null==r||""===r)){i=!1;break e}if(!(i="*"===a||this.evaluate(this._combineExpr(r,a),null,o,this._rowIndex,this._columnIndex)))break e}else if(!(i=i=a.reg.test(r.toString())===a.checkMathces))break e;i&&(n?null!=(s=n[h])&&wjcCore.isNumber(s)&&!isNaN(s)&&c++:c++)}return c}_handleSumIfs(e,t){var o,n,i,s,l,r,a=1,h=[],d=[];if(e.length%2!=1)throw"Invalid params.";if(i=e[0],!((i=this._ensureNonFunctionExpression(i))instanceof _CellRangeExpression))throw"Invalid Sum Cell Reference.";if(!i.cells)throw"Invalid Sum Cell Reference.";for(l=i.cells.rowSpan,r=i.cells.columnSpan,n=this._getItemList([i],t);a<(e.length+1)/2;a++){if(s=e[2*a-1],!((s=this._ensureNonFunctionExpression(s))instanceof _CellRangeExpression))throw"Invalid Criteria Cell Reference.";if(!s.cells)throw"Invalid Criteria Cell Reference.";if(s.cells.rowSpan!==l||s.cells.columnSpan!==r)throw"The row span and column span of each cell range has to be same with each other.";o=this._getItemList([s],t,!1),h[a-1]=o.items,d[a-1]=e[2*a]}return this._sumCellsByCriterias(h,d,n.items,t)}_sumCellsByCriterias(e,t,o,n){var i,s,l,r,a,h=0,d=0,c=0,_=e[0].length,u=[];for(null==o&&(o=e[0]);d<t.length;d++)"*"===(a=_Expression.toString(t[d],this._rowIndex,this._columnIndex,n))?u.push(a):u.push(this._parseRightExpr(a));for(;h<_;h++){s=!1,i=o[h];e:for(d=0;d<e.length;d++)if(l=e[d],r=l[h],"string"==typeof(a=u[d])){if("*"!==a&&(null==r||""===r)){s=!1;break e}if(!(s="*"===a||this.evaluate(this._combineExpr(r,a),null,n,this._rowIndex,this._columnIndex)))break e}else if(!(s=a.reg.test(r.toString())===a.checkMathces))break e;s&&wjcCore.isNumber(i)&&!isNaN(i)&&(c+=i)}return c}_getProductOfNumbers(e){var t,o=0,n=1,i=!1;if(e)for(;o<e.length;o++)t=e[o],wjcCore.isNumber(t)&&!isNaN(t)&&(n*=t,i=!0);return i?n:0}_handleSubtotal(e,t){var o,n,i,s,l=!0;if((o=_Expression.toNumber(e[0],this._rowIndex,this._columnIndex,t))>=1&&o<=11||o>=101&&o<=111){switch(o>=101&&o<=111&&(l=!1),o=wjcCore.asEnum(o,_SubtotalFunction),n=this._getItemList(e.slice(1),t,!0,!1,l),o){case _SubtotalFunction.Count:case _SubtotalFunction.CountWithoutHidden:return this._countNumberCells(n.items);case _SubtotalFunction.CountA:case _SubtotalFunction.CountAWithoutHidden:return n.items.length;case _SubtotalFunction.Product:case _SubtotalFunction.ProductWithoutHidden:return this._getProductOfNumbers(n.items);case _SubtotalFunction.Average:case _SubtotalFunction.AverageWithoutHidden:i=wjcCore.Aggregate.Avg;break;case _SubtotalFunction.Max:case _SubtotalFunction.MaxWithoutHidden:i=wjcCore.Aggregate.Max;break;case _SubtotalFunction.Min:case _SubtotalFunction.MinWithoutHidden:i=wjcCore.Aggregate.Min;break;case _SubtotalFunction.Std:case _SubtotalFunction.StdWithoutHidden:i=wjcCore.Aggregate.Std;break;case _SubtotalFunction.StdPop:case _SubtotalFunction.StdPopWithoutHidden:i=wjcCore.Aggregate.StdPop;break;case _SubtotalFunction.Sum:case _SubtotalFunction.SumWithoutHidden:i=wjcCore.Aggregate.Sum;break;case _SubtotalFunction.Var:case _SubtotalFunction.VarWithoutHidden:i=wjcCore.Aggregate.Var;break;case _SubtotalFunction.VarPop:case _SubtotalFunction.VarPopWithoutHidden:i=wjcCore.Aggregate.VarPop}return s=wjcCore.getAggregate(i,n.items),n.isDate&&(s=new Date(s)),s}throw"Invalid Subtotal function."}_handleDCount(e,t){var o,n,i,s=e[0],l=e[2];if(s=this._ensureNonFunctionExpression(s),l=this._ensureNonFunctionExpression(l),s instanceof _CellRangeExpression&&l instanceof _CellRangeExpression&&(o=e[1].evaluate(this._rowIndex,this._columnIndex,t),n=this._getColumnIndexByField(s,o),(i=this._getItemList([s],t,!0,!1,!0,n)).items&&i.items.length>1))return this._DCountWithCriterias(i.items.slice(1),s,l);throw"Invalid Count Cell Reference."}_DCountWithCriterias(e,t,o){var n,i,s,l,r,a,h,d,c,_,u,g=o.cells,w=0;if(n=this._getSheet(t.sheetRef),i=this._getSheet(o.sheetRef),g.rowSpan>1){for(s=g.topRow,l=g.bottomRow;l>g.topRow;l--){for(_=[],u=[],r=g.leftCol;r<=g.rightCol;r++)if(null!=(h=this._owner.getCellValue(l,r,!1,i))&&""!==h){if(u.push(new _Expression(h)),d=this._owner.getCellValue(s,r,!1,i),a=this._getColumnIndexByField(t,d),!(null!=(c=this._getItemList([t],n,!1,!1,!0,a)).items&&c.items.length>1))throw"Invalid Count Cell Reference.";_.push(c.items.slice(1))}w+=this._countCellsByCriterias(_,u,n,e)}return w}throw"Invalid Criteria Cell Reference."}_getColumnIndexByField(e,t){var o,n,i,s,l;if(o=e.cells,-1===(l=o.topRow))throw"Invalid Count Cell Reference.";if(wjcCore.isInt(t)&&!isNaN(t)){if(t>=1&&t<=o.columnSpan)return i=o.leftCol+t-1}else for(n=this._getSheet(e.sheetRef),i=o.leftCol;i<=o.rightCol;i++)if(s=this._owner.getCellValue(l,i,!1,n),t=wjcCore.isString(t)?t.toLowerCase():t,s=wjcCore.isString(s)?s.toLowerCase():s,t===s)return i;throw"Invalid field."}_getSumProduct(e,t){var o,n,i,s=0,l=this._getItemListForSumProduct(e,t);if(l.length>0){n=l[0].length,i=l.length;for(var r=0;r<n;r++){o=1;for(var a=0;a<i;a++)o*=l[a][r];s+=o}}return s}_getItemListForSumProduct(e,t){var o,n,i,s,l,r,a=[new Array];for(i=0;i<e.length;i++){if(r=e[i],o=new Array,(r=this._ensureNonFunctionExpression(r))instanceof _CellRangeExpression)for(l=r.getValues(!0,null,t),s=0;s<l.length;s++)n=l[s],o.push(+n);else n=r instanceof _Expression?r.evaluate(this._rowIndex,this._columnIndex,t):r,o.push(+n);if(i>0&&o.length!==a[0].length)throw"The cell ranges of the sumProduct formula must have the same dimensions.";a[i]=o}return a}_getSheet(e){var t,o=0;if(e)for(;o<this._owner.sheets.length&&(t=this._owner.sheets[o]).name!==e;o++);return t}_parseRightExpr(e){var t,o,n=!1;if(e.indexOf("?")>-1||e.indexOf("*")>-1){if(null==(t=e.match(/([\?\*]*)(\w+)([\?\*]*)(\w+)([\?\*]*)/))||6!==t.length)throw"Invalid Criteria.";return o=new RegExp("^"+(t[1].length>0?this._parseRegCriteria(t[1]):"")+t[2]+(t[3].length>0?this._parseRegCriteria(t[3]):"")+t[4]+(t[5].length>0?this._parseRegCriteria(t[5]):"")+"$","i"),/^[<>=]/.test(e)?"="===e.trim()[0]&&(n=!0):n=!0,{reg:o,checkMathces:n}}if(isNaN(+e))if(/^\w/.test(e))e='="'+e+'"';else{if(!/^[<>=]{1,2}\s*-?.+$/.test(e))throw"Invalid Criteria.";e=e.replace(/([<>=]{1,2})\s*(-?.+)/,'$1"$2"')}else e="="+ +e;return e}_combineExpr(e,t){return(wjcCore.isString(e)||wjcCore.isDate(e))&&(e='"'+e+'"'),(e="="+e)+t}_parseRegCriteria(e){for(var t=0,o=0,n="";t<e.length;t++)"*"===e[t]?(o>0&&(n+="\\w{"+o+"}",o=0),n+="\\w*"):"?"===e[t]&&o++;return o>0&&(n+="\\w{"+o+"}"),n}_calculateRate(e,t){var o,n,i,s,l,r,a,h,d,c,_=0,u=0;for(i=_Expression.toNumber(e[0],this._rowIndex,this._columnIndex,t),s=_Expression.toNumber(e[1],this._rowIndex,this._columnIndex,t),l=_Expression.toNumber(e[2],this._rowIndex,this._columnIndex,t),r=null!=e[3]?_Expression.toNumber(e[3],this._rowIndex,this._columnIndex,t):0,a=null!=e[4]?_Expression.toNumber(e[4],this._rowIndex,this._columnIndex,t):0,n=null!=e[5]?_Expression.toNumber(e[5],this._rowIndex,this._columnIndex,t):.1,Math.abs(n)<1e-7?l*(1+i*n)+s*(1+n*a)*i+r:l*(h=Math.exp(i*Math.log(1+n)))+s*(1/n+a)*(h-1)+r,d=l+s*i+r,c=l*h+s*(1/n+a)*(h-1)+r,o=n;Math.abs(d-c)>1e-7&&_<20;)n=(c*u-d*o)/(c-d),u=o,o=n,d=c,c=Math.abs(n)<1e-7?l*(1+i*n)+s*(1+n*a)*i+r:l*(h=Math.exp(i*Math.log(1+n)))+s*(1/n+a)*(h-1)+r,++_;if(Math.abs(d-c)>1e-7&&20===_)throw"It is not able to calculate the rate with current parameters.";return n}_handleHLookup(e,t){var o,n,i=e[0].evaluate(this._rowIndex,this._columnIndex,t),s=e[1],l=_Expression.toNumber(e[2],this._rowIndex,this._columnIndex,t),r=null==e[3]||_Expression.toBoolean(e[3],this._rowIndex,this._columnIndex,t);if(null==i||""==i)throw"Invalid lookup value.";if(isNaN(l)||l<0)throw"Invalid row index.";if((s=this._ensureNonFunctionExpression(s))instanceof _CellRangeExpression){if(o=s.cells,l>o.rowSpan)throw"Row index is out of the cell range.";if(r?-1===(n=this._exactMatch(i,o,t,!1))&&(n=this._approximateMatch(i,o,t)):n=this._exactMatch(i,o,t),-1===n)throw"Lookup Value is not found.";return this._owner.getCellValue(o.topRow+l-1,n,!1,t)}throw"Invalid Cell Reference."}_exactMatch(e,t,o,n=!0){var i,s,l,r,a=t.topRow;if(wjcCore.isString(e)&&(e=e.toLowerCase()),n&&wjcCore.isString(e)&&(e.indexOf("?")>-1||e.indexOf("*")>-1)){if(null==(l=e.match(/([\?\*]*)(\w+)([\?\*]*)(\w+)([\?\*]*)/))||6!==l.length)throw"Invalid lookup value.";r=new RegExp("^"+(l[1].length>0?this._parseRegCriteria(l[1]):"")+l[2]+(l[3].length>0?this._parseRegCriteria(l[3]):"")+l[4]+(l[5].length>0?this._parseRegCriteria(l[5]):"")+"$","i")}for(i=t.leftCol;i<=t.rightCol;i++)if(s=this._owner.getCellValue(a,i,!1,o),null!=r){if(r.test(s))return i}else if(wjcCore.isString(s)&&(s=s.toLowerCase()),e===s)return i;return-1}_approximateMatch(e,t,o){var n,i,s=t.topRow,l=[],r=0;for(wjcCore.isString(e)&&(e=e.toLowerCase()),i=t.leftCol;i<=t.rightCol;i++)n=this._owner.getCellValue(s,i,!1,o),n=isNaN(+n)?n:+n,l.push({value:n,index:i});for(l.sort((e,t)=>(wjcCore.isString(e.value)&&(e.value=e.value.toLowerCase()),wjcCore.isString(t.value)&&(t.value=t.value.toLowerCase()),e.value>t.value?-1:e.value===t.value?t.index-e.index:1));r<l.length;r++)if(n=l[r],wjcCore.isString(n.value)&&(n.value=n.value.toLowerCase()),e>n.value)return n.index;throw"Lookup Value is not found."}_parseToScientificValue(e,t,o,n,i){var s,l,r,a,h=0;if(Math.abs(e)>=1)for(l="+",s=Math.pow(10,t.length);e>s;)e/=s,h+=t.length;else for(l="-",s=Math.pow(10,t.length);e*s<s;)e*=s,h+=t.length;if(r=wjcCore.Globalize.format(e,"D"+t.length),o)for((r+=wjcCore.Globalize.format(e-Math.floor(e),t+o).substring(1)).indexOf(".")>-1?a=r.length-1-r.indexOf("."):(r+=".",a=0);a<o.length-1;)r+="0",a++;if(r+="E"+l+wjcCore.Globalize.format(h,"D"+n.length),i){r+=".";for(var d=1;d<i.length;d++)r+="0"}return r}_checkCache(e,t,o,n){null!=t&&(this._sheet=this._owner.sheets[t]),null!=o&&(this._rowIndex=o),null!=n&&(this._columnIndex=n);var i=this._expressionCache[e]||this._expressionCache[this._rowIndex+"_"+this._columnIndex+":"+e];if(i)return i;if(i=this._parse(e),this._token.tokenID!==_TokenID.END||this._token.tokenType!==_TokenType.GROUP)throw"Invalid Expression: "+e;return this._cacheSize>1e4&&this._clearExpressionCache(),this._expressionCache[(this._containsCellRef?this._rowIndex+"_"+this._columnIndex+":":"")+e]=i,this._cacheSize++,i}_ensureNonFunctionExpression(e,t){for(;e instanceof _FunctionExpression;)e=e.evaluate(this._rowIndex,this._columnIndex,t);return e}_getDefinedName(e,t){for(var o,n,i=0;i<this._owner.definedNames.length;i++)if((o=this._owner.definedNames[i]).name.toLowerCase()===e)if(o.sheetName){if(o.sheetName.toLowerCase()===t)return o}else n=o;return n}}exports._CalcEngine=_CalcEngine;class _Token{constructor(e,t,o){this._value=e,this._tokenID=t,this._tokenType=o}get value(){return this._value}get tokenID(){return this._tokenID}get tokenType(){return this._tokenType}}exports._Token=_Token;class _FunctionDefinition{constructor(e,t,o){this._paramMax=Number.MAX_VALUE,this._paramMin=Number.MIN_VALUE,this._func=e,wjcCore.isNumber(t)&&!isNaN(t)&&(this._paramMax=t),wjcCore.isNumber(o)&&!isNaN(o)&&(this._paramMin=o)}get paramMax(){return this._paramMax}get paramMin(){return this._paramMin}get func(){return this._func}}exports._FunctionDefinition=_FunctionDefinition;var _TokenType;!function(e){e[e.COMPARE=0]="COMPARE",e[e.ADDSUB=1]="ADDSUB",e[e.MULDIV=2]="MULDIV",e[e.POWER=3]="POWER",e[e.CONCAT=4]="CONCAT",e[e.GROUP=5]="GROUP",e[e.LITERAL=6]="LITERAL",e[e.IDENTIFIER=7]="IDENTIFIER",e[e.SQUAREBRACKETS=8]="SQUAREBRACKETS"}(_TokenType=exports._TokenType||(exports._TokenType={}));var _TokenID;!function(e){e[e.GT=0]="GT",e[e.LT=1]="LT",e[e.GE=2]="GE",e[e.LE=3]="LE",e[e.EQ=4]="EQ",e[e.NE=5]="NE",e[e.ADD=6]="ADD",e[e.SUB=7]="SUB",e[e.MUL=8]="MUL",e[e.DIV=9]="DIV",e[e.DIVINT=10]="DIVINT",e[e.MOD=11]="MOD",e[e.POWER=12]="POWER",e[e.CONCAT=13]="CONCAT",e[e.OPEN=14]="OPEN",e[e.CLOSE=15]="CLOSE",e[e.END=16]="END",e[e.COMMA=17]="COMMA",e[e.PERIOD=18]="PERIOD",e[e.ATOM=19]="ATOM"}(_TokenID=exports._TokenID||(exports._TokenID={}));var _FlexSheetAggregate;!function(e){e[e.Count=0]="Count",e[e.CountA=1]="CountA",e[e.ConutBlank=2]="ConutBlank",e[e.CountIf=3]="CountIf",e[e.CountIfs=4]="CountIfs",e[e.Rank=5]="Rank",e[e.SumIf=6]="SumIf",e[e.SumIfs=7]="SumIfs",e[e.Product=8]="Product"}(_FlexSheetAggregate||(_FlexSheetAggregate={}));var _SubtotalFunction;!function(e){e[e.Average=1]="Average",e[e.Count=2]="Count",e[e.CountA=3]="CountA",e[e.Max=4]="Max",e[e.Min=5]="Min",e[e.Product=6]="Product",e[e.Std=7]="Std",e[e.StdPop=8]="StdPop",e[e.Sum=9]="Sum",e[e.Var=10]="Var",e[e.VarPop=11]="VarPop",e[e.AverageWithoutHidden=101]="AverageWithoutHidden",e[e.CountWithoutHidden=102]="CountWithoutHidden",e[e.CountAWithoutHidden=103]="CountAWithoutHidden",e[e.MaxWithoutHidden=104]="MaxWithoutHidden",e[e.MinWithoutHidden=105]="MinWithoutHidden",e[e.ProductWithoutHidden=106]="ProductWithoutHidden",e[e.StdWithoutHidden=107]="StdWithoutHidden",e[e.StdPopWithoutHidden=108]="StdPopWithoutHidden",e[e.SumWithoutHidden=109]="SumWithoutHidden",e[e.VarWithoutHidden=110]="VarWithoutHidden",e[e.VarPopWithoutHidden=111]="VarPopWithoutHidden"}(_SubtotalFunction||(_SubtotalFunction={}));class _Expression{constructor(e){this._token=e?e instanceof _Token?e:new _Token(e,_TokenID.ATOM,_TokenType.LITERAL):new _Token(null,_TokenID.ATOM,_TokenType.IDENTIFIER)}get token(){return this._token}evaluate(e,t,o){if(this._token.tokenType!==_TokenType.LITERAL)throw"Bad expression.";return this._token.value}static toString(e,t,o,n){var i=e.evaluate(t,o,n);return wjcCore.isPrimitive(i)||(i=i.value),null!=i?i.toString():""}static toNumber(e,t,o,n){var i=e.evaluate(t,o,n),s=["January","February","March","April","May","June","July","August","September","October","November","December","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];if(wjcCore.isPrimitive(i)||(i=i.value),wjcCore.isNumber(i))return i;if(wjcCore.isBoolean(i))return i?1:0;if(wjcCore.isDate(i))return this._toOADate(i);if(wjcCore.isString(i)){if(i){if(isNaN(+i)){for(var l in s)if(i.indexOf(s[l])>-1)return this._toOADate(new Date(i));return+i}return+i}return 0}return wjcCore.changeType(i,wjcCore.DataType.Number,"")}static toBoolean(e,t,o,n){var i=e.evaluate(t,o,n);return wjcCore.isPrimitive(i)||(i=i.value),wjcCore.isBoolean(i)?i:wjcCore.isNumber(i)?0!==i:wjcCore.changeType(i,wjcCore.DataType.Boolean,"")}static toDate(e,t,o,n){var i=e.evaluate(t,o,n);return wjcCore.isPrimitive(i)||(i=i.value),wjcCore.isDate(i)?i:wjcCore.isNumber(i)?this._fromOADate(i):wjcCore.changeType(i,wjcCore.DataType.Date,"")}static _toOADate(e){var t=Date.UTC(1899,11,30);return(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())-t)/864e5}static _fromOADate(e){var t=Date.UTC(1899,11,30),o=new Date,n=e>=60?0:864e5;return new Date(864e5*e+t+6e4*o.getTimezoneOffset()+n)}_updateCellRangeExp(e,t,o,n,i){return!1}_moveCellRangeExp(e,t,o,n=!1,i=!1){return!1}_updateCellRangeExpForReorderingRows(e){return!1}_getStringExpression(){return null==this._token.value?"":wjcCore.isString(this._token.value)?'"'+this._token.value+'"':this._token.value.toString()}}exports._Expression=_Expression;class _UnaryExpression extends _Expression{constructor(e,t){super(e),this._expr=t}evaluate(e,t,o){if(this.token.tokenID===_TokenID.SUB)return null==this._evaluatedValue&&(this._evaluatedValue=-_Expression.toNumber(this._expr,e,t,o)),this._evaluatedValue;if(this.token.tokenID===_TokenID.ADD)return null==this._evaluatedValue&&(this._evaluatedValue=+_Expression.toNumber(this._expr,e,t,o)),this._evaluatedValue;throw"Bad expression."}_updateCellRangeExp(e,t,o,n,i){return this._expr._updateCellRangeExp(e,t,o,n,i)}_moveCellRangeExp(e,t,o,n=!1,i=!1){return this._expr._moveCellRangeExp(e,t,o,n,i)}_updateCellRangeExpForReorderingRows(e){return this._expr._updateCellRangeExpForReorderingRows(e)}_getStringExpression(){return this.token.tokenID===_TokenID.SUB?"-"+this._expr._getStringExpression():this.token.tokenID===_TokenID.ADD?"+"+this._expr._getStringExpression():""}}exports._UnaryExpression=_UnaryExpression;class _BinaryExpression extends _Expression{constructor(e,t,o){super(e),this._leftExpr=t,this._rightExpr=o}evaluate(e,t,o){var n,i,s,l,r,a,h,d=!1;if(null!=this._evaluatedValue)return this._evaluatedValue;if(n=_Expression.toString(this._leftExpr,e,t,o),i=_Expression.toString(this._rightExpr,e,t,o),this.token.tokenType===_TokenType.CONCAT)return this._evaluatedValue=n+i,this._evaluatedValue;if(s=this._leftExpr.evaluate(e,t,o),l=this._rightExpr.evaluate(e,t,o),d=this._isDateValue(s)||this._isDateValue(l),r=_Expression.toNumber(this._leftExpr,e,t,o),a=_Expression.toNumber(this._rightExpr,e,t,o),h=r-a,this.token.tokenType===_TokenType.COMPARE)switch(this.token.tokenID){case _TokenID.GT:return h>0;case _TokenID.LT:return h<0;case _TokenID.GE:return h>=0;case _TokenID.LE:return h<=0;case _TokenID.EQ:return isNaN(h)?(this._evaluatedValue=n.toLowerCase()===i.toLowerCase(),this._evaluatedValue):(this._evaluatedValue=0===h,this._evaluatedValue);case _TokenID.NE:return isNaN(h)?(this._evaluatedValue=n.toLowerCase()!==i.toLowerCase(),this._evaluatedValue):(this._evaluatedValue=0!==h,this._evaluatedValue)}switch(this.token.tokenID){case _TokenID.ADD:this._evaluatedValue=r+a;break;case _TokenID.SUB:this._evaluatedValue=r-a;break;case _TokenID.MUL:this._evaluatedValue=r*a;break;case _TokenID.DIV:this._evaluatedValue=r/a;break;case _TokenID.DIVINT:this._evaluatedValue=Math.floor(r/a);break;case _TokenID.MOD:this._evaluatedValue=Math.floor(r%a);break;case _TokenID.POWER:0===a&&(this._evaluatedValue=1),.5===a&&(this._evaluatedValue=Math.sqrt(r)),1===a&&(this._evaluatedValue=r),2===a&&(this._evaluatedValue=r*r),3===a&&(this._evaluatedValue=r*r*r),4===a&&(this._evaluatedValue=r*r*r*r),this._evaluatedValue=Math.pow(r,a);break;default:this._evaluatedValue=NaN}if(!isNaN(this._evaluatedValue))return d&&(this._evaluatedValue={value:_Expression._fromOADate(this._evaluatedValue),format:s.format||l.format}),this._evaluatedValue;throw"Bad expression."}_updateCellRangeExp(e,t,o,n,i){let s,l=!1;return s=this._leftExpr._updateCellRangeExp(e,t,o,n,i),l=l||s,s=this._rightExpr._updateCellRangeExp(e,t,o,n,i),l||s}_moveCellRangeExp(e,t,o,n=!1,i=!1){let s,l=!1;return s=this._leftExpr._moveCellRangeExp(e,t,o,n,i),l=l||s,s=this._rightExpr._moveCellRangeExp(e,t,o,n,i),l||s}_updateCellRangeExpForReorderingRows(e){let t,o=!1;return t=this._leftExpr._updateCellRangeExpForReorderingRows(e),o=o||t,t=this._rightExpr._updateCellRangeExpForReorderingRows(e),o||t}_getStringExpression(){let e;switch(this.token.tokenID){case _TokenID.GT:e=">";break;case _TokenID.LT:e="<";break;case _TokenID.GE:e=">=";break;case _TokenID.LE:e="<=";break;case _TokenID.EQ:e="=";break;case _TokenID.NE:e="<>";break;case _TokenID.ADD:e="+";break;case _TokenID.SUB:e="-";break;case _TokenID.MUL:e="*";break;case _TokenID.DIV:e="/";break;case _TokenID.DIVINT:e="\\";break;case _TokenID.POWER:e="^";break;default:return""}return this._leftExpr._getStringExpression()+e+this._rightExpr._getStringExpression()}_isDateValue(e){return wjcCore.isPrimitive(e)?wjcCore.isDate(e):wjcCore.isDate(e.value)}}exports._BinaryExpression=_BinaryExpression;class _CellRangeExpression extends _Expression{constructor(e,t,o,n=!0,i=!1,s=!1,l=!1,r=!1){super(),this._cells=new wjcGrid.CellRange(e.topRow,e.leftCol,e.bottomRow,e.rightCol),this._sheetRef=t,this._flex=o,this._evalutingRange={},this._isCellRange=n,this._absRow=i,this._absCol=s,this._absRow2=l,this._absCol2=r}evaluate(e,t,o){return null==this._evaluatedValue&&(this._evaluatedValue=this._getCellValue(this._cells,o,e,t)),this._evaluatedValue}getValues(e=!0,t,o){var n,i,t,s,l,r=[],a=0;if(s=null==t||isNaN(+t)?this._cells.leftCol:t,l=null==t||isNaN(+t)?this._cells.rightCol:t,!(o=this._getSheet()||o||this._flex.selectedSheet))return null;for(i=this._cells.topRow;i<=this._cells.bottomRow;i++){if(i>=o.grid.rows.length)throw"The cell reference is out of the cell range of the flexsheet.";if(e||!1!==o.grid.rows[i].isVisible)for(t=s;t<=l;t++){if(t>=o.grid.columns.length)throw"The cell reference is out of the cell range of the flexsheet.";(e||!1!==o.grid.columns[t].isVisible)&&(n=this._getCellValue(new wjcGrid.CellRange(i,t),o),wjcCore.isPrimitive(n)||(n=n.value),r[a]=n,a++)}}return r}getValuseWithTwoDimensions(e=!0,t){var o,n,i,s,l=[],r=0,a=0;if(!(t=this._getSheet()||t||this._flex.selectedSheet))return null;for(i=this._cells.topRow;i<=this._cells.bottomRow;i++){if(i>=t.grid.rows.length)throw"The cell reference is out of the cell range of the flexsheet.";if(e||!1!==t.grid.rows[i].isVisible){for(n=[],a=0,s=this._cells.leftCol;s<=this._cells.rightCol;s++){if(s>=t.grid.columns.length)throw"The cell reference is out of the cell range of the flexsheet.";e||!1!==t.grid.columns[s].isVisible?(o=this._getCellValue(new wjcGrid.CellRange(i,s),t),wjcCore.isPrimitive(o)||(o=o.value),n[a]=o,a++):a++}l[r]=n,r++}else r++}return l}get cells(){return this._cells}get sheetRef(){return this._sheetRef}_getCellValue(e,t,o,n){var t,i,s,l;if(!(t=this._getSheet()||t||this._flex.selectedSheet))return null;if(e.isSingleCell?(s=e.row,l=e.col):(null!=o&&o>=e.topRow&&o<=e.bottomRow&&e.col===e.col2&&(s=o,l=e.col),null!=n&&n>=e.leftCol&&n<=e.rightCol&&e.row===e.row2&&(s=e.row,l=n)),null==s||null==l)throw"Invalid Cell Reference.";if(i=t.name+":"+s+","+l+"-"+s+","+l,this._evalutingRange[i])throw"Circular Reference";try{if(this._flex)return this._evalutingRange[i]=!0,s<t.rowCount&&l<t.columnCount?this._flex.getCellValue(s,l,!1,t):0}finally{delete this._evalutingRange[i]}}_getSheet(){var e,t=0;if(!this._sheetRef)return null;for(;t<this._flex.sheets.length;t++)if((e=this._flex.sheets[t]).name.toLowerCase()===this._sheetRef)return e;throw"Invalid sheet reference"}_updateCellRangeExp(e,t,o,n,i){let s=this._cells,l=!1;if(this._tableParams&&this._tableParams.length>0)return!1;if(e===this._flex.selectedSheetIndex){if(this._sheetRef&&this._sheetRef.toLowerCase()!==this._flex.selectedSheet.name.toLowerCase())return!1}else if(!this._sheetRef||this._sheetRef.toLowerCase()!==this._flex.selectedSheet.name.toLowerCase())return!1;return i?n?s.topRow>=t?(s.row+=o,s.row2+=o,l=!0):s.topRow<t&&s.bottomRow>=t&&(s.row2+=o,l=!0):s.topRow>t?(s.row-=o,s.row2-=o,l=!0):s.isSingleCell?s.row>=t-o+1&&(s.row=t-o+1,s.row2=t-o+1,l=!0):s.topRow>=t-o+1?(s.row=t-o+1,s.row2-=o,l=!0):s.topRow<t-o+1&&s.bottomRow>=t-o+1&&(s.bottomRow>t?s.row2-=o:s.row2=t-o,l=!0):n?s.leftCol>=t?(s.col+=o,s.col2+=o,l=!0):s.leftCol<t&&s.rightCol>=t&&(s.col2+=o,l=!0):s.leftCol>t?(s.col-=o,s.col2-=o,l=!0):s.isSingleCell?s.col>=t-o+1&&(s.col=t-o+1,s.col2=t-o+1,l=!0):s.leftCol>=t-o+1?(s.col=t-o+1,s.col2-=o,l=!0):s.leftCol<t-o+1&&s.rightCol>=t-o+1&&(s.rightCol>t?s.col2-=o:s.col2=t-o,l=!0),l}_moveCellRangeExp(e,t,o,n=!1,i=!1){let s,l,r=this._cells,a=!1;return!(this._tableParams&&this._tableParams.length>0)&&(s=o.topRow-t.topRow,l=o.leftCol-t.leftCol,i?(0!==s&&(r.row+=i&&this._absRow?0:s,r.row2+=this._isCellRange?i&&this._absRow2?0:s:i&&this._absRow?0:s,a=!0),0!==l&&(r.col+=i&&this._absCol?0:l,r.col2+=this._isCellRange?i&&this._absCol2?0:l:i&&this._absCol?0:l,a=!0),a):(t.contains(r)?(0!==s&&(r.row+=s,r.row2+=s,a=!0),0!==l&&(r.col+=l,r.col2+=l,a=!0)):t.intersects(r)?(t.intersectsRow(r)&&0!==s&&(t.topRow<=r.topRow?s<0?(r.row+=s,a=!0):s>0&&n&&(t.topRow<r.topRow&&(r.row-=r.topRow-t.topRow),r.row2-=t.rowSpan,a=!0):t.bottomRow>=r.bottomRow?s>0?(r.row2+=s,a=!0):s<0&&n&&(t.bottomRow>r.bottomRow&&(r.row2+=t.bottomRow-r.bottomRow),r.row+=t.rowSpan,a=!0):n&&(s<0?r.row+=t.rowSpan:r.row2-=t.rowSpan,a=!0)),t.intersectsColumn(r)&&0!==l&&(t.leftCol<=r.leftCol?l<0?(r.col+=l,a=!0):l>0&&n&&(t.leftCol<r.leftCol&&(r.col-=r.leftCol-t.leftCol),r.col2-=t.columnSpan,a=!0):t.rightCol>=r.rightCol?l>0?(r.col2+=l,a=!0):l<0&&n&&(t.rightCol>r.rightCol&&(r.col2+=t.rightCol-r.rightCol),r.col+=t.columnSpan,a=!0):n&&(l<0?r.col+=t.columnSpan:r.col2-=t.columnSpan,a=!0))):n&&(r.topRow>t.bottomRow&&s>0&&(r.row-=t.rowSpan,r.row2-=t.rowSpan,a=!0),r.bottomRow<t.topRow&&s<0&&(r.row+=t.rowSpan,r.row2+=t.rowSpan,a=!0),r.leftCol>t.rightCol&&l>0&&(r.col-=t.columnSpan,r.col2-=t.columnSpan,a=!0),r.rightCol<t.leftCol&&l<0&&(r.col+=t.columnSpan,r.col2+=t.columnSpan,a=!0)),a))}_updateCellRangeExpForReorderingRows(e){let t,o=this._cells;return(t=this._cells.row+e)<0?t=0:t>=this._flex.rows.length&&(t=this._flex.rows.length-1),o.row=t,this._isCellRange&&((t=this._cells.row2+e)<0?t=0:t>=this._flex.rows.length&&(t=this._flex.rows.length-1),o.row2=t),!0}_getStringExpression(){return this._tableParams&&this._tableParams.length>0?this._getTableParamsStringExpression():(this._sheetRef?this._sheetRef+"!":"")+wjcXlsx.Workbook.xlsxAddress(this._cells.row,this._cells.col,this._absRow,this._absCol)+(this._isCellRange?":"+wjcXlsx.Workbook.xlsxAddress(this._cells.row2,this._cells.col2,this._absRow2,this._absCol2):"")}_getTableParamsStringExpression(){let e,t=0,o="",n=this._tableParams.length,i=!1;for(;t<n;t++)"#"===(e=this._tableParams[t])[0]?(o+="["+e+"]",t<n-1&&(o+=", ")):i?o+=": ["+e+"]":(o+="["+e+"]",i=!0);return n>1&&(o="["+o+"]"),this._tableName&&(o=this._tableName+o),o}}exports._CellRangeExpression=_CellRangeExpression;class _FunctionExpression extends _Expression{constructor(e,t,o,n=!0){super(),this._funcId=e,this._funcDefinition=t,this._params=o,this._needCacheEvaluatedVal=n}evaluate(e,t,o){return this._needCacheEvaluatedVal?(null==this._evaluatedValue&&(this._evaluatedValue=this._funcDefinition.func(this._params,o,e,t)),this._evaluatedValue):this._funcDefinition.func(this._params,o,e,t)}_updateCellRangeExp(e,t,o,n,i){let s,l,r,a=!1;if(this._params&&this._params.length>0)for(s=0;s<this._params.length;s++)r=(l=this._params[s])._updateCellRangeExp(e,t,o,n,i),a||(a=a||r);return a}_moveCellRangeExp(e,t,o,n=!1,i=!1){let s,l,r,a=!1;if(this._params&&this._params.length>0)for(s=0;s<this._params.length;s++)r=(l=this._params[s])._moveCellRangeExp(e,t,o,n,i),a||(a=a||r);return a}_updateCellRangeExpForReorderingRows(e){let t,o,n,i=!1;if(this._params&&this._params.length>0)for(t=0;t<this._params.length;t++)n=(o=this._params[t])._updateCellRangeExpForReorderingRows(e),i||(i=i||n);return i}_getStringExpression(){return this._funcId+this._parseParamsExpToString()}_parseParamsExpToString(){let e,t,o;if(this._params&&this._params.length>0){for(o="",e=0;e<this._params.length;e++)t=this._params[e],0===e&&(o+="("),o+=t._getStringExpression(),e<this._params.length-1?o+=", ":o+=")";return o}return"()"}}exports._FunctionExpression=_FunctionExpression;class _UndoAction{constructor(e){this._owner=e,this._sheetIndex=e.selectedSheetIndex}get sheetIndex(){return this._sheetIndex}undo(){throw"This abstract method must be overridden."}redo(){throw"This abstract method must be overridden."}saveNewState(){throw"This abstract method must be overridden."}}exports._UndoAction=_UndoAction;class _EditAction extends _UndoAction{constructor(e,t){super(e),this._isPaste=!1,this._selections=t?[t]:e.selectedSheet.selectionRanges.length>0?e.selectedSheet.selectionRanges.slice():[e.selection.clone()],this._mergeAction=new _CellMergeAction(e),this._cellStyleAction=new _CellStyleAction(e),this._saveValues(!0)}get isPaste(){return this._isPaste}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return!!this._saveValues(!1)&&(this._mergeAction.saveNewState(),this._cellStyleAction.saveNewState(),!this._checkActionState())}markIsPaste(){this._isPaste=!0}updateForPasting(e){var t=this._selections[this._selections.length-1],o=this._owner.getCellData(e.row,e.col,!!this._owner.columns[e.col].dataMap);t||(t=this._owner.selection,this._selections=[t]),o=null==o?"":o,this._oldValues["r"+e.row+"_c"+e.col]={row:e.row,col:e.col,value:o},t.row=Math.min(t.topRow,e.topRow),t.row2=Math.max(t.bottomRow,e.bottomRow),t.col=Math.min(t.leftCol,e.leftCol),t.col2=Math.max(t.rightCol,e.rightCol)}_storeDeletedTables(e){null==this._deletedTables&&(this._deletedTables=[]),this._deletedTables.push(e)}_checkActionState(){var e=this,t=!0;return Object.keys(e._oldValues).forEach(o=>{var n,i;t&&(n=e._oldValues[o],i=e._newValues[o],n&&i&&n.value!==i.value&&(t=!1))}),t}_saveValues(e){var t,o,n,i,s,l,r={};for(t=0;t<this._selections.length;t++)for(i=(o=this._selections[t]).topRow;i<=o.bottomRow;i++)for(s=o.leftCol;s<=o.rightCol;s++){if(!(n=this._owner.columns[s]))return!1;l=null==(l=this._owner.getCellData(i,s,!!n.dataMap))?"":l,r["r"+i+"_c"+s]={row:i,col:s,value:l}}return e?this._oldValues=r:this._newValues=r,!0}_handleUndoRedo(e){var t=this;t._owner._clearCalcEngine(),t._owner.selectedSheet.selectionRanges.clear(),t._owner.deferUpdate(()=>{var o,n,i,s,l=e?t._oldValues:t._newValues;if(t._deletedTables&&t._deletedTables.length>0)for(o=0;o<t._deletedTables.length;o++)n=t._deletedTables[o],e?t._owner.selectedSheet.tables.push(n):t._owner.selectedSheet.tables.remove(n);for(i=0;i<t._selections.length;i++)s=t._selections[i],t._owner.selectedSheet.selectionRanges.push(s);Object.keys(l).forEach(e=>{var o=l[e];t._owner.setCellData(o.row,o.col,o.value)}),e?(t._mergeAction.undo(),t._cellStyleAction.undo()):(t._mergeAction.redo(),t._cellStyleAction.redo()),t._owner.refresh(!1)})}}exports._EditAction=_EditAction;class _ColumnResizeAction extends _UndoAction{constructor(e,t,o){super(e),this._panel=t,this._colIndex=o,this._oldColWidth=t.columns[o].width}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return this._newColWidth=this._panel.columns[this._colIndex].width,this._oldColWidth!==this._newColWidth}_handleUndoRedo(e){var t=this._panel.columns[this._colIndex];t&&(t.width=e?this._oldColWidth:this._newColWidth)}}exports._ColumnResizeAction=_ColumnResizeAction;class _RowResizeAction extends _UndoAction{constructor(e,t,o){super(e),this._panel=t,this._rowIndex=o,this._oldRowHeight=t.rows[o].height}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return this._newRowHeight=this._panel.rows[this._rowIndex].height,this._oldRowHeight!==this._newRowHeight}_handleUndoRedo(e){var t=this._panel.rows[this._rowIndex];t&&(t.height=e?this._oldRowHeight:this._newRowHeight)}}exports._RowResizeAction=_RowResizeAction;class _ColumnsChangedAction extends _UndoAction{constructor(e,t,o,n){super(e),this._columnIndex=t,this._count=o,this._isAdding=n,this._saveValues(!0)}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return this._saveValues(!1),!0}_saveValues(e){var t,o,n,i,s=[],l=[];if(null==this._isAdding)for(t=0;t<this._owner.columns.length;t++)s.push(this._owner.columns[t]);else if(e&&!this._isAdding||!e&&this._isAdding)for(t=this._columnIndex;t<this._columnIndex+this._count&&t<this._owner.columns.length;t++)s.push(this._owner.columns[t]);if(this._owner.selectedSheet.tables&&this._owner.selectedSheet.tables.length>0)for(o=0;o<this._owner.selectedSheet.tables.length;o++)(n=this._owner.selectedSheet.tables[o])&&n.sheet.name===this._owner.selectedSheet.name&&l.push({name:n.name,range:n.getRange(),columns:n.getColumns()});i={columns:s,sortList:this._owner.sortManager._committedList.slice(),styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,mergedCells:this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,tableRanges:l,selection:this._owner.selection},e?this._oldValue=i:this._newValue=i}_handleUndoRedo(e){var t,o,n,i,s,l,r,a,h,d,c,_,u=this,g=e?u._oldValue:u._newValue;u._owner.selectedSheet&&(u._owner.deferUpdate(()=>{if(u._owner._isUndoing=!0,u._owner._clearCalcEngine(),u._owner.finishEditing(),null==u._isAdding&&(u._owner.columns.clear(),u._columnIndex=0),u._owner.selectedSheet._styledCells=null,u._owner.selectedSheet._mergedRanges.length=0,u._owner.columns.beginUpdate(),g.columns&&g.columns.length>0)for(t=0;t<g.columns.length;t++)(o=g.columns[t])&&o.isVisible&&u._owner.columns.insert(u._columnIndex+t,g.columns[t]);else for(t=u._columnIndex+u._count-1;t>=u._columnIndex;t--)(o=u._owner.columns[t])&&o.isVisible&&u._owner.columns.removeAt(t);for(u._owner.columns.endUpdate(),u._owner.selectedSheet._styledCells=u._owner._cloneObject(g.styledCells),_=0;_<g.mergedCells.length;_++)u._owner.selectedSheet._mergedRanges[_]=g.mergedCells[_];for(i=0;i<g.tableRanges.length;i++)s=g.tableRanges[i],(l=u._owner._getTable(s.name))&&l._setTableRange(s.range,s.columns);if(u._affectedFormulas&&(a=e?u._affectedFormulas.oldFormulas:u._affectedFormulas.newFormulas),a&&a.length>0)for(n=0;n<a.length;n++)null!=(r=a[n]).point?r.sheet.name===u._owner.selectedSheet.name?u._owner.setCellData(r.point.x,r.point.y,r.formula):r.sheet.grid.setCellData(r.point.x,r.point.y,r.formula):r.row._ubv[r.column._hash]=r.formula;if(u._deletedTables&&u._deletedTables.length>0)for(i=0;i<u._deletedTables.length;i++)l=u._deletedTables[i],e?u._owner.selectedSheet.tables.push(l):u._owner.selectedSheet.tables.remove(l);if(u._affectedDefinedNameVals&&(h=e?u._affectedDefinedNameVals.oldDefinedNameVals:u._affectedDefinedNameVals.newDefinedNameVals),h&&h.length>0)for(n=0;n<h.length;n++)d=h[n],(c=u._owner._getDefinedNameIndexByName(d.name))>-1&&(u._owner.definedNames[c].value=d.value);u._owner.selectedSheet.grid.wj_sheetInfo.styledCells=u._owner.selectedSheet._styledCells,u._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=u._owner.selectedSheet._mergedRanges,u._owner.sortManager.sortDescriptions.sourceCollection=g.sortList.slice(),u._owner.sortManager.commitSort(!1),u._owner.selection=g.selection,u._owner._isUndoing=!1}),u._owner._copyColumnsToSelectedSheet())}}exports._ColumnsChangedAction=_ColumnsChangedAction;class _RowsChangedAction extends _UndoAction{constructor(e,t,o,n){super(e),this._rowIndex=t,this._count=o,this._isAdding=n,this._saveValues(!0)}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return this._saveValues(!1),!0}_saveValues(e){var t,o,n,i,s,l,r=[],a=[],h=[];if(null==this._isAdding)if(this._owner.itemsSource)for(s=this._owner.itemsSource instanceof wjcCore.CollectionView?this._owner.itemsSource.sourceCollection.slice():this._owner.itemsSource.slice(),o=0;o<this._owner.columns.length;o++)a.push(this._owner.columns[o]);else for(t=0;t<this._owner.rows.length;t++)r.push(this._owner.rows[t]);else if(e&&!this._isAdding||!e&&this._isAdding)for(t=this._rowIndex;t<this._rowIndex+this._count&&t<this._owner.rows.length;t++)r.push(this._owner.rows[t]);if(this._owner.selectedSheet.tables&&this._owner.selectedSheet.tables.length>0)for(n=0;n<this._owner.selectedSheet.tables.length;n++)(i=this._owner.selectedSheet.tables[n])&&i.sheet.name===this._owner.selectedSheet.name&&h.push({name:i.name,range:i.getRange(),setting:{showHeaderRow:i.showHeaderRow,showTotalRow:i.showTotalRow}});l={rows:r,columns:a,itemsSource:s,styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,mergedCells:this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,tableSettings:h,selection:this._owner.selection},e?this._oldValue=l:this._newValue=l}_handleUndoRedo(e){var t,o,n,i,s,l,r,a,h,d,c,_,u,g,w=this,m=!!w._owner.itemsSource,C=e?w._oldValue:w._newValue;w._owner.selectedSheet&&(w._owner.deferUpdate(()=>{if(w._owner._isUndoing=!0,w._owner._clearCalcEngine(),w._owner.finishEditing(),null==w._isAdding&&(w._owner.itemsSource&&w._owner.columns.clear(),w._owner.rows.clear(),w._rowIndex=0),w._owner.selectedSheet._styledCells=null,w._owner.selectedSheet._mergedRanges.length=0,null==this._isAdding&&m){for(w._owner.collectionView.beginUpdate(),w._owner.autoGenerateColumns=!1,w._owner.itemsSource instanceof wjcCore.CollectionView?(g=[0,w._owner.itemsSource.sourceCollection.length].concat(C.itemsSource),Array.prototype.splice.apply(w._owner.itemsSource.sourceCollection,g)):w._owner.itemsSource=C.itemsSource.slice(),w._owner.columns.beginUpdate(),n=0;n<C.columns.length;n++)w._owner.columns.push(C.columns[n]);w._owner.columns.endUpdate(),w._owner.collectionView.endUpdate()}else{if(m?w._owner.collectionView.beginUpdate():w._owner.rows.beginUpdate(),C.rows&&C.rows.length>0)for(t=0;t<C.rows.length;t++)o=C.rows[t],m&&o.dataItem?(w._owner.itemsSource instanceof wjcCore.CollectionView?w._owner.itemsSource.sourceCollection.splice(w._rowIndex+t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),0,o.dataItem):w._owner.itemsSource.splice(w._rowIndex+t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),0,o.dataItem),w._owner.selectedSheet._orgItemsSource&&w._owner.selectedSheet._orgItemsSource.splice(w._rowIndex+t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),0,o.dataItem)):w._owner.rows.insert(w._rowIndex+t,o);else for(t=w._rowIndex+w._count-1;t>=w._rowIndex;t--)(o=w._owner.rows[t])&&o.isVisible&&(m&&o.dataItem?(w._owner.itemsSource instanceof wjcCore.CollectionView?w._owner.itemsSource.sourceCollection.splice(t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),1):w._owner.itemsSource.splice(t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),1),w._owner.selectedSheet._orgItemsSource&&w._owner.selectedSheet._orgItemsSource.splice(t-(w._owner.allowAddNew&&w._owner.newRowAtTop?2:1),1)):w._owner.rows.removeAt(t));m?w._owner.collectionView.endUpdate():w._owner.rows.endUpdate()}for(w._owner.selectedSheet._styledCells=w._owner._cloneObject(C.styledCells),u=0;u<C.mergedCells.length;u++)w._owner.selectedSheet._mergedRanges[u]=C.mergedCells[u];for(s=0;s<C.tableSettings.length;s++)l=C.tableSettings[s],(r=w._owner._getTable(l.name))&&(r._showHeaderRow=l.setting.showHeaderRow,r._showTotalRow=l.setting.showTotalRow,r._setTableRange(l.range));if(w._affectedFormulas&&(h=e?w._affectedFormulas.oldFormulas:w._affectedFormulas.newFormulas),h&&h.length>0)for(i=0;i<h.length;i++)null!=(a=h[i]).point?a.sheet.name===w._owner.selectedSheet.name?w._owner.setCellData(a.point.x,a.point.y,a.formula):a.sheet.grid.setCellData(a.point.x,a.point.y,a.formula):a.row._ubv[a.column._hash]=a.formula;if(w._deletedTables&&w._deletedTables.length>0)for(s=0;s<w._deletedTables.length;s++)r=w._deletedTables[s],e?w._owner.selectedSheet.tables.push(r):w._owner.selectedSheet.tables.remove(r);if(w._affectedDefinedNameVals&&(d=e?w._affectedDefinedNameVals.oldDefinedNameVals:w._affectedDefinedNameVals.newDefinedNameVals),d&&d.length>0)for(i=0;i<d.length;i++)c=d[i],(_=w._owner._getDefinedNameIndexByName(c.name))>-1&&(w._owner.definedNames[_].value=c.value);w._owner.selectedSheet.grid.wj_sheetInfo.styledCells=w._owner.selectedSheet._styledCells,w._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=w._owner.selectedSheet._mergedRanges,w._owner.selection=C.selection,w._owner._isUndoing=!1}),w._owner._copyRowsToSelectedSheet())}}exports._RowsChangedAction=_RowsChangedAction;class _CellStyleAction extends _UndoAction{constructor(e,t){super(e),this._oldStyledCells=t?e._cloneObject(t):e.selectedSheet?e._cloneObject(e.selectedSheet._styledCells):null}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return this._newStyledCells=this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,!0}_handleUndoRedo(e){var t;this._owner.selectedSheet&&(t=e?this._oldStyledCells:this._newStyledCells,this._owner.selectedSheet._styledCells=this._owner._cloneObject(t),this._owner.selectedSheet.grid.wj_sheetInfo.styledCells=this._owner.selectedSheet._styledCells,this._owner.refresh(!1))}}exports._CellStyleAction=_CellStyleAction;class _CellMergeAction extends _UndoAction{constructor(e){super(e),this._oldMergedCells=e.selectedSheet?e.selectedSheet._cloneMergedCells():null}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return this._newMergedCells=this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,!0}_handleUndoRedo(e){var t,o;if(this._owner.selectedSheet){if(t=e?this._oldMergedCells:this._newMergedCells,this._owner._clearCalcEngine(),t)for(this._owner.selectedSheet._mergedRanges.length=0,o=0;o<t.length;o++)this._owner.selectedSheet._mergedRanges[o]=t[o];this._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=this._owner.selectedSheet._mergedRanges,this._owner.refresh(!0)}}}exports._CellMergeAction=_CellMergeAction;class _SortColumnAction extends _UndoAction{constructor(e){super(e),this._saveValues(!0)}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return this._saveValues(!1),!0}_saveValues(e){var t,o,n,i,s,l=[];for(o=0;o<this._owner.columns.length;o++)l.push(this._owner.columns[o]);if(this._owner.itemsSource)i=this._owner.collectionView._view.slice();else for(n=[],t=0;t<this._owner.rows.length;t++)n.push(this._owner.rows[t]);s={sortList:this._owner.sortManager._committedList.slice(),rows:n,columns:l,selection:this._owner.selection.clone(),items:i,formulas:this._owner._scanFormulas()},e?this._oldValue=s:this._newValue=s}_handleUndoRedo(e){var t,o,n,i,s,l,r=this,a=e?r._oldValue:r._newValue,h=!!r._owner.itemsSource,d=this._owner.itemsSource instanceof wjcCore.CollectionView;r._owner.selectedSheet&&(r._owner._isUndoing=!0,r._owner.deferUpdate(()=>{if(r._owner._clearCalcEngine(),r._owner.sortManager.sortDescriptions.sourceCollection=a.sortList.slice(),r._owner.sortManager._committedList=a.sortList.slice(),h)r._owner.autoGenerateColumns=!1,d?r._owner.itemsSource.sourceCollection=a.items:(l=r._owner.selectedSheet._filterDefinition,r._owner.itemsSource=a.items);else{for(r._owner.rows.clear(),r._owner.selectedSheet.grid.rows.clear(),t=0;t<a.rows.length;t++)n=a.rows[t],r._owner.rows.push(n);r._owner._resetFormulas(a.formulas)}for(r._owner.columns.clear(),h&&!d&&(s=this._owner.rows[0]instanceof wjcGrid._NewRowTemplate?this._owner.rows[1]:this._owner.rows[0]),o=0;o<a.columns.length;o++)i=a.columns[o],r._owner.columns.push(i),s&&(s._ubv||(s._ubv={}),s._ubv[i._hash]=i.header);h&&(d||(r._owner.filter.filterDefinition=l),r._owner.selection=a.selection),r._owner._isUndoing=!1}))}}exports._SortColumnAction=_SortColumnAction;class _MoveCellsAction extends _UndoAction{constructor(e,t,o,n){super(e),e.selectedSheet&&(0===t.topRow&&t.bottomRow===e.rows.length-1?this._isDraggingColumns=!0:this._isDraggingColumns=!1,this._isCopyCells=n,this._dragRange=t,this._dropRange=o,this._saveValues(!0))}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return!!this._owner.selectedSheet&&(!!this._dropRange&&(this._saveValues(!1),!0))}_saveValues(e){var t,o,n,i,s,l,r,a,h,d,c,_;for(c=[],_={},t=this._dropRange.topRow;t<=this._dropRange.bottomRow;t++)for(o=this._dropRange.leftCol;o<=this._dropRange.rightCol;o++)this._isDraggingColumns&&(_[o]||(_[o]={dataType:this._owner.columns[o].dataType,align:this._owner.columns[o].align,format:this._owner.columns[o].format})),n=t*this._owner.columns.length+o,s=this._owner.selectedSheet._styledCells[n]?this._owner._cloneObject(this._owner.selectedSheet._styledCells[n]):null,i=this._owner.getCellData(t,o,!1),c.push({rowIndex:t,columnIndex:o,cellContent:i,cellStyle:s});if(e?(this._oldDroppingCells=c,this._oldDroppingColumnSetting=_):(this._newDroppingCells=c,this._newDroppingColumnSetting=_),this._isCopyCells){if(this._isDraggingColumns)if(e)for(t=this._dragRange.topRow;t<=this._dragRange.bottomRow;t++)for(o=this._dragRange.leftCol;o<=this._dragRange.rightCol;o++)(a=this._owner.selectedSheet.findTable(t,o))&&(h=a.getRange(),d=a.getColumns(),a.showHeaderRow&&t===h.topRow&&(this._draggingTableColumns||(this._draggingTableColumns=[]),this._draggingTableColumns.push({rowIndex:t,columnIndex:o,cellContent:d[o-h.leftCol].name})));else if(this._draggingTableColumns&&this._draggingTableColumns.length>0&&this._draggingTableColumns&&this._draggingTableColumns.length>0)for(l=0;l<this._draggingTableColumns.length;l++)r=this._draggingTableColumns[l],(a=this._owner.selectedSheet.findTable(r.rowIndex,r.columnIndex))&&(h=a.getRange(),d=a.getColumns(),a.showHeaderRow&&r.rowIndex===h.topRow&&(r.updatedCellContent=d[r.columnIndex-h.leftCol].name))}else if(e)for(this._draggingCells=[],this._draggingColumnSetting={},t=this._dragRange.topRow;t<=this._dragRange.bottomRow;t++)for(o=this._dragRange.leftCol;o<=this._dragRange.rightCol;o++)this._isDraggingColumns&&(this._draggingColumnSetting[o]||(this._draggingColumnSetting[o]={dataType:this._owner.columns[o].dataType,align:this._owner.columns[o].align,format:this._owner.columns[o].format})),n=t*this._owner.columns.length+o,s=this._owner.selectedSheet._styledCells[n]?this._owner._cloneObject(this._owner.selectedSheet._styledCells[n]):null,i=this._owner.getCellData(t,o,!1),this._draggingCells.push({rowIndex:t,columnIndex:o,cellContent:i,cellStyle:s});else if(this._isDraggingColumns&&this._draggingCells&&this._draggingCells.length>0)for(l=0;l<this._draggingCells.length;l++)r=this._draggingCells[l],(a=this._owner.selectedSheet.findTable(r.rowIndex,r.columnIndex))&&(h=a.getRange(),d=a.getColumns(),a.showHeaderRow&&r.rowIndex===h.topRow&&(r.updatedCellContent=d[r.columnIndex-h.leftCol].name))}_handleUndoRedo(e){var t,o,n,i,s,l,r,a,h,d,c=this,_=e?c._oldDroppingCells:c._newDroppingCells,u=e?c._oldDroppingColumnSetting:c._newDroppingColumnSetting;c._owner.selectedSheet&&(c._owner._clearCalcEngine(),c._owner.deferUpdate(()=>{var g,w,m;if(c._affectedFormulas&&(l=e?c._affectedFormulas.oldFormulas:c._affectedFormulas.newFormulas),l&&l.length>0)for(t=0;t<l.length;t++)(r=l[t]).sheet.name===c._owner.selectedSheet.name?c._owner.setCellData(r.point.x,r.point.y,r.formula):r.sheet.grid.setCellData(r.point.x,r.point.y,r.formula);if(c._affectedDefinedNameVals&&(a=e?c._affectedDefinedNameVals.oldDefinedNameVals:c._affectedDefinedNameVals.newDefinedNameVals),a&&a.length>0)for(t=0;t<a.length;t++)h=a[t],(d=c._owner._getDefinedNameIndexByName(h.name))>-1&&(c._owner.definedNames[d].value=h.value);for(t=0;t<_.length;t++)o=_[t],c._owner.setCellData(o.rowIndex,o.columnIndex,o.cellContent),(g=c._owner.selectedSheet.findTable(o.rowIndex,o.columnIndex))&&(w=g.getRange(),m=g.getColumns(),g.showHeaderRow&&o.rowIndex===w.topRow&&(m[o.columnIndex-w.leftCol].name=o.cellContent)),n=o.rowIndex*c._owner.columns.length+o.columnIndex,o.cellStyle?c._owner.selectedSheet._styledCells[n]=o.cellStyle:delete c._owner.selectedSheet._styledCells[n];if(c._isDraggingColumns&&u&&Object.keys(u).forEach(e=>{c._owner.columns[+e].dataType=u[+e].dataType?u[+e].dataType:wjcCore.DataType.Object,c._owner.columns[+e].align=u[+e].align,c._owner.columns[+e].format=u[+e].format}),c._isCopyCells){if(c._draggingTableColumns&&c._draggingTableColumns.length>0)for(t=0;t<c._draggingTableColumns.length;t++)o=c._draggingTableColumns[t],(g=c._owner.selectedSheet.findTable(o.rowIndex,o.columnIndex))&&(w=g.getRange(),m=g.getColumns(),g.showHeaderRow&&o.rowIndex===w.topRow&&(c._owner.setCellData(o.rowIndex,o.columnIndex,e?o.cellContent:o.updatedCellContent),m[o.columnIndex-w.leftCol].name=e?o.cellContent:o.updatedCellContent))}else{for(t=0;t<c._draggingCells.length;t++)o=c._draggingCells[t],(g=c._owner.selectedSheet.findTable(o.rowIndex,o.columnIndex))?(w=g.getRange(),m=g.getColumns(),g.showHeaderRow&&o.rowIndex===w.topRow?(c._owner.setCellData(o.rowIndex,o.columnIndex,e?o.cellContent:o.updatedCellContent),m[o.columnIndex-w.leftCol].name=e?o.cellContent:o.updatedCellContent):c._owner.setCellData(o.rowIndex,o.columnIndex,e?o.cellContent:null)):c._owner.setCellData(o.rowIndex,o.columnIndex,e?o.cellContent:null),n=o.rowIndex*c._owner.columns.length+o.columnIndex,e?o.cellStyle&&(c._owner.selectedSheet._styledCells[n]=o.cellStyle):c._owner.selectedSheet._styledCells[n]&&delete c._owner.selectedSheet._styledCells[n];if(c._isDraggingColumns&&c._draggingColumnSetting&&Object.keys(c._draggingColumnSetting).forEach(t=>{c._owner.columns[+t].dataType=e&&c._draggingColumnSetting[+t].dataType?c._draggingColumnSetting[+t].dataType:wjcCore.DataType.Object,c._owner.columns[+t].align=e?c._draggingColumnSetting[+t].align:null,c._owner.columns[+t].format=e?c._draggingColumnSetting[+t].format:null}),e){if(c._isDraggingColumns)if(c._dragRange.leftCol<c._dropRange.leftCol)for(s=c._dragRange.leftCol,i=c._dropRange.leftCol;i<=c._dropRange.rightCol;i++)c._owner._updateColumnFiler(i,s),s++;else for(s=c._dragRange.rightCol,i=c._dropRange.rightCol;i>=c._dropRange.leftCol;i--)c._owner._updateColumnFiler(i,s),s--}else if(c._isDraggingColumns)if(c._dragRange.leftCol>c._dropRange.leftCol)for(s=c._dropRange.leftCol,i=c._dragRange.leftCol;i<=c._dragRange.rightCol;i++)c._owner._updateColumnFiler(i,s),s++;else for(s=c._dropRange.rightCol,i=c._dragRange.rightCol;i>=c._dragRange.leftCol;i--)c._owner._updateColumnFiler(i,s),s--}}))}}exports._MoveCellsAction=_MoveCellsAction;class _CutAction extends _UndoAction{constructor(e){super(e),this._oldValues=[],this._mergeAction=new _CellMergeAction(e),this._celltyleAction=new _CellStyleAction(e),this._cutSheet=e._copiedSheet,this._selection=e.selection,this._cutSelection=e.selectionMode===wjcGrid.SelectionMode.ListBox?e._getSelectionForListBoxMode(this._cutSheet.grid):e._copiedRanges[0],this._saveCutValues(!0)}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){var e,t,o;this._cutSheet===this._owner.selectedSheet?this._owner:this._cutSheet.grid;for(this._saveCutValues(!1),this._newValues=[],e=this._selection.topRow;e<=this._selection.bottomRow;e++)for(t=this._selection.leftCol;t<=this._selection.rightCol;t++){if(!this._owner.columns[t])return!1;o=null==(o=this._owner.getCellData(e,t,!!this._owner.columns[t].dataMap))?"":o,this._newValues.push({row:e,col:t,value:o})}return this._mergeAction.saveNewState(),this._celltyleAction.saveNewState(),!0}updateForPasting(e){var t=this._owner.getCellData(e.row,e.col,!!this._owner.columns[e.col].dataMap);t=null==t?"":t,this._oldValues.push({row:e.row,col:e.col,value:t}),this._selection.row=Math.min(this._selection.topRow,e.topRow),this._selection.row2=Math.max(this._selection.bottomRow,e.bottomRow),this._selection.col=Math.min(this._selection.leftCol,e.leftCol),this._selection.col2=Math.max(this._selection.rightCol,e.rightCol)}_saveCutValues(e){var t,o,n,i=this._cutSheet===this._owner.selectedSheet?this._owner:this._cutSheet.grid,s=[];for(t=this._cutSelection.topRow;t<=this._cutSelection.bottomRow;t++)if(null!=i.rows[t])for(o=this._cutSelection.leftCol;o<=this._cutSelection.rightCol;o++)n=null==(n=i.getCellData(t,o,!!i.columns[o].dataMap))?"":n,s.push({row:t,col:o,value:n});e?this._oldCutValues=s:this._newCutValues=s}_handleUndoRedo(e){var t=this,o=e?t._oldCutValues:t._newCutValues,n=e?t._oldValues:t._newValues;t._owner._clearCalcEngine(),t._owner.selectedSheet.selectionRanges.clear(),t._owner.deferUpdate(()=>{var i,s,l=t._cutSheet===t._owner.selectedSheet?t._owner:t._cutSheet.grid;for(t._owner.selectedSheet.selectionRanges.push(t._selection),i=0;i<o.length;i++)s=o[i],l.setCellData(s.row,s.col,s.value);for(i=0;i<n.length;i++)s=n[i],t._owner.setCellData(s.row,s.col,s.value);e?(t._mergeAction.undo(),t._celltyleAction.undo()):(t._mergeAction.redo(),t._celltyleAction.redo()),t._owner.refresh(!1)})}}exports._CutAction=_CutAction;class _TableSettingAction extends _UndoAction{constructor(e,t){super(e),this._table=t,this._saveValues(!0)}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return this._saveValues(!1),!0}_saveValues(e){var t={name:this._table.name,style:this._table.style,showHeaderRow:this._table.showHeaderRow,showTotalRow:this._table.showTotalRow,showbandedRows:this._table.showBandedRows,showBandedColumns:this._table.showBandedColumns,alterFirstColumn:this._table.alterFirstColumn,alterLastColumn:this._table.alterLastColumn};e?this._oldTableSetting=t:this._newTableSetting=t}_handleUndoRedo(e){var t=e?this._oldTableSetting:this._newTableSetting;this._owner.beginUpdate(),this._owner._isUndoing=!0,this._table.name=t.name,this._table.style=t.style,this._table.showHeaderRow=t.showHeaderRow,this._table.showTotalRow=t.showTotalRow,this._table.showBandedRows=t.showbandedRows,this._table.showBandedColumns=t.showBandedColumns,this._table.alterFirstColumn=t.alterFirstColumn,this._table.alterLastColumn=t.alterLastColumn,this._owner._isUndoing=!1,this._owner.endUpdate()}}exports._TableSettingAction=_TableSettingAction;class _TableAction extends _UndoAction{constructor(e,t){super(e),this._addedTable=t}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}_handleUndoRedo(e){var t,o,n;if(this._addedTable.showHeaderRow)for(o=this._addedTable.getRange(),n=this._addedTable.getColumns(),t=0;t<o.columnSpan;t++)this._owner.setCellData(o.topRow,o.leftCol+t,e?this._addedTable._orgHeaderCellsContent[t]:n[t].name);e?this._owner.selectedSheet.tables.remove(this._addedTable):this._owner.selectedSheet.tables.push(this._addedTable),this._owner.refresh()}}exports._TableAction=_TableAction;class _FilteringAction extends _UndoAction{constructor(e){super(e),this._oldFilterDefinition=e.filter.filterDefinition,this._oldRowsVisible=this._getRowsVisible()}undo(){this._handleUndoRedo(!0)}redo(){this._handleUndoRedo(!1)}saveNewState(){return this._newFilterDefinition=this._owner.filter.filterDefinition,this._newRowsVisible=this._getRowsVisible(),!0}_handleUndoRedo(e){let t=e?this._oldFilterDefinition:this._newFilterDefinition;this._owner.filter.filterDefinition!==t?(this._owner._isUndoing=!0,this._owner.selectedSheet._filterDefinition=t,this._owner.selectedSheet._applyFilterSetting(),this._owner._isUndoing=!1,this._owner.filter.apply()):this._setRowVisible(e)}_getRowsVisible(){let e,t=[],o=0;for(;o<this._owner.rows.length;o++)(e=this._owner.rows[o])&&t.push(e.visible);return t}_setRowVisible(e){let t,o=e?this._oldRowsVisible:this._newRowsVisible,n=0;for(;n<o.length;n++)(t=this._owner.rows[n])&&(t.visible=o[n])}}exports._FilteringAction=_FilteringAction;class _ContextMenu extends wjcCore.Control{constructor(e,t){super(e),this._idx=-1,this._isDisableDelRow=!1,this._owner=t,this.applyTemplate("",this.getTemplate(),{_insRows:"insert-rows",_delRows:"delete-rows",_insCols:"insert-columns",_delCols:"delete-columns",_convertTable:"convert-table"}),this._init()}get visible(){return"none"!==this.hostElement.style.display}show(e,t){if(this._owner.selectedSheet){var o=(t?t.x:e.clientX)+(e?window.pageXOffset:0),n=(t?t.y:e.clientY)+(e?window.pageYOffset:0);this.hostElement.style.position="absolute",this.hostElement.style.display="inline",this._owner.itemsSource&&(wjcCore.addClass(this._insCols,"wj-state-disabled"),wjcCore.addClass(this._delCols,"wj-state-disabled")),this._owner._isDisableDeleteRow(this._owner.selection.topRow,this._owner.selection.bottomRow)&&(this._isDisableDelRow=!0,wjcCore.addClass(this._delRows,"wj-state-disabled")),this._showTableOperation(),this._owner.selection.isValid||wjcCore.addClass(this._convertTable,"wj-state-disabled"),n+this.hostElement.clientHeight>window.innerHeight&&(n-=this.hostElement.clientHeight),o+this.hostElement.clientWidth>window.innerWidth&&(o-=this.hostElement.clientWidth),this.hostElement.style.top=n+"px",this.hostElement.style.left=o+"px"}}hide(){this._idx=-1;var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e),this.hostElement.style.display="none",this._isDisableDelRow=!1,wjcCore.removeClass(this._delRows,"wj-state-disabled"),wjcCore.removeClass(this._insCols,"wj-state-disabled"),wjcCore.removeClass(this._delCols,"wj-state-disabled"),wjcCore.removeClass(this._convertTable,"wj-state-disabled")}moveToNext(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");for(this._removeSelectedState(e),this._idx++,1===this._idx&&this._isDisableDelRow&&this._idx++;e[this._idx]&&"none"===e[this._idx].style.display;)this._idx++;this._idx>=e.length&&(this._idx=0),wjcCore.addClass(e[this._idx],"wj-context-menu-item-selected")}moveToPrev(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");for(this._removeSelectedState(e),this._idx--,1===this._idx&&this._isDisableDelRow&&this._idx--;this._idx>0&&"none"===e[this._idx].style.display;)this._idx--;this._idx<0&&(this._idx=e.length-1),wjcCore.addClass(e[this._idx],"wj-context-menu-item-selected")}moveToFirst(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e),this._idx=0,wjcCore.addClass(e[this._idx],"wj-context-menu-item-selected")}moveToLast(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e),this._idx=e.length-1,e[this._idx]&&"none"===e[this._idx].style.display&&this._idx--,wjcCore.addClass(e[this._idx],"wj-context-menu-item-selected")}handleContextMenu(){if(-1===this._idx)this.moveToNext();else{switch(this.hostElement.querySelectorAll(".wj-context-menu-item")[this._idx]){case this._insCols:this._owner.insertColumns();break;case this._insRows:this._owner.insertRows();break;case this._delCols:this._owner.deleteColumns();break;case this._delRows:this._isDisableDelRow||this._owner.deleteRows();break;case this._convertTable:this._addTable()}this.hide(),this._owner.hostElement.focus()}}_init(){var e=this,t=this.hostElement.querySelectorAll(".wj-context-menu-item");e.hostElement.style.zIndex="9999",document.querySelector("body").appendChild(e.hostElement),e.addEventListener(document.body,"mousemove",()=>{e._removeSelectedState(t)}),e.addEventListener(e.hostElement,"contextmenu",e=>{e.preventDefault()}),e.addEventListener(e._insRows,"click",t=>{e._owner.insertRows(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._delRows,"click",t=>{e._isDisableDelRow||e._owner.deleteRows(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._insCols,"click",t=>{e._owner.insertColumns(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._delCols,"click",t=>{e._owner.deleteColumns(),e.hide(),e._owner.hostElement.focus()}),e.addEventListener(e._convertTable,"click",t=>{e._addTable(),e.hide(),e._owner.hostElement.focus()})}_removeSelectedState(e){for(var t=0;t<e.length;t++)wjcCore.removeClass(e[t],"wj-context-menu-item-selected")}_showTableOperation(){var e,t,o=this._owner.selection;for(e=o.topRow;e<=o.bottomRow;e++)for(t=o.leftCol;t<=o.rightCol;t++)if(null!=this._owner.selectedSheet.findTable(e,t))return this._convertTable.style.display="none",void(this._convertTable.parentElement.style.display="none");o.isSingleCell||this._owner._containsMergedCells(o)?(this._convertTable.style.display="none",this._convertTable.parentElement.style.display="none"):(this._convertTable.style.display="inline",this._convertTable.parentElement.style.display="inline")}_addTable(){var e,t;0!==this._owner.undoStack.stackSize&&(e=this._owner.selectedSheet._addTable(this._owner.selection),t=new _TableAction(this._owner,e),this._owner.undoStack._addAction(t))}}_ContextMenu.controlTemplate='<div class="wj-context-menu wj-control wj-flexsheet-context-menu" width="150px"><div class="wj-context-menu-item" wj-part="insert-rows">Insert Row</div><div class="wj-context-menu-item" wj-part="delete-rows">Delete Rows</div><div class="wj-context-menu-item" wj-part="insert-columns">Insert Column</div><div class="wj-context-menu-item" wj-part="delete-columns">Delete Columns</div><div><div class="wj-state-disabled" style="width:100%;height:1px;background-color:lightgray;"></div><div class="wj-context-menu-item" wj-part="convert-table">Convert To Table</div></div></div>',exports._ContextMenu=_ContextMenu;class _TabHolder extends wjcCore.Control{constructor(e,t){super(e),this._splitterMousedownHdl=this._splitterMousedownHandler.bind(this),this._owner=t,this.applyTemplate("",this.getTemplate(),{_divSheet:"left",_divSplitter:"splitter",_divRight:"right"}),this._init()}get sheetControl(){return this._sheetControl}get visible(){return"none"!==this.hostElement.style.display}set visible(e){this.hostElement.style.display=e?"block":"none",this._divSheet.style.display=e?"block":"none"}getSheetBlanketSize(){return 20}adjustSize(){var e=this._owner.scrollSize.width-this._owner.clientSize.width,t=(this._owner.scrollSize.height,this._owner.clientSize.height,this._divSplitter.parentElement);e<=0?(t.style.minWidth="100px",this._divSplitter.style.display="none",this._divRight.style.display="none",this._divSheet.style.width="100%",this._divSplitter.removeEventListener("mousedown",this._splitterMousedownHdl,!0)):(t.style.minWidth="300px",this._divSplitter.style.display="none",this._divRight.style.display="none",this._divSheet.style.width="100%",this._divSplitter.removeEventListener("mousedown",this._splitterMousedownHdl,!0),this._divSplitter.addEventListener("mousedown",this._splitterMousedownHdl,!0)),this._sheetControl._adjustSize()}_init(){var e=this;e._funSplitterMousedown=function(t){e._splitterMouseupHandler(t)},e._divSplitter.parentElement.style.height=e.getSheetBlanketSize()+"px",e._sheetControl=new _SheetTabs(e._divSheet,this._owner)}_splitterMousedownHandler(e){this._startPos=e.pageX,document.addEventListener("mousemove",this._splitterMousemoveHandler.bind(this),!0),document.addEventListener("mouseup",this._funSplitterMousedown,!0),e.preventDefault()}_splitterMousemoveHandler(e){null!==this._startPos&&void 0!==this._startPos&&this._adjustDis(e.pageX-this._startPos)}_splitterMouseupHandler(e){document.removeEventListener("mousemove",this._splitterMousemoveHandler,!0),document.removeEventListener("mouseup",this._funSplitterMousedown,!0),this._adjustDis(e.pageX-this._startPos),this._startPos=null}_adjustDis(e){var t=this._divRight.offsetWidth-e,o=this._divSheet.offsetWidth+e;t<=100?(t=100,e=this._divRight.offsetWidth-t,o=this._divSheet.offsetWidth+e):o<=100&&(e=(o=100)-this._divSheet.offsetWidth,t=this._divRight.offsetWidth-e),0!=e&&(this._divRight.style.width=t+"px",this._divSheet.style.width=o+"px",this._startPos=this._startPos+e)}}_TabHolder.controlTemplate='<div><div wj-part="left" style ="float:left;height:100%;overflow:hidden"></div><div wj-part="splitter" style="float:left;height:100%;width:6px;background-color:#e9eaee;padding:2px;cursor:e-resize"><div style="background-color:#8a9eb2;height:100%"></div></div><div wj-part="right" style="float:left;height:100%;background-color:#e9eaee"></div></div>',exports._TabHolder=_TabHolder;class _FlexSheetCellFactory extends wjcGrid.CellFactory{updateCell(e,t,o,n,i){var s,l,r,a,h,d,c,_,u,g,w,m,C,f,p,S=e.grid;switch(e.cellType===wjcGrid.CellType.Cell&&this._resetCellStyle(e.columns[o],n),super.updateCell(e,t,o,n,i),i&&!i.isSingleCell&&(t=i.row,o=i.col,i.row2,i.col2),p=S.selectedSheet,g=S._getBindingColumn(e,t,e.columns[o]),e.cellType){case wjcGrid.CellType.RowHeader:n.textContent=t+1+"";break;case wjcGrid.CellType.ColumnHeader:s=p&&p._showDefaultHeader||wjcCore.isNullOrWhiteSpace(g.header)||!wjcCore.isNullOrWhiteSpace(g.binding)&&(g.header===g.binding||g.header===wjcCore.toHeaderCase(g.binding))?FlexSheet.convertNumberToAlpha(o):g.header,n.textContent?n.innerHTML=n.innerHTML.replace(wjcCore.escapeHtml(n.textContent.trim()),s).replace(n.textContent,s):n.innerHTML+=s,n.style.textAlign="center";break;case wjcGrid.CellType.Cell:if(l=t*S.columns.length+o,c=p&&p._styledCells?p._styledCells[l]:null,i&&!i.isSingleCell&&(t=(m=this._getFirstVisibleCell(S,i)).row,o=m.col),e.rows[t]instanceof HeaderRow)e.columns[o].dataType===wjcCore.DataType.Boolean?1===n.childElementCount&&n.firstElementChild instanceof HTMLInputElement&&"checkbox"===n.firstElementChild.type&&(n.innerHTML=wjcCore.escapeHtml(S.getCellValue(t,o))):n.innerHTML||(n.innerHTML=wjcCore.escapeHtml(S.getCellValue(t,o))),wjcCore.addClass(n,"wj-header-row");else if(a=S.getCellValue(t,o,!1),h=S.getCellData(t,o,!1),d=null!=h&&"string"==typeof h&&"="===h[0],C=e.rows[t]instanceof wjcGrid.GroupRow,w=(c?c.format:null)||(C?null:g.format),S.editRange&&S.editRange.contains(t,o)?!wjcCore.isNumber(a)||g.dataMap||d||(w&&(a=this._getFormattedValue(a,w)),(u=n.querySelector("input"))&&(u.value=a)):e.columns[o].dataType===wjcCore.DataType.Boolean?(_=n.querySelector('[type="checkbox"]'))&&(_.checked=S.getCellValue(t,o),_.disabled=_.disabled||!S.canEditCell(t,o)):g.dataMap&&!C?(a=S.getCellValue(t,o,!0),(r=n.firstChild)&&3===r.nodeType&&r.nodeValue!==a&&(r.nodeValue=a)):0===n.childElementCount&&n.textContent===S.getCellData(t,o,!0)&&(""!==(a=S.getCellValue(t,o,!0))&&wjcCore.isNumber(+a)&&!isNaN(+a)&&/[hsmy\:]/i.test(w)&&(f=_Expression._fromOADate(+a),isNaN(f.getTime())||(a=wjcCore.Globalize.formatDate(f,w))),!w&&C||(a=wjcCore.isString(a)?a.replace(/^(\')(\s*[\w|=])/,"$2"):a,wjcCore.isString(a)?a&&this._isURL(a)?n.innerHTML='<a href="'+a+'" target="_blank">'+wjcCore.escapeHtml(a)+"</a>":n.innerHTML=wjcCore.escapeHtml(a):n.innerHTML=a)),c){var b,R=n.style;for(var y in c)"className"===y?c.className&&wjcCore.addClass(n,c.className):"format"!==y&&(b=c[y])&&(!wjcCore.hasClass(n,"wj-state-selected")&&!wjcCore.hasClass(n,"wj-state-multi-selected")||"color"!==y&&"backgroundColor"!==y?R[y]="whiteSpace"===y&&"normal"===b?"":b:R[y]="")}(n.style.backgroundColor||n.style.color)&&(c||(c={},p&&p._styledCells[l]),n.style.backgroundColor&&(c.backgroundColor=n.style.backgroundColor),n.style.color&&(c.color=n.style.color))}e.cellType===wjcGrid.CellType.Cell&&(t!==S._lastVisibleFrozenRow||wjcCore.hasClass(n,"wj-frozen-row")||wjcCore.addClass(n,"wj-frozen-row"),o!==S._lastVisibleFrozenColumn||wjcCore.hasClass(n,"wj-frozen-col")||wjcCore.addClass(n,"wj-frozen-col"))}_resetCellStyle(e,t){["fontFamily","fontSize","fontStyle","fontWeight","textDecoration","textAlign","verticalAlign","backgroundColor","color","whiteSpace","borderLeftStyle","borderLeftColor","borderLeftWidth","borderRightStyle","borderRightColor","borderRightWidth","borderTopStyle","borderTopColor","borderTopWidth","borderBottomStyle","borderBottomColor","borderBottomWidth"].forEach(o=>{"textAlign"===o?t.style.textAlign=e.getAlignment():t.style[o]=""})}_getFormattedValue(e,t){return e!==Math.round(e)&&(t=t.replace(/([a-z])(\d*)(.*)/gi,"$0112$3")),wjcCore.Globalize.formatNumber(e,t,!0)}_getFirstVisibleCell(e,t){var o,n;for(o=t.topRow;o<=t.bottomRow&&!e.rows[o].isVisible;o++);for(n=t.leftCol;n<=t.rightCol&&!e.columns[n].isVisible;n++);return new wjcGrid.CellRange(o,n)}_isURL(e){return new RegExp("^(https|http|ftp|rtsp|mms)://(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].[a-z]{2,6})(:[0-9]{1,4})?(/($|[a-zA-Z0-9.,?'\\+&amp;%$#=~_-]+))*").test(e)}}exports._FlexSheetCellFactory=_FlexSheetCellFactory;var FlexSheetFunctions=[{name:"abs",description:"Returns the absolute value of a number."},{name:"acos",description:"Returns the arccosine of a number."},{name:"and",description:"Returns TRUE if all of its arguments are TRUE."},{name:"asin",description:"Returns the arcsine of a number."},{name:"atan",description:"Returns the arctangent of a number."},{name:"atan2",description:"Returns the arctangent from x- and y-coordinates."},{name:"average",description:"Returns the average of its arguments."},{name:"ceiling",description:"Rounds a number to the nearest integer or to the nearest multiple of significance."},{name:"char",description:"Returns the character specified by the code number."},{name:"choose",description:"Chooses a value from a list of values."},{name:"code",description:"Returns a numeric code for the first character in a text string."},{name:"column",description:"Returns the column number of a reference."},{name:"columns",description:"Returns the number of columns in a reference."},{name:"concatenate",description:"Joins several text items into one text item."},{name:"cos",description:"Returns the cosine of a number."},{name:"count",description:"Counts how many numbers are in the list of arguments."},{name:"counta",description:"Counts how many values are in the list of arguments."},{name:"countblank",description:"Counts the number of blank cells within a range."},{name:"countif",description:"Counts the number of cells within a range that meet the given criteria."},{name:"countifs",description:"Counts the number of cells within a range that meet multiple criteria."},{name:"date",description:"Returns the serial number of a particular date."},{name:"datedif",description:"Calculates the number of days, months, or years between two dates."},{name:"day",description:"Converts a serial number to a day of the month."},{name:"dcount",description:"Counts the cells that contain numbers in a database."},{name:"exp",description:"Returns e raised to the power of a given number."},{name:"false",description:"Returns the logical value FALSE."},{name:"find",description:"Finds one text value within another (case-sensitive)."},{name:"floor",description:"Rounds a number down, toward zero."},{name:"hlookup",description:"Looks in the top row of an array and returns the value of the indicated cell."},{name:"hour",description:"Converts a serial number to an hour."},{name:"if",description:"Specifies a logical test to perform."},{name:"index",description:"Uses an index to choose a value from a reference."},{name:"left",description:"Returns the leftmost characters from a text value."},{name:"len",description:"Returns the number of characters in a text string."},{name:"ln",description:"Returns the natural logarithm of a number."},{name:"lower",description:"Converts text to lowercase."},{name:"max",description:"Returns the maximum value in a list of arguments."},{name:"mid",description:"Returns a specific number of characters from a text string starting at the position you specify."},{name:"min",description:"Returns the minimum value in a list of arguments."},{name:"mod",description:"Returns the remainder from division."},{name:"month",description:"Converts a serial number to a month."},{name:"not",description:"Reverses the logic of its argument."},{name:"now",description:"Returns the serial number of the current date and time."},{name:"or",description:"Returns TRUE if any argument is TRUE."},{name:"pi",description:"Returns the value of pi."},{name:"power",description:"Returns the result of a number raised to a power."},{name:"product",description:"Multiplies its arguments."},{name:"proper",description:"Capitalizes the first letter in each word of a text value."},{name:"rand",description:"Returns a random number between 0 and 1."},{name:"rank",description:"Returns the rank of a number in a list of numbers."},{name:"rate",description:"Returns the interest rate per period of an annuity."},{name:"replace",description:"Replaces characters within text."},{name:"rept",description:"Repeats text a given number of times."},{name:"right",description:"Returns the rightmost characters from a text value."},{name:"round",description:"Rounds a number to a specified number of digits."},{name:"rounddown",description:"Rounds a number down, toward zero."},{name:"roundup",description:"Rounds a number up, away from zero."},{name:"row",description:"Returns the row number of a reference."},{name:"rows",description:"Returns the number of rows in a reference."},{name:"search",description:"Finds one text value within another (not case-sensitive)."},{name:"sin",description:"Returns the sine of the given angle."},{name:"sqrt",description:"Returns a positive square root."},{name:"stdev",description:"Estimates standard deviation based on a sample."},{name:"stdevp",description:"Calculates standard deviation based on the entire population."},{name:"substitute",description:"Substitutes new text for old text in a text string."},{name:"subtotal",description:"Returns a subtotal in a list or database."},{name:"sum",description:"Adds its arguments."},{name:"sumif",description:"Adds the cells specified by a given criteria."},{name:"sumifs",description:"Adds the cells in a range that meet multiple criteria."},{name:"sumproduct",description:"Multiplies corresponding components in the given arrays, and returns the sum of those products."},{name:"tan",description:"Returns the tangent of a number."},{name:"text",description:"Formats a number and converts it to text."},{name:"time",description:"Returns the serial number of a particular time."},{name:"today",description:"Returns the serial number of today's date."},{name:"trim",description:"Removes spaces from text."},{name:"true",description:"Returns the logical value TRUE."},{name:"trunc",description:"Truncates a number to an integer."},{name:"upper",description:"Converts text to uppercase."},{name:"value",description:"Converts a text argument to a number."},{name:"var",description:"Estimates variance based on a sample."},{name:"varp",description:"Calculates variance based on the entire population."},{name:"year",description:"Converts a serial number to a year."}];class FlexSheet extends wjcGrid.FlexGrid{constructor(e,t){super(e,t),this._selectedSheetIndex=-1,this._columnHeaderClicked=!1,this._addingSheet=!1,this._mouseMoveHdl=this._mouseMove.bind(this),this._clickHdl=this._click.bind(this),this._touchStartHdl=this._touchStart.bind(this),this._touchEndHdl=this._touchEnd.bind(this),this._isContextMenuKeyDown=!1,this._isClicking=!1,this._definedNames=new wjcCore.ObservableArray,this._builtInTableStylesCache=null,this._needCopyToSheet=!0,this._isSorting=!1,this.selectedSheetChanged=new wjcCore.Event,this.draggingRowColumn=new wjcCore.Event,this.droppingRowColumn=new wjcCore.Event,this.loaded=new wjcCore.Event,this.unknownFunction=new wjcCore.Event,this.sheetCleared=new wjcCore.Event,this.prepareChangingRow=new wjcCore.Event,this.prepareChangingColumn=new wjcCore.Event,this.rowChanged=new wjcCore.Event,this.columnChanged=new wjcCore.Event,this._needCopyToSheet=!1,this._colorThemes=["FFFFFF","000000","EEECE1","1F497D","4F818D","C0504D","9BBB59","8064A2","4BACC6","F79646"],this._eCt.style.backgroundColor="white",wjcCore.addClass(this.hostElement,"wj-flexsheet"),wjcCore.setCss(this.hostElement,{fontFamily:"Arial"}),this._cf=new _FlexSheetCellFactory,this._bndSortConverter=this._sheetSortConverter.bind(this),this.quickAutoSize=!1,this._init(),this.showSort=!1,this.allowSorting=!1,this.showGroups=!1,this.showMarquee=!0,this.showSelectedHeaders=wjcGrid.HeadersVisibility.All,this.allowResizing=wjcGrid.AllowResizing.Both,this.allowDragging=wjcGrid.AllowDragging.None,this._needCopyToSheet=!0}_getProductInfo(){return"R20I,FlexSheet"}get sheets(){return this._sheets||(this._sheets=new SheetCollection,this._sheets.selectedSheetChanged.addHandler(this._selectedSheetChange,this),this._sheets.collectionChanged.addHandler(this._sourceChange,this),this._sheets.sheetVisibleChanged.addHandler(this._sheetVisibleChange,this),this._sheets.sheetCleared.addHandler(this.onSheetCleared,this)),this._sheets}get selectedSheetIndex(){return this._selectedSheetIndex}set selectedSheetIndex(e){e!==this._selectedSheetIndex&&(this._showSheet(e),this._sheets.selectedIndex=e)}get selectedSheet(){return this._sheets[this._selectedSheetIndex]}get isFunctionListOpen(){return this._functionListHost&&"none"!==this._functionListHost.style.display}get isTabHolderVisible(){return this._tabHolder.visible}set isTabHolderVisible(e){e!==this._tabHolder.visible&&(e?(this._divContainer.style.height=this._divContainer.parentElement.clientHeight-this._tabHolder.getSheetBlanketSize()+"px",this._eFocus.removeAttribute("tabindex")):(this._divContainer.style.height=this._divContainer.parentElement.clientHeight+"px",this._eFocus.tabIndex=this._tabIndex),this._tabHolder.visible=e)}get undoStack(){return this._undoStack}get sortManager(){return this._sortManager}get filter(){return this._filter}get showFilterIcons(){return!!this._filter&&this._filter.showFilterIcons}set showFilterIcons(e){this._filter&&this._filter.showFilterIcons!==e&&(this._filter.showFilterIcons=e)}get definedNames(){return this._definedNames}onSelectedSheetChanged(e){this.selectedSheetChanged.raise(this,e)}onDraggingRowColumn(e){this.draggingRowColumn.raise(this,e)}onDroppingRowColumn(e){this.droppingRowColumn.raise(this,new wjcCore.EventArgs)}onLoaded(e){var t=this;t._toRefresh&&(clearTimeout(t._toRefresh),t._toRefresh=null),t._toRefresh=setTimeout(()=>{t._setFlexSheetToDirty(),t.invalidate()},10),t.loaded.raise(this,new wjcCore.EventArgs)}onUnknownFunction(e){this.unknownFunction.raise(this,e)}onSheetCleared(e){this.sheetCleared.raise(this,new wjcCore.EventArgs)}onPrepareChangingRow(e){this.prepareChangingRow.raise(this,e)}onPrepareChangingColumn(e){this.prepareChangingColumn.raise(this,e)}onRowChanged(e){this.rowChanged.raise(this,e)}onColumnChanged(e){this.columnChanged.raise(this,e)}refresh(e=!0){var t,o,n;if(this._divContainer.style.height=this._divContainer.parentElement.clientHeight-(this.isTabHolderVisible?this._tabHolder.getSheetBlanketSize():0)+"px",!this.preserveSelectedState&&this.selectedSheet&&(this.selectedSheet.selectionRanges.clear(),this.selectedSheet.selectionRanges.push(this.selection)),e&&this._clearCalcEngine(),this._lastVisibleFrozenRow=-1,this.frozenRows>0)for(var i=this.frozenRows-1;i>=0;i--)if(this.rows[i]&&this.rows[i].isVisible){this._lastVisibleFrozenRow=i;break}if(this._lastVisibleFrozenColumn=-1,this.frozenColumns>0)for(var s=this.frozenColumns-1;s>=0;s--)if(this.columns[s]&&this.columns[s].isVisible){this._lastVisibleFrozenColumn=s;break}if(this.selectedSheet){if(this.selectedSheet._freezeHiddenRowCnt>0)for(t=0;t<this.selectedSheet._freezeHiddenRowCnt;t++)(o=this.rows[t])instanceof HeaderRow||(o.visible=!1);if(this.selectedSheet._freezeHiddenColumnCnt>0)for(n=0;n<this.selectedSheet._freezeHiddenColumnCnt;n++)this.columns[n].visible=!1}super.refresh(e),this._tabHolder.adjustSize()}setCellData(e,t,o,n=!1,i=!0){var s=wjcCore.isString(o)&&o.length>1&&"="===o[0];return this._clearCalcEngine(),this.cells.setCellData(e,t,o,n&&!s,i)}containsFocus(){return this.isFunctionListOpen||super.containsFocus()}addUnboundSheet(e,t,o,n,i){var s=this._addSheet(e,t,o,n,i);return 0===s.selectionRanges.length&&s.selectionRanges.push(this.selection),s}addBoundSheet(e,t,o,n){var i=this._addSheet(e,0,0,o,n);return t&&(i.itemsSource=t,this.childItemsPath&&(i.grid.childItemsPath=this.childItemsPath)),0===i.selectionRanges.length&&i.selectionRanges.push(this.selection),i}applyCellsStyle(e,t,o=!1){var n,i,s,l,r,a=t||[this.selection];if(this.selectedSheet){if(!e&&this._cloneStyle)return this.selectedSheet._styledCells=this._cloneObject(this._cloneStyle),this._cloneStyle=null,void this.refresh(!1);if(a){for(t||o?o&&!this._cloneStyle&&(this._cloneStyle=this._cloneObject(this.selectedSheet._styledCells)):(this.undoStack.stackSize>0&&(r=new _CellStyleAction(this,this._cloneStyle)),this._cloneStyle=null),l=0;l<a.length;l++)for(n=(s=a[l]).topRow;n<=s.bottomRow;n++)for(i=s.leftCol;i<=s.rightCol;i++)this._applyStyleForCell(n,i,e);r&&(r.saveNewState(),this._undoStack._addAction(r))}t||this.refresh(!1)}}freezeAtCursor(){var e,t,o,n,i,s=this;if(s.selectedSheet){if(s.selection&&0===s.frozenRows&&0===s.frozenColumns){if(s._ptScrl.y<0)for(e=0;e<s.selection.topRow-1;e++)if(!((i=s.rows[e])instanceof HeaderRow)){if(!(i._pos+s._ptScrl.y<0)){s.selectedSheet._freezeHiddenRowCnt=e;break}i.visible=!1}if(s._ptScrl.x<0)for(t=0;t<s.selection.leftCol-1;t++){if(!(s.columns[t]._pos+s._ptScrl.x<0)){s.selectedSheet._freezeHiddenColumnCnt=t;break}s.columns[t].visible=!1}o=s.selection.leftCol>0?s.selection.leftCol:0,n=s.selection.topRow>0?s.selection.topRow:0}else{for(e=0;e<s.frozenRows-1;e++)s.rows[e].visible=!0;for(t=0;t<s.frozenColumns-1;t++)s.columns[t].visible=!0;s._filter.apply(),o=0,n=0,s.selectedSheet._freezeHiddenRowCnt=0,s.selectedSheet._freezeHiddenColumnCnt=0}s.frozenRows=s.selectedSheet.grid.frozenRows=n,s.frozenColumns=s.selectedSheet.grid.frozenColumns=o,setTimeout(()=>{s._setFlexSheetToDirty(),s.invalidate(),s.scrollIntoView(s.selection.topRow,s.selection.leftCol)},10)}}showColumnFilter(){var e=this.selection.col>0?this.selection.col:0;this.columns.length>0&&this._filter.editColumnFilter(this.columns[e])}clear(){this.beginUpdate(),this.selection=new wjcGrid.CellRange,this.sheets.clear(),this._selectedSheetIndex=-1,this.columns.clear(),this.rows.clear(),this.columnHeaders.columns.clear(),this.rowHeaders.rows.clear(),this._undoStack.clear(),this._ptScrl=new wjcCore.Point,this._clearCalcEngine(),this._definedNames.clear(),this._builtInTableStylesCache=null,this.addUnboundSheet(),this.endUpdate()}getSelectionFormatState(){var e,t,o=this.rows.length,n=this.columns.length,i={isBold:!1,isItalic:!1,isUnderline:!1,textAlign:"left",isMergedCell:!1};if(0===o||0===n)return i;if(this.selection){if(this.selection.row>=o||this.selection.row2>=o||this.selection.col>=n||this.selection.col2>=n)return i;for(e=this.selection.topRow;e<=this.selection.bottomRow;e++)for(t=this.selection.leftCol;t<=this.selection.rightCol;t++)this._checkCellFormat(e,t,i)}return i}insertRows(e,t){var o,n,i,s,l,r,a=wjcCore.isNumber(e)&&e>=0?e:this.selection&&this.selection.topRow>-1?this.selection.topRow:0,h=wjcCore.isNumber(t)?t:1,d=this.rows[a],c=!1;if(this.selectedSheet){if(this.rows.length>0?a>=this.rows.length&&(a=this.rows.length-1):a=0,this._clearCalcEngine(),this.finishEditing(),0===a&&d&&d.constructor===HeaderRow&&(a=1),this.onPrepareChangingRow(new RowColumnChangedEventArgs(a,h,!0)),this.undoStack.stackSize>0&&(o=new _RowsChangedAction(this,a,h,!0)),this._updateCellsForUpdatingRow(this.rows.length,a,h),(!this.collectionView||0===this.collectionView.sortDescriptions.length)&&(n=this._updateAffectedFormula(a,h,!0,!0),i=this._updateAffectedNamedRanges(a,h,!0,!0)),o&&(o._affectedFormulas=n,o._affectedDefinedNameVals=i),this.collectionView){for(c=!0,l=this.itemsSource instanceof wjcCore.CollectionView,this.collectionView.beginUpdate(),s=0;s<h;s++)l?(r=this.itemsSource.newItemCreator?this.itemsSource.newItemCreator():{},this.itemsSource.sourceCollection.splice(a-(this.allowAddNew&&this.newRowAtTop?2:1),0,r)):(this.selectedSheet.grid.collectionView.beginUpdate(),r={},this.itemsSource.splice(a-(this.allowAddNew&&this.newRowAtTop?2:1),0,r),this.itemsSource!==this.selectedSheet.grid.itemsSource&&this.selectedSheet.grid.itemsSource.splice(a-(this.allowAddNew&&this.newRowAtTop?2:1),0,r)),this.selectedSheet._orgItemsSource&&this.selectedSheet._orgItemsSource.splice(a-(this.allowAddNew&&this.newRowAtTop?2:1),0,r);l||this.selectedSheet.grid.collectionView.endUpdate(),this.collectionView.endUpdate()}else{for(this.rows.beginUpdate(),s=0;s<h;s++)this.rows.insert(a,new wjcGrid.Row);this.rows.endUpdate()}this._updateTablesForUpdatingRow(a,h),this.selection&&-1!==this.selection.row&&-1!==this.selection.col||(this.selection=new wjcGrid.CellRange(0,0)),o&&(o.saveNewState(),this._undoStack._addAction(o)),this.onRowChanged(new RowColumnChangedEventArgs(a,h,!0)),c&&this.refresh()}}deleteRows(e,t){var o,n,i,s,l,r,a,h,d,c=wjcCore.isNumber(t)&&t>=0?t:this.selection&&this.selection.topRow>-1?this.selection.bottomRow-this.selection.topRow+1:1,_=wjcCore.isNumber(e)&&e>=0?e:this.selection&&this.selection.topRow>-1?this.selection.topRow:-1,u=wjcCore.isNumber(e)&&e>=0?e+c-1:this.selection&&this.selection.topRow>-1?this.selection.bottomRow:-1,g=!1;if(this.selectedSheet&&!(_>=this.rows.length)&&(u=Math.min(u,this.rows.length-1),this._clearCalcEngine(),this.finishEditing(),_>-1&&u>-1)){for(this.onPrepareChangingRow(new RowColumnChangedEventArgs(_,c,!1)),this.undoStack.stackSize>0&&(o=new _RowsChangedAction(this,_,c,!1)),this._updateCellsForUpdatingRow(this.rows.length,_,c,!0),n=this._updateAffectedFormula(u,u-_+1,!1,!0),i=this._updateAffectedNamedRanges(u,u-_+1,!1,!0),s=this._updateTablesForUpdatingRow(_,c,!0),o&&(o._affectedFormulas=n,o._affectedDefinedNameVals=i,o._deletedTables=s),d=!!this.collectionView&&this.itemsSource instanceof wjcCore.CollectionView,this.rows.beginUpdate();u>=_;u--)(!(l=this.rows[u])||l.constructor!==HeaderRow&&l.isVisible)&&(l.dataItem&&this.collectionView?(g=!0,this.collectionView.beginUpdate(),(r=this._getCvIndex(u))>-1&&(a=this.collectionView.items[r],d?this.itemsSource.sourceCollection.splice(this.itemsSource.sourceCollection.indexOf(a),1):(this.selectedSheet.grid.collectionView.beginUpdate(),this.itemsSource.splice(this.itemsSource.indexOf(a),1),this.itemsSource!==this.selectedSheet.grid.itemsSource&&this.selectedSheet.grid.itemsSource.splice(this.itemsSource.indexOf(a),1)),this.selectedSheet._orgItemsSource&&this.selectedSheet._orgItemsSource.splice(this.selectedSheet._orgItemsSource.indexOf(a),1)),d||this.selectedSheet.grid.collectionView.endUpdate(),this.collectionView.endUpdate()):this.rows.removeAt(u));this.rows.endUpdate(),h=this.rows.length,this.selectedSheet.selectionRanges.clear(),0===h?(this.select(new wjcGrid.CellRange),"move"===this.hostElement.style.cursor&&(this.hostElement.style.cursor="default")):u===h-1?this.select(new wjcGrid.CellRange(u,0,u,this.columns.length-1)):this.select(new wjcGrid.CellRange(this.selection.topRow,this.selection.col,this.selection.topRow,this.selection.col2)),o&&(o.saveNewState(),this._undoStack._addAction(o)),this.onRowChanged(new RowColumnChangedEventArgs(_,c,!1)),g&&this.refresh()}}insertColumns(e,t){var o,n,i,s,l,r=wjcCore.isNumber(e)&&e>=0?e:this.selection&&this.selection.leftCol>-1?this.selection.leftCol:0,a=wjcCore.isNumber(t)?t:1;if(this.selectedSheet&&!this.itemsSource){for(this.columns.length>0?r>=this.columns.length&&(r=this.columns.length-1):r=0,this._clearCalcEngine(),this.finishEditing(),this.onPrepareChangingColumn(new RowColumnChangedEventArgs(r,a,!0)),this.undoStack.stackSize>0&&(o=new _ColumnsChangedAction(this,r,a,!0)),this._updateCellsForUpdatingColumn(this.columns.length,r,a),s=this._updateAffectedFormula(r,a,!0,!1),l=this._updateAffectedNamedRanges(r,a,!0,!1),o&&(o._affectedFormulas=s,o._affectedDefinedNameVals=l),this.columns.beginUpdate(),i=0;i<a;i++)(n=new wjcGrid.Column).isRequired=!1,this.columns.insert(r,n);this.columns.endUpdate(),this._updateTablesForUpdatingColumn(r,a),this.selection&&-1!==this.selection.row&&-1!==this.selection.col||(this.selection=new wjcGrid.CellRange(0,0)),o&&(o.saveNewState(),this._undoStack._addAction(o)),this.onColumnChanged(new RowColumnChangedEventArgs(r,a,!0))}}deleteColumns(e,t){var o,n,i,s,l,r=wjcCore.isNumber(t)&&t>=0?t:this.selection&&this.selection.leftCol>-1?this.selection.rightCol-this.selection.leftCol+1:1,a=wjcCore.isNumber(e)&&e>=0?e:this.selection&&this.selection.leftCol>-1?this.selection.leftCol:-1,h=wjcCore.isNumber(e)&&e>=0?e+r-1:this.selection&&this.selection.leftCol>-1?this.selection.rightCol:-1;if(this.selectedSheet&&!this.itemsSource&&!(a>=this.columns.length)&&(h=Math.min(h,this.columns.length-1),this._clearCalcEngine(),this.finishEditing(),a>-1&&h>-1)){for(this.onPrepareChangingColumn(new RowColumnChangedEventArgs(a,r,!1)),this.undoStack.stackSize>0&&(n=new _ColumnsChangedAction(this,a,r,!1)),this._updateCellsForUpdatingColumn(this.columns.length,a,r,!0),i=this._updateAffectedFormula(h,h-a+1,!1,!1),s=this._updateAffectedNamedRanges(h,h-a+1,!1,!1),l=this._updateTablesForUpdatingColumn(a,r,!0),n&&(n._affectedFormulas=i,n._affectedDefinedNameVals=s,n._deletedTables=l),this.columns.beginUpdate();h>=a;h--)this.columns[h].isVisible&&(this.columns.removeAt(h),this._sortManager.deleteSortLevel(h));this.columns.endUpdate(),this._sortManager.commitSort(!1),o=this.columns.length,this.selectedSheet.selectionRanges.clear(),0===o?(this.select(new wjcGrid.CellRange),"move"===this.hostElement.style.cursor&&(this.hostElement.style.cursor="default")):h===o-1?this.select(new wjcGrid.CellRange(0,h,this.rows.length-1,h)):this.select(new wjcGrid.CellRange(this.selection.row,this.selection.leftCol,this.selection.row2,this.selection.leftCol)),n&&(n.saveNewState(),this._undoStack._addAction(n)),this.onColumnChanged(new RowColumnChangedEventArgs(a,r,!1))}}mergeRange(e,t=!1){var o,n,i,s=e||this.selection,l=-1,r=-1;if(this.selectedSheet){if(s){if(1===s.rowSpan&&1===s.columnSpan)return;for(o=s.topRow;o<=s.bottomRow;o++)for(n=s.leftCol;n<=s.rightCol;n++)if(this.selectedSheet.findTable(o,n))return;if(e||t||(this.undoStack.stackSize>0&&(i=new _CellMergeAction(this)),this.hostElement.focus()),!this._resetMergedRange(s)){for(o=s.topRow;o<=s.bottomRow;o++)if(this.rows[o].isVisible){l=o;break}for(n=s.leftCol;n<=s.rightCol;n++)if(this.columns[n].isVisible){r=n;break}l>-1&&r>-1&&this.selectedSheet._mergedRanges.push(new wjcGrid.CellRange(l,r,s.bottomRow,s.rightCol))}i&&(i.saveNewState(),this._undoStack._addAction(i))}e||this.refresh()}}getMergedRange(e,t,o,n=!0){var i,s,l,r,a=this.selectedSheet?this.selectedSheet._getMergedRange(t,o):null;return e===this.cells&&a?!a.isSingleCell&&(this.frozenRows>0||this.frozenColumns>0)&&(a.topRow<this.frozenRows&&a.bottomRow>=this.frozenRows||a.leftCol<this.frozenColumns&&a.rightCol>=this.frozenColumns)?(i=a.topRow,s=a.bottomRow,l=a.leftCol,r=a.rightCol,t>=this.frozenRows&&a.topRow<this.frozenRows&&(i=this.frozenRows),t<this.frozenRows&&a.bottomRow>=this.frozenRows&&(s=this.frozenRows-1),s>=this.rows.length&&(s=this.rows.length-1),o>=this.frozenColumns&&a.leftCol<this.frozenColumns&&(l=this.frozenColumns),o<this.frozenColumns&&a.rightCol>=this.frozenColumns&&(r=this.frozenColumns-1),r>=this.columns.length&&(r=this.columns.length-1),new wjcGrid.CellRange(i,l,s,r)):a.bottomRow>=this.rows.length?new wjcGrid.CellRange(a.topRow,a.leftCol,this.rows.length-1,a.rightCol):a.rightCol>=this.columns.length?new wjcGrid.CellRange(a.topRow,a.leftCol,a.bottomRow,this.columns.length-1):a.clone():o>=0&&this.columns&&this.columns.length>o&&t>=0&&this.rows&&this.rows.length>t?super.getMergedRange(e,t,o,n):null}evaluate(e,t,o,n=!0){let i=this._evaluate(e,t,o);return n&&null!=i&&!wjcCore.isPrimitive(i)?i.value:i}getCellValue(e,t,o=!1,n){var i,s,l=n&&n!==this.selectedSheet?n.grid.columns[t]:this.columns[t],r=this._getCellStyle(e,t,n);return i=r&&r.format?r.format:"",s=n&&n!==this.selectedSheet?n.grid.getCellData(e,t,!1):this.getCellData(e,t,!1),wjcCore.isString(s)&&"="===s[0]&&(s=this._evaluate(s,o?i:"",n,e,t)),o?(i||null==s||wjcCore.isPrimitive(s)||(r?r.format=s.format:this._applyStyleForCell(e,t,{format:s.format})),s=this._formatEvaluatedResult(s,l,i)):null==s||wjcCore.isPrimitive(s)||(s=s.value),null==s?"":s}showFunctionList(e){var t,o,n=this,i=n._cumulativeOffset(e),s=n._cumulativeOffset(n._root);n._functionTarget=wjcCore.tryCast(e,HTMLInputElement),n._functionTarget&&n._functionTarget.value&&"="===n._functionTarget.value[0]?(n._functionList._cv.filter=(e=>{var t,o=e.actualvalue.toLowerCase(),i=n._getCurrentFormulaIndex(n._functionTarget.value);return-1===i&&(i=0),(t=n._functionTarget.value.substr(i+1).trim().toLowerCase()).length>0&&0===o.indexOf(t)||"="===n._functionTarget.value}),n._functionList.selectedIndex=0,t=i.y+e.clientHeight+2+(wjcCore.hasClass(e,"wj-grid-editor")?this._ptScrl.y:0),o=i.x+(wjcCore.hasClass(e,"wj-grid-editor")?this._ptScrl.x:0),wjcCore.setCss(n._functionListHost,{height:n._functionList._cv.items.length>5?"218px":"auto",display:n._functionList._cv.items.length>0?"block":"none",top:"",left:""}),n._functionListHost.scrollTop=0,n._functionListHost.offsetHeight+t>s.y+n._root.offsetHeight?t=t-e.clientHeight-n._functionListHost.offsetHeight-5:t+=5,n._functionListHost.offsetWidth+o>s.x+n._root.offsetWidth&&(o=s.x+n._root.offsetWidth-n._functionListHost.offsetWidth),wjcCore.setCss(n._functionListHost,{top:t,left:o})):n.hideFunctionList()}hideFunctionList(){this._functionListHost.style.display="none"}selectPreviousFunction(){this._functionList.selectedIndex>0&&this._functionList.selectedIndex--}selectNextFunction(){this._functionList.selectedIndex<this._functionList.itemsSource.length&&this._functionList.selectedIndex++}applyFunctionToCell(){var e,t=this;t._functionTarget&&(-1===(e=t._getCurrentFormulaIndex(t._functionTarget.value))?e=t._functionTarget.value.indexOf("="):e+=1,t._functionTarget.value=t._functionTarget.value.substring(0,e)+t._functionList.selectedValue+"(","="!==t._functionTarget.value[0]&&(t._functionTarget.value="="+t._functionTarget.value),t._functionTarget.focus(),t.hideFunctionList())}save(e){var t=this._saveToWorkbook();return e&&t.save(e),t}saveAsync(e,t,o){var n=this._saveToWorkbook();return n.saveAsync(e,t,o),n}saveToWorkbookOM(){return this._saveToWorkbook()._serialize()}load(e){var t,o,n=this;if(e instanceof Blob)(o=new FileReader).onload=(()=>{var e=o.result;e=wjcXlsx.Workbook._base64EncArr(new Uint8Array(e)),(t=new wjcXlsx.Workbook).load(e),n._loadFromWorkbook(t)}),o.readAsArrayBuffer(e);else if(e instanceof wjcXlsx.Workbook)n._loadFromWorkbook(e);else{if(e instanceof ArrayBuffer)e=wjcXlsx.Workbook._base64EncArr(new Uint8Array(e));else if(!wjcCore.isString(e))throw"Invalid workbook.";(t=new wjcXlsx.Workbook).load(e),n._loadFromWorkbook(t)}}loadAsync(e,t,o){var n,i,s=this;if(e instanceof Blob)(i=new FileReader).onload=(()=>{var e=i.result;e=wjcXlsx.Workbook._base64EncArr(new Uint8Array(e)),(n=new wjcXlsx.Workbook).loadAsync(e,e=>{s._loadFromWorkbook(e),t&&t(e)},o)}),i.readAsArrayBuffer(e);else if(e instanceof wjcXlsx.Workbook)s._loadFromWorkbook(e),t&&t(e);else{if(e instanceof ArrayBuffer)e=wjcXlsx.Workbook._base64EncArr(new Uint8Array(e));else if(!wjcCore.isString(e))throw"Invalid workbook.";(n=new wjcXlsx.Workbook).loadAsync(e,e=>{s._loadFromWorkbook(e),t&&t(e)},o)}}loadFromWorkbookOM(e){var t;e instanceof wjcXlsx.Workbook?t=e:(t=new wjcXlsx.Workbook)._deserialize(e),this._loadFromWorkbook(t)}undo(){var e=this;setTimeout(()=>{e._undoStack.undo()},100)}redo(){var e=this;setTimeout(()=>{e._undoStack.redo()},100)}select(e,t=!0){var o,n,i;if(wjcCore.isNumber(e)&&wjcCore.isNumber(t)&&(e=new wjcGrid.CellRange(e,t),t=!0),e.rowSpan!==this.rows.length&&e.columnSpan!==this.columns.length)for(n=e.topRow;n<=e.bottomRow;n++)for(i=e.leftCol;i<=e.rightCol;i++)(o=this.getMergedRange(this.cells,n,i))&&!e.equals(o)&&(e.row<=e.row2?(e.row=Math.min(e.topRow,o.topRow),e.row2=Math.max(e.bottomRow,o.bottomRow)):(e.row=Math.max(e.bottomRow,o.bottomRow),e.row2=Math.min(e.topRow,o.topRow)),e.col<=e.col2?(e.col=Math.min(e.leftCol,o.leftCol),e.col2=Math.max(e.rightCol,o.rightCol)):(e.col=Math.max(e.rightCol,o.rightCol),e.col2=Math.min(e.leftCol,o.leftCol)));this._isPasting&&this.collectionView&&(this.collectionView._pendingRefresh=!1),super.select(e,t)}addCustomFunction(e,t,o,n,i){wjcCore._deprecated("addCustomFunction","addFunction"),this._calcEngine.addCustomFunction(e,t,n,i),this._addCustomFunctionDescription(e,o)}addFunction(e,t,o,n,i){this._calcEngine.addFunction(e,t,n,i),this._addCustomFunctionDescription(e,o)}dispose(){var e=window.navigator.userAgent;this._needCopyToSheet=!1,document.removeEventListener("mousemove",this._mouseMoveHdl),document.body.removeEventListener("click",this._clickHdl),(e.match(/iPad/i)||e.match(/iPhone/i))&&(document.body.removeEventListener("touchstart",this._touchStartHdl),document.body.removeEventListener("touchend",this._touchEndHdl)),this.hideFunctionList(),super.dispose()}getClipString(e){var t,o,n,i,s,l,r="",a=!0;if(!this.selectedSheet)return super.getClipString(e);if(this._isCutting=!1,!e)if(this.selectedSheet.selectionRanges.length>1){if(this._isMultipleRowsSelected()){for(r="",0===(t=this.selectedSheet.selectionRanges.slice(0)).length&&(t=[this.selection]),t.sort(this._sortByRow),n=0;n<t.length;n++)r&&(r+="\n"),r+=this.getClipString(t[n]);return r}if(this._isMultipleColumnsSelected()){for(r="",0===(t=this.selectedSheet.selectionRanges.slice(0)).length&&(t=[this.selection]),t.sort(this._sortByColumn),o=(i=t[0]).topRow,a=!0;o<=i.bottomRow;o++)for(a||(r+="\n"),a=!1,n=0,_=!0;n<t.length;n++)s=t[n],_||(r+="\t"),_=!1,r+=this.getClipString(new wjcGrid.CellRange(o,s.col,o,s.col2));return r}wjcCore.assert(!1,"Copy or Cut operation cannot be used on multiple selections.")}else switch(e=this.selection,this.selectionMode){case wjcGrid.SelectionMode.Row:case wjcGrid.SelectionMode.RowRange:e.col=0,e.col2=this.columns.length-1;break;case wjcGrid.SelectionMode.ListBox:e.col=0,e.col2=this.columns.length-1;for(var h=0;h<this.rows.length;h++)this.rows[h].isSelected&&this.rows[h].isVisible&&(e.row=e.row2=h,r&&(r+="\n"),r+=this.getClipString(e));return r}if(!(e=wjcCore.asType(e,wjcGrid.CellRange)).isValid)return"";for(var d=e.topRow,a=!0;d<=e.bottomRow;d++)if(this.rows[d].isVisible){a||(r+="\n"),a=!1;for(var c=e.leftCol,_=!0;c<=e.rightCol;c++)this.columns[c].isVisible&&(_||(r+="\t"),_=!1,(l=(l=this.getCellValue(d,c,!0).toString()).replace(/\t/g," ")).indexOf("\n")>-1&&(l='"'+l.replace(/"/g,'""')+'"'),r+=l)}return r}setClipString(e,t){var o,n,i,s,l,r,a,h,d,c,_,u,g,w,m,C,f,p,S,b,R,y=null==t,v=!1,T=!1;if(this.selectedSheet){if(t=t?wjcCore.asType(t,wjcGrid.CellRange):this.selection,(e=wjcCore.asString(e).replace(/\r\n/g,"\n").replace(/\r/g,"\n"))&&"\n"==e[e.length-1]&&(e=e.substring(0,e.length-1)),S=e,r=this._edtHdl._parseClipString(wjcCore.asString(e)),y&&!t.isSingleCell&&r.length&&this._edtHdl._expandClipRows(r,t),T=this._containsMultiLineText(r),(!this._copiedRanges||0===this._copiedRanges.length||S.trim()!==this._getRangeString(this._copiedRanges,this._copiedSheet).trim()&&!this._containsRandFormula(this._copiedRanges,this._copiedSheet)||this._cutValue)&&!T)return S!==this._cutValue&&(this._cutValue=null,super.setClipString(e)),this._copiedRanges=null,void(this._copiedSheet=null);if(o=new wjcGrid.CellRange(t.topRow,t.leftCol),this.beginUpdate(),T||!this._copiedRanges||this._copiedRanges.length>1||0===this._copiedRanges.length)for(n=t.topRow,s=(C=this._copiedRanges&&this._copiedRanges.length>1?this._copiedRanges[0]:new wjcGrid.CellRange).topRow,d=0;d<r.length&&n<this.rows.length;d++,n++)if(this.rows[n].isVisible){for(a=r[d],l=C.leftCol,u=(i=t.leftCol)-l,c=0;c<a.length&&i<this.columns.length;c++,i++)this.columns[i].isVisible?(h=a[c],this.columns[i].isReadOnly||this.rows[n].isReadOnly||(v=this._postSetClipStringProcess(h,n,i,s,l),o.row2=Math.max(o.row2,n),o.col2=Math.max(o.col2,i)),l>=0&&l++):c--;s>=0&&s++}else d--;else if(this._copiedRanges&&1===this._copiedRanges.length)for(f=0,(C=this.selectionMode===wjcGrid.SelectionMode.ListBox?this._getSelectionForListBoxMode(this._copiedSheet.grid):this._copiedRanges[0]).rowSpan>t.rowSpan?C.rowSpan:t.rowSpan,C.columnSpan>t.columnSpan?C.columnSpan:t.columnSpan,n=t.topRow,d=0;d<r.length&&n<this.rows.length;d++,n++)if(p=0,this.rows[n].isVisible){for(;this._copiedSheet.grid.rows[C.topRow+f]&&!this._copiedSheet.grid.rows[C.topRow+f].isVisible;)f++;if(f>=C.rowSpan&&(f%=C.rowSpan),!this._copiedSheet.grid.rows[C.topRow+f])break;for(_=n-C.topRow-f,a=r[d],i=t.leftCol,c=0;c<a.length&&i<this.columns.length;c++,i++)if(this.columns[i]&&this.columns[i].isVisible){if(p>=C.columnSpan&&(p%=C.columnSpan),!this._copiedSheet.grid.columns[C.leftCol+p])break;if(u=i-C.leftCol-p,!this.columns[i].isReadOnly&&!this.rows[n].isReadOnly){if(b=null!=this._copiedSheet.grid.columns[C.leftCol+p].dataMap,h=this._copiedSheet.grid.getCellData(C.topRow+f,C.leftCol+p,b),R=this._getCellStyle(C.topRow+f,C.leftCol+p,this._copiedSheet),h&&"string"==typeof h&&"="===h[0]&&(0!==_||0!==u))try{g=this._calcEngine._checkCache(h,this.selectedSheetIndex,C.topRow+f,C.leftCol+p),w=new wjcGrid.CellRange(C.topRow+f,C.leftCol+p),m=new wjcGrid.CellRange(C.topRow+f+_,C.leftCol+p+u),g._moveCellRangeExp(this.selectedSheetIndex,w,m,!1,!0)&&(h="="+g._getStringExpression())}catch(e){}this._copiedSheet.grid.columns[C.leftCol+p].format&&(R?R.format||(R.format=this._copiedSheet.grid.columns[C.leftCol+p].format):R={format:this._copiedSheet.grid.columns[C.leftCol+p].format}),v=this._postSetClipStringProcess(h,n,i,C.topRow+f,C.leftCol+p,R),o.row2=Math.max(o.row2,n),o.col2=Math.max(o.col2,i)}p++}else c--;f++}else d--;this._isCutting&&(this._delCutData(),this._isCutting=!1,this._cutValue=S,this._copiedRanges=null,this._copiedSheet=null),this.endUpdate(),this.collectionView&&v&&this.collectionView.refresh(),this.select(o)}else super.setClipString(e,t)}getBuiltInTableStyle(e){var t;return null==this._builtInTableStylesCache&&(this._builtInTableStylesCache={}),null==(t=this._builtInTableStylesCache[e.toLowerCase()])&&(t=this._createBuiltInTableStyle(e),Object.freeze(t),this._builtInTableStylesCache[e.toLowerCase()]=t),t}_getCvIndex(e){return e>-1&&this.collectionView?this.rows[e]instanceof HeaderRow?e:super._getCvIndex(e):-1}_init(){var e=this,t=window.navigator.userAgent,o=t=>{document.removeEventListener("mouseup",o),e._mouseUp(t)};e.hostElement.setAttribute("tabindex","-1"),e._divContainer=e.hostElement.querySelector('[wj-part="container"]'),e._tabHolder=new _TabHolder(e.hostElement.querySelector('[wj-part="tab-holder"]'),e),e._contextMenu=new _ContextMenu(e.hostElement.querySelector('[wj-part="context-menu"]'),e),e._gpCells=new FlexSheetPanel(e,wjcGrid.CellType.Cell,e.rows,e.columns,e._eCt),e._gpCHdr=new FlexSheetPanel(e,wjcGrid.CellType.ColumnHeader,e._hdrRows,e.columns,e._eCHdrCt),e._gpRHdr=new FlexSheetPanel(e,wjcGrid.CellType.RowHeader,e.rows,e._hdrCols,e._eRHdrCt),e._gpTL=new FlexSheetPanel(e,wjcGrid.CellType.TopLeft,e._hdrRows,e._hdrCols,e._eTLCt),e._sortManager=new SortManager(e),e._filter=new FlexSheetFilter(e),e._filter.filterApplied.addHandler(()=>{e.selectedSheet&&(e.selectedSheet._filterDefinition=e._filter.filterDefinition,e.selectedSheet.itemsSource&&(e.selectedSheet._storeRowSettings(),e.selectedSheet._setRowSettings()))}),e._calcEngine=new _CalcEngine(e),e._calcEngine.unknownFunction.addHandler((t,o)=>{e.onUnknownFunction(o)},e),e._initFuncsList(),e._undoStack=new UndoStack(e),e.loadedRows.addHandler(()=>{if(e.itemsSource&&!(e.rows[0]instanceof HeaderRow)){for(var t,o=new HeaderRow,n=0;n<e.columns.length;n++)t=e.columns[n],o._ubv||(o._ubv={}),o._ubv[t._hash]=t.header;e.rows[0]instanceof wjcGrid._NewRowTemplate&&e.newRowAtTop?e.rows.insert(1,o):e.rows.insert(0,o)}e._filter&&e._filter.apply()}),e.itemsSourceChanged.addHandler(()=>{var t;for(t=0;t<e.columns.length;t++)e.columns[t].isRequired=!1;e.collectionView&&e.collectionView.currentChanged.removeHandler(this._cvCurrentChanged,this)}),e.copied.addHandler((t,o)=>{var n;e.selectedSheet&&(e._copiedSheet=e.selectedSheet,e._needCopyToSheet=!0,e.selectedSheet.selectionRanges.length>1?e._isMultipleRowsSelected()?((n=e.selectedSheet.selectionRanges.slice(0)).sort(e._sortByRow),e._copiedRanges=n):e._isMultipleColumnsSelected()?((n=e.selectedSheet.selectionRanges.slice(0)).sort(e._sortByColumn),e._copiedRanges=n):wjcCore.assert(!1,"Copy operation cannot be used on multiple selections."):e._copiedRanges=[o.range])}),e.rows.collectionChanged.addHandler((t,o)=>{e._clearForEmptySheet("rows"),e.itemsSource||!e.selectedSheet||!e._needCopyToSheet||e._isCopying||e._isUndoing||o.item instanceof wjcGrid._NewRowTemplate||e._copyRowsToSelectedSheet()},e),e.columns.collectionChanged.addHandler((t,o)=>{e._clearForEmptySheet("columns"),e.selectedSheet&&e._needCopyToSheet&&!e._isCopying&&!e._isUndoing&&e._copyColumnsToSelectedSheet()},e),e.definedNames.collectionChanged.addHandler((t,o)=>{if(o.action===wjcCore.NotifyCollectionChangedAction.Add||o.action===wjcCore.NotifyCollectionChangedAction.Change){var n=o.action===wjcCore.NotifyCollectionChangedAction.Add?"inserted":"updated";if(!(o.item instanceof DefinedName))throw e.definedNames.remove(o.item),"Invalid defined name item object was "+n+".  The DefinedName instance should be "+n+" in the definedNames array.";if(!o.item||!o.item.name||null==o.item.value)throw e.definedNames.remove(o.item),"Invalid defined name was "+n+".";if(null!=o.item.sheetName&&!e._validateSheetName(o.item.sheetName))throw e.definedNames.remove(o.item),"The sheet name ("+o.item.sheetName+") does not exist in FlexSheet.";if(e._checkExistDefinedName(o.item.name,o.item.sheetName,o.index))throw e.definedNames.remove(o.item),"The "+o.item.name+" already existed in definedNames."}}),e.addEventListener(e.hostElement,"mousedown",t=>{document.addEventListener("mouseup",o),e._isDescendant(e._divContainer,t.target)&&e._mouseDown(t)},!0),e.addEventListener(e.hostElement,"drop",()=>{e._columnHeaderClicked=!1}),e.addEventListener(e.hostElement,"contextmenu",t=>{var o,n,i,s,l,r,a,h,d;!t.defaultPrevented&&e.selectedSheet&&(e.activeEditor||(e._isContextMenuKeyDown&&e.selection.row>-1&&e.selection.col>-1&&e.rows.length>0&&e.columns.length>0?(i=e.columns[e.selection.col],n=e.rows[e.selection.row],a=e._cumulativeOffset(e.hostElement),h=e._cumulativeScrollOffset(e.hostElement),s=i.pos+e._eCt.offsetLeft+a.x+i.renderSize/2+e._ptScrl.x,l=n.pos+e._eCt.offsetTop+a.y+n.renderSize/2+e._ptScrl.y,r=new wjcCore.Point(s-h.x,l-h.y),o=e.hitTest(s,l),e._isContextMenuKeyDown=!1):o=e.hitTest(t),t.preventDefault(),o&&o.cellType!==wjcGrid.CellType.None&&(d=new wjcGrid.CellRange(o.row,o.col),o.cellType!==wjcGrid.CellType.Cell||d.intersects(e.selection)||(e.selection=d,e.selectedSheet&&(e.selectedSheet.selectionRanges.clear(),e.selectedSheet.selectionRanges.push(d))),e._contextMenu.show(t,r))))}),e.prepareCellForEdit.addHandler(e._prepareCellForEditHandler,e),e.cellEditEnded.addHandler((t,o)=>{(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)&&setTimeout(()=>{e.hideFunctionList()},200)}),e.cellEditEnding.addHandler((t,o)=>{(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)&&e._clearCalcEngine()}),e.pasting.addHandler(()=>{e._needCopyToSheet=!1,e._isPasting=!0}),e.pasted.addHandler(()=>{e.selection;e._needCopyToSheet=!0,e._isPasting=!1,e._clearCalcEngine()}),e.resizingColumn.addHandler(()=>{e._resizing=!0}),e.resizingRow.addHandler(()=>{e._resizing=!0}),e.resizedColumn.addHandler(()=>{e._resizing=!1}),e.resizedRow.addHandler(()=>{e._resizing=!1}),e.selectionChanged.addHandler(()=>{let t=e.selection;e._isCopying||!t.isValid||e.containsFocus()||e.hostElement.focus(),t.rightCol>=e.columns.length&&(e.selection=new wjcGrid.CellRange(t.row,Math.min(t.col,e.columns.length-1),t.row2,Math.min(e.selection.col2,e.columns.length-1))),e._enableMulSel||e._isCopying||!e.selectedSheet||e.selectedSheet.selectionRanges.clear()}),e.addEventListener(e.hostElement,"keydown",t=>{var o,n,i=!1,s=!1;if(t.ctrlKey){if(89===t.keyCode&&(e.finishEditing(),e.redo(),t.preventDefault()),90===t.keyCode&&(e.finishEditing(),e.undo(),t.preventDefault()),e.selectedSheet&&65===t.keyCode&&(e.selectedSheet.selectionRanges.clear(),e.selectedSheet.selectionRanges.push(e.selection)),67!==t.keyCode&&45!=t.keyCode||(e.activeEditor&&(e._copiedRanges=null,e._copiedSheet=null),e._cutValue=null),88===t.keyCode&&!e.activeEditor){if(t.stopPropagation(),e.selectionMode===wjcGrid.SelectionMode.ListBox)for(var l=0;l<e.rows.length;l++)if(e.rows[l].isSelected)if(i){if(s)continue;wjcCore.assert(!1,"Cut operation cannot be used on multiple selections.")}else i=!0,s=!0;else s&&(s=!1);1===e.selectedSheet.selectionRanges.length?(e.finishEditing(),o=new wjcGrid.CellRangeEventArgs(e.cells,e.selection),e.onCopying(o)&&(e._cutValue=null,n=e.getClipString(),e._isCutting=!0,wjcCore.Clipboard.copy(n),e.onCopied(o))):wjcCore.assert(!1,"Cut operation cannot be used on multiple selections.")}t.keyCode===wjcCore.Key.Space&&e.selection.isValid&&e.selectionMode===wjcGrid.SelectionMode.CellRange&&e.select(new wjcGrid.CellRange(0,e.selection.col,e.rows.length-1,e.selection.col))}if(t.keyCode===wjcCore.Key.Escape&&e._contextMenu.hide(),(93===t.keyCode||t.shiftKey&&121===t.keyCode)&&(e._isContextMenuKeyDown=!0),e.selectedSheet&&!e._edtHdl.activeEditor)switch(t.keyCode){case wjcCore.Key.Left:case wjcCore.Key.Right:case wjcCore.Key.Up:case wjcCore.Key.Down:case wjcCore.Key.PageUp:case wjcCore.Key.PageDown:case wjcCore.Key.Home:case wjcCore.Key.End:case wjcCore.Key.Tab:case wjcCore.Key.Enter:e.scrollIntoView(e.selection.row,e.selection.col),e.selectedSheet._addSelection(e.selection)}}),e.addEventListener(document.body,"keydown",t=>{!e._isDescendant(e.hostElement,t.target)&&e.hostElement!==t.target||e._edtHdl.activeEditor||!e.selectedSheet||t.keyCode!==wjcCore.Key.Delete&&t.keyCode!==wjcCore.Key.Back||(e._delSeletionContent(t),t.preventDefault()),e._contextMenu.visible&&(t.keyCode===wjcCore.Key.Down&&e._contextMenu.moveToNext(),t.keyCode===wjcCore.Key.Up&&e._contextMenu.moveToPrev(),t.keyCode===wjcCore.Key.Home&&e._contextMenu.moveToFirst(),t.keyCode===wjcCore.Key.End&&e._contextMenu.moveToLast(),t.keyCode===wjcCore.Key.Enter&&e._contextMenu.handleContextMenu(),t.preventDefault())},!0),document.body.addEventListener("click",e._clickHdl),document.addEventListener("mousemove",e._mouseMoveHdl),(t.match(/iPad/i)||t.match(/iPhone/i))&&(document.body.addEventListener("touchstart",e._touchStartHdl),document.body.addEventListener("touchend",e._touchEndHdl)),e.addEventListener(e.hostElement,"drop",()=>{e._htDown=null})}_initFuncsList(){var e=this;e._functionListHost=document.createElement("div"),wjcCore.addClass(e._functionListHost,"wj-flexsheet-formula-list"),document.querySelector("body").appendChild(e._functionListHost),e._functionListHost.style.display="none",e._functionListHost.style.position="absolute",e._functionList=new wjcInput.ListBox(e._functionListHost),e._functionList.isContentHtml=!0,e._functionList.itemsSource=e._getFunctions(),e._functionList.displayMemberPath="displayValue",e._functionList.selectedValuePath="actualvalue",e.addEventListener(e._functionListHost,"click",e.applyFunctionToCell.bind(e)),e.addEventListener(e._functionListHost,"keydown",t=>{t.keyCode===wjcCore.Key.Escape&&(e.hideFunctionList(),e.hostElement.focus(),t.preventDefault()),t.keyCode===wjcCore.Key.Enter&&(e.applyFunctionToCell(),e.hostElement.focus(),t.preventDefault(),t.stopPropagation())})}_getFunctions(){for(var e,t=[],o=0;o<FlexSheetFunctions.length;o++)e=FlexSheetFunctions[o],t.push({displayValue:'<div class="wj-flexsheet-formula-name">'+e.name+'</div><div class="wj-flexsheet-formula-description">'+e.description+"</div>",actualvalue:e.name});return t}_addCustomFunctionDescription(e,t){for(var o={displayValue:'<div class="wj-flexsheet-formula-name">'+e+"</div>"+(t?'<div class="wj-flexsheet-formula-description">'+t+"</div>":""),actualvalue:e},n=this._functionList.itemsSource,i=-1,s=0;s<n.length;s++)if(n[s].actualvalue===e){i=s;break}i>-1?n.splice(i,1,o):n.push(o)}_getCurrentFormulaIndex(e){var t=-1;return["+","-","*","/","^","(","&"].forEach(o=>{var n=e.lastIndexOf(o);n>t&&(t=n)}),t}_prepareCellForEditHandler(){var e=this,t=e._edtHdl._edt;t&&(e.addEventListener(t,"keydown",t=>{if(e.isFunctionListOpen)switch(t.keyCode){case wjcCore.Key.Up:e.selectPreviousFunction(),t.preventDefault(),t.stopPropagation();break;case wjcCore.Key.Down:e.selectNextFunction(),t.preventDefault(),t.stopPropagation();break;case wjcCore.Key.Tab:case wjcCore.Key.Enter:e.applyFunctionToCell(),t.preventDefault(),t.stopPropagation();break;case wjcCore.Key.Escape:e.hideFunctionList(),t.preventDefault(),t.stopPropagation()}}),e.addEventListener(t,"keyup",o=>{(o.keyCode>40||o.keyCode<32)&&o.keyCode!==wjcCore.Key.Tab&&o.keyCode!==wjcCore.Key.Escape&&setTimeout(()=>{e.showFunctionList(t)},0)}))}_addSheet(e,t,o,n,i){var s=this,l=new Sheet(s,i,e,t,o);return s.sheets.isValidSheetName(l)||l._setValidName(s.sheets.getValidSheetName(l)),l.nameChanged.addHandler((e,t)=>{s._updateDefinedNameWithSheetRefUpdating(t.oldValue,t.newValue)}),"number"==typeof n?(n<0&&(n=0),n>=s.sheets.length&&(n=s.sheets.length)):n=s.sheets.length,s.sheets.insert(n,l),l}_showSheet(e){!this.sheets||!this.sheets.length||e>=this.sheets.length||e<0||e===this.selectedSheetIndex||this.sheets[e]&&!this.sheets[e].visible||(this.finishEditing(),this._clearCalcEngine(),this._isCopying=!0,this.selectedSheetIndex>-1&&this.selectedSheetIndex<this.sheets.length&&this._copyTo(this.sheets[this.selectedSheetIndex]),this.sheets[e]&&(this._selectedSheetIndex=e,this._copyFrom(this.sheets[e])),this._isCopying=!1,this._filter.closeEditor())}_selectedSheetChange(e,t){this._showSheet(t.newValue),this.invalidate(!0),this.onSelectedSheetChanged(t)}_sourceChange(e,t){if(t.action===wjcCore.NotifyCollectionChangedAction.Add||t.action===wjcCore.NotifyCollectionChangedAction.Change)t.item._attachOwner(this),t.action===wjcCore.NotifyCollectionChangedAction.Add?(this._addingSheet=!0,t.index<=this.selectedSheetIndex&&(this._selectedSheetIndex+=1)):t.index===this.selectedSheetIndex&&this._copyFrom(t.item,!0),this.selectedSheetIndex=t.index;else if(t.action===wjcCore.NotifyCollectionChangedAction.Reset){for(var o=0;o<this.sheets.length;o++)this.sheets[o]._attachOwner(this);this.sheets.length>0?(0===this.selectedSheetIndex&&this._copyFrom(this.selectedSheet,!0),this.selectedSheetIndex=0):(this.rows.clear(),this.columns.clear(),this._selectedSheetIndex=-1)}else this.sheets.length>0?this.selectedSheetIndex>=this.sheets.length?this.selectedSheetIndex=0:this.selectedSheetIndex>t.index&&(this._selectedSheetIndex-=1):(this.rows.clear(),this.columns.clear(),this._selectedSheetIndex=-1);this.invalidate(!0)}_sheetVisibleChange(e,t){t.item.visible||t.index===this.selectedSheetIndex&&(this.selectedSheetIndex===this.sheets.length-1?this.selectedSheetIndex=t.index-1:this.selectedSheetIndex=t.index+1)}_applyStyleForCell(e,t,o){var n,i,s,l=this,r=l.rows[e];null==r||r instanceof HeaderRow||!r.isVisible||(s=e*l.columns.length+t,(i=l.selectedSheet._getMergedRange(e,t))&&(s=i.topRow*l.columns.length+i.leftCol),(n=l.selectedSheet._styledCells[s])?(n.className="normal"===o.className?"":o.className||n.className,n.textAlign=o.textAlign||n.textAlign,n.verticalAlign=o.verticalAlign||n.verticalAlign,n.fontFamily=o.fontFamily||n.fontFamily,n.fontSize=o.fontSize||n.fontSize,n.backgroundColor=o.backgroundColor||n.backgroundColor,n.color=o.color||n.color,n.fontStyle="none"===o.fontStyle?"":o.fontStyle||n.fontStyle,n.fontWeight="none"===o.fontWeight?"":o.fontWeight||n.fontWeight,n.textDecoration="none"===o.textDecoration?"":o.textDecoration||n.textDecoration,n.format=o.format||n.format,n.whiteSpace=o.whiteSpace||n.whiteSpace,n.borderTopColor=o.borderTopColor||n.borderTopColor,n.borderTopStyle=o.borderTopStyle||n.borderTopStyle,n.borderTopWidth=o.borderTopWidth||n.borderTopWidth,n.borderBottomColor=o.borderBottomColor||n.borderBottomColor,n.borderBottomStyle=o.borderBottomStyle||n.borderBottomStyle,n.borderBottomWidth=o.borderBottomWidth||n.borderBottomWidth,n.borderLeftColor=o.borderLeftColor||n.borderLeftColor,n.borderLeftStyle=o.borderLeftStyle||n.borderLeftStyle,n.borderLeftWidth=o.borderLeftWidth||n.borderLeftWidth,n.borderRightColor=o.borderRightColor||n.borderRightColor,n.borderRightStyle=o.borderRightStyle||n.borderRightStyle,n.borderRightWidth=o.borderRightWidth||n.borderRightWidth):l.selectedSheet._styledCells[s]={className:o.className,textAlign:o.textAlign,verticalAlign:o.verticalAlign,fontStyle:o.fontStyle,fontWeight:o.fontWeight,fontFamily:o.fontFamily,fontSize:o.fontSize,textDecoration:o.textDecoration,backgroundColor:o.backgroundColor,color:o.color,format:o.format,whiteSpace:o.whiteSpace,borderTopColor:o.borderTopColor,borderTopStyle:o.borderTopStyle,borderTopWidth:o.borderTopWidth,borderBottomColor:o.borderBottomColor,borderBottomStyle:o.borderBottomStyle,borderBottomWidth:o.borderBottomWidth,borderLeftColor:o.borderLeftColor,borderLeftStyle:o.borderLeftStyle,borderLeftWidth:o.borderLeftWidth,borderRightColor:o.borderRightColor,borderRightStyle:o.borderRightStyle,borderRightWidth:o.borderRightWidth})}_checkCellFormat(e,t,o){var n,i,s=e*this.columns.length+t;this.selectedSheet&&((n=this.selectedSheet._getMergedRange(e,t))&&(o.isMergedCell=!0,s=n.topRow*this.columns.length+n.leftCol),(i=this.selectedSheet._styledCells[s])&&(o.isBold=o.isBold||"bold"===i.fontWeight,o.isItalic=o.isItalic||"italic"===i.fontStyle,o.isUnderline=o.isUnderline||"underline"===i.textDecoration),e===this.selection.row&&t===this.selection.col&&(i&&i.textAlign?o.textAlign=i.textAlign:t>-1&&(o.textAlign=this.columns[t].getAlignment()||o.textAlign)))}_resetMergedRange(e){var t,o,n,i,s=!1;for(t=e.topRow;t<=e.bottomRow;t++)for(o=e.leftCol;o<=e.rightCol;o++)(i=this.selectedSheet._getMergedRange(t,o))&&(s=!0,n=this.selectedSheet._mergedRanges.indexOf(i),this.selectedSheet._mergedRanges.splice(n,1));return s}_updateCellsForUpdatingRow(e,t,o,n){var i,s,l,r,a,h,d,c=e*this.columns.length;if(n)for(s=i=t*this.columns.length;s<c;s++)l=s-o*this.columns.length,(r=this.selectedSheet._styledCells[s])&&(s>=(t+o)*this.columns.length&&(this.selectedSheet._styledCells[l]=r),delete this.selectedSheet._styledCells[s]);else for(i=t*this.columns.length-1,s=c-1;s>i;s--)l=s+this.columns.length*o,(r=this.selectedSheet._styledCells[s])&&(this.selectedSheet._styledCells[l]=r,delete this.selectedSheet._styledCells[s]);if(this.selectedSheet._mergedRanges.length>0)for(h=this.selectedSheet._mergedRanges.length-1;h>=0;h--)a=this.selectedSheet._mergedRanges[h],n?(d=t+o-1)<a.topRow?(a.row-=o,a.row2-=o):d>=a.topRow&&d<=a.bottomRow?t<=a.topRow&&d>=a.bottomRow?this.selectedSheet._mergedRanges.splice(h,1):t<a.topRow?a.row<=a.row2?(a.row+=t-a.topRow,a.row2-=o):(a.row2+=t-a.topRow,a.row-=o):t===a.topRow&&o===a.rowSpan?this.selectedSheet._mergedRanges.splice(h,1):a.row<=a.row2?a.row2-=o:a.row-=o:t<=a.topRow?this.selectedSheet._mergedRanges.splice(h,1):t<=a.bottomRow&&(a.row<=a.row2?a.row2+=t-a.bottomRow-1:a.row+=t-a.bottomRow-1):t<=a.topRow?(a.row+=o,a.row2+=o):t>a.topRow&&t<=a.bottomRow&&(a.row<=a.row2?a.row2+=o:a.row+=o)}_updateCellsForUpdatingColumn(e,t,o,n){var i,s,l,r,a,h,d,c=this.rows.length*e;if(n)for(i=t;i<c;i++)s=i-o*(Math.floor(i/e)+((r=i%e)>=t?1:0)),(l=this.selectedSheet._styledCells[i])&&((r<t||r>=t+o)&&(this.selectedSheet._styledCells[s]=l),delete this.selectedSheet._styledCells[i]);else for(i=c-1;i>=t;i--)s=i+Math.floor(i/e)*o+((r=i%e)>=t?1:0),(l=this.selectedSheet._styledCells[i])&&(this.selectedSheet._styledCells[s]=l,delete this.selectedSheet._styledCells[i]);if(this.selectedSheet._mergedRanges.length>0)for(h=this.selectedSheet._mergedRanges.length-1;h>=0;h--)a=this.selectedSheet._mergedRanges[h],n?(d=t+o-1)<a.leftCol?(a.col-=o,a.col2-=o):d>=a.leftCol&&d<=a.rightCol?t<=a.leftCol&&d>=a.rightCol?this.selectedSheet._mergedRanges.splice(h,1):t<a.leftCol?a.col<=a.col2?(a.col+=t-a.leftCol,a.col2-=o):(a.col2+=t-a.leftCol,a.col-=o):t===a.leftCol&&o===a.columnSpan?this.selectedSheet._mergedRanges.splice(h,1):a.col<=a.col2?a.col2-=o:a.col-=o:t<=a.leftCol?this.selectedSheet._mergedRanges.splice(h,1):t<=a.rightCol&&(a.col<=a.col2?a.col2-=a.rightCol-t+1:a.col-=a.rightCol-t+1):t<=a.leftCol?(a.col+=o,a.col2+=o):t>a.leftCol&&t<=a.rightCol&&(a.col<=a.col2?a.col2+=o:a.col+=o)}_cloneObject(e){var t;if(null==e||!wjcCore.isObject(e))return e;t={};for(var o in e)e.hasOwnProperty(o)&&e[o]&&(e[o].clone?t[o]=e[o].clone():t[o]=this._cloneObject(e[o]));return t}_evaluate(e,t,o,n,i){return e&&e.length>1?(e="="===e[0]?e:"="+e,this._calcEngine.evaluate(e,t,o,n,i)):e}_copyTo(e){var t,o,n,i=this,s=e.grid.autoGenerateColumns;if(e._storeRowSettings(),n=this.selection.clone(),e.grid.selection=new wjcGrid.CellRange,e.grid.rows.clear(),e.grid.columns.clear(),e.grid.columnHeaders.columns.clear(),e.grid.rowHeaders.rows.clear(),i.itemsSource)e.grid.autoGenerateColumns=!1,e.itemsSource=i.itemsSource,e.grid.collectionView.beginUpdate();else for(e.itemsSource=null,o=0;o<i.rows.length;o++)e.grid.rows.push(i.rows[o]);for(e._sortList=i.sortManager._committedList.slice(),e._getFilterSetting(),t=0;t<i.columns.length;t++)e.grid.columns.push(i.columns[t]);e.grid.collectionView&&(i._resetMappedColumns(e.grid),e.grid.collectionView.endUpdate()),e.grid.loadedRows.addHandler(()=>{e._setRowSettings()}),e.grid.autoGenerateColumns=s,e.grid.frozenRows=i.frozenRows,e.grid.frozenColumns=i.frozenColumns,e.grid.allowAddNew=i.allowAddNew,null!=i.newRowAtTop&&(e.grid.newRowAtTop=i.newRowAtTop),e.grid.selection=n,e._scrollPosition=i.scrollPosition,setTimeout(()=>{i._setFlexSheetToDirty(),i.refresh(!0)},10)}_copyFrom(e,t=!0){var o,n,i,s,l,r,a=this,h=a.autoGenerateColumns;if(a._isCopying=!0,a._dragable=!1,a.itemsSource=null,a.rows.clear(),a.columns.clear(),a.columnHeaders.columns.clear(),a.rowHeaders.rows.clear(),r=e.grid.selection.clone(),a.selection=new wjcGrid.CellRange,e.selectionRanges.length>1&&a.selectionMode===wjcGrid.SelectionMode.CellRange&&(a._enableMulSel=!0),e.itemsSource)a.autoGenerateColumns=!1,a.itemsSource=e.itemsSource,a.collectionView.beginUpdate();else for(n=0;n<e.grid.rows.length;n++)a.rows.push(e.grid.rows[n]);for(a.sortManager.sortDescriptions.sourceCollection=e._sortList.slice(),a.sortManager._committedList=e._sortList.slice(),o=0;o<e.grid.columns.length;o++)(s=e.grid.columns[o]).isRequired=!1,a.columns.push(s);for(a.collectionView&&(a._resetMappedColumns(a),a.collectionView.endUpdate(),a.collectionView.collectionChanged.addHandler((t,o)=>{switch(o.action){case wjcCore.NotifyCollectionChangedAction.Add:e._orgItemsSource&&e._orgItemsSource.splice(o.index,0,o.item);break;case wjcCore.NotifyCollectionChangedAction.Remove:e._orgItemsSource&&e._orgItemsSource.splice(e._orgItemsSource.indexOf(o.item),1);break;case wjcCore.NotifyCollectionChangedAction.Reset:setTimeout(()=>{a.invalidate()},10)}},a)),a.rows.length&&a.columns.length&&(a.selection=r),e._applyFilterSetting(),n=0;n<a.rows.length;n++)(i=e._rowSettings[n])&&((l=a.rows[n]).height=i.height,l.allowMerging=i.allowMerging,l.visible=i.visible,l instanceof wjcGrid.GroupRow&&(l.isCollapsed=!!i.isCollapsed),l.isSelected=!!i.isSelected,l.isReadOnly=!!i.readOnly);a.autoGenerateColumns=h,a.frozenRows=e.grid.frozenRows,a.frozenColumns=e.grid.frozenColumns,a._isCopying=!1,a._addingSheet?(a._toRefresh&&(clearTimeout(a._toRefresh),a._toRefresh=null),a._toRefresh=setTimeout(()=>{a._setFlexSheetToDirty(),a.invalidate()},10),a._addingSheet=!1):t&&a.refresh(),a.scrollPosition=e._scrollPosition}_resetMappedColumns(e){var t,o,n=0;if(e._mappedColumns=null,e.collectionView)for(o=e.collectionView.sortDescriptions;n<o.length;n++)(t=e.columns.getColumn(o[n].property))&&t.dataMap&&(e._mappedColumns||(e._mappedColumns={}),e._mappedColumns[t.binding]=t.dataMap)}_loadFromWorkbook(e){var t,o,n,i,s=0,l=this;if(null!=e.sheets&&0!==e.sheets.length){if(l.beginUpdate(),l.clear(),l._reservedContent=e.reservedContent,t=e.sheets.length,e.colorThemes&&e.colorThemes.length>0)for(i=0;i<this._colorThemes.length;i++)this._colorThemes[i]=e.colorThemes[i];for(;s<t;s++){if(s>0&&l.addUnboundSheet(),l.selectedSheet.grid.wj_sheetInfo={},wjcGridXlsx.FlexGridXlsxConverter.load(l.selectedSheet.grid,e,{sheetIndex:s,includeColumnHeaders:!1}),l.selectedSheet.name=l.selectedSheet.grid.wj_sheetInfo.name,l.selectedSheet.visible=l.selectedSheet.grid.wj_sheetInfo.visible,l.selectedSheet._styledCells=l.selectedSheet.grid.wj_sheetInfo.styledCells,l.selectedSheet.grid.wj_sheetInfo.mergedRanges)for(n=0;n<l.selectedSheet.grid.wj_sheetInfo.mergedRanges.length;n++)l.selectedSheet._mergedRanges[n]=l.selectedSheet.grid.wj_sheetInfo.mergedRanges[n];if(l._copyFrom(l.selectedSheet,!1),null!=l.selectedSheet.grid.wj_sheetInfo.tables&&l.selectedSheet.grid.wj_sheetInfo.tables.length>0)for(i=0;i<l.selectedSheet.grid.wj_sheetInfo.tables.length;i++)this._parseFromWorkbookTable(l.selectedSheet.grid.wj_sheetInfo.tables[i],l.selectedSheet)}if(null!=e.activeWorksheet&&e.activeWorksheet>-1&&e.activeWorksheet<l.sheets.length?l.selectedSheetIndex=e.activeWorksheet:l.selectedSheetIndex=0,e.definedNames&&e.definedNames.length>0)for(i=0;i<e.definedNames.length;i++)o=e.definedNames[i],l.definedNames.push(new DefinedName(l,o.name,o.value,o.sheetName));l.endUpdate(),l.onLoaded()}}_saveToWorkbook(){var e,t,o,n,i,s;if(0===this.sheets.length)throw"The flexsheet is empty.";if(n=this.sheets[0],0===this.selectedSheetIndex&&(n._storeRowSettings(),n.itemsSource instanceof wjcCore.CollectionView||this._copyRowsToSelectedSheet()),n._setRowSettings(),n.tables.length>0)for(n.grid.wj_sheetInfo.tables=[],s=0;s<n.tables.length;s++)n.grid.wj_sheetInfo.tables.push(this._parseToWorkbookTable(n.tables[s]));for((e=wjcGridXlsx.FlexGridXlsxConverter.save(n.grid,{sheetName:n.name,sheetVisible:n.visible,includeColumnHeaders:!1})).reservedContent=this._reservedContent,i=1;i<this.sheets.length;i++){if(n=this.sheets[i],this.selectedSheetIndex===i&&(n._storeRowSettings(),n.itemsSource instanceof wjcCore.CollectionView||this._copyRowsToSelectedSheet()),n._setRowSettings(),n.tables.length>0)for(n.grid.wj_sheetInfo.tables=[],s=0;s<n.tables.length;s++)n.grid.wj_sheetInfo.tables.push(this._parseToWorkbookTable(n.tables[s]));t=wjcGridXlsx.FlexGridXlsxConverter.save(n.grid,{sheetName:n.name,sheetVisible:n.visible,includeColumnHeaders:!1}),e._addWorkSheet(t.sheets[0],i)}for(e.activeWorksheet=this.selectedSheetIndex,s=0;s<this.definedNames.length;s++){var l=this.definedNames[s];(o=new wjcXlsx.DefinedName).name=l.name,o.value=l.value,o.sheetName=l.sheetName,e.definedNames.push(o)}if(this._colorThemes&&this._colorThemes.length>0)for(s=0;s<this._colorThemes.length;s++)e.colorThemes[s]=this._colorThemes[s];return e}_mouseDown(e){var t,o,n,i=window.navigator.userAgent,s=this.hitTest(e);this.columns;if(this.selectedSheet&&(this.selectedSheet._scrollPosition=this.scrollPosition),this._wholeColumnsSelected=!1,this._dragable)return this._isDragging=!0,this._draggingMarker=document.createElement("div"),wjcCore.setCss(this._draggingMarker,{position:"absolute",display:"none",borderStyle:"dotted",cursor:"move"}),document.body.appendChild(this._draggingMarker),this._draggingTooltip=new wjcCore.Tooltip,this._draggingCells=this.selection,this.selectedSheet&&this.selectedSheet.selectionRanges.clear(),this.onDraggingRowColumn(new DraggingRowColumnEventArgs(this._draggingRow,e.shiftKey)),void e.preventDefault();if(s.cellType!==wjcGrid.CellType.None&&(this._isClicking=!0),this.selectionMode===wjcGrid.SelectionMode.CellRange?e.ctrlKey?this._enableMulSel||(this._enableMulSel=!0):s.cellType!==wjcGrid.CellType.None&&(this.selectedSheet&&this.selectedSheet.selectionRanges.clear(),this._enableMulSel&&this.refresh(!1),this._enableMulSel=!1):(this._enableMulSel=!1,this.selectedSheet&&this.selectedSheet.selectionRanges.clear()),this._htDown=s,0!==this.rows.length&&0!==this.columns.length&&(i.match(/iPad/i)||i.match(/iPhone/i)||this._contextMenu.hide(),this.selectionMode===wjcGrid.SelectionMode.CellRange)){if(s.cellType===wjcGrid.CellType.RowHeader&&3===e.which)return n=new wjcGrid.CellRange(s.row,0,s.row,this.columns.length-1),void(this.selection.contains(n)||(this.selection=n));if((s.cellType===wjcGrid.CellType.ColumnHeader||s.cellType===wjcGrid.CellType.None)&&!(s.col>-1&&this.columns[s.col].isSelected)&&wjcCore.hasClass(e.target,"wj-cell")&&!s.edgeRight){if(this._columnHeaderClicked=!0,this._wholeColumnsSelected=!0,o=this.itemsSource&&this.rows[0]&&!this.rows[0].isVisible?1:0,e.shiftKey)this._multiSelectColumns(s);else{if(t=new wjcGrid.CellRange(o,s.col,this.rows.length-1,s.col),3===e.which&&this.selection.contains(t))return;this.select(t)}this._eCt.children[o]&&this._eCt.children[o].children[s.col]&&this._eCt.children[o].children[s.col].focus()}}}_mouseMove(e){var t,o=this.hitTest(e),n=this.selection,i=this.rows.length,s=this.columns.length,l=this.hostElement.style.cursor;return 0===this.rows.length||0===this.columns.length?(this._dragable=!1,void(o.cellType===wjcGrid.CellType.Cell&&(this.hostElement.style.cursor="default"))):this._isDragging?(this.hostElement.style.cursor="move",void this._showDraggingMarker(e)):(t=this.itemsSource?0===n.topRow||1===n.topRow:0===n.topRow,n&&o.cellType!==wjcGrid.CellType.None&&!this.itemsSource&&(this._draggingColumn=t&&n.bottomRow===i-1,this._draggingRow=0===n.leftCol&&n.rightCol===s-1,o.cellType===wjcGrid.CellType.Cell?(this._draggingColumn&&((o.col===n.leftCol-1||o.col===n.rightCol)&&o.edgeRight||o.row===i-1&&o.edgeBottom)&&(l="move"),this._draggingRow&&!this._containsGroupRows(n)&&((o.row===n.topRow-1||o.row===n.bottomRow)&&o.edgeBottom||o.col===s-1&&o.edgeRight)&&(l="move")):o.cellType===wjcGrid.CellType.ColumnHeader?o.edgeBottom&&(this._draggingColumn&&o.col>=n.leftCol&&o.col<=n.rightCol?l="move":this._draggingRow&&0===n.topRow&&(l="move")):o.cellType===wjcGrid.CellType.RowHeader&&o.edgeRight&&(this._draggingColumn&&0===n.leftCol?l="move":this._draggingRow&&o.row>=n.topRow&&o.row<=n.bottomRow&&!this._containsGroupRows(n)&&(l="move")),this._dragable="move"===l,this.hostElement.style.cursor=l),void(this._htDown&&this._htDown.panel&&(o=new wjcGrid.HitTestInfo(this._htDown.panel,e),this._multiSelectColumns(o),o.cellType===wjcGrid.CellType.Cell&&this.scrollIntoView(o.row,o.col))))}_mouseUp(e){try{this._isDragging&&(this._draggingCells.equals(this._dropRange)||(this._handleDropping(e),this.onDroppingRowColumn()))}finally{this._isDragging&&(this._draggingCells=null,this._dropRange=null,document.body.removeChild(this._draggingMarker),this._draggingMarker=null,this._draggingTooltip.hide(),this._draggingTooltip=null,this._isDragging=!1,this._draggingColumn=!1,this._draggingRow=!1),this._htDown&&this._htDown.cellType!==wjcGrid.CellType.None&&this.selectedSheet&&(this._htDown.cellType===wjcGrid.CellType.TopLeft&&this.selectionMode===wjcGrid.SelectionMode.CellRange&&(this.selection=new wjcGrid.CellRange(0,0,this.rows.length-1,this.columns.length-1)),this.selection.isValid&&this.selectedSheet._addSelection(this.selection),this._enableMulSel=!1),this._isClicking=!1,this._columnHeaderClicked=!1,this._htDown=null}}_click(){var e=this,t=window.navigator.userAgent;t.match(/iPad/i)||t.match(/iPhone/i)||e._contextMenu.hide(),setTimeout(()=>{e.hideFunctionList()},200)}_touchStart(e){var t=this;wjcCore.hasClass(e.target,"wj-context-menu-item")||t._contextMenu.hide(),t._longClickTimer=setTimeout(()=>{var o;!(o=t.hitTest(e))||o.cellType===wjcGrid.CellType.None||t.itemsSource||t._resizing||t._contextMenu.show(null,new wjcCore.Point(e.pageX+10,e.pageY+10))},500)}_touchEnd(){clearTimeout(this._longClickTimer)}_showDraggingMarker(e){var t,o,n,i,s,l,r,a,h,d=new wjcGrid.HitTestInfo(this.cells,e),c=this.selection,_=this.columns.length,u=this.rows.length,g=this._cumulativeScrollOffset(this.hostElement),w=this._root.getBoundingClientRect(),m=w.left+g.x,C=w.top+g.y;if(this.scrollIntoView(d.row,d.col),this._draggingColumn){for(o=c.rightCol-c.leftCol+1,s=0,((n=d.col)<0||n+o>_)&&(n=_-o),t=this.cells.getCellBoundingRect(0,n),l=this._root.offsetHeight-this._eCHdr.offsetHeight,i=(i=this.cells.height)>l?l:i,r=0;r<o;r++)s+=this.columns[n+r].renderSize;a=FlexSheet.convertNumberToAlpha(n)+" : "+FlexSheet.convertNumberToAlpha(n+o-1),this._dropRange?(this._dropRange.col=n,this._dropRange.col2=n+o-1):this._dropRange=new wjcGrid.CellRange(0,n,this.rows.length-1,n+o-1)}else if(this._draggingRow){for(o=c.bottomRow-c.topRow+1,i=0,((n=d.row)<0||n+o>u)&&(n=u-o),t=this.cells.getCellBoundingRect(n,0),l=this._root.offsetWidth-this._eRHdr.offsetWidth,r=0;r<o;r++)i+=this.rows[n+r].renderSize;s=(s=this.cells.width)>l?l:s,a=n+1+" : "+(n+o),this._dropRange?(this._dropRange.row=n,this._dropRange.row2=n+o-1):this._dropRange=new wjcGrid.CellRange(n,0,n+o-1,this.columns.length-1)}if(t){if(h={display:"inline",zIndex:"9999",opacity:.5,top:t.top-(this._draggingColumn?this._ptScrl.y:0)+g.y,left:t.left-(this._draggingRow?this._ptScrl.x:0)+g.x,height:i,width:s},t.top=t.top-(this._draggingColumn?this._ptScrl.y:0),t.left=t.left-(this._draggingRow?this._ptScrl.x:0),this.rightToLeft&&this._draggingRow&&(h.left=h.left-s+t.width+2*this._ptScrl.x,t.left=t.left+2*this._ptScrl.x),this._draggingRow){if(m+this._eRHdr.offsetWidth!==h.left||C+this._root.offsetHeight+1<h.top+h.height)return}else if(C+this._eCHdr.offsetHeight!==h.top||m+this._root.offsetWidth+1<h.left+h.width)return;wjcCore.setCss(this._draggingMarker,h),this._draggingTooltip.show(this.hostElement,a,t)}}_handleDropping(e){var t,o,n,i,s,l,r,a=this;if(a.selectedSheet&&a._draggingCells&&a._dropRange&&!a._containsMergedCells(a._draggingCells)&&!a._containsMergedCells(a._dropRange)){if(a._clearCalcEngine(),a._draggingColumn&&a._draggingCells.leftCol>a._dropRange.leftCol||a._draggingRow&&a._draggingCells.topRow>a._dropRange.topRow)if(e.shiftKey){if(!a._allowExchangeCells(a._draggingRow,!0))return void console.warn("Can not complete operation: You are attempting to change a position of table row or column in a way that is not allowed.");if(a._draggingColumn){for(i=a._dropRange.leftCol,o=a._draggingCells.leftCol;o<=a._draggingCells.rightCol;o++)a.columns.moveElement(o,i),i++;a._exchangeTableColumns(!0)}else if(a._draggingRow)for(n=a._dropRange.topRow,t=a._draggingCells.topRow;t<=a._draggingCells.bottomRow;t++)a.rows.moveElement(t,n),n++;a._exchangeCellStyle(!0)}else{for(this.undoStack.stackSize>0&&(s=new _MoveCellsAction(a,a._draggingCells,a._dropRange,e.ctrlKey)),n=a._dropRange.topRow,t=a._draggingCells.topRow;t<=a._draggingCells.bottomRow;t++){for(i=a._dropRange.leftCol,o=a._draggingCells.leftCol;o<=a._draggingCells.rightCol;o++)a._moveCellContent(t,o,n,i,e.ctrlKey),a._draggingColumn&&n===a._dropRange.topRow&&(a.columns[i].dataType=a.columns[o].dataType?a.columns[o].dataType:wjcCore.DataType.Object,a.columns[i].align=a.columns[o].align,a.columns[i].format=a.columns[o].format,e.ctrlKey||(a.columns[o].dataType=wjcCore.DataType.Object,a.columns[o].align=null,a.columns[o].format=null)),i++;n++}if(a._draggingColumn&&!e.ctrlKey)for(i=a._dropRange.leftCol,o=a._draggingCells.leftCol;o<=a._draggingCells.rightCol;o++)a._updateColumnFiler(o,i),i++}else if(a._draggingColumn&&a._draggingCells.leftCol<a._dropRange.leftCol||a._draggingRow&&a._draggingCells.topRow<a._dropRange.topRow)if(e.shiftKey){if(!a._allowExchangeCells(a._draggingRow,!1))return void console.warn("Can not complete operation: You are attempting to change a position of table row or column in a way that is not allowed.");if(a._draggingColumn){for(i=a._dropRange.rightCol,o=a._draggingCells.rightCol;o>=a._draggingCells.leftCol;o--)a.columns.moveElement(o,i),i--;a._exchangeTableColumns(!1)}else if(a._draggingRow)for(n=a._dropRange.bottomRow,t=a._draggingCells.bottomRow;t>=a._draggingCells.topRow;t--)a.rows.moveElement(t,n),n--;a._exchangeCellStyle(!1)}else{for(this.undoStack.stackSize>0&&(s=new _MoveCellsAction(a,a._draggingCells,a._dropRange,e.ctrlKey)),n=a._dropRange.bottomRow,t=a._draggingCells.bottomRow;t>=a._draggingCells.topRow;t--){for(i=a._dropRange.rightCol,o=a._draggingCells.rightCol;o>=a._draggingCells.leftCol;o--)a._moveCellContent(t,o,n,i,e.ctrlKey),a._draggingColumn&&n===a._dropRange.bottomRow&&(a.columns[i].dataType=a.columns[o].dataType?a.columns[o].dataType:wjcCore.DataType.Object,a.columns[i].align=a.columns[o].align,a.columns[i].format=a.columns[o].format,e.ctrlKey||(a.columns[o].dataType=wjcCore.DataType.Object,a.columns[o].align=null,a.columns[o].format=null)),i--;n--}if(a._draggingColumn&&!e.ctrlKey)for(i=a._dropRange.rightCol,o=a._draggingCells.rightCol;o>=a._draggingCells.leftCol;o--)a._updateColumnFiler(o,i),i--}e.ctrlKey||(l=a._updateFormulaForDropping(e.shiftKey),r=a._updateNamedRangesForDropping(e.shiftKey)),s&&s.saveNewState()&&(s._affectedFormulas=l,s._affectedDefinedNameVals=r,a._undoStack._addAction(s)),a._undoStack._pendingAction&&(a._undoStack._pendingAction._affectedFormulas=l,a._undoStack._pendingAction._affectedDefinedNameVals=r),a.select(a._dropRange),a.selectedSheet._addSelection(a.selection),a.hostElement.focus()}}_moveCellContent(e,t,o,n,i){var s,l,r,a,h,d,c,_,u=this.getCellData(e,t,!1),g=e*this.columns.length+t,w=o*this.columns.length+n,m=this.selectedSheet._styledCells[g],C=!0;if((l=this.selectedSheet.findTable(o,n))&&(c=l.getRange(),_=l.getColumns(),l.showHeaderRow&&o===c.topRow&&(h=_[a=n-c.leftCol].name,null==u||""===u?C=!1:_[a].name=u)),C?this.setCellData(o,n,u):C=!0,m?this.selectedSheet._styledCells[w]=this._cloneObject(m):delete this.selectedSheet._styledCells[w],i)(s=this.selectedSheet.findTable(e,t))&&(d=s.getRange(),s===l&&e===o&&s.showHeaderRow&&e===d.topRow&&(r=t-d.leftCol,s._updateColumnName(r,u)));else{if(delete this.selectedSheet._styledCells[g],s=this.selectedSheet.findTable(e,t)){if(d=s.getRange(),s===l&&e===o&&s.showHeaderRow&&e===d.topRow)return r=t-d.leftCol,void s._updateColumnName(r,h);if(s.showHeaderRow&&e===d.topRow)return}this.setCellData(e,t,null)}}_allowExchangeCells(e,t){let o,n,i,s,l,r,a=this.selectedSheet.tables;for(o=0;o<a.length;o++)if(n=a[o],e?(i=n.getRange(TableSection.Data),r=this._draggingCells.rowSpan,s=new wjcGrid.CellRange(this._draggingCells.topRow,i.leftCol,this._draggingCells.bottomRow,i.rightCol),l=new wjcGrid.CellRange(this._dropRange.topRow,i.leftCol,this._dropRange.bottomRow,i.rightCol)):(i=n.getRange(),r=this._draggingCells.columnSpan,s=new wjcGrid.CellRange(i.topRow,this._draggingCells.leftCol,i.bottomRow,this._draggingCells.rightCol),l=new wjcGrid.CellRange(i.topRow,this._dropRange.leftCol,i.bottomRow,this._dropRange.rightCol)),i.intersects(s)&&!i.contains(s)||i.intersects(l)&&!i.contains(l)||i.contains(s)&&!i.contains(l)||!i.contains(s)&&i.contains(l))return!1;return!0}_exchangeTableColumns(e){let t,o,n,i,s,l,r=this.selectedSheet.tables;for(t=0;t<r.length;t++)if(o=r[t],(n=o.getRange()).leftCol<=this._draggingCells.leftCol&&n.rightCol>=this._draggingCells.rightCol)for(i=(e?this._draggingCells.leftCol:this._draggingCells.rightCol)-n.leftCol,s=(e?this._dropRange.leftCol:this._dropRange.rightCol)-n.leftCol,l=0;l<this._draggingCells.columnSpan;l++)o._moveColumns(i,s),e?(i++,s++):(i--,s--)}_exchangeCellStyle(e){var t,o,n,i,s,l=0,r=[];for(t=this._draggingCells.topRow;t<=this._draggingCells.bottomRow;t++)for(o=this._draggingCells.leftCol;o<=this._draggingCells.rightCol;o++)n=t*this.columns.length+o,this.selectedSheet._styledCells[n]?(r.push(this._cloneObject(this.selectedSheet._styledCells[n])),delete this.selectedSheet._styledCells[n]):r.push(void 0);if(e){if(this._draggingColumn)for(s=this._draggingCells.rightCol-this._draggingCells.leftCol+1,o=this._draggingCells.leftCol-1;o>=this._dropRange.leftCol;o--)for(t=0;t<this.rows.length;t++)n=t*this.columns.length+o,i=t*this.columns.length+o+s,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i];else if(this._draggingRow)for(s=this._draggingCells.bottomRow-this._draggingCells.topRow+1,t=this._draggingCells.topRow-1;t>=this._dropRange.topRow;t--)for(o=0;o<this.columns.length;o++)n=t*this.columns.length+o,i=(t+s)*this.columns.length+o,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i]}else if(this._draggingColumn)for(s=this._draggingCells.rightCol-this._draggingCells.leftCol+1,o=this._draggingCells.rightCol+1;o<=this._dropRange.rightCol;o++)for(t=0;t<this.rows.length;t++)n=t*this.columns.length+o,i=t*this.columns.length+o-s,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i];else if(this._draggingRow)for(s=this._draggingCells.bottomRow-this._draggingCells.topRow+1,t=this._draggingCells.bottomRow+1;t<=this._dropRange.bottomRow;t++)for(o=0;o<this.columns.length;o++)n=t*this.columns.length+o,i=(t-s)*this.columns.length+o,this.selectedSheet._styledCells[n]?(this.selectedSheet._styledCells[i]=this._cloneObject(this.selectedSheet._styledCells[n]),delete this.selectedSheet._styledCells[n]):delete this.selectedSheet._styledCells[i];for(t=this._dropRange.topRow;t<=this._dropRange.bottomRow;t++)for(o=this._dropRange.leftCol;o<=this._dropRange.rightCol;o++)n=t*this.columns.length+o,r[l]?this.selectedSheet._styledCells[n]=r[l]:delete this.selectedSheet._styledCells[n],l++}_containsMergedCells(e,t){var o,n,i,s,l;if(t=t||this.selectedSheet,l=t===this.selectedSheet?this:t.grid,!t)return!1;for(o=e.topRow;o<=e.bottomRow;o++)for(n=e.leftCol;n<=e.rightCol;n++)if(i=o*l.columns.length+n,(s=t._mergedRanges[i])&&s.isValid&&!s.isSingleCell)return!0;return!1}_multiSelectColumns(e){var t;e&&this._columnHeaderClicked&&((t=new wjcGrid.CellRange(e.row,e.col)).row=this.itemsSource&&this.rows[0]&&!this.rows[0].isVisible?1:0,t.row2=this.rows.length-1,t.col2=this.selection.col2,this.select(t))}_cumulativeOffset(e){var t=0,o=0;do{t+=e.offsetTop||0,o+=e.offsetLeft||0,e=e.offsetParent}while(e);return new wjcCore.Point(o,t)}_cumulativeScrollOffset(e){var t=0,o=0;do{t+=e.scrollTop||0,o+=e.scrollLeft||0,e=e.offsetParent}while(e&&!(e instanceof HTMLBodyElement));return t+=document.body.scrollTop||document.documentElement.scrollTop,o+=document.body.scrollLeft||document.documentElement.scrollLeft,new wjcCore.Point(o,t)}_checkHitWithinSelection(e){var t;if(null!=e&&e.cellType===wjcGrid.CellType.Cell){if((t=this.getMergedRange(this.cells,e.row,e.col))&&t.contains(this.selection))return!0;if(this.selection.row===e.row&&this.selection.col===e.col)return!0}return!1}_clearForEmptySheet(e){this.selectedSheet&&0===this[e].length&&!0!==this._isCopying&&!0!==this._isUndoing&&(this.selectedSheet._mergedRanges.length=0,this.selectedSheet._styledCells=null,this.select(new wjcGrid.CellRange))}_containsGroupRows(e){var t;for(t=e.topRow;t<=e.bottomRow;t++)if(this.rows[t]instanceof wjcGrid.GroupRow)return!0;return!1}_delSeletionContent(e){var t,o,n,i,s,l,r,a,h,d,c=this.selectedSheet.selectionRanges.slice(),_=!1,u=new _EditAction(this),g=this.editableCollectionView,w=!1;if(!this.isReadOnly)if(this.allowDelete&&this.selection.isValid&&0===this.selection.leftCol&&this.selection.rightCol===this.columns.length-1)this.deleteRows(this.selection.topRow,this.selection.rowSpan);else{for(this.beginUpdate(),this.undoStack.stackSize>0&&(u=new _EditAction(this)),null!=c&&0!==c.length||(c=[this.selection]),n=0;n<c.length;n++){if(t=c[n],o=new wjcGrid.CellRange,h=new wjcGrid.CellEditEndingEventArgs(this.cells,o,e),this.selectedSheet.tables.length>0)for(l=0;l<this.selectedSheet.tables.length;l++)r=this.selectedSheet.tables[l],t.contains(r.getRange())&&(u&&u._storeDeletedTables(r),this.selectedSheet.tables.remove(r));for(s=t.topRow;s<=t.bottomRow;s++)if((d=this.rows[s])&&!d.isReadOnly)for(i=t.leftCol;i<=t.rightCol;i++)(!(a=this._getBindingColumn(this.cells,s,this.columns[i])).isReadOnly&&!1===a.isRequired||null==a.isRequired&&a.dataType==wjcCore.DataType.String)&&this.getCellData(s,i,!0)&&(o.setRange(s,i),h.cancel=!1,this.onBeginningEdit(h)&&(g&&(w||(w=!0,g.beginUpdate()),g.editItem(d.dataItem),this._edtHdl._edItem=g.currentEditItem),this.setCellData(s,i,"",!0),_=!0,this.onCellEditEnding(h),this.onCellEditEnded(h)));w&&g.endUpdate()}_&&u&&(u.saveNewState(),this._undoStack._addAction(u)),this.endUpdate()}}_updateAffectedFormula(e,t,o,n){var i,s,l,r,a,h,d,c,_,u=[],g=[],w=this.selection.clone();for(this.selectedSheet._storeRowSettings(),this.beginUpdate(),i=0;i<this.sheets.length;i++)for(l=(s=this.sheets[i]).grid,r=0;r<l.rows.length;r++)for(a=0;a<l.columns.length;a++)if((c=l.getCellData(r,a,!1))&&wjcCore.isString(c)&&"="===c[0]&&(_=this._updateCellRef(c,i,e,t,o,n,r,a))){if(u.push({sheet:s,point:new wjcCore.Point(r,a),formula:c}),h=r,d=a,i===this.selectedSheetIndex&&(n?r>=e&&(o?h+=t:h-=t):a>=e&&(o?d+=t:d-=t),!o&&(n&&r<=e&&r>=e-t+1||!n&&a<=e&&a>=e-t+1)))continue;l.setCellData(r,a,_,!1),g.push({sheet:s,point:new wjcCore.Point(h,d),formula:_})}return this.selection=w,this.endUpdate(),{oldFormulas:u,newFormulas:g}}_updateAffectedNamedRanges(e,t,o,n){var i,s,l,r,a=[],h=[];for(i=0;i<this.definedNames.length;i++)(l=(s=this.definedNames[i]).value)&&wjcCore.isString(l)&&(r=this._updateCellRef(l,this.selectedSheetIndex,e,t,o,n))&&(a.push({name:s.name,value:l}),s.value=r,h.push({name:s.name,value:r}));return{oldDefinedNameVals:a,newDefinedNameVals:h}}_updateColumnFiler(e,t){for(var o=JSON.parse(this._filter.filterDefinition),n=0;n<o.filters.length;n++){var i=o.filters[n];if(i.columnIndex===e){i.columnIndex=t;break}}this._filter.filterDefinition=JSON.stringify(o)}_isDescendant(e,t){for(var o=t.parentNode;null!=o;){if(o===e)return!0;o=o.parentNode}return!1}_clearCalcEngine(){this._calcEngine._clearExpressionCache()}_getRangeString(e,t,o=!0){var n,i,s,l,r,a="",h=!0,d=t.grid;if(wjcCore.isArray(e))if(e.length>1){if(this._isMultipleRowsSelected(e,t)){for(a="",i=0;i<e.length;i++)a&&(a+="\n"),a+=this._getRangeString(e[i],t);return a}if(!this._isMultipleColumnsSelected(e,t))return"";for(a="",n=0,h=!0;n<d.rows.length;n++){for(h||(a+="\n"),h=!1,i=0,g=!0;i<e.length;i++)(s=e[i].clone()).row=s.row2=n,g||(a+="\t"),g=!1,a+=this._getRangeString(e[i],t);return a}}else switch(r=e[0],this.selectionMode){case wjcGrid.SelectionMode.Row:case wjcGrid.SelectionMode.RowRange:r.col=0,r.col2=t.grid.columns.length-1;break;case wjcGrid.SelectionMode.ListBox:r.col=0,r.col2=t.grid.columns.length-1;for(var c=0;c<t.grid.rows.length;c++)t.grid.rows[c].isSelected&&t.grid.rows[c].isVisible&&(r.row=r.row2=c,a&&(a+="\n"),a+=this._getRangeString(r,t));return a}for(var _=(r=wjcCore.asType(wjcCore.isArray(e)?e[0]:e,wjcGrid.CellRange)).topRow;_<=r.bottomRow;_++)if(d.rows[_]&&d.rows[_].isVisible){h||(a+="\n"),h=!1;for(var u=r.leftCol,g=!0;u<=r.rightCol;u++)if(d.columns[u]&&d.columns[u].isVisible){g||(a+="\t"),g=!1;var w=this._getCellStyle(_,u,t),m=w?w.format:"",C=d.columns[u];o?(l=d.getCellData(_,u,!1),wjcCore.isString(l)&&"="===l[0]&&(l=this._evaluate(l,m,t,_,u)),l=this._formatEvaluatedResult(l,C,m)):(l=d.getCellData(_,u,!1),wjcCore.isDate(l)&&(l=wjcCore.Globalize.formatDate(l,m||C.format))),(l=(l=null==l?"":l.toString()).replace(/\t/g," ")).indexOf("\n")>-1&&(l='"'+l.replace(/"/g,'""')+'"'),a+=l}}return a}_getSelectionForListBoxMode(e){let t,o=0;for(;o<e.rows.length;o++)e.rows[o].isSelected&&(t?t.row2=o:t=new wjcGrid.CellRange(o,0,o,e.columns.length-1));return t}_containsRandFormula(e,t){for(var o=0;o<e.length;o++)for(var n=e[o],i=n.topRow;i<=n.bottomRow&&i<t.grid.rows.length;i++)for(var s=n.leftCol;s<=n.rightCol&&s<t.grid.columns.length;s++){var l=t.grid.getCellData(i,s,!1);if(wjcCore.isString(l)&&"="===l[0]&&-1!==l.search(/rand/i))return!0}return!1}_isMultipleRowsSelected(e,t){var o,n,i;e&&e.length>1?i=e:this.selectedSheet.selectionRanges.length>1&&(i=this.selectedSheet.selectionRanges),o=i[0];for(var s=1;s<i.length;s++)if((n=i[s]).leftCol!==o.leftCol||n.rightCol!==o.rightCol)return!1;return!0}_isMultipleColumnsSelected(e,t){var o,n,i;e&&e.length>1?i=e:this.selectedSheet.selectionRanges.length>1&&(i=this.selectedSheet.selectionRanges),o=i[0];for(var s=0;s<i.length;s++)if((n=i[s]).topRow!==o.topRow||n.bottomRow!==o.bottomRow)return!1;return!0}_postSetClipStringProcess(e,t,o,n,i,s){var l,r,a,h,d,c,_=!1;return n>=0&&i>=0&&this._copiedSheet&&(l=n*this._copiedSheet.grid.columns.length+i,(r=this._copiedSheet._mergedRanges[l])&&r.topRow===n&&r.leftCol===i&&(a=(a=t+r.rowSpan-1)<this.rows.length?a:this.rows.length-1,h=(h=o+r.columnSpan-1)<this.columns.length?h:this.columns.length-1,this.mergeRange(new wjcGrid.CellRange(t,o,a,h),!0))),d=new wjcGrid.CellRangeEventArgs(this.cells,new wjcGrid.CellRange(t,o),e),this.onPastingCell(d)&&this.cells.setCellData(t,o,d.data)&&(wjcCore.isString(d.data)&&(c=d.data.match(/\n/g))&&c.length>0&&(s?s.whiteSpace="pre":s={whiteSpace:"pre"},this.rows[t].height=this.rows.defaultSize*(c.length+1)),s&&this._applyStyleForCell(t,o,s),this.onPastedCell(d),_=!0),_}_delCutData(){var e,t,o,n,i=this._copiedSheet===this.selectedSheet?this:this._copiedSheet.grid;for(e=(n=this.selectionMode===wjcGrid.SelectionMode.ListBox?this._getSelectionForListBoxMode(i):this._copiedRanges[0]).topRow;e<=n.bottomRow;e++)if(null!=i.rows[e])for(t=n.leftCol;t<=n.rightCol;t++)(this._copiedSheet!==this.selectedSheet||e<this.selection.topRow||e>this.selection.bottomRow||t<this.selection.leftCol||t>this.selection.rightCol)&&(0==(o=i._getBindingColumn(i.cells,e,i.columns[t])).isRequired||null==o.isRequired&&o.dataType==wjcCore.DataType.String)&&i.getCellData(e,t,!0)&&i.setCellData(e,t,"",!0)}_containsMultiLineText(e){for(var t=0;t<e.length;t++)for(var o=e[t],n=0;n<o.length;n++)if(o[n].indexOf("\n")>=0)return!0;return!1}_sortByRow(e,t){return e.topRow>t.topRow?1:e.topRow<t.topRow?-1:0}_sortByColumn(e,t){return e.leftCol>t.leftCol?1:e.leftCol<t.leftCol?-1:0}_setFlexSheetToDirty(){this.columns._dirty=!0,this.rows._dirty=!0,this.rowHeaders.columns._dirty=!0,this.rowHeaders.rows._dirty=!0,this.columnHeaders.columns._dirty=!0,this.columnHeaders.rows._dirty=!0}static convertNumberToAlpha(e){var t,o,n="";if(e>=0)do{t=Math.floor(e/26),o=e%26,n=String.fromCharCode(o+65)+n,e=t-1}while(t);return n}_updateFormulaForReorderingRows(e,t){var o,n,i=t-e;this.beginUpdate();for(var s=0;s<this.columns.length;s++)if((o=this.getCellData(t,s,!1))&&"string"==typeof o&&"="===o[0]&&0!==i){try{n=this._calcEngine._checkCache(o,this.selectedSheetIndex,t,s)}catch(e){continue}n._updateCellRangeExpForReorderingRows(i)&&this.setCellData(t,s,"="+n._getStringExpression())}this.endUpdate()}_updateFormulaForDropping(e){var t,o,n,i,s,l,r,a,h,d=[],c=[];for(this.beginUpdate(),n=0;n<this.sheets.length;n++)for(o=(t=this.sheets[n]).grid,i=0;i<o.rows.length;i++)for(l=0;l<o.columns.length;l++)(a=o.getCellData(i,l,!1))&&"string"==typeof a&&"="===a[0]&&(h=this._updateCellRefForDropping(a,n,e,i,l))&&(o.setCellData(i,l,h,!1),e&&n===this.selectedSheetIndex?(s=o.rows[i],r=o.columns[l],d.push({sheet:t,row:s,column:r,formula:a}),c.push({sheet:t,row:s,column:r,formula:h})):(d.push({sheet:t,point:new wjcCore.Point(i,l),formula:a}),c.push({sheet:t,point:new wjcCore.Point(i,l),formula:h})));return this.endUpdate(),{oldFormulas:d,newFormulas:c}}_updateNamedRangesForDropping(e){var t,o,n,i,s=[],l=[];for(t=0;t<this.definedNames.length;t++)(n=(o=this.definedNames[t]).value)&&wjcCore.isString(n)&&(i=this._updateCellRefForDropping(n,this.selectedSheetIndex,e))&&(s.push({name:o.name,value:n}),o.value=i,l.push({name:o.name,value:i}));return{oldDefinedNameVals:s,newDefinedNameVals:l}}_updateCellRefForDropping(e,t,o=!1,n,i){let s;try{s=this._calcEngine._checkCache(e,t,n,i)}catch(e){return null}return s._moveCellRangeExp(t,this._draggingCells,this._dropRange,o)?"="+s._getStringExpression():null}_scanFormulas(){for(var e=[],t=0;t<this.rows.length;t++)for(var o=0;o<this.columns.length;o++){var n=this.getCellData(t,o,!1);n&&wjcCore.isString(n)&&"="===n[0]&&e.push({row:t,column:o,formula:n})}return e}_resetFormulas(e){var t=this;e&&t.deferUpdate(()=>{for(var o=0;o<e.length;o++){var n=e[o];t.setCellData(n.row,n.column,n.formula)}})}_getCellStyle(e,t,o){var n;return(o=o||this.selectedSheet)?(n=e*o.grid.columns.length+t,o._styledCells[n]):null}_validateSheetName(e){for(let t=0;t<this.sheets.length;t++)if(this.sheets[t].name===e)return!0;return!1}_checkExistDefinedName(e,t,o=-1){for(let n=0;n<this.definedNames.length;n++)if(this.definedNames[n].name===e&&this.definedNames[n].sheetName===t&&n!==o)return!0;return!1}_updateDefinedNameWithSheetRefUpdating(e,t){for(var o,n,i,s=0;s<this.definedNames.length;s++)if((o=this.definedNames[s]).sheetName===e&&null!=o.sheetName&&(o._sheetName=t),(n=o.value.match(/(\w+)\!\$?[A-Za-z]+\$?\d+/g))&&n.length>0)for(var l=0;l<n.length;l++)(i=n[l]).substring(0,i.indexOf("!"))===e&&(o.value=o.value.replace(i,i.replace(e,t)))}_updateFormulasWithNameUpdating(e,t,o=!1){let n,i,s,l,r,a,h,d,c,_,u,g=this.selection.clone(),w=!1;for(u=o?/\[/:/\w/,this.selectedSheet._storeRowSettings(),this.beginUpdate(),n=0;n<this.sheets.length;n++)for(r=(l=this.sheets[n]).grid,i=0;i<r.rows.length;i++)for(s=0;s<r.columns.length;s++)if((a=r.getCellData(i,s,!1))&&"string"==typeof a&&"="===a[0]){for(w=!1,h=a.indexOf(e),_=new RegExp(e,"g");h>-1;)d="",c="",h>0&&(d=a[h-1]),h+e.length<a.length&&(c=a[h+e.length]),!/\w/.test(d)&&(o&&u.test(c)||!o&&!u.test(c))&&(a=a.replace(_,(o,n)=>n===h?t:e),w=!0),h=a.indexOf(e,h+e.length);w&&r.setCellData(i,s,a,!1)}this.selection=g,this.endUpdate()}_getDefinedNameIndexByName(e){for(var t=0;t<this.definedNames.length;t++)if(this.definedNames[t].name===e)return t;return-1}_updateTablesForUpdatingRow(e,t,o){var n,i,s,l,r;if(this.selectedSheet.tables.length>0)for(n=this.selectedSheet.tables.length-1;n>=0;n--)if(i=this.selectedSheet.tables[n],s=i.getRange(),o)if((l=e+t-1)<s.topRow)i._updateTableRange(-t,-t,0,0);else if(l>=s.topRow&&l<=s.bottomRow)if(e<s.topRow)i.showHeaderRow&&(i._showHeaderRow=!1),i._updateTableRange(e-s.topRow,-t,0,0);else{if(e===s.topRow&&t===s.rowSpan){null==r&&(r=[]),r.push(i),this.selectedSheet.tables.remove(i);continue}e===s.topRow&&i.showHeaderRow&&(i._showHeaderRow=!1),l===s.bottomRow&&i.showTotalRow&&(i._showTotalRow=!1),i._updateTableRange(0,-t,0,0)}else e<=s.topRow?(null==r&&(r=[]),r.push(i),this.selectedSheet.tables.remove(i)):e<=s.bottomRow&&(i.showTotalRow&&(i._showTotalRow=!1),i._updateTableRange(0,e-s.bottomRow-1,0,0));else e<=s.topRow?i._updateTableRange(t,t,0,0):e>s.topRow&&e<=s.bottomRow&&i._updateTableRange(0,t,0,0);return r}_updateTablesForUpdatingColumn(e,t,o){var n,i,s,l,r,a,h,d;if(this.selectedSheet.tables.length>0)for(n=this.selectedSheet.tables.length-1;n>=0;n--)if(i=this.selectedSheet.tables[n],s=i.getRange(),o)if((l=e+t-1)<s.leftCol)i._updateTableRange(0,0,-t,-t);else if(l>=s.leftCol&&l<=s.rightCol){if(e<s.leftCol)r=t-s.leftCol+e,a=s.leftCol,i._updateTableRange(0,0,e-s.leftCol,-t);else{if(e===s.leftCol&&t===s.columnSpan){null==d&&(d=[]),d.push(i),this.selectedSheet.tables.remove(i);continue}r=t,a=e,i._updateTableRange(0,0,0,-r)}i._columns.splice(a-s.leftCol,r)}else e<=s.leftCol?(null==d&&(d=[]),d.push(i),this.selectedSheet.tables.remove(i)):e<=s.rightCol&&(r=s.rightCol-e+1,i._updateTableRange(0,0,0,-r),i._columns.splice(e,r));else if(e<=s.leftCol)i._updateTableRange(0,0,t,t);else if(e>s.leftCol&&e<=s.rightCol)for(i._updateTableRange(0,0,0,t),a=e-s.leftCol,h=0;h<t;h++)i._addColumn(a+h);return d}_isDisableDeleteRow(e,t){var o,n,i;if(this.selectedSheet.tables.length>0)for(o=0;o<this.selectedSheet.tables.length;o++)if(n=this.selectedSheet.tables[o],i=n.getRange(),n.showHeaderRow&&i.topRow>=e&&i.topRow<=t)return!0;return!1}_copy(e,t){var o,n;if("columns"==e){if(super._copy(e,t),this.itemsSource&&(o=this.rows[0])instanceof HeaderRow){o._ubv=null,o._ubv={};for(var i=0;i<this.columns.length;i++)n=this.columns[i],o._ubv[n._hash]=n.header}return!0}return!1}_getTableSheetIndex(e,t){this.sheets;for(let o=0;o<e.length;o++)if(e[o].indexOf(t)>-1)return o;return-1}_sheetSortConverter(e,t,o,n){return o=super._sortConverter(e,t,o,n),wjcCore.isString(o)&&o.length>0&&"="===o[0]&&(o=this.evaluate(o)),o}_formatEvaluatedResult(e,t,o){return wjcCore.isPrimitive(e)?(t.dataMap&&(e=t.dataMap.getDisplayValue(e)),!wjcCore.isInt(e)||t.format||t.dataMap||o?((o||t.format)&&wjcCore.isString(e)&&(+e).toString()===e&&(e=+e),e=null!=e?wjcCore.Globalize.format(e,o||t.format):""):e=e.toString()):e&&(!wjcCore.isInt(e.value)||t.format||t.dataMap||o||e.format?(wjcCore.isString(e.value)&&(+e.value).toString()===e.value&&(e.value=+e.value),e=null!=e.value?wjcCore.Globalize.format(e.value,o||e.format||t.format):""):e=e.value.toString()),e}_updateCellRef(e,t,o,n,i,s,l,r){let a;try{a=this._calcEngine._checkCache(e,t,l,r)}catch(e){return null}return a._updateCellRangeExp(t,o,n,i,s)?"="+a._getStringExpression():null}_copyRowsToSelectedSheet(){var e,t=this;if(t.selectedSheet){for(t.selectedSheet.grid.rows.clear(),e=0;e<t.rows.length;e++)t.selectedSheet.grid.rows.push(t.rows[e]);setTimeout(()=>{t._setFlexSheetToDirty(),t.invalidate()},10)}}_copyColumnsToSelectedSheet(){var e,t=this;if(t.selectedSheet){for(t.selectedSheet.grid.columns.clear(),e=0;e<t.columns.length;e++)t.selectedSheet.grid.columns.push(t.columns[e]);setTimeout(()=>{t._setFlexSheetToDirty(),t.invalidate()},10)}}_parseFromWorkbookTable(e,t){var o,n,i,s,l,r,a,h,d,c,_,u=t===this.selectedSheet?this:t.grid;if(n=e.range.split(":"),i=n[0],s=n[1],l=wjcXlsx.Workbook.tableAddress(i),o=new wjcGrid.CellRange(l.row,l.col),r=wjcXlsx.Workbook.tableAddress(s),o.row2=r.row,o.col2=r.col,o.bottomRow>=t.rowCount)for(_=o.bottomRow-t.rowCount+1,g=0;g<_;g++)u.rows.push(new wjcGrid.Row);if(o.rightCol>=t.columnCount)for(_=o.rightCol-t.columnCount+1,g=0;g<_;g++)u.columns.push(new wjcGrid.Column);if(e.columns&&e.columns.length>0){a=[];for(var g=0;g<e.columns.length;g++)h=e.columns[g],a[g]=new TableColumn(h.name,h.totalRowLabel,h.totalRowFunction,h.showFilterButton)}return null!=e.style&&(d=this._isBuiltInStyleName(e.style.name)?this.getBuiltInTableStyle(e.style.name):this._parseFromWorkbookTableStyle(e.style)),c=new Table(e.name,o,d,a,{showHeaderRow:e.showHeaderRow,showTotalRow:e.showTotalRow,showBandedColumns:e.showBandedColumns,showBandedRows:e.showBandedRows,alterFirstColumn:e.alterFirstColumn,alterLastColumn:e.alterLastColumn}),t.tables.push(c),c}_parseFromWorkbookTableStyle(e){var t=new TableStyle(e.name);return null!=e.firstBandedColumnStyle&&(t.firstBandedColumnStyle=this._parseFromWorkbookTableStyleElement(e.firstBandedColumnStyle)),null!=e.firstBandedRowStyle&&(t.firstBandedRowStyle=this._parseFromWorkbookTableStyleElement(e.firstBandedRowStyle)),null!=e.firstColumnStyle&&(t.firstColumnStyle=this._parseFromWorkbookTableStyleElement(e.firstColumnStyle)),null!=e.firstHeaderCellStyle&&(t.firstHeaderCellStyle=this._parseFromWorkbookTableStyleElement(e.firstHeaderCellStyle)),null!=e.firstTotalCellStyle&&(t.firstTotalCellStyle=this._parseFromWorkbookTableStyleElement(e.firstTotalCellStyle)),null!=e.headerRowStyle&&(t.headerRowStyle=this._parseFromWorkbookTableStyleElement(e.headerRowStyle)),null!=e.lastColumnStyle&&(t.lastColumnStyle=this._parseFromWorkbookTableStyleElement(e.lastColumnStyle)),null!=e.lastHeaderCellStyle&&(t.lastHeaderCellStyle=this._parseFromWorkbookTableStyleElement(e.lastHeaderCellStyle)),null!=e.lastTotalCellStyle&&(t.lastTotalCellStyle=this._parseFromWorkbookTableStyleElement(e.lastTotalCellStyle)),null!=e.secondBandedColumnStyle&&(t.secondBandedColumnStyle=this._parseFromWorkbookTableStyleElement(e.secondBandedColumnStyle)),null!=e.secondBandedRowStyle&&(t.secondBandedRowStyle=this._parseFromWorkbookTableStyleElement(e.secondBandedRowStyle)),null!=e.totalRowStyle&&(t.totalRowStyle=this._parseFromWorkbookTableStyleElement(e.totalRowStyle)),null!=e.wholeTableStyle&&(t.wholeTableStyle=this._parseFromWorkbookTableStyleElement(e.wholeTableStyle)),t}_parseFromWorkbookTableStyleElement(e){var t;return t={fontWeight:e.font&&e.font.bold?"bold":"none",fontStyle:e.font&&e.font.italic?"italic":"none",textDecoration:e.font&&e.font.underline?"underline":"none",fontFamily:e.font&&e.font.family?e.font.family:"",fontSize:e.font&&e.font.size?e.font.size+"px":"",color:e.font&&e.font.color?e.font.color:"",backgroundColor:e.fill&&e.fill.color?e.fill.color:""},e.borders&&(e.borders.left&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.left.style,"Left",t),t.borderLeftColor=e.borders.left.color),e.borders.right&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.right.style,"Right",t),t.borderRightColor=e.borders.right.color),e.borders.top&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.top.style,"Top",t),t.borderTopColor=e.borders.top.color),e.borders.bottom&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.bottom.style,"Bottom",t),t.borderBottomColor=e.borders.bottom.color),e.borders.vertical&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.vertical.style,"Vertical",t),t.borderVerticalColor=e.borders.vertical.color),e.borders.horizontal&&(wjcGridXlsx.FlexGridXlsxConverter._parseBorderStyle(e.borders.horizontal.style,"Horizontal",t),t.borderHorizontalColor=e.borders.horizontal.color)),null!=e.size&&(t.size=e.size),t}_parseToWorkbookTable(e){var t,o,n=new wjcXlsx.WorkbookTable,i=e.getRange(),s=e.getColumns();n.name=e.name,t=wjcXlsx.Workbook.xlsxAddress(i.topRow,i.leftCol),o=wjcXlsx.Workbook.xlsxAddress(i.bottomRow,i.rightCol),n.range=t+":"+o,null!=e.style&&(e.style.isBuiltIn?(n.style=new wjcXlsx.WorkbookTableStyle,n.style.name=e.style.name):n.style=this._parseToWorkbookTableStyle(e.style)),n.showBandedColumns=e.showBandedColumns,n.showBandedRows=e.showBandedRows,n.showHeaderRow=e.showHeaderRow,n.showTotalRow=e.showTotalRow,n.alterFirstColumn=e.alterFirstColumn,n.alterLastColumn=e.alterLastColumn;for(var l=0;l<s.length;l++){var r=s[l],a=new wjcXlsx.WorkbookTableColumn;a.name=r.name,a.totalRowLabel=r.totalRowLabel,a.totalRowFunction=r.totalRowFunction,a.showFilterButton=r.showFilterButton,n.columns.push(a)}return n}_parseToWorkbookTableStyle(e){var t=new wjcXlsx.WorkbookTableStyle;return t.name=e.name,null!=e.firstBandedColumnStyle&&(t.firstBandedColumnStyle=this._parseToWorkbookTableStyleElement(e.firstBandedColumnStyle,!0)),null!=e.firstBandedRowStyle&&(t.firstBandedRowStyle=this._parseToWorkbookTableStyleElement(e.firstBandedRowStyle,!0)),null!=e.firstColumnStyle&&(t.firstColumnStyle=this._parseToWorkbookTableStyleElement(e.firstColumnStyle)),null!=e.firstHeaderCellStyle&&(t.firstHeaderCellStyle=this._parseToWorkbookTableStyleElement(e.firstHeaderCellStyle)),null!=e.firstTotalCellStyle&&(t.firstTotalCellStyle=this._parseToWorkbookTableStyleElement(e.firstTotalCellStyle)),null!=e.headerRowStyle&&(t.headerRowStyle=this._parseToWorkbookTableStyleElement(e.headerRowStyle)),null!=e.lastColumnStyle&&(t.lastColumnStyle=this._parseToWorkbookTableStyleElement(e.lastColumnStyle)),null!=e.lastHeaderCellStyle&&(t.lastHeaderCellStyle=this._parseToWorkbookTableStyleElement(e.lastHeaderCellStyle)),null!=e.lastTotalCellStyle&&(t.lastTotalCellStyle=this._parseToWorkbookTableStyleElement(e.lastTotalCellStyle)),null!=e.secondBandedColumnStyle&&(t.secondBandedColumnStyle=this._parseToWorkbookTableStyleElement(e.secondBandedColumnStyle,!0)),null!=e.secondBandedRowStyle&&(t.secondBandedRowStyle=this._parseToWorkbookTableStyleElement(e.secondBandedRowStyle,!0)),null!=e.totalRowStyle&&(t.totalRowStyle=this._parseToWorkbookTableStyleElement(e.totalRowStyle)),null!=e.wholeTableStyle&&(t.wholeTableStyle=this._parseToWorkbookTableStyleElement(e.wholeTableStyle)),t}_parseToWorkbookTableStyleElement(e,t=!1){var o,n=wjcGridXlsx.FlexGridXlsxConverter._parseCellStyle(e,!0);return t?(o=new wjcXlsx.WorkbookTableBandedStyle).size=e.size:o=new wjcXlsx.WorkbookTableCommonStyle,o._deserialize(n),o}_isBuiltInStyleName(e){var t;if(0===e.search(/TableStyleLight/i)){if(t=+e.substring(15),!isNaN(t)&&t>=1&&t<=21)return!0}else if(0===e.search(/TableStyleMedium/i)){if(t=+e.substring(16),!isNaN(t)&&t>=1&&t<=28)return!0}else if(0===e.search(/TableStyleDark/i)&&(t=+e.substring(14),!isNaN(t)&&t>=1&&t<=11))return!0;return!1}_getTable(e){for(var t,o,n,i=0;i<this.sheets.length;i++)for(o=this.sheets[i].tables,n=0;n<o.length;n++)if((t=o[n]).name.toLowerCase()===e.toLowerCase())return t;return null}_isTableColumnRef(e,t){return new RegExp("\\[(\\s*@)?"+t+"\\]","i").test(e)}_getThemeColor(e,t){var o,n,i=this._colorThemes[e];return null!=t?(o=new wjcCore.Color("#"+i),n=o.getHsl(),n[2]=t<0?n[2]*(1+t):n[2]*(1-t)+(1-1*(1-t)),(o=wjcCore.Color.fromHsl(n[0],n[1],n[2])).toString()):"#"+i}_createBuiltInTableStyle(e){var t;if(0===e.search(/TableStyleLight/i)){if(t=+e.substring(15),!isNaN(t)&&t>=1&&t<=21)return t<=7?this._generateTableLightStyle1(t-1,e,!0):t<=14?this._generateTableLightStyle2(t-8,e):this._generateTableLightStyle1(t-15,e,!1)}else if(0===e.search(/TableStyleMedium/i)){if(t=+e.substring(16),!isNaN(t)&&t>=1&&t<=28)return t<=7?this._generateTableMediumStyle1(t-1,e):t<=14?this._generateTableMediumStyle2(t-8,e):t<=21?this._generateTableMediumStyle3(t-15,e):this._generateTableMediumStyle4(t-22,e)}else if(0===e.search(/TableStyleDark/i)&&(t=+e.substring(14),!isNaN(t)&&t>=1&&t<=11))return t<=7?this._generateTableDarkStyle1(t-1,e):this._generateTableDarkStyle2(t-8,e);return null}_generateTableLightStyle1(e,t,o){var n=new TableStyle(t,!0),i=0===e?1:e+3,s=o?"1px":"2px",l=o?"solid":"double",r=o?"1px":"3px";return n.wholeTableStyle={borderTopColor:this._getThemeColor(i),borderTopStyle:"solid",borderTopWidth:"1px",borderBottomColor:this._getThemeColor(i),borderBottomStyle:"solid",borderBottomWidth:"1px"},n.firstColumnStyle={fontWeight:"bold"},n.lastColumnStyle={fontWeight:"bold"},n.headerRowStyle={borderBottomColor:this._getThemeColor(i),borderBottomStyle:"solid",borderBottomWidth:s,fontWeight:"bold"},n.totalRowStyle={borderTopColor:this._getThemeColor(i),borderTopStyle:l,borderTopWidth:r,fontWeight:"bold"},0===e?(n.wholeTableStyle.color=this._getThemeColor(i),n.firstColumnStyle.color=this._getThemeColor(i),n.lastColumnStyle.color=this._getThemeColor(i),n.headerRowStyle.color=this._getThemeColor(i),n.totalRowStyle.color=this._getThemeColor(i),n.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.15)},n.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.15)}):(o?(n.wholeTableStyle.color=this._getThemeColor(i,-.25),n.firstColumnStyle.color=this._getThemeColor(i,-.25),n.lastColumnStyle.color=this._getThemeColor(i,-.25),n.headerRowStyle.color=this._getThemeColor(i,-.25),n.totalRowStyle.color=this._getThemeColor(i,-.25)):(n.wholeTableStyle.color=this._getThemeColor(1),n.firstColumnStyle.color=this._getThemeColor(1),n.lastColumnStyle.color=this._getThemeColor(1),n.headerRowStyle.color=this._getThemeColor(1),n.totalRowStyle.color=this._getThemeColor(1)),n.firstBandedRowStyle={backgroundColor:this._getThemeColor(i,.8)},n.firstBandedColumnStyle={backgroundColor:this._getThemeColor(i,.8)}),o||(n.wholeTableStyle.borderLeftColor=this._getThemeColor(i),n.wholeTableStyle.borderLeftStyle="solid",n.wholeTableStyle.borderLeftWidth="1px",n.wholeTableStyle.borderRightColor=this._getThemeColor(i),n.wholeTableStyle.borderRightStyle="solid",n.wholeTableStyle.borderRightWidth="1px",n.wholeTableStyle.borderHorizontalColor=this._getThemeColor(i),n.wholeTableStyle.borderHorizontalStyle="solid",n.wholeTableStyle.borderHorizontalWidth="1px",n.wholeTableStyle.borderVerticalColor=this._getThemeColor(i),n.wholeTableStyle.borderVerticalStyle="solid",n.wholeTableStyle.borderVerticalWidth="1px"),n}_generateTableLightStyle2(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"1px",borderBottomColor:this._getThemeColor(n),borderBottomStyle:"solid",borderBottomWidth:"1px",borderLeftColor:this._getThemeColor(n),borderLeftStyle:"solid",borderLeftWidth:"1px",borderRightColor:this._getThemeColor(n),borderRightStyle:"solid",borderRightWidth:"1px",color:this._getThemeColor(1)},o.firstBandedRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"1px"},o.secondBandedRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"1px"},o.firstBandedColumnStyle={borderLeftColor:this._getThemeColor(n),borderLeftStyle:"solid",borderLeftWidth:"1px"},o.secondBandedColumnStyle={borderLeftColor:this._getThemeColor(n),borderLeftStyle:"solid",borderLeftWidth:"1px"},o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"double",borderTopWidth:"3px",fontWeight:"bold",color:this._getThemeColor(1)},o}_generateTableMediumStyle1(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopStyle:"solid",borderTopWidth:"1px",borderBottomStyle:"solid",borderBottomWidth:"1px",borderLeftStyle:"solid",borderLeftWidth:"1px",borderRightStyle:"solid",borderRightWidth:"1px",borderHorizontalStyle:"solid",borderHorizontalWidth:"1px",color:this._getThemeColor(1)},0===e?(o.wholeTableStyle.borderTopColor=this._getThemeColor(n),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n),o.wholeTableStyle.borderRightColor=this._getThemeColor(n),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.15)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.15)}):(o.wholeTableStyle.borderTopColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderRightColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n,.4),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,.8)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,.8)}),o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"double",borderTopWidth:"3px",fontWeight:"bold",color:this._getThemeColor(1)},o}_generateTableMediumStyle2(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderVerticalStyle:"solid",borderVerticalWidth:"1px",borderVerticalColor:this._getThemeColor(0),borderHorizontalStyle:"solid",borderHorizontalWidth:"1px",borderHorizontalColor:this._getThemeColor(0),color:this._getThemeColor(1)},0===e?(o.wholeTableStyle.backgroundColor=this._getThemeColor(0,-.15),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.35)}):(o.wholeTableStyle.backgroundColor=this._getThemeColor(n,.8),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,.6)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,.6)}),o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.headerRowStyle={borderBottomColor:this._getThemeColor(0),borderBottomStyle:"solid",borderBottomWidth:"3px",backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(0),borderTopStyle:"solid",borderTopWidth:"3px",backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o}_generateTableMediumStyle3(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopStyle:"solid",borderTopWidth:"2px",borderTopColor:this._getThemeColor(1),borderBottomStyle:"solid",borderBottomWidth:"2px",borderBottomColor:this._getThemeColor(1),color:this._getThemeColor(1)},0===e&&(o.wholeTableStyle.borderLeftColor=this._getThemeColor(1),o.wholeTableStyle.borderLeftStyle="solid",o.wholeTableStyle.borderLeftWidth="1px",o.wholeTableStyle.borderRightColor=this._getThemeColor(1),o.wholeTableStyle.borderRightStyle="solid",o.wholeTableStyle.borderRightWidth="1px",o.wholeTableStyle.borderVerticalColor=this._getThemeColor(1),o.wholeTableStyle.borderVerticalStyle="solid",o.wholeTableStyle.borderVerticalWidth="1px",o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(1),o.wholeTableStyle.borderHorizontalStyle="solid",o.wholeTableStyle.borderHorizontalWidth="1px"),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n)},o.headerRowStyle={borderBottomColor:this._getThemeColor(1),borderBottomStyle:"solid",borderBottomWidth:"2px",backgroundColor:this._getThemeColor(n),fontWeight:"bold",color:this._getThemeColor(0)},o.totalRowStyle={borderTopColor:this._getThemeColor(1),borderTopStyle:"double",borderTopWidth:"3px"},o}_generateTableMediumStyle4(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;return o.wholeTableStyle={borderTopStyle:"solid",borderTopWidth:"1px",borderBottomStyle:"solid",borderBottomWidth:"1px",borderLeftStyle:"solid",borderLeftWidth:"1px",borderRightStyle:"solid",borderRightWidth:"1px",borderVerticalStyle:"solid",borderVerticalWidth:"1px",borderHorizontalStyle:"solid",borderHorizontalWidth:"1px",color:this._getThemeColor(1)},0===e?(o.wholeTableStyle.borderTopColor=this._getThemeColor(n),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n),o.wholeTableStyle.borderRightColor=this._getThemeColor(n),o.wholeTableStyle.borderVerticalColor=this._getThemeColor(n),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n),o.wholeTableStyle.backgroundColor=this._getThemeColor(0,-.15),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.35)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.35)}):(o.wholeTableStyle.borderTopColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderBottomColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderLeftColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderRightColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderVerticalColor=this._getThemeColor(n,.4),o.wholeTableStyle.borderHorizontalColor=this._getThemeColor(n,.4),o.wholeTableStyle.backgroundColor=this._getThemeColor(n,.8),o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,.6)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,.6)}),o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.totalRowStyle={borderTopColor:this._getThemeColor(n),borderTopStyle:"solid",borderTopWidth:"2px",fontWeight:"bold",color:this._getThemeColor(1)},o}_generateTableDarkStyle1(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3,i=0===e?.25:-.25;return o.wholeTableStyle={color:this._getThemeColor(0)},o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,i)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,i)},o.firstColumnStyle={borderRightColor:this._getThemeColor(0),borderRightStyle:"solid",borderRightWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n,i)},o.lastColumnStyle={borderLeftColor:this._getThemeColor(0),borderLeftStyle:"solid",borderLeftWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(n,i)},o.headerRowStyle={borderBottomColor:this._getThemeColor(0),borderBottomStyle:"solid",borderBottomWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0),backgroundColor:this._getThemeColor(1)},o.totalRowStyle={borderTopColor:this._getThemeColor(0),borderTopStyle:"solid",borderTopWidth:"2px",fontWeight:"bold",color:this._getThemeColor(0)},0===e?(o.wholeTableStyle.backgroundColor=this._getThemeColor(n,.5),o.totalRowStyle.backgroundColor=this._getThemeColor(n,.15)):(o.wholeTableStyle.backgroundColor=this._getThemeColor(n),o.totalRowStyle.backgroundColor=this._getThemeColor(n,-.5)),o}_generateTableDarkStyle2(e,t){var o=new TableStyle(t,!0),n=0===e?0:2*e+2,i=0===e?1:2*e+3,s=0===e?-.15:.8;return o.wholeTableStyle={backgroundColor:this._getThemeColor(n,s)},o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,s-.2)},o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,s-.2)},o.firstColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.lastColumnStyle={fontWeight:"bold",color:this._getThemeColor(1)},o.headerRowStyle={color:this._getThemeColor(0),backgroundColor:this._getThemeColor(i)},o.totalRowStyle={borderTopColor:this._getThemeColor(1),borderTopStyle:"double",borderTopWidth:"3px",fontWeight:"bold",color:this._getThemeColor(1)},o}}FlexSheet.controlTemplate='<div style="width:100%;height:100%"><div wj-part="container" style="width:100%">'+wjcGrid.FlexGrid.controlTemplate+'</div><div wj-part="tab-holder" class="wj-tabholder" style="width:100%; min-width:100px"></div><div wj-part="context-menu" style="display:none;z-index:100"></div></div>',exports.FlexSheet=FlexSheet;class DraggingRowColumnEventArgs extends wjcCore.EventArgs{constructor(e,t){super(),this._isDraggingRows=e,this._isShiftKey=t}get isDraggingRows(){return this._isDraggingRows}get isShiftKey(){return this._isShiftKey}}exports.DraggingRowColumnEventArgs=DraggingRowColumnEventArgs;class UnknownFunctionEventArgs extends wjcCore.EventArgs{constructor(e,t){super(),this._funcName=e,this._params=t}get funcName(){return this._funcName}get params(){return this._params}}exports.UnknownFunctionEventArgs=UnknownFunctionEventArgs;class RowColumnChangedEventArgs extends wjcCore.EventArgs{constructor(e,t,o){super(),this._index=e,this._count=t,this._added=o}get index(){return this._index}get count(){return this._count}get added(){return this._added}get isAdd(){return wjcCore._deprecated("RowColumnChangedEventArgs.isAdd","RowColumnChangedEventArgs.added"),this._added}}exports.RowColumnChangedEventArgs=RowColumnChangedEventArgs;class FlexSheetPanel extends wjcGrid.GridPanel{constructor(e,t,o,n,i){super(e,t,o,n,i)}getSelectedState(e,t,o){var n,i,s,l,r,a;if(this.grid){if(a=this.grid.getMergedRange(this,e,t),n=this.grid.selectedSheet?this.grid.selectedSheet.selectionRanges:null,r=super.getSelectedState(e,t,o),i=n?n.length:0,r===wjcGrid.SelectedState.None&&i>0)for(s=0;s<n.length;s++)if((l=n[s])&&l instanceof wjcGrid.CellRange){if(this.cellType===wjcGrid.CellType.Cell){if(a){if(a.contains(l.row,l.col))return s!==i-1||this.grid._isClicking?wjcGrid.SelectedState.Selected:this.grid.showMarquee?wjcGrid.SelectedState.None:wjcGrid.SelectedState.Cursor;if(a.intersects(l))return wjcGrid.SelectedState.Selected}if(l.row===e&&l.col===t)return s!==i-1||this.grid._isClicking?wjcGrid.SelectedState.Selected:this.grid.showMarquee?wjcGrid.SelectedState.None:wjcGrid.SelectedState.Cursor;if(l.contains(e,t))return wjcGrid.SelectedState.Selected}if(this.grid.showSelectedHeaders&wjcGrid.HeadersVisibility.Row&&this.cellType===wjcGrid.CellType.RowHeader&&l.containsRow(e))return wjcGrid.SelectedState.Selected;if(this.grid.showSelectedHeaders&wjcGrid.HeadersVisibility.Column&&this.cellType===wjcGrid.CellType.ColumnHeader&&l.containsColumn(t))return wjcGrid.SelectedState.Selected}return r}}getCellData(e,t,o){var n,i,s,l,r;if(wjcCore.isString(t)&&(t=this.columns.indexOf(t))<0)throw"Invalid column name or binding.";return e>=this.rows.length||wjcCore.asNumber(t,!1,!0)>=this.columns.length?null:(n=super.getCellData(e,t,o),i=this.columns[wjcCore.asNumber(t,!1,!0)],s=this.grid?this.grid._getBindingColumn(this,e,i):i,o&&(r=super.getCellData(e,t,!1),l=this.grid?this.grid._getCellStyle(e,t):null,!wjcCore.isNumber(r)||0===r||!s||s.format||s.dataMap||l||(n=r.toString())),n)}setCellData(e,t,o,n=!0,i=!0){var s,l=this.getCellData(e,t,!1),r=this.grid._isPasting;return n&&o&&wjcCore.isString(o)&&"'"!==o[0]&&(this.grid.columns[t].dataType===wjcCore.DataType.String||wjcCore.isNullOrWhiteSpace(o)||isNaN(+o)?this.grid.columns[t].dataType===wjcCore.DataType.Boolean?o=wjcCore.changeType(o,wjcCore.DataType.Boolean,null):"="!==o[0]&&(s=wjcCore.Globalize.parseDate(o,""))&&(o=s):o=+o),(o&&wjcCore.isString(o)&&("="===o[0]||"'"===o[0])||wjcCore.isString(l))&&(n=!1),super.setCellData(e,t,o,n&&!r,i)}_renderCell(e,t,o,n,i,s){var l,r,a,h,d=t*this.grid.columns.length+o,c=this.grid.getMergedRange(this,t,o);return h=super._renderCell(e,t,o,n,i,s),this.cellType!==wjcGrid.CellType.Cell?h:c&&d>c.topRow*this.grid.columns.length+c.leftCol?h:((l=e.childNodes[s])&&(null!=this.grid.editRange&&this.grid.editRange.contains(t,o)||this.grid.selectedSheet&&(a=this.grid.selectedSheet.findTable(t,o))&&a._updateCell(t,o,l),wjcCore.hasClass(l,"wj-state-selected")||wjcCore.hasClass(l,"wj-state-multi-selected")?(l.style.backgroundColor="",l.style.color=""):this.grid.selectedSheet&&(r=this.grid.selectedSheet._styledCells[d])&&(""!==r.backgroundColor&&(l.style.backgroundColor=r.backgroundColor),""!==r.color&&(l.style.color=r.color))),h)}}exports.FlexSheetPanel=FlexSheetPanel;class HeaderRow extends wjcGrid.Row{constructor(){super(),this.isReadOnly=!0}}exports.HeaderRow=HeaderRow;class DefinedName{constructor(e,t,o,n){if(this._owner=e,this._name=t,this._value=o,null!=n){if(!e._validateSheetName(n))throw"The sheet name:("+n+") does not exist in FlexSheet.";this._sheetName=n}}get name(){return this._name}set name(e){var t;if(this._name!==e){if(this._owner._checkExistDefinedName(name,this._sheetName))throw"The "+name+" already existed in definedNames.";t=this._name,this._name=e,this._owner._updateFormulasWithNameUpdating(t,this._name)}}get value(){return this._value}set value(e){this._value!==e&&(this._value=e)}get sheetName(){return this._sheetName}}exports.DefinedName=DefinedName;class Sheet{constructor(e,t,o,n,i){this._visible=!0,this._unboundSortDesc=new wjcCore.ObservableArray,this._currentStyledCells={},this._currentMergedRanges=[],this._isEmptyGrid=!1,this._rowSettings=[],this._scrollPosition=new wjcCore.Point,this._freezeHiddenRowCnt=0,this._freezeHiddenColumnCnt=0,this._showDefaultHeader=!1,this.nameChanged=new wjcCore.Event,this.visibleChanged=new wjcCore.Event;var s=this;s._owner=e,s._name=o,s._sortList=[new ColumnSortDescription(-1,!0)],wjcCore.isNumber(n)&&!isNaN(n)&&n>=0?s._rowCount=n:s._rowCount=200,wjcCore.isNumber(i)&&!isNaN(i)&&i>=0?s._columnCount=i:s._columnCount=20,t?(s._showDefaultHeader=!0,s._grid=t):s._grid=this._createGrid(),s._grid.itemsSourceChanged.addHandler(this._gridItemsSourceChanged,this),s._addHeaderRow(),s._unboundSortDesc.collectionChanged.addHandler(()=>{var e,t,o=s._unboundSortDesc;for(e=0;e<o.length;e++)if(!wjcCore.tryCast(o[e],_UnboundSortDescription))throw"sortDescriptions array must contain SortDescription objects.";if(s._owner){if(s._owner.rows.beginUpdate(),s._owner.rows.sort(s._compareRows()),!s._owner._isUndoing)for(e=0;e<s._owner.rows.length;e++)e!==(t=s._owner.rows[e])._idx&&s._owner._updateFormulaForReorderingRows(t._idx,e);s._owner.rows.endUpdate(),s._owner.rows._dirty=!0,s._owner.rows._update(),s._owner.selectedSheet&&(s._owner._copyTo(s._owner.selectedSheet),s._owner._copyFrom(s._owner.selectedSheet))}}),s.tables.collectionChanged.addHandler((e,t)=>{if(null!=t.item&&!(t.item instanceof Table))throw"The tables only allows to handle Table instance.";if(t.action===wjcCore.NotifyCollectionChangedAction.Add||t.action===wjcCore.NotifyCollectionChangedAction.Change){if(t.item){let e,o,n,i=t.item,l=i.getRange(),r=s===s._owner.selectedSheet?s._owner:s.grid;try{if(l.topRow>=r.rows.length||l.leftCol>=r.columns.length)throw"";if(l.leftCol+l.columnSpan>r.columns.length)throw"";if(l.topRow+l.rowSpan>r.rows.length)throw"";for(e=l.topRow;e<=l.bottomRow;e++)for(o=l.leftCol;o<=l.rightCol;o++)if((n=s.findTable(e,o))!==i)throw"";i._attachSheet(s)}catch(e){s.tables.removeAt(t.index)}}}else t.action===wjcCore.NotifyCollectionChangedAction.Remove&&t.item&&t.item._detachSheet()})}get grid(){return null==this._grid.wj_sheetInfo&&(this._grid.wj_sheetInfo={}),this._grid}get name(){return this._name}set name(e){if(!wjcCore.isNullOrWhiteSpace(e)&&(this._name&&this._name.toLowerCase()!==e.toLowerCase()||!this._name)){var t=new wjcCore.PropertyChangedEventArgs("sheetName",this._name,e);this._name=e,this.grid.wj_sheetInfo.name=e,this.onNameChanged(t)}}get visible(){return this._visible}set visible(e){this._visible!==e&&(this._visible=e,this.grid.wj_sheetInfo.visible=e,this.onVisibleChanged(new wjcCore.EventArgs))}get rowCount(){return null!=this._grid?this._grid.rows.length:0}set rowCount(e){var t;if(!this.itemsSource&&wjcCore.isNumber(e)&&!isNaN(e)&&e>=0&&this._rowCount!==e){if(this._rowCount<e)for(t=0;t<e-this._rowCount;t++)this.grid.rows.push(new wjcGrid.Row);else this.grid.rows.splice(e,this._rowCount-e);this._rowCount=e,this._owner&&this._owner.selectedSheet&&this._name===this._owner.selectedSheet.name&&this._owner._copyFrom(this,!0)}}get columnCount(){return null!=this._grid?this._grid.columns.length:0}set columnCount(e){var t;if(!this.itemsSource&&wjcCore.isNumber(e)&&!isNaN(e)&&e>=0&&this._columnCount!==e){if(this._columnCount<e)for(t=0;t<e-this._columnCount;t++)this._grid.columns.push(new wjcGrid.Column);else this._grid.columns.splice(e,this._columnCount-e);this._columnCount=e,this._owner&&this._owner.selectedSheet&&this._name===this._owner.selectedSheet.name&&this._owner._copyFrom(this,!0)}}get selectionRanges(){return this._selectionRanges||(this._selectionRanges=new wjcCore.ObservableArray,this._selectionRanges.collectionChanged.addHandler(()=>{var e,t;this._owner&&!this._owner._isClicking&&((e=this._selectionRanges.length)>0&&(t=this._selectionRanges[e-1])&&t instanceof wjcGrid.CellRange&&(this._owner.selection=t),e>1?(this._owner._enableMulSel=!0,this._owner.refresh(!1)):this._owner.refresh(),this._owner._enableMulSel=!1)},this)),this._selectionRanges}get itemsSource(){return null!=this._grid?this._grid.itemsSource:null}set itemsSource(e){var t=this;null==t._grid&&(t._createGrid(),t._grid.itemsSourceChanged.addHandler(t._gridItemsSourceChanged,t)),t._isEmptyGrid&&t._clearGrid(),t._grid.loadedRows.addHandler(()=>{t._addHeaderRow()}),t._grid.itemsSource=e,t._owner&&t._owner._isCopying||null==e||(t._orgItemsSource=t._grid.collectionView._view.slice())}get filterSetting(){return this===this._owner.selectedSheet&&this._getFilterSetting(),this._filterSetting}set filterSetting(e){this._filterSetting=e,this===this._owner.selectedSheet&&this._applyFilterSetting()}get tables(){return null==this._tables&&(this._tables=new wjcCore.ObservableArray),this._tables}get _styledCells(){return this._currentStyledCells||(this._currentStyledCells={}),this._currentStyledCells}set _styledCells(e){this._currentStyledCells=e}get _mergedRanges(){return this._currentMergedRanges||(this._currentMergedRanges=[]),this._currentMergedRanges}onNameChanged(e){this.nameChanged.raise(this,e)}onVisibleChanged(e){this.visibleChanged.raise(this,e)}getCellStyle(e,t){var o,n=this._grid.rows.length,i=this._grid.columns.length;return e>=n||t>=i?null:(o=e*i+t,this._styledCells[o])}addTableFromArray(e,t,o,n,i,s,l,r=!0){let a,h,d,c,_,u,g,w,m,C,f,p,S=!1,b=this===this._owner.selectedSheet?this._owner:this.grid;if(null==o||0===o.length)throw"Invalid array to load.";if(!(null!=n&&0!==n.length||null!=(n=Object.keys(o[0]))&&0!==n.length))throw"Invalid array to load.";if(e>=this.rowCount||t>=this.columnCount)return null;let R=null==(l&&l.showHeaderRow)||l.showHeaderRow,y=!(!l||!l.showTotalRow),v=e+(R?1:0),T=v+o.length-1+(y?1:0);for(h=[],C=0;C<n.length;C++)f=n[C],d=new TableColumn(f),0===C?d._totalRowLabel="Total":C===n.length-1&&(d._totalRowFunction="Sum"),h.push(d);if(c=new wjcGrid.CellRange(e,t,T,t+n.length-1),0!==(_=this._needShiftForTable(c))){if(!r)return null;if(!this._canShiftCells(c))return null;if(u=this._needAddRowCountForAddTable(_,c),b.collectionView){for(p=b.itemsSource instanceof wjcCore.CollectionView,b.collectionView.beginUpdate(),w=0;w<u;w++)p?b.itemsSource.sourceCollection.push({}):b.itemsSource.push({});b.collectionView.endUpdate()}else for(w=0;w<u;w++)b.rows.push(new wjcGrid.Row);S=!0}if(t+n.length>=b.columns.length){if(!r)return null;if(g=t+n.length-b.columns.length+1,this.itemsSource&&g>0)return null;for(b.columns.beginUpdate(),w=0;w<g;w++)b.columns.push(new wjcGrid.Column);b.columns.endUpdate()}if(b.beginUpdate(),S&&this._moveDownCells(_,c),R)for(C=0;C<n.length;C++)f=n[C],b.setCellData(e,t+C,f);for(m=0;m<o.length;m++)for(C=0;C<n.length;C++)f=n[C],b.setCellData(v+m,t+C,o[m][f]);return b.endUpdate(),a=this._addTable(c,i,s,h,l)}findTable(e,t){var o,n;if(this._tables&&this._tables.length>0)for(var i=0;i<this._tables.length;i++)if(o=this._tables[i],n=o.getRange(),e>=n.topRow&&e<=n.bottomRow&&t>=n.leftCol&&t<=n.rightCol)return o;return null}_attachOwner(e){this._owner!==e&&(this._owner=e)}_setValidName(e){this._name=e,this.grid.wj_sheetInfo.name=e}_storeRowSettings(){var e,t=0;for(this._rowSettings=[];t<this._grid.rows.length;t++)(e=this._owner.rows[t])&&(this._rowSettings[t]={height:e.height,allowMerging:e.allowMerging,isCollapsed:e instanceof wjcGrid.GroupRow?e.isCollapsed:null,visible:e.visible,isSelected:e.isSelected,readOnly:e.isReadOnly})}_setRowSettings(){for(var e,t,o=0;o<this._rowSettings.length;o++)(t=this._rowSettings[o])&&(e=this._grid.rows[o])&&(e.height=t.height,e.allowMerging=t.allowMerging,e.visible=t.visible,e instanceof wjcGrid.GroupRow&&(e.isCollapsed=!!t.isCollapsed),e.isSelected=!!t.isSelected,e.isReadOnly=!!t.readOnly)}_addTable(e,t,o,n,i){if(!e.isValid)return null;let s;return null!=t&&null==this._owner._getTable(t)||(t=this._getUniqueTableName()),s=new Table(t,e,o,n,i),this.tables.push(s),s}_addSelection(e){let t,o;for(this.selectionRanges.beginUpdate(),o=this.selectionRanges.length-1;o>=0;o--)t=this.selectionRanges[o],e.contains(t)&&this.selectionRanges.removeAt(o);e.isValid&&this.selectionRanges.push(e),this.selectionRanges.endUpdate()}_compareRows(){var e=this,t=this._unboundSortDesc;return function(o,n){for(var i=0;i<t.length;i++){var s=t[i],l=o._ubv&&s.column?o._ubv[s.column._hash]:"",r=n._ubv&&s.column?n._ubv[s.column._hash]:"";if(wjcCore.isString(l)&&"="===l[0]&&(l=e._owner.evaluate(l)),wjcCore.isString(r)&&"="===r[0]&&(r=e._owner.evaluate(r)),l!==l&&(l=null),r!==r&&(r=null),wjcCore.isString(l)&&(l=l.toLowerCase()+l),wjcCore.isString(r)&&(r=r.toLowerCase()+r),""===l||null==l)return 1;if(""===r||null==r)return-1;var a=l<r?-1:l>r?1:0;if(wjcCore.isString(l)&&wjcCore.isNumber(r)&&(a=1),wjcCore.isString(r)&&wjcCore.isNumber(l)&&(a=-1),0!==a)return s.ascending?+a:-a}return 0}}_createGrid(){var e,t,o,n,i=document.createElement("div");for(this._isEmptyGrid=!0,i.style.visibility="hidden",document.body.appendChild(i),e=new wjcGrid.FlexGrid(i),document.body.removeChild(i),n=0;n<this._rowCount;n++)e.rows.push(new wjcGrid.Row);for(o=0;o<this._columnCount;o++)(t=new wjcGrid.Column).isRequired=!1,e.columns.push(t);return e.wj_sheetInfo={name:this.name,visible:this.visible,styledCells:this._styledCells,mergedRanges:this._mergedRanges},e}_clearGrid(){this._grid.rows.clear(),this._grid.columns.clear(),this._grid.columnHeaders.columns.clear(),this._grid.rowHeaders.rows.clear()}_gridItemsSourceChanged(){var e=this;e._owner&&!e._owner._isCopying&&e._owner.selectedSheet&&e._name===e._owner.selectedSheet.name&&(e._owner.filter.clear(),e._owner._copyFrom(e,!1),setTimeout(()=>{e._owner._setFlexSheetToDirty(),e._owner.invalidate()},10))}_addHeaderRow(){if(this._grid.itemsSource&&!(this._grid.rows[0]instanceof HeaderRow)){for(var e,t=new HeaderRow,o=0;o<this._grid.columns.length;o++)e=this._grid.columns[o],t._ubv||(t._ubv={}),t._ubv[e._hash]=e.header;this._grid.rows.insert(0,t)}}_getUniqueTableName(){for(var e="Table1",t=2;;){if(null==this._owner._getTable(e))break;e="Table"+t,t+=1}return e}_needShiftForTable(e){let t,o,n,i=0,s=0,l=this===this._owner.selectedSheet?this._owner:this.grid;for(t=e.topRow;t<=e.bottomRow;t++){if(t>=l.rows.length)return i=e.rowSpan-s;for(o=e.leftCol;o<=e.rightCol&&o<l.columns.length;o++)if(null!=(n=l.getCellData(t,o,!1))&&""!==n)return i=e.rowSpan-s;s++}return i}_needAddRowCountForAddTable(e,t){var o,n,i,s,l,r=this===this._owner.selectedSheet?this._owner:this.grid;for(o=1;o<=e;o++)for(n=r.rows.length-o,i=t.leftCol;i<=t.rightCol&&i<r.columns.length;i++)if(s=r.getCellData(n,i,!1),l=this.getCellStyle(n,i),null!=s&&""!==s||null!=l)return e-o+1;return 0}_moveDownTable(e){var t,o,n,i,s=e.getRange(),l=this===this._owner.selectedSheet?this._owner:this.grid;for(t=s.bottomRow;t>=s.topRow;t--)for(o=s.leftCol;o<=s.rightCol;o++)i=null!=l.columns[o].dataMap,n=l.getCellData(t,o,i),l.setCellData(t+1,o,n),l.setCellData(t,o,"");e._updateTableRange(1,1,0,0)}_moveDownCells(e,t){var o,n,i,s,l,r,a,h,d,c,_=this===this._owner.selectedSheet?this._owner:this.grid;for(o=_.rows.length-1-e;o>=t.topRow;o--)for(n=t.leftCol;n<=t.rightCol&&n<_.columns.length;n++)c=null!=_.columns[n].dataMap,i=_.getCellData(o,n,c),_.setCellData(o+e,n,i),_.setCellData(o,n,""),s=this.getCellStyle(o,n),r=(o+e)*_.columns.length+n,l=o*_.columns.length+n,s&&(this._styledCells[r]=s,this._styledCells[l]=null),(a=this._mergedRanges[l])&&(a.row+=e,a.row2+=e,this._mergedRanges[r]=a,this._mergedRanges[l]=null),(h=this.findTable(o,n))&&(d=h.getRange()).topRow===o&&d.leftCol===n&&h._updateTableRange(e,e,0,0)}_moveUpCells(e,t){var o,n,i,s,l,r,a,h,d,c,_=this===this._owner.selectedSheet?this._owner:this.grid;for(o=t.topRow;o<_.rows.length;o++)for(n=t.leftCol;n<=t.rightCol&&n<_.columns.length;n++)c=null!=_.columns[n].dataMap,i=_.getCellData(o,n,c),_.setCellData(o-e,n,i),_.setCellData(o,n,""),s=this.getCellStyle(o,n),r=(o-e)*_.columns.length+n,l=o*_.columns.length+n,s&&(this._styledCells[r]=s,this._styledCells[l]=null),(a=this._mergedRanges[l])&&(a.row-=e,a.row2-=e,this._mergedRanges[r]=a,this._mergedRanges[l]=null),(h=this.findTable(o,n))&&(d=h.getRange()).topRow===o&&d.leftCol===n&&h._updateTableRange(-e,-e,0,0)}_moveDownCellsWithinTable(e,t,o){var n,i,s,l,r=this===this._owner.selectedSheet?this._owner:this.grid;for(n=o.bottomRow;n>o.topRow+e;n--)for(i=o.leftCol;i<=o.rightCol;i++)l=null!=r.columns[i].dataMap,s=r.getCellData(n,i,l),r.setCellData(n+t,i,s),r.setCellData(n,i,""),(n+t)*r.columns.length+i,n*r.columns.length+i}_moveUpCellsWithinTable(e,t,o){var n,i,s,l,r=o.topRow+e,a=this===this._owner.selectedSheet?this._owner:this.grid;for(n=r;n<=o.bottomRow;n++)for(i=o.leftCol;i<=o.rightCol;i++)n>=r+t&&(l=null!=a.columns[i].dataMap,s=a.getCellData(n,i,l),a.setCellData(n-t,i,s)),a.setCellData(n,i,""),(n-t)*a.columns.length+i,n*a.columns.length+i}_canShiftCells(e){var t,o,n,i,s,l,r=this===this._owner.selectedSheet?this._owner:this.grid;for(t=e.topRow;t<r.rows.length;t++)for(o=e.leftCol;o<=e.rightCol&&o<r.columns.length;o++){if((s=this.findTable(t,o))&&((l=s.getRange()).leftCol<e.leftCol||l.rightCol>e.rightCol))return!1;if(n=t*r.columns.length+o,(i=this._mergedRanges[n])&&(i.leftCol<e.leftCol||i.rightCol>e.rightCol))return!1}return!0}_needMoveDownTable(e){var t,o,n=e.getRange(),i=e.getColumns(),s=this===this._owner.selectedSheet?this._owner:this.grid;if(0===n.topRow)return!0;for(t=0;t<i.length;t++)if(null!=(o=s.getCellData(n.topRow-1,n.leftCol+t,!1))&&""!==o)return!0;return!1}_needAddRowCountForInsertTableRows(e,t){var o,n,i,s,l,r=this===this._owner.selectedSheet?this._owner:this.grid;for(o=1;o<=e;o++){if((n=r.rows.length-o)<=t.bottomRow)return e;for(i=t.leftCol;i<=t.rightCol&&i<r.columns.length;i++)if(s=r.getCellData(n,i,!1),l=this.getCellStyle(n,i),null!=s&&""!==s||null!=l)return e-o+1}return 0}_getFilterSetting(){let e,t=0;for(this._filterDefinition=this._owner.filter.filterDefinition,this._filterSetting={},this._filterSetting.filterColumns=this._owner.filter.filterColumns,this._filterSetting.columnFilterSettings||(this._filterSetting.columnFilterSettings=[]);t<this._owner.filter._filters.length;t++)(e=this._owner.filter._filters[t])&&this._filterSetting.columnFilterSettings.push({column:e.column,filterType:e.filterType,dataMap:e.dataMap,valueFilterSetting:{maxValues:e.valueFilter.maxValues,uniqueValues:e.valueFilter.uniqueValues,sortValues:e.valueFilter.sortValues,dataMap:e.valueFilter.dataMap},conditionFilterSetting:{dataMap:e.conditionFilter.dataMap}})}_applyFilterSetting(){let e,t,o,n,i,s,l,r,a,h,d=0;if(null==this._filterSetting)this._clearFilterSetting();else if(this._owner.filter.filterColumns=this._filterSetting.filterColumns,this._filterDefinition&&(this._owner.filter.filterDefinition=this._filterDefinition),null!=(e=this._filterSetting.columnFilterSettings)&&e.length>0)for(;d<e.length;d++)(t=e[d])&&null!=t.column&&(i=this._owner.filter.getColumnFilter(t.column))&&(s=i.valueFilter.showValues,l=i.valueFilter.filterText,r={operator:i.conditionFilter.condition1.operator,value:i.conditionFilter.condition1.value},a={operator:i.conditionFilter.condition2.operator,value:i.conditionFilter.condition2.value},h=i.conditionFilter.and,null!=t.dataMap&&(i.dataMap=t.dataMap),null!=t.filterType&&(i.filterType=t.filterType),(o=t.valueFilterSetting)&&(o.dataMap&&(i.valueFilter.dataMap=o.dataMap),null!=o.maxValues&&(i.valueFilter.maxValues=o.maxValues),null!=o.sortValues&&(i.valueFilter.sortValues=o.sortValues),o.uniqueValues&&(i.valueFilter.uniqueValues=o.uniqueValues)),(n=t.conditionFilterSetting)&&n.dataMap&&(i.conditionFilter.dataMap=n.dataMap),i.valueFilter.showValues=s,i.valueFilter.filterText=l,i.conditionFilter.condition1.operator=r.operator,i.conditionFilter.condition1.value=r.value,i.conditionFilter.condition2.operator=a.operator,i.conditionFilter.condition2.value=a.value,i.conditionFilter.and=h)}_clearFilterSetting(){let e,t=0;for(this._owner.filter.filterColumns=null;t<this._owner.filter._filters.length;t++)(e=this._owner.filter._filters[t])&&(e.filterType=null,e.dataMap=null,e.valueFilter.uniqueValues=null,e.valueFilter.dataMap=null,e.valueFilter.maxValues=250,e.valueFilter.showValues=null,e.conditionFilter.dataMap=null);this._filterDefinition&&(this._owner.filter.filterDefinition=this._filterDefinition)}_cloneMergedCells(){let e,t=0,o=[];for(;t<this._mergedRanges.length;t++)e=this._mergedRanges[t],o.push(e.clone());return o}_getMergedRange(e,t){let o,n;for(o=0;o<this._mergedRanges.length;o++)if(n=this._mergedRanges[o],e>=n.topRow&&e<=n.bottomRow&&t>=n.leftCol&&t<=n.rightCol)return n;return null}}exports.Sheet=Sheet;class SheetCollection extends wjcCore.ObservableArray{constructor(){super(...arguments),this._current=-1,this.sheetCleared=new wjcCore.Event,this.selectedSheetChanged=new wjcCore.Event,this.sheetNameChanged=new wjcCore.Event,this.sheetVisibleChanged=new wjcCore.Event}onSheetCleared(){this.sheetCleared.raise(this,new wjcCore.EventArgs)}get selectedIndex(){return this._current}set selectedIndex(e){this._moveCurrentTo(+e)}onSelectedSheetChanged(e){this.selectedSheetChanged.raise(this,e)}insert(e,t){var o;(o=t.name?this.getValidSheetName(t):this._getUniqueName())!==t.name&&(t.name=o),super.insert(e,t),this._postprocessSheet(t)}push(...e){this.length;for(var t,o=0;o<e.length;o++)(t=e[o].name?this.getValidSheetName(e[o]):this._getUniqueName())!==e[o].name&&(e[o].name=t),super.push(e[o]),this._postprocessSheet(e[o]);return this.length}splice(e,t,o){var n;return o?((n=o.name?this.getValidSheetName(o):this._getUniqueName())!==o.name&&(o.name=n),this._postprocessSheet(o),super.splice(e,t,o)):super.splice(e,t,o)}removeAt(e){this.hide(e)&&(super.removeAt(e),e<this.selectedIndex&&(this._current-=1))}onSheetNameChanged(e){this.sheetNameChanged.raise(this,e)}onSheetVisibleChanged(e){this.sheetVisibleChanged.raise(this,e)}selectFirst(){return this._moveCurrentTo(0)}selectLast(){return this._moveCurrentTo(this.length-1)}selectPrevious(){return this._moveCurrentTo(this._current-1)}selectNext(){return this._moveCurrentTo(this._current+1)}hide(e){return!(e<0&&e>=this.length)&&(!!this[e].visible&&(this[e].visible=!1,!0))}show(e){return!(e<0&&e>=this.length)&&(this[e].visible=!0,this._moveCurrentTo(e),!0)}clear(){super.clear(),this._current=-1,this.onSheetCleared()}isValidSheetName(e){var t=this._getSheetIndexFrom(e.name),o=this.indexOf(e);return-1===t||t===o}getValidSheetName(e){for(var t,o=e.name,n=1,i=this.indexOf(e);;){if(-1===(t=this._getSheetIndexFrom(o))||t===i)break;o=e.name.concat((n+1).toString()),n+=1}return o}_moveCurrentTo(e){var t,o=e;if(e<0||e>=this.length)return!1;if(this._current<o||0===o)for(;o<this.length&&!this[o].visible;)o++;else if(this._current>o)for(;o>=0&&!this[o].visible;)o--;if(o===this.length)for(o=e;o>=0&&!this[o].visible;)o--;return!(o<0)&&(o!==this._current&&(t=new wjcCore.PropertyChangedEventArgs("sheetIndex",this._current,o),this._current=o,this.onSelectedSheetChanged(t)),!0)}_getSheetIndexFrom(e){var t;if(!e)return-1;e=e.toLowerCase();for(var o=0;o<this.length;o++)if(t=this[o],(t.name?t.name.toLowerCase():"")===e)return o;return-1}_postprocessSheet(e){var t=this;e.nameChanged.addHandler(()=>{var o,n=t._getSheetIndexFrom(e.name);t.isValidSheetName(e)||e._setValidName(t.getValidSheetName(e)),o=new wjcCore.NotifyCollectionChangedEventArgs(wjcCore.NotifyCollectionChangedAction.Change,e,wjcCore.isNumber(n)?n:t.length-1),t.onSheetNameChanged(o)}),e.visibleChanged.addHandler(()=>{var o=t._getSheetIndexFrom(e.name),n=new wjcCore.NotifyCollectionChangedEventArgs(wjcCore.NotifyCollectionChangedAction.Change,e,wjcCore.isNumber(o)?o:t.length-1);t.onSheetVisibleChanged(n)})}_getUniqueName(){for(var e="Sheet1",t=2;;){if(-1===this._getSheetIndexFrom(e))break;e="Sheet"+t,t+=1}return e}}exports.SheetCollection=SheetCollection;class _SheetTabs extends wjcCore.Control{constructor(e,t,o){super(e,o),this._rtl=!1,this._sheetTabClicked=!1;var n=this;n._owner=t,n._sheets=t.sheets,n._rtl="rtl"==getComputedStyle(n._owner.hostElement).direction,n._initControl(),n.deferUpdate(()=>{o&&n.initialize(o)})}refresh(e){this._tabContainer.innerHTML="",this._tabContainer.innerHTML=this._getSheetTabs(),this._rtl&&this._adjustSheetsPosition(),this._adjustSize()}_sourceChanged(e,t=wjcCore.NotifyCollectionChangedEventArgs.reset){var o=t;switch(o.action){case wjcCore.NotifyCollectionChangedAction.Add:o.index-1<0&&0,this._tabContainer.innerHTML="",this._tabContainer.innerHTML=this._getSheetTabs(),this._rtl&&this._adjustSheetsPosition(),this._adjustSize();break;case wjcCore.NotifyCollectionChangedAction.Remove:this._tabContainer.removeChild(this._tabContainer.children[o.index]),this._tabContainer.hasChildNodes()&&this._updateTabActive(o.index,!0),this._adjustSize();break;default:this.invalidate()}}_selectedSheetChanged(e,t){this._updateTabActive(t.oldValue,!1),this._updateTabActive(t.newValue,!0),this._sheetTabClicked?this._sheetTabClicked=!1:this._scrollToActiveSheet(t.newValue,t.oldValue),this._adjustSize()}_initControl(){var e=this;e.applyTemplate("",e.getTemplate(),{_sheetContainer:"sheet-container",_tabContainer:"container",_sheetPage:"sheet-page",_newSheet:"new-sheet"}),e._rtl&&(e._sheetPage.style.right="0px",e._tabContainer.parentElement.style.right=e._sheetPage.clientWidth+"px",e._tabContainer.style.right="0px",e._tabContainer.style.cssFloat="right",e._newSheet.style.right=e._sheetPage.clientWidth+e._tabContainer.parentElement.clientWidth+"px"),e._adjustNavigationButtons(e._rtl),e.addEventListener(e._newSheet,"click",t=>{var o=e._owner.selectedSheetIndex;e._owner.addUnboundSheet(),e._scrollToActiveSheet(e._owner.selectedSheetIndex,o)}),e._sheets.collectionChanged.addHandler(e._sourceChanged,e),e._sheets.selectedSheetChanged.addHandler(e._selectedSheetChanged,e),e._sheets.sheetNameChanged.addHandler(e._updateSheetName,e),e._sheets.sheetVisibleChanged.addHandler(e._updateTabShown,e),e._initSheetPage(),e._initSheetTab()}_initSheetTab(){var e=this;e.addEventListener(e._tabContainer,"mousedown",t=>{var o,n=t.target;n instanceof HTMLLIElement&&(e._sheetTabClicked=!0,o=e._getItemIndex(e._tabContainer,n),e._scrollSheetTabContainer(n),o>-1&&(e._sheets.selectedIndex=o))})}_initSheetPage(){var e=this;e.hostElement.querySelector("div.wj-sheet-page").addEventListener("click",t=>{var o="[object HTMLButtonElement]"===t.target.toString()?t.target:t.target.parentElement,n=e._getItemIndex(e._sheetPage,o);if(0!==e._sheets.length)switch(n){case 0:e._sheets.selectFirst();break;case 1:e._sheets.selectPrevious();break;case 2:e._sheets.selectNext();break;case 3:e._sheets.selectLast()}})}_getSheetTabs(){var e,t="";for(e=0;e<this._sheets.length;e++)t+=this._getSheetElement(this._sheets[e],this._sheets.selectedIndex===e);return t}_getSheetElement(e,t=!1){var o="<li";return e.visible?t&&(o+=' class="active"'):o+=' class="hidden"',o+=">"+e.name+"</li>"}_updateTabActive(e,t){e<0||e>=this._tabContainer.children.length||(t?wjcCore.addClass(this._tabContainer.children[e],"active"):wjcCore.removeClass(this._tabContainer.children[e],"active"))}_updateTabShown(e,t){t.index<0||t.index>=this._tabContainer.children.length||(t.item.visible?wjcCore.removeClass(this._tabContainer.children[t.index],"hidden"):wjcCore.addClass(this._tabContainer.children[t.index],"hidden"),this._adjustSize())}_adjustSize(){var e,t,o=this._tabContainer.childElementCount,n=0,i=0;if("none"!==this.hostElement.style.display){for(i=this._tabContainer.parentElement.scrollLeft,this._tabContainer.parentElement.style.width="",this._tabContainer.style.width="",this._sheetPage.parentElement.style.width="",e=0;e<o;e++)n+=this._tabContainer.children[e].offsetWidth+1;t=this.hostElement.offsetWidth-this._sheetPage.offsetWidth-this._newSheet.offsetWidth-2,this._tabContainer.parentElement.style.width=(n>t?t:n)+"px",this._tabContainer.style.width=n+"px",this._sheetPage.parentElement.style.width=this._sheetPage.offsetWidth+this._newSheet.offsetWidth+this._tabContainer.parentElement.offsetWidth+3+"px",this._tabContainer.parentElement.scrollLeft=i}}_getItemIndex(e,t){for(var o=0;o<e.children.length;o++)if(e.children[o]===t)return o;return-1}_updateSheetName(e,t){this._tabContainer.querySelectorAll("li")[t.index].textContent=t.item.name,this._adjustSize()}_scrollSheetTabContainer(e){var t,o=this._tabContainer.parentElement.scrollLeft,n=this._sheetPage.offsetWidth,i=this._newSheet.offsetWidth,s=this._tabContainer.parentElement.offsetWidth;if(this._rtl)switch(wjcGrid.FlexGrid._getRtlMode()){case"rev":(t=-this._tabContainer.offsetLeft)+e.offsetLeft+e.offsetWidth>s+o?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:t+e.offsetLeft<o&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth);break;case"neg":e.offsetLeft<o?this._tabContainer.parentElement.scrollLeft-=e.offsetWidth:e.offsetLeft+e.offsetWidth>s+o&&(this._tabContainer.parentElement.scrollLeft+=e.offsetWidth);break;default:e.offsetLeft-i+o<0?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:e.offsetLeft+e.offsetWidth-i+o>s&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth)}else e.offsetLeft+e.offsetWidth-n>s+o?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:e.offsetLeft-n<o&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth)}_adjustSheetsPosition(){var e,t,o=this._tabContainer.querySelectorAll("li"),n=0;for(t=0;t<o.length;t++)(e=o[t]).style.cssFloat="right",e.style.right=n+"px",n+=o[t].clientWidth}_scrollToActiveSheet(e,t){var o,n,i,s=this._tabContainer.querySelectorAll("li");if(n=this._tabContainer.clientWidth>this._tabContainer.parentElement.clientWidth?this._tabContainer.clientWidth-this._tabContainer.parentElement.clientWidth:0,s.length>0&&e<s.length&&t<s.length){if(0===e&&!this._rtl||e===s.length-1&&this._rtl){if(this._rtl)switch(wjcGrid.FlexGrid._getRtlMode()){case"rev":this._tabContainer.parentElement.scrollLeft=0;break;case"neg":this._tabContainer.parentElement.scrollLeft=-n;break;default:this._tabContainer.parentElement.scrollLeft=n}else this._tabContainer.parentElement.scrollLeft=0;return}if(0===e&&this._rtl||e===s.length-1&&!this._rtl){if(this._rtl)switch(wjcGrid.FlexGrid._getRtlMode()){case"rev":this._tabContainer.parentElement.scrollLeft=n;break;case"neg":default:this._tabContainer.parentElement.scrollLeft=0}else this._tabContainer.parentElement.scrollLeft=n;return}if(e>=t)for(i=t+1;i<=e;i++)o=s[i],this._scrollSheetTabContainer(o);else for(i=t-1;i>=e;i--)o=s[i],this._scrollSheetTabContainer(o)}}_adjustNavigationButtons(e){var t,o=this.hostElement.querySelectorAll(".wj-sheet-page button");o&&4===o.length&&(e?(t=o[0].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-step-backward"),wjcCore.addClass(t,"wj-glyph-step-forward"),t=o[1].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-left"),wjcCore.addClass(t,"wj-glyph-right"),t=o[2].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-right"),wjcCore.addClass(t,"wj-glyph-left"),t=o[3].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-step-forward"),wjcCore.addClass(t,"wj-glyph-step-backward")):(t=o[0].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-step-forward"),wjcCore.addClass(t,"wj-glyph-step-backward"),t=o[1].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-right"),wjcCore.addClass(t,"wj-glyph-left"),t=o[2].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-left"),wjcCore.addClass(t,"wj-glyph-right"),t=o[3].querySelector("span"),wjcCore.removeClass(t,"wj-glyph-step-backward"),wjcCore.addClass(t,"wj-glyph-step-forward")))}}_SheetTabs.controlTemplate='<div wj-part="sheet-container" class="wj-sheet" style="height:100%;position:relative"><div wj-part="sheet-page" class="wj-btn-group wj-sheet-page"><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-step-backward"></span></button><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-left"></span></button><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-right"></span></button><button type="button" class="wj-btn wj-btn-default"><span class="wj-sheet-icon wj-glyph-step-forward"></span></button></div><div class="wj-sheet-tab" style="height:100%;overflow:hidden"><ul wj-part="container"></ul></div><div wj-part="new-sheet" class="wj-new-sheet"><span class="wj-sheet-icon wj-glyph-file"></span></div></div>',exports._SheetTabs=_SheetTabs;class _UnboundSortDescription{constructor(e,t){this._column=e,this._ascending=t}get column(){return this._column}get ascending(){return this._ascending}}exports._UnboundSortDescription=_UnboundSortDescription;class SortManager{constructor(e){this._owner=e,this._sortDescriptions=new wjcCore.CollectionView,this._committedList=[new ColumnSortDescription(-1,!0)],this._sortDescriptions.newItemCreator=(()=>new ColumnSortDescription(-1,!0))}get sortDescriptions(){return this._sortDescriptions}set sortDescriptions(e){this._sortDescriptions=e,this.commitSort()}addSortLevel(e,t=!0){var o=this._sortDescriptions.addNew();null!=e&&!isNaN(e)&&wjcCore.isInt(e)&&(o.columnIndex=e),o.ascending=t,this._sortDescriptions.commitNew()}deleteSortLevel(e){var t;(t=null!=e?this._getSortItem(e):this._sortDescriptions.currentItem)&&this._sortDescriptions.remove(t)}copySortLevel(){var e=this._sortDescriptions.currentItem;if(e){var t=this._sortDescriptions.addNew();t.columnIndex=parseInt(e.columnIndex),t.ascending=e.ascending,this._sortDescriptions.commitNew()}}editSortLevel(e,t){null!=e&&(this._sortDescriptions.currentItem.columnIndex=e),null!=t&&(this._sortDescriptions.currentItem.ascending=t)}moveSortLevel(e){var t=this._sortDescriptions.currentItem;if(t){var o=this._sortDescriptions.sourceCollection,n=o.indexOf(t),i=n+e;n>-1&&i>-1&&(o.splice(n,1),o.splice(i,0,t),this._sortDescriptions.refresh(),this._sortDescriptions.moveCurrentTo(t))}}checkSortItemExists(e){for(var t=0,o=this._sortDescriptions.itemCount;t<o;t++)if(+this._sortDescriptions.items[t].columnIndex===e)return t;return-1}commitSort(e=!0){var t,o,n,i,s,l,r,a,h,d,c=this._owner.itemsSource instanceof wjcCore.CollectionView;if(this._owner.selectedSheet){if(this._owner._needCopyToSheet=!1,l=this._owner.selectedSheet._unboundSortDesc,e&&this._owner.undoStack.stackSize>0&&(r=new _SortColumnAction(this._owner)),this._sortDescriptions.itemCount>0?this._committedList=this._cloneSortList(this._sortDescriptions.items):this._committedList=[new ColumnSortDescription(-1,!0)],this._owner.collectionView){for(this._owner._isSorting=!0,this._owner.beginUpdate(),this._owner.collectionView.canSort=!0,(a=this._owner.editableCollectionView)&&a.currentEditItem&&-1!==a.items.indexOf(a.currentEditItem)&&!this._isEmpty(a.currentEditItem)&&a.commitEdit(),this._owner.collectionView.beginUpdate(),this._owner.selectedSheet.grid.collectionView.beginUpdate(),(n=this._owner.collectionView.sortDescriptions).clear(),h=this._owner.selection.clone(),c?this._owner.itemsSource.sourceCollection=this._owner.selectedSheet._orgItemsSource.slice():(this._owner.autoGenerateColumns=!1,this._owner.selectedSheet.grid.collectionView.canSort=!0,d=this._owner.selectedSheet._filterDefinition,this._owner.itemsSource=this._owner.selectedSheet._orgItemsSource.slice(),this._synchColumn(),(i=this._owner.selectedSheet.grid.collectionView.sortDescriptions).clear()),this._owner.selection=h,navigator.userAgent.toLowerCase().indexOf("chrome")>-1&&(this._owner.collectionView.useStableSort=!0,c||(this._owner.selectedSheet.grid.collectionView.useStableSort=!0)),s=0;s<this._sortDescriptions.itemCount;s++)(t=this._sortDescriptions.items[s]).columnIndex>-1&&(o=new wjcCore.SortDescription(this._owner.columns[t.columnIndex].binding,t.ascending),n.push(o),c||(this._owner.collectionView.sortDescriptions.push(o),i.push(o)));this._owner.selectedSheet.selectionRanges.clear(),this._owner.collectionView.endUpdate(),this._owner.selectedSheet.grid.collectionView.endUpdate(),h=this._owner.selection.clone(),c?this._owner.itemsSource.sourceCollection=this._owner.collectionView._view.slice():(this._owner.itemsSource=this._owner.collectionView._view.slice(),this._owner._isUndoing||(this._synchColumn(),d&&(this._owner.filter.filterDefinition=d)),this._owner.selectedSheet.grid.collectionView.canSort=!1),this._owner.selection=h,this._owner.collectionView.canSort=!1,this._owner.endUpdate(),this._owner._isSorting=!1}else for(l.clear(),s=0;s<this._sortDescriptions.itemCount;s++)(t=this._sortDescriptions.items[s]).columnIndex>-1&&l.push(new _UnboundSortDescription(this._owner.columns[t.columnIndex],t.ascending));r&&(r.saveNewState(),this._owner.undoStack._addAction(r)),this._owner._copiedRanges=null,this._owner._needCopyToSheet=!0}}cancelSort(){this._sortDescriptions.sourceCollection=this._committedList.slice()}clearSort(){this._sortDescriptions.sourceCollection=[],this.commitSort()}_getColumnIndex(e){for(var t=0,o=this._owner.columns.length;t<o;t++)if(this._owner.columns[t].binding===e)return t;return-1}_getSortItem(e){var t=this.checkSortItemExists(e);if(t>-1)return this._sortDescriptions.items[t]}_cloneSortList(e){for(var t=[],o=0;o<e.length;o++)t[o]=e[o].clone();return t}_synchColumn(){let e,t,o;for(this._owner.columns.clear(),e=this._owner.rows[0]instanceof wjcGrid._NewRowTemplate?this._owner.rows[1]:this._owner.rows[0],t=0;t<this._owner.selectedSheet.grid.columns.length;t++)(o=this._owner.selectedSheet.grid.columns[t]).isRequired=!1,this._owner.columns.push(o),e._ubv||(e._ubv={}),e._ubv[o._hash]=o.header}_isEmpty(e){var t=Object.prototype.hasOwnProperty;if(null==e)return!0;if(e.length>0)return!1;if(0===e.length)return!0;for(var o in e)if(t.call(e,o))return!1;return!0}}exports.SortManager=SortManager;class ColumnSortDescription{constructor(e,t){this._columnIndex=e,this._ascending=t}get columnIndex(){return this._columnIndex}set columnIndex(e){this._columnIndex=+e}get ascending(){return this._ascending}set ascending(e){this._ascending=e}clone(){return new ColumnSortDescription(this._columnIndex,this._ascending)}}exports.ColumnSortDescription=ColumnSortDescription;class UndoStack{constructor(e){this.MAX_STACK_SIZE=500,this._stack=[],this._pointer=-1,this._resizingTriggered=!1,this.undoStackChanged=new wjcCore.Event;var t=this;t._owner=e,t._owner.prepareCellForEdit.addHandler(t._initCellEditAction,t),t._owner.cellEditEnded.addHandler((e,o)=>{t._pendingAction&&(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)&&t._pendingAction instanceof _EditAction&&!t._pendingAction.isPaste&&t._afterProcessCellEditAction(t)},t),t._owner.pasting.addHandler(t._initCellEditActionForPasting,t),t._owner.pastingCell.addHandler((e,o)=>{t._pendingAction&&(t._pendingAction instanceof _EditAction?t._pendingAction.updateForPasting(o.range):t._pendingAction instanceof _CutAction&&t._pendingAction.updateForPasting(o.range))},t),t._owner.pasted.addHandler(()=>{t._pendingAction&&(t._pendingAction instanceof _EditAction&&t._pendingAction.isPaste?t._afterProcessCellEditAction(t):t._pendingAction instanceof _CutAction&&(t._pendingAction.saveNewState(),t._addAction(t._pendingAction),t._pendingAction=null))},t),t._owner.resizingColumn.addHandler((e,o)=>{0!==t.stackSize&&t._owner.selectedSheet&&(t._resizingTriggered||(t._pendingAction=new _ColumnResizeAction(t._owner,o.panel,o.col),t._resizingTriggered=!0))},t),t._owner.resizedColumn.addHandler((e,o)=>{t._pendingAction instanceof _ColumnResizeAction&&t._pendingAction.saveNewState()&&t._addAction(t._pendingAction),t._pendingAction=null,t._resizingTriggered=!1},t),t._owner.resizingRow.addHandler((e,o)=>{0!==t.stackSize&&t._owner.selectedSheet&&(t._resizingTriggered||(t._pendingAction=new _RowResizeAction(t._owner,o.panel,o.row),t._resizingTriggered=!0))},t),t._owner.resizedRow.addHandler((e,o)=>{t._pendingAction instanceof _RowResizeAction&&t._pendingAction.saveNewState()&&t._addAction(t._pendingAction),t._pendingAction=null,t._resizingTriggered=!1},t),t._owner.draggingRowColumn.addHandler((e,o)=>{0!==t.stackSize&&t._owner.selectedSheet&&o.isShiftKey&&(o.isDraggingRows?t._pendingAction=new _RowsChangedAction(t._owner):t._pendingAction=new _ColumnsChangedAction(t._owner))},t),t._owner.droppingRowColumn.addHandler(()=>{t._pendingAction&&t._pendingAction.saveNewState()&&t._addAction(t._pendingAction),t._pendingAction=null},t)}get stackSize(){return null==this._stackSize?this.MAX_STACK_SIZE:this._stackSize}set stackSize(e){wjcCore.isNumber(e)&&(e<0?this._stackSize=0:e>this.MAX_STACK_SIZE?this._stackSize=this.MAX_STACK_SIZE:this._stackSize=Math.floor(e))}get canUndo(){return this._pointer>-1&&this._pointer<this._stack.length}get canRedo(){return this._pointer+1>-1&&this._pointer+1<this._stack.length}onUndoStackChanged(){this.undoStackChanged.raise(this)}undo(){var e;this.canUndo&&(e=this._stack[this._pointer],this._beforeUndoRedo(e),e.undo(),this._pointer--,this.onUndoStackChanged())}redo(){var e;this.canRedo&&(this._pointer++,e=this._stack[this._pointer],this._beforeUndoRedo(e),e.redo(),this.onUndoStackChanged())}_addAction(e){this._stack.length>0&&this._stack.length>this._pointer+1&&this._stack.splice(this._pointer+1,this._stack.length-this._pointer-1),this._stack.length>=this.stackSize&&this._stack.splice(0,this._stack.length-this.stackSize+1),this._pointer=this._stack.length,this._stack.push(e),this.onUndoStackChanged()}_pop(){var e;return this._pointer<0?null:(e=this._stack[this._pointer],this._pointer--,e)}clear(){this._stack.length=0}_initCellEditAction(e,t){0!==this.stackSize&&this._owner.selectedSheet&&(this._pendingAction=new _EditAction(this._owner,t.range))}_initCellEditActionForPasting(){0!==this.stackSize&&this._owner.selectedSheet&&(this._owner._isCutting?this._pendingAction=new _CutAction(this._owner):(this._pendingAction=new _EditAction(this._owner),this._pendingAction.markIsPaste()))}_afterProcessCellEditAction(e){e._pendingAction&&(e._pendingAction instanceof _EditAction&&e._pendingAction.saveNewState()&&e._addAction(this._pendingAction),e._pendingAction=null)}_beforeUndoRedo(e){this._owner.selectedSheetIndex=e.sheetIndex}}exports.UndoStack=UndoStack;class Table{constructor(e,t,o,n,i){if(this._showHeaderRow=!0,this._showTotalRow=!1,this._showBandedColumns=!1,this._showBandedRows=!0,this._alterFirstColumn=!1,this._alterLastColumn=!1,this._orgHeaderCellsContent=[],!t.isValid)throw"The range of this table is invalid.";this._name=e,this._range=t.clone(),this._style=o,null!=n&&n.length>0&&this._pushTableColumns(n),null!=i&&(null!=i.showHeaderRow&&(this._showHeaderRow=i.showHeaderRow),null!=i.showTotalRow&&(this._showTotalRow=i.showTotalRow),null!=i.showBandedColumns&&(this._showBandedColumns=i.showBandedColumns),null!=i.showBandedRows&&(this._showBandedRows=i.showBandedRows),null!=i.alterFirstColumn&&(this._alterFirstColumn=i.alterFirstColumn),null!=i.alterLastColumn&&(this._alterLastColumn=i.alterLastColumn))}get name(){return this._name}set name(e){var t,o;if(null==e||""===e)throw"The name of the Table should not be empty.";this._name.toLowerCase()!==e.toLowerCase()&&(o=this._name,this._name=e,this._owner&&(!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._owner._updateFormulasWithNameUpdating(o,e,!0),t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null)))}get sheet(){return this._sheet}get style(){return this._style}set style(e){var t;e.name!==this._style.name&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._style=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))}get showHeaderRow(){return this._showHeaderRow}set showHeaderRow(e){var t,o;if(e!==this._showHeaderRow&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),o=this._showHeaderRow,this._showHeaderRow=e,this._owner))try{this._owner.beginUpdate(),this._adjustTableRangeWithHeaderRow(),t&&(t.saveNewState(),this._owner.undoStack._addAction(t))}catch(e){throw this._showHeaderRow=o,e}finally{t=null,this._owner.endUpdate()}}get showTotalRow(){return this._showTotalRow}set showTotalRow(e){var t,o;if(e!==this._showTotalRow&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),o=this._showTotalRow,this._showTotalRow=e,this._owner))try{this._owner.beginUpdate(),this._adjustTableRangeWithTotalRow(),t&&(t.saveNewState(),this._owner.undoStack._addAction(t))}catch(e){throw this._showTotalRow=o,e}finally{t=null,this._owner.endUpdate()}}get showBandedColumns(){return this._showBandedColumns}set showBandedColumns(e){var t;e!==this._showBandedColumns&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._showBandedColumns=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))}get showBandedRows(){return this._showBandedRows}set showBandedRows(e){var t;e!==this._showBandedRows&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._showBandedRows=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))}get alterFirstColumn(){return this._alterFirstColumn}set alterFirstColumn(e){var t;e!==this._alterFirstColumn&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._alterFirstColumn=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))}get alterLastColumn(){return this._alterLastColumn}set alterLastColumn(e){var t;e!==this._alterLastColumn&&(this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this)),this._alterLastColumn=e,this._owner&&(t&&(t.saveNewState(),this._owner.undoStack._addAction(t),t=null),this._owner.refresh()))}getRange(e=TableSection.All,t){let o;switch(e){case TableSection.Data:o=this._getDataRange();break;case TableSection.Header:o=this._getHeaderRange();break;case TableSection.Footer:o=this._getFooterRange();break;default:o=this._range.clone()}if(null!=t&&o){let e=this._getColumnIndex(t);if(null==e)return null;o.col=o.col2=o.leftCol+e}return o}getColumns(){return this._columns?this._columns.slice():[]}insertRows(e,t,o=!0){var n,i,s,l,r,a=this.getRange(),h=!1;if(null==t&&(t=1),!wjcCore.isInt(t)||t<1)return!1;if(0===e&&this._showHeaderRow||e===this._range.rowSpan-1&&this._showTotalRow||e<0||e>=this._range.rowSpan)return!1;if(this._owner){if(this._owner.beginUpdate(),l=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid,o){if(s=new wjcGrid.CellRange(a.bottomRow+1,a.col,a.bottomRow+1,a.col2),this._sheet._canShiftCells(s)){if(n=this._sheet._needAddRowCountForInsertTableRows(t,a),l.collectionView){for(r=l.itemsSource instanceof wjcCore.CollectionView,l.collectionView.beginUpdate(),i=0;i<n;i++)r?l.itemsSource.sourceCollection.push({}):l.itemsSource.push({});l.collectionView.endUpdate()}else for(i=0;i<n;i++)l.rows.push(new wjcGrid.Row);this._sheet._moveDownCells(t,s),h=!0}}else this._canInsertRowsWithoutShift(t)&&(h=!0);h&&(this._sheet._moveDownCellsWithinTable(e,t,a),this._updateTableRange(0,t,0,0)),this._owner.endUpdate()}else this._updateTableRange(0,t,0,0),h=!0;return h}deleteRows(e,t,o=!0){var n,i=!1,s=this.getRange();null==t&&(t=1),!wjcCore.isInt(t)||t<1||0===e&&this._showHeaderRow||e===this._range.rowSpan-1&&this._showTotalRow||e<0||e>=this._range.rowSpan||e+t>this._range.rowSpan-(this._showTotalRow?1:0)||(this._owner?(this._owner.beginUpdate(),o?(n=new wjcGrid.CellRange(s.bottomRow+1,s.col,s.bottomRow+1,s.col2),this._sheet._canShiftCells(n)&&(i=!0)):i=!0,i&&(this._sheet._moveUpCellsWithinTable(e,t,s),o&&this._sheet._moveUpCells(t,n),this._updateTableRange(0,-t,0,0)),this._owner.endUpdate()):this._updateTableRange(0,-t,0,0))}_addColumn(e,t){var o,n=this.getRange();if(e<=0||e>this._columns.length)throw"The column index is out of range.";t=this._getUniqueColumnName(e,t),(o=new TableColumn(t))._attach(this),this._columns.splice(e,0,o),this.showHeaderRow&&this._owner&&this._sheet&&(this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid).setCellData(n.topRow,n.leftCol+e,t)}_updateCell(e,t,o){var n,i=e-this._range.topRow,s=t-this._range.leftCol;null!=this._style&&(n=this._getTableCellAppliedStyles(i,s),this._applyStylesForCell(n,o))}_updateTableRange(e,t,o,n){this._range.row<=this._range.row2?(this._range.row+=e,this._range.row2+=t):(this._range.row2+=e,this._range.row+=t),this._range.col<=this._range.col2?(this._range.col+=o,this._range.col2+=n):(this._range.col2+=o,this._range.col+=n)}_setTableRange(e,t){var o;if(this._range=e,null!=t)for(this._columns.splice(0,this._columns.length),o=0;o<t.length;o++)this._columns.push(t[o])}_updateColumnName(e,t){var o=this._columns[e];t=this._getUniqueColumnName(null,t),o.name=t,this._showHeaderRow&&this._owner&&this._sheet&&(this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid).setCellData(this._range.topRow,this._range.leftCol+e,t)}_updateColumnTotalRowContent(e,t){var o,n;null==t&&(t=this._columns.indexOf(e)),t<0||(e.totalRowFunction?n=null!=(o=this._getSubtotalFunction(e.totalRowFunction.toLowerCase()))?"=subtotal("+o+",["+e.name+"])":"="===e.totalRowFunction[0]?e.totalRowFunction:"="+e.totalRowFunction:0===t?(e.totalRowLabel||(e.totalRowLabel="Total"),n=e.totalRowLabel):t===this._columns.length-1?(e.totalRowFunction="=subtotal(109, ["+e.name+"])",n=e.totalRowFunction):n=e.totalRowLabel,this._owner&&this._sheet&&(this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid).setCellData(this._range.bottomRow,this._range.leftCol+t,n,!1))}_attachSheet(e){var t=this.getRange();if(!(this._sheet&&this._owner||(this._sheet=e,this._owner=e._owner,null==this._owner))){if(this._owner._containsMergedCells(this._range,e))throw"Table does not allow the merged cell within the table.";null==this._style&&(this._style=this._owner.getBuiltInTableStyle("TableStyleMedium9")),null!=this._columns&&0!==this._columns.length||this._generateColumns(this._showHeaderRow);try{this._owner.beginUpdate(),this._showHeaderRow&&1===t.rowSpan&&this._adjustTableRangeWithHeaderRow(),this._showTotalRow&&this._updateTotalRow()}finally{this._owner.endUpdate()}}}_detachSheet(){this._sheet=null,this._owner=null}_pushTableColumns(e){var t,o;for(this._columns=[],o=0;o<e.length;o++)(t=e[o])._attach(this),this._columns.push(t)}_generateColumns(e){var t,o,n,i,s,l=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(!this._range.isValid)throw"The range of the table is invalid.";this._columns=[];for(var r=0;r<this._range.columnSpan;r++)i=this._sheet.grid.columns[this._range.leftCol+r],s=this._range.topRow*this._sheet.grid.columns.length+this._range.leftCol+r,1===this._range.rowSpan?t=this._getUniqueColumnName(r+1):(t=this._sheet.grid.getCellData(this._range.topRow,this._range.leftCol+r,!1)||"",wjcCore.isString(t)&&"="===t[0]&&(t=this._owner.evaluate(t,"",this._sheet,!1)),n=this._sheet._styledCells[s],t=this._owner._formatEvaluatedResult(t,i,n?n.format:""),t=this._getUniqueColumnName(r+1,t.toString())),e&&this._range.rowSpan>1&&(this._orgHeaderCellsContent[r]=this._sheet.grid.getCellData(this._range.topRow,this._range.leftCol+r,!1),isNaN(+t)||i.format||n&&n.format||(n?n.format="@":this._sheet._styledCells[s]={format:"@"}),l.setCellData(this._range.topRow,this._range.leftCol+r,t,!1)),(o=new TableColumn(t))._attach(this),0===r?o._totalRowLabel="Total":r===this._range.columnSpan-1&&(o._totalRowFunction="Sum"),this._columns.push(o)}_getTableCellAppliedStyles(e,t){var o,n={},i=!1,s=!1,l=0;return this._showHeaderRow&&(l=1),this._showHeaderRow&&0===e?i=!0:this._showTotalRow&&e===this._range.rowSpan-1&&(s=!0),this._extendStyle(n,this._style.wholeTableStyle,e,t,i,s),i||s||(!this._showBandedColumns||null==this._style.firstBandedColumnStyle&&null==this._style.secondBandedColumnStyle||(t%((o=this._style.firstBandedColumnStyle?null==this._style.firstBandedColumnStyle.size?1:this._style.firstBandedColumnStyle.size:1)+(this._style.secondBandedColumnStyle?null==this._style.secondBandedColumnStyle.size?1:this._style.secondBandedColumnStyle.size:1))>=o?this._style.secondBandedColumnStyle&&this._extendStyle(n,this._style.secondBandedRowStyle,e,t,i,s):this._style.firstBandedColumnStyle&&this._extendStyle(n,this._style.firstBandedColumnStyle,e,t,i,s)),!this._showBandedRows||null==this._style.firstBandedRowStyle&&null==this._style.secondBandedRowStyle||((e-l)%((o=this._style.firstBandedRowStyle?null==this._style.firstBandedRowStyle.size?1:this._style.firstBandedRowStyle.size:1)+(this._style.secondBandedRowStyle?null==this._style.secondBandedRowStyle.size?1:this._style.secondBandedRowStyle.size:1))>=o?this._style.secondBandedRowStyle&&this._extendStyle(n,this._style.secondBandedRowStyle,e,t,i,s):this._style.firstBandedRowStyle&&this._extendStyle(n,this._style.firstBandedRowStyle,e,t,i,s))),this._alterLastColumn&&t===this._range.columnSpan-1&&this._style.lastColumnStyle&&this._extendStyle(n,this._style.lastColumnStyle,e,t,i,s),this._alterFirstColumn&&0===t&&this._style.firstColumnStyle&&this._extendStyle(n,this._style.firstColumnStyle,e,t,i,s),i?(this._style.headerRowStyle&&this._extendStyle(n,this._style.headerRowStyle,e,t,i,s),t===this._range.columnSpan-1&&this._style.lastHeaderCellStyle&&this._extendStyle(n,this._style.lastHeaderCellStyle,e,t,i,s),0===t&&this._style.firstHeaderCellStyle&&this._extendStyle(n,this._style.firstHeaderCellStyle,e,t,i,s)):s&&(this._style.totalRowStyle&&this._extendStyle(n,this._style.totalRowStyle,e,t,i,s),t===this._range.columnSpan-1&&this._style.lastTotalCellStyle&&this._extendStyle(n,this._style.lastTotalCellStyle,e,t,i,s),0===t&&this._style.firstTotalCellStyle&&this._extendStyle(n,this._style.firstTotalCellStyle,e,t,i,s)),n}_applyStylesForCell(e,t){var o,n=t.style;for(var i in e)(o=e[i])&&(n[i]=o)}_extendStyle(e,t,o,n,i,s){var l;for(var r in t)null!==(l=t[r])&&(r.indexOf("borderTop")>-1?(0===o||s)&&(e[r]=l):r.indexOf("borderBottom")>-1?(o===this._range.rowSpan-1||i)&&(e[r]=l):r.indexOf("borderLeft")>-1?0===n&&(e[r]=l):r.indexOf("borderRight")>-1?n===this._range.columnSpan-1&&(e[r]=l):r.indexOf("borderHorizontal")>-1?o<this._range.rowSpan-1&&("borderHorizontalStyle"===r?e.borderBottomStyle=l:"borderHorizontalWidth"===r?e.borderBottomWidth=l:e.borderBottomColor=l):r.indexOf("borderVertical")>-1?n<this._range.columnSpan-1&&("borderVerticalStyle"===r?e.borderRightStyle=l:"borderVerticalWidth"===r?e.borderRightWidth=l:e.borderRightColor=l):e[r]=l)}_getSubtotalFunction(e){switch(e){case"average":return"101";case"countnums":return"102";case"count":return"103";case"max":return"104";case"min":return"105";case"stddev":return"107";case"sum":return"109";case"var":return"110"}return null}_checkColumnNameExist(e){var t,o=this.getColumns();for(t=0;t<o.length;t++)if(o[t].name.toLowerCase()===e.toLowerCase())return!0;return!1}_adjustTableRangeWithHeaderRow(){var e,t,o,n,i=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(this._showHeaderRow){if(this._sheet._needMoveDownTable(this)){if(o=this.getRange(),n=new wjcGrid.CellRange(o.bottomRow+1,o.col,o.bottomRow+1,o.col2),!this._sheet._canShiftCells(n))throw"The operation is not allowed.  The operation is attempting to shift the cells in a table or a merged cell on the current sheet.";1===this._sheet._needAddRowCountForInsertTableRows(1,o)&&(i.collectionView?(i.collectionView.beginUpdate(),i.itemsSource instanceof wjcCore.CollectionView?i.itemsSource.sourceCollection.push({}):i.itemsSource.push({}),i.collectionView.endUpdate()):i.rows.push(new wjcGrid.Row)),this._sheet._moveDownCells(1,n),this._sheet._moveDownTable(this)}for(this._range.row<=this._range.row2?this._range.row-=1:this._range.row2-=1,e=0;e<this._columns.length;e++)t=this._columns[e],this._orgHeaderCellsContent[e]=i.getCellData(this._range.topRow,this._range.leftCol+e,!1),i.setCellData(this._range.topRow,this._range.leftCol+e,t.name)}else{for(e=this._range.leftCol;e<=this._range.rightCol;e++)i.setCellData(this._range.topRow,e,"");this._range.row<=this._range.row2?this._range.row+=1:this._range.row2+=1}}_adjustTableRangeWithTotalRow(){var e,t,o,n=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(t=this.getRange(),o=new wjcGrid.CellRange(t.bottomRow+1,t.col,t.bottomRow+1,t.col2),this._showTotalRow){if(this._sheet._canShiftCells(o))1===this._sheet._needAddRowCountForInsertTableRows(1,t)&&(n.collectionView?(n.collectionView.beginUpdate(),n.itemsSource instanceof wjcCore.CollectionView?n.itemsSource.sourceCollection.push({}):n.itemsSource.push({}),n.collectionView.endUpdate()):n.rows.push(new wjcGrid.Row)),this._sheet._moveDownCells(1,o),this._owner._updateAffectedFormula(this._range.bottomRow+1,1,!0,!0);else if(!this._beneathRowIsEmpty())throw"The operation is not allowed.  The operation is attempting to shift the cells in a table or a merged cell on the current sheet.";this._range.row<=this._range.row2?this._range.row2+=1:this._range.row+=1,this._updateTotalRow()}else{for(e=this._range.leftCol;e<=this._range.rightCol;e++)n.setCellData(this._range.bottomRow,e,"");this._sheet._canShiftCells(o)&&(this._sheet._moveUpCells(1,o),this._owner._updateAffectedFormula(this._range.bottomRow+1,1,!1,!0)),this._range.row<=this._range.row2?this._range.row2-=1:this._range.row-=1}}_updateTotalRow(){let e;if(this.showTotalRow)for(let t=0;t<this._columns.length;t++)e=this._columns[t],this._updateColumnTotalRowContent(e,t)}_getUniqueColumnName(e,t){var o,n=1;if(t||(t="Column"+e),this._checkColumnNameExist(t)){for(o=t+n;this._checkColumnNameExist(o);)o=t+ ++n;t=o}return t}_moveColumns(e,t){if(!this._columns)return;let o=this._columns[e];this._columns.splice(e,1),t<0&&(t=this._columns.length),this._columns.splice(t,0,o)}_canInsertRowsWithoutShift(e){var t,o,n,i,s,l=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(this._range.bottomRow+e>=l.rows.length)return!1;for(t=1;t<=e;t++)for(o=this._range.bottomRow+t,n=this._range.leftCol;n<=this._range.rightCol;n++)if(i=l.getCellData(o,n,!1),s=this._sheet.getCellStyle(o,n),null!=i&&""!==i||null!=s)return!1;return!0}_beneathRowIsEmpty(){let e,t,o,n,i,s,l=this._range.bottomRow+1,r=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid;if(l>=r.rows.length)return!1;for(e=this._range.leftCol;e<=this._range.rightCol;e++){if(null!=(t=r.getCellData(this._range.bottomRow+1,e,!1))&&""!==t)return!1;if(null!=(o=this._sheet.getCellStyle(this._range.bottomRow+1,e)))return!1;if(null!=(n=this._sheet.findTable(l,e)))return null;if(i=l*r.columns.length+e,null!=(s=this._sheet._mergedRanges[i]))return!1}return!0}_getDataRange(){var e=this._range.topRow,t=this._range.bottomRow;return this._showHeaderRow&&(e+=1),this._showTotalRow&&(t-=1),new wjcGrid.CellRange(e,this._range.leftCol,t,this._range.rightCol)}_getHeaderRange(){return this._showHeaderRow?new wjcGrid.CellRange(this._range.topRow,this._range.leftCol,this._range.topRow,this._range.rightCol):null}_getFooterRange(){return this._showTotalRow?new wjcGrid.CellRange(this._range.bottomRow,this._range.leftCol,this._range.bottomRow,this._range.rightCol):null}_getColumnIndex(e){var t,o,n;if(wjcCore.isInt(e)&&e>=0&&e<this._columns.length)t=e;else{e instanceof TableColumn?o=e.name.toLowerCase():wjcCore.isString(e)&&""!==e&&(o=e.toLowerCase()),n=this.getColumns();for(var i=0;i<n.length;i++)if(n[i].name.toLowerCase()===o){t=i;break}}return t}}exports.Table=Table;class TableColumn{constructor(e,t,o,n=!0){this._name=e,this._totalRowLabel=t,this._totalRowFunction=o,null!=n&&(this._showFilterButton=n)}get table(){return this._table}get name(){return this._name}set name(e){e!==this._name&&(this._name=e)}get totalRowLabel(){return this._totalRowLabel}set totalRowLabel(e){e!==this._totalRowLabel&&(this._totalRowLabel=e,this._updateTableTotalInfo())}get totalRowFunction(){return this._totalRowFunction}set totalRowFunction(e){e!==this._totalRowFunction&&(this._totalRowFunction=e,this._updateTableTotalInfo())}get showFilterButton(){return this._showFilterButton}set showFilterButton(e){this._showFilterButton!==e&&(this._showFilterButton=e)}_attach(e){this._table=e}_updateTableTotalInfo(){this._table&&(this._table._updateColumnTotalRowContent(this),this._table._owner&&this._table._owner.refresh())}}exports.TableColumn=TableColumn;class TableStyle{constructor(e,t=!1){this._name=e,this._isBuiltIn=t}get name(){return this._name}set name(e){e!==this._name&&(this._name=e)}get wholeTableStyle(){return this._wholeTableStyle}set wholeTableStyle(e){this._wholeTableStyle=e}get firstBandedColumnStyle(){return this._firstBandedColumnStyle}set firstBandedColumnStyle(e){this._firstBandedColumnStyle=e}get secondBandedColumnStyle(){return this._secondBandedColumnStyle}set secondBandedColumnStyle(e){this._secondBandedColumnStyle=e}get firstBandedRowStyle(){return this._firstBandedRowStyle}set firstBandedRowStyle(e){this._firstBandedRowStyle=e}get secondBandedRowStyle(){return this._secondBandedRowStyle}set secondBandedRowStyle(e){this._secondBandedRowStyle=e}get firstColumnStyle(){return this._firstColumnStyle}set firstColumnStyle(e){this._firstColumnStyle=e}get lastColumnStyle(){return this._lastColumnStyle}set lastColumnStyle(e){this._lastColumnStyle=e}get headerRowStyle(){return this._headerRowStyle}set headerRowStyle(e){this._headerRowStyle=e}get totalRowStyle(){return this._totalRowStyle}set totalRowStyle(e){this._totalRowStyle=e}get firstHeaderCellStyle(){return this._firstHeaderCellStyle}set firstHeaderCellStyle(e){this._firstHeaderCellStyle=e}get lastHeaderCellStyle(){return this._lastHeaderCellStyle}set lastHeaderCellStyle(e){this._lastHeaderCellStyle=e}get firstTotalCellStyle(){return this._firstTotalCellStyle}set firstTotalCellStyle(e){this._firstTotalCellStyle=e}get lastTotalCellStyle(){return this._lastTotalCellStyle}set lastTotalCellStyle(e){this._lastTotalCellStyle=e}get isBuiltIn(){return this._isBuiltIn}}exports.TableStyle=TableStyle;var TableSection;!function(e){e[e.All=0]="All",e[e.Data=1]="Data",e[e.Header=2]="Header",e[e.Footer=3]="Footer"}(TableSection=exports.TableSection||(exports.TableSection={}));class FlexSheetValueFilter extends wjcGridFilter.ValueFilter{constructor(e){super(e),null!=e.dataMap&&(this.dataMap=e.dataMap)}apply(e){var t=this.column.grid;return!(t instanceof FlexSheet)||(!this.showValues||!Object.keys(this.showValues).length||(t.rows[e]instanceof wjcGrid._NewRowTemplate||(e=this.dataMap?this.dataMap.getDisplayValue(t.getCellValue(e,this.column.index)):t.getCellValue(e,this.column.index,!0),void 0!=this.showValues[e])))}}exports.FlexSheetValueFilter=FlexSheetValueFilter;class FlexSheetValueFilterEditor extends wjcGridFilter.ValueFilterEditor{updateEditor(){var e,t,o,n,i,s,l,r,a,h=this.filter.column,d=h.grid,c=h.index,_=[],u={};if(this.filter.uniqueValues||null!=d.itemsSource&&null!=d.childItemsPath)super.updateEditor();else{for(m=0;m<d.rows.length;m++)i=this.filter.apply(m),n=this.filter.showValues,this.filter.showValues=null,s=d.filter._filter(m),this.filter.showValues=n,(!(t=d.getMergedRange(d.cells,m,c))||m===t.topRow&&c===t.leftCol)&&((e=d.rows[m])instanceof HeaderRow||e instanceof wjcGrid.GroupRow||e instanceof wjcGrid._NewRowTemplate||!(e.visible||!i&&s)||(o=d.getCellValue(m,c),l=this.filter.dataMap?this.filter.dataMap.getDisplayValue(o):d.getCellValue(m,c,!0),o=""===o?null:o,r=d.getCellData(m,c,!0),u[l]||(u[l]=!0,a=r&&"="===r[0]?m+"_"+c:"",_.push({value:o,text:l,cellRef:a}))));var g=this.filter.showValues;if(g&&0!=Object.keys(g).length){for(var w in g)for(m=0;m<_.length;m++)if(g[w]&&""!==_[m].cellRef&&_[m].cellRef===g[w].cellRef)g[_[m].text]={show:!0,cellRef:_[m].cellRef},_[m].show=!0,delete g[w];else if(_[m].text==w){_[m].show=!0;break}}else for(var m=0;m<_.length;m++)_[m].show=!0;this._lbValues.isContentHtml=h.isContentHtml,this._cmbFilter.text=this.filter.filterText,this._filterText=this._cmbFilter.text.toLowerCase(),this._view.pageSize=this.filter.maxValues,this._view.sourceCollection=_,this._view.moveCurrentToPosition(-1)}}updateFilter(){var e=null,t=this._view.items;if(this._filterText||this._cbSelectAll.indeterminate){e={};for(var o=0;o<t.length;o++){var n=t[o];n.show&&(e[n.text]={show:!0,cellRef:n.cellRef})}}this._filter.showValues=e,this._filter.filterText=this._filterText}}exports.FlexSheetValueFilterEditor=FlexSheetValueFilterEditor;class FlexSheetConditionFilter extends wjcGridFilter.ConditionFilter{constructor(e){super(e),null!=e.dataMap&&(this.dataMap=e.dataMap)}apply(e){var t,o,n,i=this.column,s=i.grid,l=this.condition1,r=this.condition2;if(!(s instanceof FlexSheet))return!0;if(!this.isActive)return!0;if(s.rows[e]instanceof wjcGrid._NewRowTemplate)return!0;""===(t=s.getCellValue(e,i.index))&&i.dataType!==wjcCore.DataType.String&&(t=null),o=n=t,this.dataMap?o=n=t=this.dataMap.getDisplayValue(t):wjcCore.isDate(t)?(wjcCore.isString(l.value)||wjcCore.isString(r.value))&&(o=n=t=s.getCellValue(e,i.index,!0)):wjcCore.isNumber(t)&&(o=n=t=wjcCore.Globalize.parseFloat(s.getCellValue(e,i.index,!0)),0!==t||i.dataType||(l.isActive&&""===l.value&&(o=t.toString()),r.isActive&&""===r.value&&(n=n.toString())));var a=l.apply(o),h=r.apply(n);return l.isActive&&r.isActive?this.and?a&&h:a||h:l.isActive?a:!r.isActive||h}}exports.FlexSheetConditionFilter=FlexSheetConditionFilter;class FlexSheetColumnFilter extends wjcGridFilter.ColumnFilter{constructor(e,t){super(e,t),this._valueFilter=new FlexSheetValueFilter(t),this._conditionFilter=new FlexSheetConditionFilter(t)}}exports.FlexSheetColumnFilter=FlexSheetColumnFilter;class FlexSheetColumnFilterEditor extends wjcGridFilter.ColumnFilterEditor{constructor(e,t,o=!0){super(e,t,o);var n,i,s=this;o&&(this._divSort.style.display=""),n=this.cloneElement(this._btnAsc),i=this.cloneElement(this._btnDsc),this._btnAsc.parentNode.replaceChild(n,this._btnAsc),this._btnDsc.parentNode.replaceChild(i,this._btnDsc),n.addEventListener("click",e=>{s._sortBtnClick(e,!0)}),i.addEventListener("click",e=>{s._sortBtnClick(e,!1)})}_showFilter(e){e==wjcGridFilter.FilterType.Value&&null==this._edtVal&&(this._edtVal=new FlexSheetValueFilterEditor(this._divEdtVal,this.filter.valueFilter)),super._showFilter(e)}_sortBtnClick(e,t){var o,n,i=this.filter.column,s=i.grid.sortManager;e.preventDefault(),e.stopPropagation(),(o=s.checkSortItemExists(i.index))>-1?(s.sortDescriptions.moveCurrentToPosition(o),s.sortDescriptions.currentItem.ascending=t,n=-o):(s.addSortLevel(i.index,t),n=-(s.sortDescriptions.items.length-1)),s.moveSortLevel(n),s.commitSort(),this.updateEditor(),this.onButtonClicked()}cloneElement(e){for(var t=e.cloneNode();e.firstChild;)t.appendChild(e.lastChild);return t}}exports.FlexSheetColumnFilterEditor=FlexSheetColumnFilterEditor;class FlexSheetFilter extends wjcGridFilter.FlexGridFilter{get filterDefinition(){for(var e={filters:[]},t=0;t<this._filters.length;t++){var o=this._filters[t];if(o&&o.column)if(o.conditionFilter.isActive){var n=o.conditionFilter;e.filters.push({columnIndex:o.column.index,type:"condition",condition1:{operator:n.condition1.operator,value:n.condition1.value},and:n.and,condition2:{operator:n.condition2.operator,value:n.condition2.value}})}else if(o.valueFilter.isActive){var i=o.valueFilter;e.filters.push({columnIndex:o.column.index,type:"value",filterText:i.filterText,showValues:i.showValues})}}return JSON.stringify(e)}set filterDefinition(e){var t=JSON.parse(wjcCore.asString(e));this.clear();for(var o=0;o<t.filters.length;o++){var n=t.filters[o],i=this.grid.columns[n.columnIndex],s=this.getColumnFilter(i,!0);if(s)switch(n.type){case"condition":var l=s.conditionFilter;l.condition1.value=i.dataType==wjcCore.DataType.Date?wjcCore.changeType(n.condition1.value,i.dataType,null):n.condition1.value,l.condition1.operator=n.condition1.operator,l.and=n.and,l.condition2.value=i.dataType==wjcCore.DataType.Date?wjcCore.changeType(n.condition2.value,i.dataType,null):n.condition2.value,l.condition2.operator=n.condition2.operator;break;case"value":var r=s.valueFilter;r.filterText=n.filterText,r.showValues=n.showValues}}this.apply()}apply(){var e=this;e.grid.deferUpdate(()=>{for(var t,o,n,i=-1,s=0;s<e.grid.rows.length;s++)if(!((t=e.grid.rows[s])instanceof HeaderRow||s<=i))if(i=-1,o=e._filter(s),t instanceof wjcGrid.GroupRow){if(n=t.getCellRange(),null==t.dataItem||t.dataItem instanceof wjcCore.CollectionViewGroup)t.visible=e._checkGroupVisible(n);else if(t.visible=o,i=n.bottomRow,n.isValid)for(var l=n.topRow;l<=n.bottomRow;l++)e.grid.rows[l].visible=o}else t.visible=o;e.grid._isCopying||e.grid._isUndoing||e.grid._isSorting||e.onFilterApplied()})}editColumnFilter(e,t){var o=this;o.closeEditor(),e=wjcCore.isString(e)?o.grid.columns.getColumn(e):wjcCore.asType(e,wjcGrid.Column,!1);var n=new wjcGrid.CellRangeEventArgs(o.grid.cells,new wjcGrid.CellRange(-1,e.index));if(o.onFilterChanging(n),!n.cancel){n.cancel=!0,o.grid.undoStack.stackSize>0&&(o._undoAcion=new _FilteringAction(o.grid));var i=document.createElement("div"),s=o.getColumnFilter(e),l=new FlexSheetColumnFilterEditor(i,s,o.showSortButtons);wjcCore.addClass(i,"wj-dropdown-panel"),o.grid.rightToLeft&&(i.dir="rtl"),l.filterChanged.addHandler(()=>{n.cancel=!1,o._filterChanged=!0,setTimeout(()=>{n.cancel||(o.apply(),o._undoAcion&&(o._undoAcion.saveNewState(),o.grid.undoStack._addAction(o._undoAcion),o._undoAcion=null))})}),l.buttonClicked.addHandler(()=>{o.closeEditor(),o.grid.focus(),o.onFilterChanged(n)}),l.lostFocus.addHandler(()=>{setTimeout(()=>{var e=wjcCore.Control.getControl(o._divEdt);e&&!e.containsFocus()&&o.closeEditor()},10)});var r=o.grid.columnHeaders,a=t?t.row:r.rows.length-1,h=t?t.col:e.index,d=r.getCellBoundingRect(a,h),c=document.elementFromPoint(d.left+d.width/2,d.top+d.height/2);(c=wjcCore.closest(c,".wj-cell"))?wjcCore.showPopup(i,c,!1,!1,!1):wjcCore.showPopup(i,d),l.focus(),o._divEdt=i,o._edtCol=e}}closeEditor(){this._undoAcion&&!this._filterChanged&&(this._undoAcion=null),super.closeEditor()}getColumnFilter(e,t=!0){if(wjcCore.isString(e)?e=this.grid.columns.getColumn(e):wjcCore.isNumber(e)&&(e=this.grid.columns[e]),!e)return null;e=wjcCore.asType(e,wjcGrid.Column);for(var o=0;o<this._filters.length;o++)if(this._filters[o].column==e)return this._filters[o];if(t){var n=new FlexSheetColumnFilter(this,e);return this._filters.push(n),n}return null}_checkGroupVisible(e){for(var t,o=!0,n=e.topRow+1;n<=e.bottomRow;n++)if(t=this.grid.rows[n])if(t instanceof wjcGrid.GroupRow)o=this._checkGroupVisible(t.getCellRange());else if(o=this._filter(n))break;return o}}exports.FlexSheetFilter=FlexSheetFilter;