@mescius/wijmo.grid.sheet 5.20232.939

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es5-esm.js ADDED
@@ -0,0 +1,14 @@
1
+ /*!
2
+ *
3
+ * Wijmo Library 5.20232.939
4
+ * https://developer.mescius.com/wijmo
5
+ *
6
+ * Copyright(c) MESCIUS inc. All rights reserved.
7
+ *
8
+ * Licensed under the End-User License Agreement For MESCIUS Wijmo Software.
9
+ * us.sales@mescius.com
10
+ * https://developer.mescius.com/wijmo/licensing
11
+ *
12
+ */
13
+
14
+ var _a,_KnownErrors,__extends=this&&this.__extends||function(){var extendStatics=function(e,t){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])})(e,t)};return function(e,t){extendStatics(e,t);function __(){this.constructor=e}e.prototype=null===t?Object.create(t):(__.prototype=t.prototype,new __)}}();import{isBoolean,isInt,isString,CollectionView,DataType,Point,SortDescription,ObservableArray,Control,addClass,removeClass,hasClass,culture,Event,EventArgs,PropertyChangedEventArgs,isNumber,tryCast,isNullOrWhiteSpace,toggleClass,setSelectionRange,removeChild,NotifyCollectionChangedEventArgs,NotifyCollectionChangedAction,Key,CancelEventArgs,Globalize,isDate,escapeRegExp,enable,asString,changeType,closest,showPopup,asType,CollectionViewGroup,contains,setCss,isPrimitive,escapeHtml,Clipboard,Tooltip,Color,isObject,isArray,isFirefox,asNumber,asInt,assert,toHeaderCase,_deprecated,_addCultureInfo,asBoolean,asEnum,Aggregate,_getModule,_registerModule}from"@mescius/wijmo";import{Row,Column,CellRange,GridPanel,SelectionMode,FlexGrid,GroupRow,CellEditEndingEventArgs,CellRangeEventArgs,_NewRowTemplate,HitTestInfo,CellFactory,CellType,DataMapEditor,RowColFlags,_SelectionHandler,HeadersVisibility,AllowDragging,AllowResizing,AllowSorting,KeyAction,SelectedState}from"@mescius/wijmo.grid";import{ColumnFilter,FilterType,ValueFilter,ConditionFilter,ValueFilterEditor,ColumnFilterEditor,FlexGridFilter}from"@mescius/wijmo.grid.filter";import{Menu}from"@mescius/wijmo.input";import{Workbook}from"@mescius/wijmo.xlsx";import{FlexGridXlsxConverter,_blobToBuffer}from"@mescius/wijmo.grid.xlsx";import*as mInput from"@mescius/wijmo.input";import*as mXlsx from"@mescius/wijmo.xlsx";import*as selfModule from"@mescius/wijmo.grid.sheet";export function softInput(){return _getModule("wijmo.input")}export function softXlsx(){return _getModule("wijmo.xlsx")}export var _ErrorMessages={InvalidCellRef:"Invalid cell reference.",InvalidSheetRef:"Invalid sheet reference.",InvalidTableRef:"Invalid table reference.",InvalidTableColRef:"Invalid table column reference.",InvalidParameters:"Invalid parameters.",BadExpression:"Bad expression.",CircRef:"Circular reference.",InvalidParameter:function(e){return'Invalid parameter: "'+e+'".'},ParameterIsOutOfRange:function(e){return'Parameter is out of range: "'+e+'".'},RowIsOutOfTableRange:function(e){return"The row is out of the table ("+e+") range."},UnkFuncName:function(e){return'The function "'+e+'" has not supported in FlexSheet yet.'},DefNameInvalidSheet:function(e){return'The defined name item works in "'+e+'". It does not work in current sheet.'},InvalidTable:function(e){return"The Table("+e+") is not located in any sheet."},InvalidExpression:function(e){return"Invalid Expression: "+e},Atan2ArgsLessThanZero:"The x number and y number can't both be zero for the atan2 function.",RateCriteriaFails:"It is not able to calculate the rate with current parameters.",RangesMustBeTheSame:"The row span and column span of each cell range has to be same with each other.",TooFewParameters:"Too few parameters.",TooManyParameters:"Too many parameters.",ExpressionExpected:"Expression expected.",UnbalancedParenthesis:"Unbalanced parenthesis.",UnbalancedSquareBrackets:"Unbalanced square brackets.",TableReferencesExpected:"Table references expected.",IdentifierExpected:"Identifier expected.",CantFindFinalQuote:"Can't find final quote.",IllegalCrossSheetReference:"Illegal cross sheet reference.",CantFindFinalDateDelimiter:'Can\'t find final date delimiter ("#").',CellRefMustBeInSameSheet:"The cell reference must be in the same sheet.",SyntaxError:"Syntax error."};!function(e){e.Div="#DIV/0!";e.Name="#NAME?";e.Ref="#REF!";e.Num="#NUM!";e.Val="#VALUE!";e.Null="#NULL!";e.NA="#N/A"}(_KnownErrors||(_KnownErrors={}));var FormulaError=function(){function FormulaError(e,t){this._error=e;this._data=t}Object.defineProperty(FormulaError.prototype,"error",{get:function(){return this._error},enumerable:!0,configurable:!0});Object.defineProperty(FormulaError.prototype,"data",{get:function(){return this._data},enumerable:!0,configurable:!0});FormulaError.prototype.toString=function(){return this._error||(this._data||"").toString()};return FormulaError}();export{FormulaError};var DivideByZeroError=function(e){__extends(DivideByZeroError,e);function DivideByZeroError(t){return e.call(this,_KnownErrors.Div,t)||this}return DivideByZeroError}(FormulaError);export{DivideByZeroError};var NameError=function(e){__extends(NameError,e);function NameError(t){return e.call(this,_KnownErrors.Name,t)||this}return NameError}(FormulaError);export{NameError};var ReferenceError=function(e){__extends(ReferenceError,e);function ReferenceError(t){return e.call(this,_KnownErrors.Ref,t)||this}return ReferenceError}(FormulaError);export{ReferenceError};var NumericError=function(e){__extends(NumericError,e);function NumericError(t){return e.call(this,_KnownErrors.Num,t)||this}return NumericError}(FormulaError);export{NumericError};var ValueError=function(e){__extends(ValueError,e);function ValueError(t){return e.call(this,_KnownErrors.Val,t)||this}return ValueError}(FormulaError);export{ValueError};var NotAvailableError=function(e){__extends(NotAvailableError,e);function NotAvailableError(t){return e.call(this,_KnownErrors.NA,t)||this}return NotAvailableError}(FormulaError);export{NotAvailableError};var NullError=function(e){__extends(NullError,e);function NullError(t){return e.call(this,_KnownErrors.Null,t)||this}return NullError}(FormulaError);export{NullError};var UnknownError=function(e){__extends(UnknownError,e);function UnknownError(t){return e.call(this,"",t)||this}return UnknownError}(FormulaError);export{UnknownError};var SyntaxError=function(e){__extends(SyntaxError,e);function SyntaxError(t){return e.call(this,"#SYNTAX",t)||this}return SyntaxError}(FormulaError);export{SyntaxError};var _FormulaErrorHelper=function(){function _FormulaErrorHelper(){}_FormulaErrorHelper.asError=function(e){return e instanceof FormulaError?e:"string"==typeof e?this.fromString(e):null};_FormulaErrorHelper.fromString=function(e){e=e.toUpperCase();if(this._errTypeMap[e])switch(e){case _KnownErrors.Div:return new DivideByZeroError;case _KnownErrors.Name:return new NameError;case _KnownErrors.NA:return new NotAvailableError;case _KnownErrors.Null:return new NullError;case _KnownErrors.Num:return new NumericError;case _KnownErrors.Ref:return new ReferenceError;case _KnownErrors.Val:return new ValueError}return null};_FormulaErrorHelper._errTypeMap=function(){var e={};Object.keys(_KnownErrors).forEach((function(t){return e[_KnownErrors[t]]=1}));return e}();return _FormulaErrorHelper}();export{_FormulaErrorHelper};var Table=function(){function Table(e,t,o,n,i){this._showHeaderRow=!0;this._showTotalRow=!1;this._showBandedColumns=!1;this._showBandedRows=!0;this._alterFirstColumn=!1;this._alterLastColumn=!1;this._orgHeaderCellsContent=[];if(!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);if(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)}}Object.defineProperty(Table.prototype,"name",{get:function(){return this._name},set:function(e){if(null==e||""===e)throw"The name of the Table should not be empty.";if(this._name.toLowerCase()!==e.toLowerCase()){var t=this._name;this._name=e;if(this._owner){var o=void 0;!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(o=new _TableSettingAction(this._owner,this));this._owner._updateFormulasWithNameUpdating(t,e,!0);if(o){o.saveNewState();this._owner.undoStack._addAction(o);o=null}}}},enumerable:!0,configurable:!0});Object.defineProperty(Table.prototype,"sheet",{get:function(){return this._sheet},enumerable:!0,configurable:!0});Object.defineProperty(Table.prototype,"style",{get:function(){return this._style},set:function(e){if(e.name!==this._style.name){var t=void 0;this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this));this._style=e;if(this._owner){if(t){t.saveNewState();this._owner.undoStack._addAction(t);t=null}this._owner.refresh()}}},enumerable:!0,configurable:!0});Object.defineProperty(Table.prototype,"showHeaderRow",{get:function(){return this._showHeaderRow},set:function(e){if(e!==this._showHeaderRow){var t=void 0,o=this._showHeaderRow;this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this));this._showHeaderRow=e;if(this._owner)try{this._owner.beginUpdate();this._adjustTableRangeWithHeaderRow();if(t){t.saveNewState();this._owner.undoStack._addAction(t)}}catch(e){this._showHeaderRow=o;throw e}finally{t=null;this._owner.endUpdate()}}},enumerable:!0,configurable:!0});Object.defineProperty(Table.prototype,"showTotalRow",{get:function(){return this._showTotalRow},set:function(e){if(e!==this._showTotalRow){var t=void 0,o=this._showTotalRow;this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this));this._showTotalRow=e;if(this._owner)try{this._owner.beginUpdate();this._adjustTableRangeWithTotalRow();if(t){t.saveNewState();this._owner.undoStack._addAction(t)}}catch(e){this._showTotalRow=o;throw e}finally{t=null;this._owner.endUpdate()}}},enumerable:!0,configurable:!0});Object.defineProperty(Table.prototype,"showBandedColumns",{get:function(){return this._showBandedColumns},set:function(e){if(e!==this._showBandedColumns){var t=void 0;this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this));this._showBandedColumns=e;if(this._owner){if(t){t.saveNewState();this._owner.undoStack._addAction(t);t=null}this._owner.refresh()}}},enumerable:!0,configurable:!0});Object.defineProperty(Table.prototype,"showBandedRows",{get:function(){return this._showBandedRows},set:function(e){if(e!==this._showBandedRows){var t=void 0;this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this));this._showBandedRows=e;if(this._owner){if(t){t.saveNewState();this._owner.undoStack._addAction(t);t=null}this._owner.refresh()}}},enumerable:!0,configurable:!0});Object.defineProperty(Table.prototype,"alterFirstColumn",{get:function(){return this._alterFirstColumn},set:function(e){if(e!==this._alterFirstColumn){var t=void 0;this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this));this._alterFirstColumn=e;if(this._owner){if(t){t.saveNewState();this._owner.undoStack._addAction(t);t=null}this._owner.refresh()}}},enumerable:!0,configurable:!0});Object.defineProperty(Table.prototype,"alterLastColumn",{get:function(){return this._alterLastColumn},set:function(e){if(e!==this._alterLastColumn){var t=void 0;this._owner&&!this._owner._isUndoing&&this._owner.undoStack.stackSize>0&&(t=new _TableSettingAction(this._owner,this));this._alterLastColumn=e;if(this._owner){if(t){t.saveNewState();this._owner.undoStack._addAction(t);t=null}this._owner.refresh()}}},enumerable:!0,configurable:!0});Table.prototype._isHeaderRow=function(e){return this._showHeaderRow&&e===this._range.topRow};Table.prototype._getTableRange=function(){return this._range};Table.prototype._getColumns=function(){return this._columns||[]};Table.prototype.getRange=function(e,t){void 0===e&&(e=TableSection.All);var 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){var n=this._getColumnIndex(t);if(null==n)return null;o.col=o.col2=o.leftCol+n}return o};Table.prototype.getColumns=function(){return this._columns?this._columns.slice():[]};Table.prototype.insertRows=function(e,t,o){void 0===o&&(o=!0);var n=!1;null==t&&(t=1);if(!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){var i=this.getRange(),l=this._flex;this._owner.beginUpdate();if(o){var r=new CellRange(i.bottomRow+1,i.col,i.bottomRow+1,i.col2);if(this._sheet._canShiftCells(r)){var s=this._sheet._needAddRowCountForInsertTableRows(t,i);if(l.collectionView){var a=l.itemsSource instanceof CollectionView;l.collectionView.beginUpdate();for(var h=0;h<s;h++)a?l.itemsSource.sourceCollection.push({}):l.itemsSource.push({});l.collectionView.endUpdate(!0)}else for(h=0;h<s;h++)l.rows.push(new Row);this._sheet._moveDownCells(t,r);n=!0}}else this._canInsertRowsWithoutShift(t)&&(n=!0);if(n){this._sheet._moveDownCellsWithinTable(e,t,i);this._updateTableRange(0,t,0,0)}this._owner.endUpdate()}else{this._updateTableRange(0,t,0,0);n=!0}return n};Table.prototype.deleteRows=function(e,t,o){void 0===o&&(o=!0);null==t&&(t=1);if(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)))if(this._owner){var n=!1,i=this.getRange(),l=void 0;this._owner.beginUpdate();if(o){l=new CellRange(i.bottomRow+1,i.col,i.bottomRow+1,i.col2);this._sheet._canShiftCells(l)&&(n=!0)}else n=!0;if(n){this._sheet._moveUpCellsWithinTable(e,t,i);o&&this._sheet._moveUpCells(t,l);this._updateTableRange(0,-t,0,0)}this._owner.endUpdate()}else this._updateTableRange(0,-t,0,0)};Table.prototype._addColumn=function(e,t){if(e<=0||e>this._columns.length)throw"The column index is out of range.";t=this._getUniqueColumnName(e,t);var o=new TableColumn(t);o._attach(this);this._columns.splice(e,0,o);if(this.showHeaderRow&&this._owner&&this._sheet){var n=this.getRange();this._flex.setCellData(n.topRow,n.leftCol+e,t)}};Table.prototype._updateCell=function(e,t,o){if(null!=this._style){var n=e-this._range.topRow,i=t-this._range.leftCol,l=this._getTableCellAppliedStyles(n,i);this._applyStylesForCell(l,o)}};Table.prototype._updateTableRange=function(e,t,o,n){if(this._range.row<=this._range.row2){this._range.row+=e;this._range.row2+=t}else{this._range.row2+=e;this._range.row+=t}if(this._range.col<=this._range.col2){this._range.col+=o;this._range.col2+=n}else{this._range.col2+=o;this._range.col+=n}};Table.prototype._setTableRange=function(e,t){this._range=e;if(null!=t){this._columns.splice(0,this._columns.length);for(var o=0;o<t.length;o++)this._columns.push(t[o])}};Table.prototype._updateColumnName=function(e,t,o){void 0===o&&(o=!0);var n=this._columns[e];if(!n||!n.name||n.name!==t){t=this._getUniqueColumnName(null,t);n.name=t;if(this._showHeaderRow&&this._owner&&this._sheet&&o){this._flex.setCellData(this._range.topRow,this._range.leftCol+e,t)}}};Table.prototype._updateColumnTotalRowContent=function(e,t){null==t&&(t=this._columns.indexOf(e));if(!(t<0)){var o;if(e.totalRowFunction){var n=this._getSubtotalFunction(e.totalRowFunction.toLowerCase());o=null!=n?"=subtotal("+n+",["+e.name+"])":"="===e.totalRowFunction[0]?e.totalRowFunction:"="+e.totalRowFunction}else if(0===t){e.totalRowLabel||(e.totalRowLabel="Total");o=e.totalRowLabel}else o=e.totalRowLabel;if(this._owner&&this._sheet){this._flex.setCellData(this._range.bottomRow,this._range.leftCol+t,o,!1)}}};Table.prototype._attachSheet=function(e){if(!this._sheet||!this._owner){this._sheet=e;this._owner=e._owner;if(null!=this._owner){if(this._owner._containsMergedCells(this._range,e))throw"Table does not allow the merged cell within the table.";var t=this.getRange();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._attached=!0;this._owner.endUpdate()}}}};Table.prototype._detachSheet=function(){this._attached=!1;this._sheet=null;this._owner=null};Object.defineProperty(Table.prototype,"_flex",{get:function(){return this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid},enumerable:!0,configurable:!0});Table.prototype._pushTableColumns=function(e){this._columns=[];for(var t=0;t<e.length;t++){var o=e[t];o._attach(this);this._columns.push(o)}};Table.prototype._generateColumns=function(e){if(!this._range.isValid)throw"The range of the table is invalid.";this._columns=[];for(var t=0;t<this._range.columnSpan;t++){var o=null,n=this._sheet.grid.columns[this._range.leftCol+t],i=this._range.topRow*this._sheet.grid.columns.length+this._range.leftCol+t,l=void 0,r=void 0,s=this._flex;if(1===this._range.rowSpan)l=this._getUniqueColumnName(t+1);else{null==(l=o=this._sheet.grid.getCellData(this._range.topRow,this._range.leftCol+t,!1))&&(l="");_isFormula(l)&&(l=this._owner.evaluate(l,"",this._sheet,!1));r=this._sheet._styledCells[i];var a=this._owner._formatEvaluatedResult(l,n,r?r.format:"");null!=l&&""==a||(l=a);l=this._getUniqueColumnName(t+1,l.toString())}if(e&&this._range.rowSpan>1){this._orgHeaderCellsContent[t]=this._sheet.grid.getCellData(this._range.topRow,this._range.leftCol+t,!1);isNaN(+l)||n.format||r&&r.format||(r?r.format="@":this._sheet._styledCells[i]={format:"@"});s.setCellData(this._range.topRow,this._range.leftCol+t,n.dataType===DataType.Boolean&&isBoolean(o)?o:l,!1)}var h=new TableColumn(l);h._attach(this);0===t?h._totalRowLabel="Total":t===this._range.columnSpan-1&&(h._totalRowFunction="Sum");this._columns.push(h)}};Table.prototype._getTableCellAppliedStyles=function(e,t){var o={},n=0,i=!1,l=!1;this._showHeaderRow&&(n=1);this._showHeaderRow&&0===e?i=!0:this._showTotalRow&&e===this._range.rowSpan-1&&(l=!0);this._extendStyle(o,this._style.wholeTableStyle,e,t,i,l);if(!i&&!l){if(this._showBandedColumns&&(null!=this._style.firstBandedColumnStyle||null!=this._style.secondBandedColumnStyle)){var r=void 0;t%((r=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))>=r?this._style.secondBandedColumnStyle&&this._extendStyle(o,this._style.secondBandedRowStyle,e,t,i,l):this._style.firstBandedColumnStyle&&this._extendStyle(o,this._style.firstBandedColumnStyle,e,t,i,l)}if(this._showBandedRows&&(null!=this._style.firstBandedRowStyle||null!=this._style.secondBandedRowStyle)){r=void 0;(e-n)%((r=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))>=r?this._style.secondBandedRowStyle&&this._extendStyle(o,this._style.secondBandedRowStyle,e,t,i,l):this._style.firstBandedRowStyle&&this._extendStyle(o,this._style.firstBandedRowStyle,e,t,i,l)}}this._alterLastColumn&&t===this._range.columnSpan-1&&this._style.lastColumnStyle&&this._extendStyle(o,this._style.lastColumnStyle,e,t,i,l);this._alterFirstColumn&&0===t&&this._style.firstColumnStyle&&this._extendStyle(o,this._style.firstColumnStyle,e,t,i,l);if(i){this._style.headerRowStyle&&this._extendStyle(o,this._style.headerRowStyle,e,t,i,l);t===this._range.columnSpan-1&&this._style.lastHeaderCellStyle&&this._extendStyle(o,this._style.lastHeaderCellStyle,e,t,i,l);0===t&&this._style.firstHeaderCellStyle&&this._extendStyle(o,this._style.firstHeaderCellStyle,e,t,i,l)}else if(l){this._style.totalRowStyle&&this._extendStyle(o,this._style.totalRowStyle,e,t,i,l);t===this._range.columnSpan-1&&this._style.lastTotalCellStyle&&this._extendStyle(o,this._style.lastTotalCellStyle,e,t,i,l);0===t&&this._style.firstTotalCellStyle&&this._extendStyle(o,this._style.firstTotalCellStyle,e,t,i,l)}return o};Table.prototype._applyStylesForCell=function(e,t){var o=t.style;for(var n in e){var i=e[n];i&&(o[n]=i)}};Table.prototype._extendStyle=function(e,t,o,n,i,l){for(var r in t){var s=t[r];null!==s&&(r.indexOf("borderTop")>-1?(0===o||l)&&(e[r]=s):r.indexOf("borderBottom")>-1?(o===this._range.rowSpan-1||i)&&(e[r]=s):r.indexOf("borderLeft")>-1?0===n&&(e[r]=s):r.indexOf("borderRight")>-1?n===this._range.columnSpan-1&&(e[r]=s):r.indexOf("borderHorizontal")>-1?o<this._range.rowSpan-1&&("borderHorizontalStyle"===r?e.borderBottomStyle=s:"borderHorizontalWidth"===r?e.borderBottomWidth=s:e.borderBottomColor=s):r.indexOf("borderVertical")>-1?n<this._range.columnSpan-1&&("borderVerticalStyle"===r?e.borderRightStyle=s:"borderVerticalWidth"===r?e.borderRightWidth=s:e.borderRightColor=s):e[r]=s)}};Table.prototype._getSubtotalFunction=function(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};Table.prototype._checkColumnNameExist=function(e){for(var t=this.getColumns(),o=0;o<t.length;o++){if(t[o].name.toLowerCase()===e.toLowerCase())return!0}return!1};Table.prototype._adjustTableRangeWithHeaderRow=function(){var e=this._flex;if(this._showHeaderRow){if(this._sheet._needMoveDownTable(this)){var t=this.getRange(),o=new CellRange(t.bottomRow+1,t.col,t.bottomRow+1,t.col2);if(!this._sheet._canShiftCells(o))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.";if(1===this._sheet._needAddRowCountForInsertTableRows(1,t))if(e.collectionView){e.collectionView.beginUpdate();e.itemsSource instanceof CollectionView?e.itemsSource.sourceCollection.push({}):e.itemsSource.push({});e.collectionView.endUpdate(!0)}else e.rows.push(new Row);this._sheet._moveDownCells(1,o);this._sheet._moveDownTable(this)}this._range.row<=this._range.row2?this._range.row-=1:this._range.row2-=1;for(var n=0;n<this._columns.length;n++){var i=this._columns[n];this._orgHeaderCellsContent[n]=e.getCellData(this._range.topRow,this._range.leftCol+n,!1);e.setCellData(this._range.topRow,this._range.leftCol+n,i.name)}}else{for(n=this._range.leftCol;n<=this._range.rightCol;n++)e.setCellData(this._range.topRow,n,"");this._range.row<=this._range.row2?this._range.row+=1:this._range.row2+=1}};Table.prototype._adjustTableRangeWithTotalRow=function(){var e=this._sheet===this._owner.selectedSheet?this._owner:this._sheet.grid,t=this.getRange(),o=new CellRange(t.bottomRow+1,t.col,t.bottomRow+1,t.col2);if(this._showTotalRow){if(this._sheet._canShiftCells(o)){if(1===this._sheet._needAddRowCountForInsertTableRows(1,t))if(e.collectionView){e.collectionView.beginUpdate();e.itemsSource instanceof CollectionView?e.itemsSource.sourceCollection.push({}):e.itemsSource.push({});e.collectionView.endUpdate(!0)}else e.rows.push(new Row);this._sheet._moveDownCells(1,o);this._owner._updateAffectedFormula(this._range.bottomRow+1,1,!0,!0,this.getRange())}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(var n=this._range.leftCol;n<=this._range.rightCol;n++)e.setCellData(this._range.bottomRow,n,"");if(this._sheet._canShiftCells(o)){this._owner._updateAffectedFormula(this._range.bottomRow,1,!1,!0,this.getRange());this._sheet._moveUpCells(1,o)}this._range.row<=this._range.row2?this._range.row2-=1:this._range.row-=1}};Table.prototype._updateTotalRow=function(){if(this.showTotalRow)for(var e=0;e<this._columns.length;e++){var t=this._columns[e];this._updateColumnTotalRowContent(t,e)}};Table.prototype._getUniqueColumnName=function(e,t){null!=t&&""!==t||(t="Column"+e);if(this._checkColumnNameExist(t)){for(var o=1,n=t+o;this._checkColumnNameExist(n);)n=t+ ++o;t=n}return t};Table.prototype._moveColumns=function(e,t){if(this._columns){var o=this._columns[e];this._columns.splice(e,1);t<0&&(t=this._columns.length);this._columns.splice(t,0,o)}};Table.prototype._canInsertRowsWithoutShift=function(e){var t=this._flex;if(this._range.bottomRow+e>=t.rows.length)return!1;for(var o=1;o<=e;o++)for(var n=this._range.bottomRow+o,i=this._range.leftCol;i<=this._range.rightCol;i++){var l=t.getCellData(n,i,!1),r=this._sheet.getCellStyle(n,i);if(null!=l&&""!==l||null!=r)return!1}return!0};Table.prototype._beneathRowIsEmpty=function(){var e=this._range.bottomRow+1,t=this._flex;if(e>=t.rows.length)return!1;for(var o=this._range.leftCol;o<=this._range.rightCol;o++){var n=t.getCellData(this._range.bottomRow+1,o,!1);if(null!=n&&""!==n)return!1;if(null!=this._sheet.getCellStyle(this._range.bottomRow+1,o))return!1;if(this._sheet.findTable(e,o))return null;var i=e*t.columns.length+o;if(null!=this._sheet._mergedRanges[i])return!1}return!0};Table.prototype._getDataRange=function(){var e=this._range.topRow,t=this._range.bottomRow;this._showHeaderRow&&(e+=1);this._showTotalRow&&(t-=1);return new CellRange(e,this._range.leftCol,t,this._range.rightCol)};Table.prototype._getHeaderRange=function(){return this._showHeaderRow?new CellRange(this._range.topRow,this._range.leftCol,this._range.topRow,this._range.rightCol):null};Table.prototype._getFooterRange=function(){return this._showTotalRow?new CellRange(this._range.bottomRow,this._range.leftCol,this._range.bottomRow,this._range.rightCol):null};Table.prototype._getColumnIndex=function(e){var t;if(isInt(e)&&e>=0&&e<this._columns.length)t=e;else{var o=void 0;e instanceof TableColumn?o=e.name.toLowerCase():isString(e)&&""!==e&&(o=e.toLowerCase());for(var n=this.getColumns(),i=0;i<n.length;i++)if(n[i].name.toLowerCase()===o){t=i;break}}return t};return Table}();export{Table};var TableColumn=function(){function TableColumn(e,t,o,n){void 0===n&&(n=!0);this._name=e;this._totalRowLabel=t;this._totalRowFunction=o;null!=n&&(this._showFilterButton=n)}Object.defineProperty(TableColumn.prototype,"table",{get:function(){return this._table},enumerable:!0,configurable:!0});Object.defineProperty(TableColumn.prototype,"name",{get:function(){return this._name},set:function(e){e!==this._name&&(this._name=e)},enumerable:!0,configurable:!0});Object.defineProperty(TableColumn.prototype,"totalRowLabel",{get:function(){return this._totalRowLabel},set:function(e){if(e!==this._totalRowLabel){this._totalRowLabel=e;this._updateTableTotalInfo()}},enumerable:!0,configurable:!0});Object.defineProperty(TableColumn.prototype,"totalRowFunction",{get:function(){return this._totalRowFunction},set:function(e){if(e!==this._totalRowFunction){this._totalRowFunction=e;this._updateTableTotalInfo()}},enumerable:!0,configurable:!0});Object.defineProperty(TableColumn.prototype,"showFilterButton",{get:function(){return this._showFilterButton},set:function(e){this._showFilterButton!==e&&(this._showFilterButton=e)},enumerable:!0,configurable:!0});TableColumn.prototype._attach=function(e){this._table=e};TableColumn.prototype._updateTableTotalInfo=function(){if(this._table&&this._table.showTotalRow){this._table._updateColumnTotalRowContent(this);this._table._owner&&this._table._owner.refresh()}};return TableColumn}();export{TableColumn};var TableStyle=function(){function TableStyle(e,t){void 0===t&&(t=!1);this._name=e;this._isBuiltIn=t}Object.defineProperty(TableStyle.prototype,"name",{get:function(){return this._name},set:function(e){e!==this._name&&(this._name=e)},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"wholeTableStyle",{get:function(){return this._wholeTableStyle},set:function(e){this._wholeTableStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"firstBandedColumnStyle",{get:function(){return this._firstBandedColumnStyle},set:function(e){this._firstBandedColumnStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"secondBandedColumnStyle",{get:function(){return this._secondBandedColumnStyle},set:function(e){this._secondBandedColumnStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"firstBandedRowStyle",{get:function(){return this._firstBandedRowStyle},set:function(e){this._firstBandedRowStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"secondBandedRowStyle",{get:function(){return this._secondBandedRowStyle},set:function(e){this._secondBandedRowStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"firstColumnStyle",{get:function(){return this._firstColumnStyle},set:function(e){this._firstColumnStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"lastColumnStyle",{get:function(){return this._lastColumnStyle},set:function(e){this._lastColumnStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"headerRowStyle",{get:function(){return this._headerRowStyle},set:function(e){this._headerRowStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"totalRowStyle",{get:function(){return this._totalRowStyle},set:function(e){this._totalRowStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"firstHeaderCellStyle",{get:function(){return this._firstHeaderCellStyle},set:function(e){this._firstHeaderCellStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"lastHeaderCellStyle",{get:function(){return this._lastHeaderCellStyle},set:function(e){this._lastHeaderCellStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"firstTotalCellStyle",{get:function(){return this._firstTotalCellStyle},set:function(e){this._firstTotalCellStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"lastTotalCellStyle",{get:function(){return this._lastTotalCellStyle},set:function(e){this._lastTotalCellStyle=e},enumerable:!0,configurable:!0});Object.defineProperty(TableStyle.prototype,"isBuiltIn",{get:function(){return this._isBuiltIn},enumerable:!0,configurable:!0});return TableStyle}();export{TableStyle};export 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||(TableSection={}));var _UndoAction=function(){function _UndoAction(e){this._owner=e;this._sheetUuid=e.selectedSheet?e.selectedSheet._uid:-1}Object.defineProperty(_UndoAction.prototype,"sheetUid",{get:function(){return this._sheetUuid},enumerable:!0,configurable:!0});_UndoAction.prototype.undo=function(){throw"This abstract method must be overridden."};_UndoAction.prototype.redo=function(){throw"This abstract method must be overridden."};_UndoAction.prototype.saveNewState=function(){throw"This abstract method must be overridden."};return _UndoAction}();export{_UndoAction};var _EditAction=function(e){__extends(_EditAction,e);function _EditAction(t,o){var n=e.call(this,t)||this;n._isPaste=!1;n._selections=o?[o]:t.selectedSheet.selectionRanges.length>0?t.selectedSheet.selectionRanges.slice():[t.selection.clone()];n._mergeAction=new _CellMergeAction(t);n._cellStyleAction=new _CellStyleAction(t);n._saveValues(!0);return n}Object.defineProperty(_EditAction.prototype,"isPaste",{get:function(){return this._isPaste},enumerable:!0,configurable:!0});_EditAction.prototype.undo=function(){this._handleUndoRedo(!0)};_EditAction.prototype.redo=function(){this._handleUndoRedo(!1)};_EditAction.prototype.saveNewState=function(){if(!this._saveValues(!1))return!1;this._mergeAction.saveNewState();this._cellStyleAction.saveNewState();return this._checkActionState()};_EditAction.prototype.markIsPaste=function(){this._isPaste=!0};_EditAction.prototype.updateForPasting=function(e){var t=this._selections[this._selections.length-1],o=this._owner.getCellData(e.row,e.col,!!this._owner.columns[e.col].dataMap);if(!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)};_EditAction.prototype._storeDeletedTables=function(e){null==this._deletedTables&&(this._deletedTables=[]);this._deletedTables.push(e)};_EditAction.prototype._checkActionState=function(){var e=this,t=!1;Object.keys(e._oldValues).forEach((function(o){var n,i;if(!t){n=e._oldValues[o];i=e._newValues[o];n&&i&&n.value!==i.value&&(t=!0)}}));return t||e._mergeAction._checkActionState()||e._cellStyleAction._checkActionState()};_EditAction.prototype._saveValues=function(e){for(var t={},o=0;o<this._selections.length;o++)for(var n=this._selections[o],i=n.topRow;i<=n.bottomRow;i++)if(!(i<0))for(var l=n.leftCol;l<=n.rightCol;l++){var r=this._owner.columns[l];if(!r)return!1;var s=this._owner.getCellData(i,l,!!r.dataMap);s=null==s?"":s;t["r"+i+"_c"+l]={row:i,col:l,value:s}}e?this._oldValues=t:this._newValues=t;return!0};_EditAction.prototype._handleUndoRedo=function(e){var t=this;t._owner._clearCalcEngine();t._owner.selectedSheet.selectionRanges.clear();t._owner.deferUpdate((function(){var o,n=e?t._oldValues:t._newValues;if(t._deletedTables&&t._deletedTables.length>0)for(var i=0;i<t._deletedTables.length;i++){var l=t._deletedTables[i];e?t._owner.selectedSheet.tables.push(l):t._owner.selectedSheet.tables.remove(l)}for(i=0;i<t._selections.length;i++){var r=t._selections[i];t._owner.selectedSheet.selectionRanges.push(r)}Object.keys(n).forEach((function(e){var o=n[e];t._owner.setCellData(o.row,o.col,o.value)}));t._affectedFormulas&&(o=e?t._affectedFormulas.oldFormulas:t._affectedFormulas.newFormulas);if(o&&o.length>0)for(i=0;i<o.length;i++){var s=o[i];t._owner.setCellData(s.point.x,s.point.y,s.formula)}if(e){t._mergeAction.undo();t._cellStyleAction.undo()}else{t._mergeAction.redo();t._cellStyleAction.redo()}t._owner.refresh(!1)}))};return _EditAction}(_UndoAction);export{_EditAction};var _ColumnResizeAction=function(e){__extends(_ColumnResizeAction,e);function _ColumnResizeAction(t,o,n){var i=e.call(this,t)||this;i._panel=o;i._colIndex=n;i._oldColWidth=o.columns[n].width;return i}_ColumnResizeAction.prototype.undo=function(){this._handleUndoRedo(!0)};_ColumnResizeAction.prototype.redo=function(){this._handleUndoRedo(!1)};_ColumnResizeAction.prototype.saveNewState=function(){this._newColWidth=this._panel.columns[this._colIndex].width;return this._oldColWidth!==this._newColWidth};_ColumnResizeAction.prototype._handleUndoRedo=function(e){var t=this._panel.columns[this._colIndex];t&&(t.width=e?this._oldColWidth:this._newColWidth)};return _ColumnResizeAction}(_UndoAction);export{_ColumnResizeAction};var _RowResizeAction=function(e){__extends(_RowResizeAction,e);function _RowResizeAction(t,o,n){var i=e.call(this,t)||this;i._panel=o;i._rowIndex=n;i._oldRowHeight=o.rows[n].height;return i}_RowResizeAction.prototype.undo=function(){this._handleUndoRedo(!0)};_RowResizeAction.prototype.redo=function(){this._handleUndoRedo(!1)};_RowResizeAction.prototype.saveNewState=function(){this._newRowHeight=this._panel.rows[this._rowIndex].height;return this._oldRowHeight!==this._newRowHeight};_RowResizeAction.prototype._handleUndoRedo=function(e){var t=this._panel.rows[this._rowIndex];t&&(t.height=e?this._oldRowHeight:this._newRowHeight)};return _RowResizeAction}(_UndoAction);export{_RowResizeAction};var _ColumnsChangedAction=function(e){__extends(_ColumnsChangedAction,e);function _ColumnsChangedAction(t,o,n,i){var l=e.call(this,t)||this;l._delSubActions=[];l._columnIndex=o;l._count=n;l._isAdding=i;l._saveValues(!0);return l}_ColumnsChangedAction.prototype.undo=function(){this._handleUndoRedo(!0)};_ColumnsChangedAction.prototype.redo=function(){this._handleUndoRedo(!1)};_ColumnsChangedAction.prototype.saveNewState=function(){this._saveValues(!1);return!0};_ColumnsChangedAction.prototype._saveValues=function(e){var t=[],o=[];if(null==this._isAdding)for(var n=0;n<this._owner.columns.length;n++)t.push(this._owner.columns[n]);else if(e&&!this._isAdding||!e&&this._isAdding)for(n=this._columnIndex;n<this._columnIndex+this._count&&n<this._owner.columns.length;n++)t.push(this._owner.columns[n]);if(this._owner.selectedSheet.tables&&this._owner.selectedSheet.tables.length>0)for(n=0;n<this._owner.selectedSheet.tables.length;n++){var i=this._owner.selectedSheet.tables[n];i&&i.sheet.name===this._owner.selectedSheet.name&&o.push({name:i.name,range:i.getRange(),columns:i.getColumns()})}var l={columns:t,sortList:this._owner.sortManager._cloneSortList(this._owner.sortManager._committedList),styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,mergedCells:this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,tableRanges:o,selection:this._owner.selection,filterDef:this._owner.selectedSheet._filterDefinition};e?this._oldValue=l:this._newValue=l};_ColumnsChangedAction.prototype._handleUndoRedo=function(e,t){var o=this;void 0===t&&(t=!0);var n=e?this._oldValue:this._newValue;if(this._owner.selectedSheet)if(this._delSubActions.length)this._owner.deferUpdate((function(){if(e)for(var t=o._delSubActions.length-1;t>=0;t--){o._delSubActions[t]._handleUndoRedo(e,!1)}else for(t=0;t<o._delSubActions.length;t++){o._delSubActions[t]._handleUndoRedo(e,!1)}}));else{try{t&&this._owner.beginUpdate();var i=void 0;this._owner._isUndoing=!0;this._owner._clearCalcEngine();this._owner.finishEditing();if(null==this._isAdding){this._owner.columns.clear();this._columnIndex=0}this._owner.selectedSheet._styledCells=null;this._owner.selectedSheet._mergedRanges.length=0;this._owner.columns.beginUpdate();if(n.columns&&n.columns.length>0)for(var l=0;l<n.columns.length;l++){if((r=n.columns[l])&&r.isVisible){this._owner.columns.insert(this._columnIndex+l,r);if(this._owner.itemsSource&&(i=this._owner.rows[this._owner._getDataRowsOffset()-1])){i._ubv||(i._ubv={});i._ubv[r._hash]=r.header}}}else for(l=this._columnIndex+this._count-1;l>=this._columnIndex;l--){var r;(r=this._owner.columns[l])&&r.isVisible&&this._owner.columns.removeAt(l)}this._owner.columns.endUpdate();this._owner.selectedSheet._styledCells=this._owner._cloneObject(n.styledCells);for(var s=0;s<n.mergedCells.length;s++)this._owner.selectedSheet._mergedRanges[s]=n.mergedCells[s];for(s=0;s<n.tableRanges.length;s++){var a=n.tableRanges[s];(c=this._owner._getTable(a.name))&&c._setTableRange(a.range,a.columns)}var h=void 0;this._affectedFormulas&&(h=e?this._affectedFormulas.oldFormulas:this._affectedFormulas.newFormulas);if(h&&h.length>0)for(s=0;s<h.length;s++){var u=h[s];null!=u.point?u.sheet.name===this._owner.selectedSheet.name?this._owner.setCellData(u.point.x,u.point.y,u.formula):u.sheet.grid.setCellData(u.point.x,u.point.y,u.formula):u.row._ubv[u.column._hash]=u.formula}if(this._deletedTables&&this._deletedTables.length>0)for(s=0;s<this._deletedTables.length;s++){var c=this._deletedTables[s];e?this._owner.selectedSheet.tables.push(c):this._owner.selectedSheet.tables.remove(c)}var d=void 0;this._affectedDefinedNameVals&&(d=e?this._affectedDefinedNameVals.oldDefinedNameVals:this._affectedDefinedNameVals.newDefinedNameVals);if(d&&d.length>0)for(s=0;s<d.length;s++){var _=d[s],f=this._owner.definedNames._getIndexByName(_.name);f>-1&&(this._owner.definedNames[f].value=_.value)}this._owner.selectedSheet.grid.wj_sheetInfo.styledCells=this._owner.selectedSheet._styledCells;this._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=this._owner.selectedSheet._mergedRanges}finally{t&&this._owner.endUpdate()}this._owner._copyColumnsToSelectedSheet();this._owner.sortManager.sortDescriptions.sourceCollection=n.sortList.slice();if(this._owner.selectedSheet._filterDefinition!==n.filterDef){this._owner._isUndoing=!0;this._owner.selectedSheet._filterDefinition=n.filterDef;this._owner.selectedSheet._applyFilterSetting();this._owner._isUndoing=!1;this._owner.filter.apply()}this._owner.sortManager.commitSort(!1);this._owner.selection=n.selection;this._owner._isUndoing=!1}};return _ColumnsChangedAction}(_UndoAction);export{_ColumnsChangedAction};var _RowsChangedAction=function(e){__extends(_RowsChangedAction,e);function _RowsChangedAction(t,o,n,i){var l=e.call(this,t)||this;l._delSubActions=[];l._headerRowIndex=-1;if(t.itemsSource){l._headerRowAtTop=t._headerRowAtTop();if(!l._headerRowAtTop)for(var r=0;r<t.rows.length;r++)if(t.rows[r]instanceof HeaderRow){l._headerRowIndex=r;break}}l._rowIndex=o;l._count=n;l._isAdding=i;l._saveValues(!0);return l}_RowsChangedAction.prototype.undo=function(){this._handleUndoRedo(!0)};_RowsChangedAction.prototype.redo=function(){this._handleUndoRedo(!1)};_RowsChangedAction.prototype.saveNewState=function(){this._saveValues(!1);return!0};_RowsChangedAction.prototype.addDeleteSubAction=function(e){this._delSubActions.push(e)};_RowsChangedAction.prototype._saveValues=function(e){var t,o,n=[],i=[],l=[];if(null==this._isAdding)if(this._owner.itemsSource){t=this._owner.itemsSource instanceof CollectionView?this._owner.itemsSource.sourceCollection.slice():this._owner.itemsSource.slice();for(var r=0;r<this._owner.columns.length;r++)i.push(this._owner.columns[r])}else for(r=0;r<this._owner.rows.length;r++)n.push(this._owner.rows[r]);else{if(e&&!this._isAdding||!e&&this._isAdding)for(r=this._rowIndex;r<this._rowIndex+this._count&&r<this._owner.rows.length;r++){var s=this._owner.rows[r];s.isVisible||this._isAdding?n.push(s):n.push(null)}this._owner.collectionView&&this._owner.collectionView.sortDescriptions.length>0&&(o=this._owner.collectionView._view.slice())}if(this._owner.selectedSheet.tables&&this._owner.selectedSheet.tables.length>0)for(r=0;r<this._owner.selectedSheet.tables.length;r++){var a=this._owner.selectedSheet.tables[r];a&&a.sheet.name===this._owner.selectedSheet.name&&l.push({name:a.name,range:a.getRange(),setting:{showHeaderRow:a.showHeaderRow,showTotalRow:a.showTotalRow}})}var h={rows:n,columns:i,itemsSource:t,styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,mergedCells:this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null,tableSettings:l,selection:this._owner.selection,dataView:o,scrollPosition:this._owner.scrollPosition};e?this._oldValue=h:this._newValue=h};_RowsChangedAction.prototype._handleUndoRedo=function(e,t){var o=this;void 0===t&&(t=!0);var n,i=this,l=!!i._owner.itemsSource,r=e?i._oldValue:i._newValue;if(i._owner.selectedSheet)if(this._delSubActions.length)i._owner.deferUpdate((function(){if(e)for(var t=o._delSubActions.length-1;t>=0;t--){o._delSubActions[t]._handleUndoRedo(e,!1)}else{for(t=0;t<o._delSubActions.length;t++){o._delSubActions[t]._handleUndoRedo(e,!1)}i._owner.selection=o._newValue.selection}}));else{try{t&&i._owner.beginUpdate();i._owner._isUndoing=!0;i._owner._clearCalcEngine();i._owner.finishEditing();if(null==i._isAdding){i._owner.itemsSource&&i._owner.columns.clear();i._owner.rows.clear();i._rowIndex=0}i._owner.selectedSheet._styledCells=null;i._owner.selectedSheet._mergedRanges.length=0;if(null==this._isAdding&&l){n=i._owner.autoGenerateColumns;i._owner.autoGenerateColumns=!1;i._owner.collectionView.beginUpdate();if(i._owner.itemsSource instanceof CollectionView){var s=[0,i._owner.itemsSource.sourceCollection.length].concat(r.itemsSource);Array.prototype.splice.apply(i._owner.itemsSource.sourceCollection,s)}else i._owner.itemsSource=r.itemsSource.slice();i._owner.columns.beginUpdate();for(var a=0;a<r.columns.length;a++)i._owner.columns.push(r.columns[a]);i._owner.columns.endUpdate();i._owner.collectionView.endUpdate(!0);i._owner.autoGenerateColumns=n}else{i._owner.rows.beginUpdate();if(l){n=i._owner.autoGenerateColumns;i._owner.autoGenerateColumns=!1;i._owner.collectionView.beginUpdate()}var h=i._owner.collectionView,u=h instanceof CollectionView?h:null;if(r.rows&&r.rows.length>0){var c=void 0;if(l){var d=i._owner._getDataRowsOffset();c=Math.max(i._rowIndex-d,0);!i._isAdding&&!i._headerRowAtTop&&i._owner._headerRowAtTop()&&i._rowIndex>=d&&c<i._headerRowIndex&&c++}for(a=0;a<r.rows.length;a++){if(w=r.rows[a])if(l&&w.dataItem){var _=null!=w.dataItem._itemIdx?w.dataItem._itemIdx:c+a;i._owner._updateItemIndexForInsertingRow(h.sourceCollection,_,1);h.sourceCollection.splice(_,0,w.dataItem);if(u&&u.trackChanges){var f=u.itemsRemoved.indexOf(w.dataItem)>=0;f&&u.itemsRemoved.remove(w.dataItem);!f&&u.itemsAdded.indexOf(w.dataItem)<=0&&u.itemsAdded.push(w.dataItem)}}else i._owner.rows.insert(i._rowIndex+a,w)}}else{var g=i._rowIndex;!i._isAdding&&!i._headerRowAtTop&&i._owner._headerRowAtTop()&&g<i._headerRowIndex&&g++;for(var p=g+i._count-1;p>=g;p--){var w;if(w=i._owner.rows[p])if(l&&w.dataItem){_=null!=w.dataItem._itemIdx?w.dataItem._itemIdx:p-i._owner._getDataRowsOffset();h.sourceCollection.splice(_,1);i._owner._updateItemIndexForRemovingRow(h.sourceCollection,_);if(u&&u.trackChanges){var m=u.itemsAdded.indexOf(w.dataItem)>=0;m&&u.itemsAdded.remove(w.dataItem);!m&&u.itemsRemoved.indexOf(w.dataItem)<0&&u.itemsRemoved.push(w.dataItem)}}else i._owner.rows.removeAt(p)}}if(l){i._owner._lastCount=i._owner.collectionView.itemCount;i._owner.collectionView.endUpdate(!0);i._owner.selectedSheet._dataView=i._owner.collectionView._view.slice();if(r.dataView&&r.dataView.length>0){i._owner.collectionView._view=r.dataView;i._owner.collectionView._pgView=i._owner.collectionView._getPageView();if(!(i._owner.itemsSource instanceof CollectionView)){i._owner.selectedSheet.grid.collectionView._view=r.dataView;i._owner.selectedSheet.grid.collectionView._pgView=i._owner.selectedSheet.grid.collectionView._getPageView()}i._owner._bindGrid(!1);i._owner.selectedSheet.grid._bindGrid(!1)}i._owner.autoGenerateColumns=n}i._owner.rows.endUpdate()}i._owner.selectedSheet._styledCells=i._owner._cloneObject(r.styledCells);for(a=0;a<r.mergedCells.length;a++)i._owner.selectedSheet._mergedRanges[a]=r.mergedCells[a];for(a=0;a<r.tableSettings.length;a++){var C=r.tableSettings[a];if(v=i._owner._getTable(C.name)){v._showHeaderRow=C.setting.showHeaderRow;v._showTotalRow=C.setting.showTotalRow;v._setTableRange(C.range)}}var S=void 0;i._affectedFormulas&&(S=e?i._affectedFormulas.oldFormulas:i._affectedFormulas.newFormulas);if(S&&S.length>0)for(a=0;a<S.length;a++){var b=S[a];null!=b.point?b.sheet.name===i._owner.selectedSheet.name?i._owner.setCellData(b.point.x,b.point.y,b.formula):b.sheet.grid.setCellData(b.point.x,b.point.y,b.formula):b.row._ubv[b.column._hash]=b.formula}if(i._deletedTables&&i._deletedTables.length>0)for(a=0;a<i._deletedTables.length;a++){var v=i._deletedTables[a];e?i._owner.selectedSheet.tables.push(v):i._owner.selectedSheet.tables.remove(v)}var y=void 0;i._affectedDefinedNameVals&&(y=e?i._affectedDefinedNameVals.oldDefinedNameVals:i._affectedDefinedNameVals.newDefinedNameVals);if(y&&y.length>0)for(a=0;a<y.length;a++){var R=y[a],x=i._owner.definedNames._getIndexByName(R.name);x>-1&&(i._owner.definedNames[x].value=R.value)}i._owner.selectedSheet.grid.wj_sheetInfo.styledCells=i._owner.selectedSheet._styledCells;i._owner.selectedSheet.grid.wj_sheetInfo.mergedRanges=i._owner.selectedSheet._mergedRanges;i._owner.selection=r.selection;i._owner.scrollPosition=r.scrollPosition;i._owner._isUndoing=!1}finally{t&&i._owner.endUpdate()}i._owner._copyRowsToSelectedSheet()}};return _RowsChangedAction}(_UndoAction);export{_RowsChangedAction};var _CellStyleAction=function(e){__extends(_CellStyleAction,e);function _CellStyleAction(t,o){var n=e.call(this,t)||this;n._oldStyledCells=o?t._cloneObject(o):t.selectedSheet?t._cloneObject(t.selectedSheet._styledCells):null;return n}_CellStyleAction.prototype.undo=function(){this._handleUndoRedo(!0)};_CellStyleAction.prototype.redo=function(){this._handleUndoRedo(!1)};_CellStyleAction.prototype.saveNewState=function(){this._newStyledCells=this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null;return!0};_CellStyleAction.prototype._checkActionState=function(){return null!=this._oldStyledCells&&null==this._newStyledCells||null==this._oldStyledCells&&null!=this._newStyledCells||null!=this._oldStyledCells&&null!=this._newStyledCells&&this._oldStyledCells.length!==this._newStyledCells.length};_CellStyleAction.prototype._handleUndoRedo=function(e){var t;if(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)}};return _CellStyleAction}(_UndoAction);export{_CellStyleAction};var _CellMergeAction=function(e){__extends(_CellMergeAction,e);function _CellMergeAction(t){var o=e.call(this,t)||this;o._oldMergedCells=t.selectedSheet?t.selectedSheet._cloneMergedCells():null;return o}_CellMergeAction.prototype.undo=function(){this._handleUndoRedo(!0)};_CellMergeAction.prototype.redo=function(){this._handleUndoRedo(!1)};_CellMergeAction.prototype.saveNewState=function(){this._newMergedCells=this._owner.selectedSheet?this._owner.selectedSheet._cloneMergedCells():null;return!0};_CellMergeAction.prototype._handleUndoRedo=function(e){var t,o;if(this._owner.selectedSheet){t=e?this._oldMergedCells:this._newMergedCells;this._owner._clearCalcEngine();if(t){this._owner.selectedSheet._mergedRanges.length=0;for(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)}};_CellMergeAction.prototype._checkActionState=function(){var e,t,o;if(null!=this._oldMergedCells&&null==this._newMergedCells||null==this._oldMergedCells&&null!=this._newMergedCells)return!0;if(null!=this._oldMergedCells&&null!=this._newMergedCells&&this._oldMergedCells.length!==this._newMergedCells.length)return!0;if(null!=this._oldMergedCells&&null!=this._newMergedCells&&this._oldMergedCells.length===this._newMergedCells.length)for(e=0;e<this._oldMergedCells.length;e++){o=this._oldMergedCells[e];t=this._oldMergedCells[e];if(!o.equals(t))return!0}return!1};return _CellMergeAction}(_UndoAction);export{_CellMergeAction};var _SortColumnAction=function(e){__extends(_SortColumnAction,e);function _SortColumnAction(t){var o=e.call(this,t)||this;o._saveValues(!0);return o}_SortColumnAction.prototype.undo=function(){this._handleUndoRedo(!0)};_SortColumnAction.prototype.redo=function(){this._handleUndoRedo(!1)};_SortColumnAction.prototype.saveNewState=function(){this._saveValues(!1);return!0};_SortColumnAction.prototype._saveValues=function(e){for(var t,o,n,i=[],l=0;l<this._owner.columns.length;l++)i.push(this._owner.columns[l]);if(this._owner.itemsSource){var r=this._owner._getDataRowsOffset();o=[];for(var s=0;s<this._owner.rows.length-r;s++){var a=this._owner.rows[s+r],h=a.dataItem;if(h){o[null!=h._itemIdx?h._itemIdx:s]=a.visible}}e&&(n=this._owner.collectionView._view.slice())}else{t=[];for(s=0;s<this._owner.rows.length;s++)t.push(this._owner.rows[s])}var u={sortList:this._owner.sortManager._committedList.slice(),rows:t,columns:i,selection:this._owner.selection.clone(),formulas:this._owner._scanFormulas(),styledCells:this._owner.selectedSheet?this._owner._cloneObject(this._owner.selectedSheet._styledCells):null,rowsVisible:o,dataView:n};e?this._oldValue=u:this._newValue=u};_SortColumnAction.prototype._handleUndoRedo=function(e){var t=this,o=e?t._oldValue:t._newValue,n=!!t._owner.itemsSource,i=this._owner.itemsSource instanceof CollectionView;if(t._owner.selectedSheet){t._owner._isUndoing=!0;t._owner.deferUpdate((function(){t._owner._clearCalcEngine();t._owner.sortManager.sortDescriptions.sourceCollection=o.sortList.slice();t._owner.sortManager.commitSort(!1);t._owner.selectedSheet._styledCells=t._owner._cloneObject(o.styledCells);if(n){if(o.dataView&&o.dataView.length>0){t._owner.collectionView._view=o.dataView;t._owner.collectionView._pgView=t._owner.collectionView._getPageView();if(!i){t._owner.selectedSheet.grid.collectionView._view=o.dataView;t._owner.selectedSheet.grid.collectionView._pgView=t._owner.selectedSheet.grid.collectionView._getPageView()}t._owner._bindGrid(!1);t._owner.selectedSheet.grid._bindGrid(!1)}}else{t._owner.rows.clear();t._owner.selectedSheet.grid.rows.clear();for(var e=0;e<o.rows.length;e++){var l=o.rows[e];t._owner.selectedSheet.grid.rows.push(l);t._owner.rows.push(l)}t._owner.columns.clear();for(e=0;e<o.columns.length;e++){var r=o.columns[e];t._owner.columns.push(r)}t._owner._resetFormulas(o.formulas)}t._owner._isUndoing=!1}))}};return _SortColumnAction}(_UndoAction);export{_SortColumnAction};var _MoveCellsAction=function(e){__extends(_MoveCellsAction,e);function _MoveCellsAction(t,o,n,i){var l=e.call(this,t)||this;if(!t.selectedSheet)return l;0===o.topRow&&o.bottomRow===t.rows.length-1?l._isDraggingColumns=!0:l._isDraggingColumns=!1;l._isCopyCells=i;l._dragRange=o;l._dropRange=n;l._saveValues(!0);return l}_MoveCellsAction.prototype.undo=function(){this._handleUndoRedo(!0)};_MoveCellsAction.prototype.redo=function(){this._handleUndoRedo(!1)};_MoveCellsAction.prototype.saveNewState=function(){if(!this._owner.selectedSheet)return!1;if(this._dropRange){this._saveValues(!1);return!0}return!1};_MoveCellsAction.prototype._saveValues=function(e){for(var t=[],o={},n=this._dropRange.topRow;n<=this._dropRange.bottomRow;n++)for(var i=this._dropRange.leftCol;i<=this._dropRange.rightCol;i++){this._isDraggingColumns&&(o[i]||(o[i]={dataType:this._owner.columns[i].dataType,align:this._owner.columns[i].align,format:this._owner.columns[i].format}));var l=n*this._owner.columns.length+i,r=this._owner.selectedSheet._styledCells[l]?this._owner._cloneObject(this._owner.selectedSheet._styledCells[l]):null,s=this._owner.getCellData(n,i,!1);t.push({rowIndex:n,columnIndex:i,cellContent:s,cellStyle:r})}if(e){this._oldDroppingCells=t;this._oldDroppingColumnSetting=o}else{this._newDroppingCells=t;this._newDroppingColumnSetting=o}if(this._isCopyCells){if(this._isDraggingColumns)if(e)for(n=this._dragRange.topRow;n<=this._dragRange.bottomRow;n++)for(i=this._dragRange.leftCol;i<=this._dragRange.rightCol;i++){if((d=this._owner.selectedSheet.findTable(n,i))&&d._isHeaderRow(n)){var a=d._getTableRange(),h=d._getColumns();this._draggingTableColumns||(this._draggingTableColumns=[]);this._draggingTableColumns.push({rowIndex:n,columnIndex:i,cellContent:h[i-a.leftCol].name})}}else if(this._draggingTableColumns&&this._draggingTableColumns.length>0&&this._draggingTableColumns&&this._draggingTableColumns.length>0)for(var u=0;u<this._draggingTableColumns.length;u++){var c=this._draggingTableColumns[u];if((d=this._owner.selectedSheet.findTable(c.rowIndex,c.columnIndex))&&d._isHeaderRow(c.rowIndex)){a=d._getTableRange(),h=d._getColumns();c.updatedCellContent=h[c.columnIndex-a.leftCol].name}}}else if(e){this._draggingCells=[];this._draggingColumnSetting={};for(n=this._dragRange.topRow;n<=this._dragRange.bottomRow;n++)for(i=this._dragRange.leftCol;i<=this._dragRange.rightCol;i++){this._isDraggingColumns&&(this._draggingColumnSetting[i]||(this._draggingColumnSetting[i]={dataType:this._owner.columns[i].dataType,align:this._owner.columns[i].align,format:this._owner.columns[i].format}));l=n*this._owner.columns.length+i,r=this._owner.selectedSheet._styledCells[l]?this._owner._cloneObject(this._owner.selectedSheet._styledCells[l]):null,s=this._owner.getCellData(n,i,!1);this._draggingCells.push({rowIndex:n,columnIndex:i,cellContent:s,cellStyle:r})}}else if(this._isDraggingColumns&&this._draggingCells&&this._draggingCells.length>0)for(u=0;u<this._draggingCells.length;u++){var d;c=this._draggingCells[u];if((d=this._owner.selectedSheet.findTable(c.rowIndex,c.columnIndex))&&d._isHeaderRow(c.rowIndex)){a=d._getTableRange(),h=d._getColumns();c.updatedCellContent=h[c.columnIndex-a.leftCol].name}}};_MoveCellsAction.prototype._handleUndoRedo=function(e){var t=this,o=e?t._oldDroppingCells:t._newDroppingCells,n=e?t._oldDroppingColumnSetting:t._newDroppingColumnSetting;if(t._owner.selectedSheet){t._owner._clearCalcEngine();t._owner.deferUpdate((function(){var i,l;t._affectedFormulas&&(i=e?t._affectedFormulas.oldFormulas:t._affectedFormulas.newFormulas);if(i&&i.length>0)for(var r=0;r<i.length;r++){var s=i[r];s.sheet.name===t._owner.selectedSheet.name?t._owner.setCellData(s.point.x,s.point.y,s.formula):s.sheet.grid.setCellData(s.point.x,s.point.y,s.formula)}t._affectedDefinedNameVals&&(l=e?t._affectedDefinedNameVals.oldDefinedNameVals:t._affectedDefinedNameVals.newDefinedNameVals);if(l&&l.length>0)for(r=0;r<l.length;r++){var a=l[r],h=t._owner.definedNames._getIndexByName(a.name);h>-1&&(t._owner.definedNames[h].value=a.value)}for(r=0;r<o.length;r++){var u=o[r];t._owner.setCellData(u.rowIndex,u.columnIndex,u.cellContent);if((f=t._owner.selectedSheet.findTable(u.rowIndex,u.columnIndex))&&f._isHeaderRow(u.rowIndex)){var c=f._getTableRange();(_=f._getColumns())[u.columnIndex-c.leftCol].name=u.cellContent}var d=u.rowIndex*t._owner.columns.length+u.columnIndex;u.cellStyle?t._owner.selectedSheet._styledCells[d]=u.cellStyle:delete t._owner.selectedSheet._styledCells[d]}t._isDraggingColumns&&n&&Object.keys(n).forEach((function(e){t._owner.columns[+e].dataType=n[+e].dataType?n[+e].dataType:DataType.Object;t._owner.columns[+e].align=n[+e].align;t._owner.columns[+e].format=n[+e].format}));if(t._isCopyCells){if(t._draggingTableColumns&&t._draggingTableColumns.length>0)for(r=0;r<t._draggingTableColumns.length;r++){u=t._draggingTableColumns[r];if((f=t._owner.selectedSheet.findTable(u.rowIndex,u.columnIndex))&&f._isHeaderRow(u.rowIndex)){c=f._getTableRange();var _=f._getColumns();t._owner.setCellData(u.rowIndex,u.columnIndex,e?u.cellContent:u.updatedCellContent);_[u.columnIndex-c.leftCol].name=e?u.cellContent:u.updatedCellContent}}}else{for(r=0;r<t._draggingCells.length;r++){var f;u=t._draggingCells[r];if(f=t._owner.selectedSheet.findTable(u.rowIndex,u.columnIndex)){c=f._getTableRange(),_=f._getColumns();if(f._isHeaderRow(u.rowIndex)){t._owner.setCellData(u.rowIndex,u.columnIndex,e?u.cellContent:u.updatedCellContent);_[u.columnIndex-c.leftCol].name=e?u.cellContent:u.updatedCellContent}else t._owner.setCellData(u.rowIndex,u.columnIndex,e?u.cellContent:null)}else t._owner.setCellData(u.rowIndex,u.columnIndex,e?u.cellContent:null);d=u.rowIndex*t._owner.columns.length+u.columnIndex;e?u.cellStyle&&(t._owner.selectedSheet._styledCells[d]=u.cellStyle):t._owner.selectedSheet._styledCells[d]&&delete t._owner.selectedSheet._styledCells[d]}t._isDraggingColumns&&t._draggingColumnSetting&&Object.keys(t._draggingColumnSetting).forEach((function(o){t._owner.columns[+o].dataType=e&&t._draggingColumnSetting[+o].dataType?t._draggingColumnSetting[+o].dataType:DataType.Object;t._owner.columns[+o].align=e?t._draggingColumnSetting[+o].align:null;t._owner.columns[+o].format=e?t._draggingColumnSetting[+o].format:null}));if(e){if(t._isDraggingColumns)if(t._dragRange.leftCol<t._dropRange.leftCol)for(var g=t._dragRange.leftCol,p=t._dropRange.leftCol;p<=t._dropRange.rightCol;p++){t._owner._updateColumnFiler(p,g);g++}else for(g=t._dragRange.rightCol,p=t._dropRange.rightCol;p>=t._dropRange.leftCol;p--){t._owner._updateColumnFiler(p,g);g--}}else if(t._isDraggingColumns)if(t._dragRange.leftCol>t._dropRange.leftCol)for(g=t._dropRange.leftCol,p=t._dragRange.leftCol;p<=t._dragRange.rightCol;p++){t._owner._updateColumnFiler(p,g);g++}else for(g=t._dropRange.rightCol,p=t._dragRange.rightCol;p>=t._dragRange.leftCol;p--){t._owner._updateColumnFiler(p,g);g--}}}))}};return _MoveCellsAction}(_UndoAction);export{_MoveCellsAction};var _CutAction=function(e){__extends(_CutAction,e);function _CutAction(t){var o=e.call(this,t)||this;o._oldValues=[];o._mergeAction=new _CellMergeAction(t);o._celltyleAction=new _CellStyleAction(t);o._cutSheet=t._copiedSheet;o._selection=t.selection;o._cutSelection=t.selectionMode===SelectionMode.ListBox?t._getSelectionForListBoxMode(o._cutSheet.grid):t._copiedRanges[0];o._saveCutValues(!0);return o}_CutAction.prototype.undo=function(){this._handleUndoRedo(!0)};_CutAction.prototype.redo=function(){this._handleUndoRedo(!1)};_CutAction.prototype.saveNewState=function(){this._cutSheet===this._owner.selectedSheet?this._owner:this._cutSheet.grid;this._saveCutValues(!1);this._newValues=[];for(var e=this._selection.topRow;e<=this._selection.bottomRow;e++)for(var t=this._selection.leftCol;t<=this._selection.rightCol;t++){if(!this._owner.columns[t])return!1;var o=this._owner.getCellData(e,t,!!this._owner.columns[t].dataMap);o=null==o?"":o;this._newValues.push({row:e,col:t,value:o})}this._mergeAction.saveNewState();this._celltyleAction.saveNewState();return!0};_CutAction.prototype.updateForPasting=function(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)};_CutAction.prototype._saveCutValues=function(e){for(var t=this._cutSheet===this._owner.selectedSheet?this._owner:this._cutSheet.grid,o=[],n=this._cutSelection.topRow;n<=this._cutSelection.bottomRow;n++)if(null!=t.rows[n])for(var i=this._cutSelection.leftCol;i<=this._cutSelection.rightCol;i++){var l=t.getCellData(n,i,!!t.columns[i].dataMap);""===(l=null==l?"":l)&&t.columns[i].dataMap&&(l=null);o.push({row:n,col:i,value:l})}e?this._oldCutValues=o:this._newCutValues=o};_CutAction.prototype._handleUndoRedo=function(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((function(){var i,l,r=t._cutSheet===t._owner.selectedSheet?t._owner:t._cutSheet.grid;t._owner.selectedSheet.selectionRanges.push(t._selection);for(i=0;i<o.length;i++){l=o[i];r.setCellData(l.row,l.col,l.value)}for(i=0;i<n.length;i++){l=n[i];t._owner.setCellData(l.row,l.col,l.value)}if(e){t._mergeAction.undo();t._celltyleAction.undo()}else{t._mergeAction.redo();t._celltyleAction.redo()}t._owner.refresh(!1)}))};return _CutAction}(_UndoAction);export{_CutAction};var _TableSettingAction=function(e){__extends(_TableSettingAction,e);function _TableSettingAction(t,o){var n=e.call(this,t)||this;n._table=o;n._saveValues(!0);return n}_TableSettingAction.prototype.undo=function(){this._handleUndoRedo(!0)};_TableSettingAction.prototype.redo=function(){this._handleUndoRedo(!1)};_TableSettingAction.prototype.saveNewState=function(){this._saveValues(!1);return!0};_TableSettingAction.prototype._saveValues=function(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};_TableSettingAction.prototype._handleUndoRedo=function(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()};return _TableSettingAction}(_UndoAction);export{_TableSettingAction};var _TableAction=function(e){__extends(_TableAction,e);function _TableAction(t,o){var n=e.call(this,t)||this;n._addedTable=o;o.showHeaderRow&&(n._orgHeaderCellsContent=o._orgHeaderCellsContent.slice());return n}_TableAction.prototype.undo=function(){this._handleUndoRedo(!0)};_TableAction.prototype.redo=function(){this._handleUndoRedo(!1)};_TableAction.prototype._handleUndoRedo=function(e){e?this._owner.selectedSheet.tables.remove(this._addedTable):this._owner.selectedSheet.tables.push(this._addedTable);if(this._addedTable.showHeaderRow)for(var t=this._addedTable.getRange(),o=this._addedTable.getColumns(),n=0;n<t.columnSpan;n++)this._owner.setCellData(t.topRow,t.leftCol+n,e?this._orgHeaderCellsContent[n]:o[n].name);this._owner.refresh()};return _TableAction}(_UndoAction);export{_TableAction};var _FilteringAction=function(e){__extends(_FilteringAction,e);function _FilteringAction(t){var o=e.call(this,t)||this;o._oldFilterDefinition=t.filter.filterDefinition;o._oldRowsVisible=o._getRowsVisible();return o}_FilteringAction.prototype.undo=function(){this._handleUndoRedo(!0)};_FilteringAction.prototype.redo=function(){this._handleUndoRedo(!1)};_FilteringAction.prototype.saveNewState=function(){this._newFilterDefinition=this._owner.filter.filterDefinition;this._newRowsVisible=this._getRowsVisible();return!0};_FilteringAction.prototype._handleUndoRedo=function(e){var t=e?this._oldFilterDefinition:this._newFilterDefinition;if(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()}else this._setRowVisible(e)};_FilteringAction.prototype._getRowsVisible=function(){for(var e,t=[],o=0;o<this._owner.rows.length;o++)(e=this._owner.rows[o])&&t.push(e.visible);return t};_FilteringAction.prototype._setRowVisible=function(e){for(var t,o=e?this._oldRowsVisible:this._newRowsVisible,n=0;n<o.length;n++)(t=this._owner.rows[n])&&(t.visible=o[n])};return _FilteringAction}(_UndoAction);export{_FilteringAction};var _FillAction=function(e){__extends(_FillAction,e);function _FillAction(t,o){var n=e.call(this,t)||this;n._fillSource=o.clone();n._oldCellSettings=t._orgCellSettings;return n}_FillAction.prototype.undo=function(){this._handleUndoRedo(!0)};_FillAction.prototype.redo=function(){this._handleUndoRedo(!1)};_FillAction.prototype.saveNewState=function(){this._fillRange=this._owner.selection.clone();this._newCellSettings=this._owner._getCellSettingsForFill(this._fillSource,this._fillRange);return!0};_FillAction.prototype._handleUndoRedo=function(e){var t,o,n,i,l,r,s=e?this._oldCellSettings:this._newCellSettings,a=e?this._fillSource:this._fillRange;this._owner.beginUpdate();r=this._fillRange.topRow<this._fillSource.topRow?new CellRange(this._fillRange.topRow,this._fillRange.col,this._fillSource.topRow-1,this._fillRange.col2):this._fillRange.leftCol===this._fillSource.leftCol&&this._fillRange.rightCol===this._fillSource.rightCol?new CellRange(this._fillSource.bottomRow+1,this._fillRange.col,this._fillRange.bottomRow,this._fillRange.col2):this._fillRange.leftCol<this._fillSource.leftCol?new CellRange(this._fillRange.row,this._fillRange.leftCol,this._fillRange.row2,this._fillSource.leftCol-1):new CellRange(this._fillRange.row,this._fillSource.rightCol+1,this._fillRange.row2,this._fillRange.rightCol);this._owner._resetMergedRange(r);if(s&&s.length>0)for(t=0;t<s.length;t++){n=(o=s[t]).row;i=o.col;l=n*this._owner.columns.length+i;this._owner.selectedSheet._styledCells[l]=o.style;this._owner.setCellData(n,i,o.value);o.mergedCell&&this._owner.mergeRange(o.mergedCell)}this._owner.selection=a;this._owner.endUpdate()};return _FillAction}(_UndoAction);export{_FillAction};var SortManager=function(){function SortManager(e){this._owner=e;this._sortDescriptions=new CollectionView;this._committedList=[new ColumnSortDescription(-1,!0)];this._sortDescriptions.newItemCreator=function(){return new ColumnSortDescription(-1,!0)}}Object.defineProperty(SortManager.prototype,"sortDescriptions",{get:function(){return this._sortDescriptions},set:function(e){this._sortDescriptions=e;this.commitSort()},enumerable:!0,configurable:!0});SortManager.prototype.addSortLevel=function(e,t){void 0===t&&(t=!0);var o=this._sortDescriptions.addNew();null!=e&&!isNaN(e)&&isInt(e)&&(o.columnIndex=e);o.ascending=t;this._sortDescriptions.commitNew()};SortManager.prototype.deleteSortLevel=function(e){var t;(t=null!=e?this._getSortItem(e):this._sortDescriptions.currentItem)&&this._sortDescriptions.remove(t)};SortManager.prototype.copySortLevel=function(){var e=this._sortDescriptions.currentItem;if(e){var t=this._sortDescriptions.addNew();t.columnIndex=parseInt(e.columnIndex);t.ascending=e.ascending;this._sortDescriptions.commitNew()}};SortManager.prototype.editSortLevel=function(e,t){null!=e&&(this._sortDescriptions.currentItem.columnIndex=e);null!=t&&(this._sortDescriptions.currentItem.ascending=t)};SortManager.prototype.moveSortLevel=function(e){var t=this._sortDescriptions.currentItem;if(t){var o=this._sortDescriptions.sourceCollection,n=o.indexOf(t),i=n+e;if(n>-1&&i>-1){o.splice(n,1);o.splice(i,0,t);this._sortDescriptions.refresh();this._sortDescriptions.moveCurrentTo(t)}}};SortManager.prototype.checkSortItemExists=function(e){for(var t=0,o=this._sortDescriptions.itemCount;t<o;t++)if(+this._sortDescriptions.items[t].columnIndex===e)return t;return-1};SortManager.prototype.commitSort=function(e){void 0===e&&(e=!0);var t,o,n,i,l,r,s,a,h,u,c,d,_,f,g,p=this._owner,w=this._owner.itemsSource instanceof CollectionView,m={};if(this._owner.selectedSheet&&0!==this._owner.columns.length){var C=null==this._owner.selectedSheet.grid.collectionView;p._needCopyToSheet=!1;r=p.selectedSheet._unboundSortDesc;e&&p.undoStack.stackSize>0&&(s=new _SortColumnAction(p));this._sortDescriptions.itemCount>0?this._committedList=this._cloneSortList(this._sortDescriptions.items):this._committedList=[new ColumnSortDescription(-1,!0)];if(p.collectionView){p._isSorting=!0;p.beginUpdate();(a=p.editableCollectionView)&&a.currentEditItem&&-1!==a.items.indexOf(a.currentEditItem)&&!this._isEmpty(a.currentEditItem)&&a.commitEdit();p.collectionView.beginUpdate();C||p.selectedSheet.grid.collectionView.beginUpdate();(n=p.collectionView.sortDescriptions).clear();h=p.selection.clone();u=p.scrollPosition;g=p._getDataRowsOffset();var S=[];if(!p._isUndoing&&!p._isDeletingColumns)for(l=0;l<p.rows.length-g;l++)(f=(_=p.rows[l+g]).dataItem)&&(S[d=null!=f._itemIdx?f._itemIdx:l]=_.visible);w||(i=C?p.collectionView.sortDescriptions:p.selectedSheet.grid.collectionView.sortDescriptions).clear();p.collectionView.sourceCollection.map((function(e,t){null==e._itemIdx&&(e._itemIdx=t)}));p.select(h,!1);p.scrollPosition=u;if(navigator.userAgent.toLowerCase().indexOf("chrome")>-1){p.collectionView.useStableSort=!0;w||C||(p.selectedSheet.grid.collectionView.useStableSort=!0)}for(l=0;l<this._sortDescriptions.itemCount;l++)if((t=this._sortDescriptions.items[l]).columnIndex>-1&&t.columnIndex<p.columns.length){o=new SortDescription(p.columns[t.columnIndex].binding,t.ascending);n.push(o);w||i.push(o)}p.selectedSheet.selectionRanges.clear();p.collectionView.endUpdate(!1);C||p.selectedSheet.grid.collectionView.endUpdate(!1);h=p.selection.clone();u=p.scrollPosition;c=p.collectionView._view.slice();var b=Array(c.length);for(l=0;l<c.length;l++){l!==(f=c[l])._itemIdx&&p._updateFormulaForReorderingRows(f._itemIdx+g,l+g);p._updateCellStyleForReorderingRows(f._itemIdx+g,l+g,m);b[l+g]=p._heights[f._itemIdx+g]}p.setHeights(b);p.updateRowHeights();if(S.length)for(l=0;l<p.rows.length-g;l++)if(f=(_=p.rows[l+g]).dataItem){d=null!=f._itemIdx?f._itemIdx:l;_.visible=S[d]}c.map((function(e,t){e._itemIdx=t}));p.selectedSheet._styledCells=m;p.select(h,!1);p.scrollPosition=u;p.endUpdate();p._copyColumnsToSelectedSheet();p._isSorting=!1}else{r.clear();for(l=0;l<this._sortDescriptions.itemCount;l++)(t=this._sortDescriptions.items[l]).columnIndex>-1&&r.push(new _UnboundSortDescription(p.columns[t.columnIndex],t.ascending));!p.filter||!p._isUndoing&&p.filter._isActive()||setTimeout((function(){p._checkCollectionOwner(p.columns,!1);p.filter.apply()}),10)}if(s){s.saveNewState();p.undoStack._addAction(s)}p._copiedRanges=null;p._needCopyToSheet=!0}};SortManager.prototype.cancelSort=function(){this._sortDescriptions.sourceCollection=this._committedList.slice()};SortManager.prototype.clearSort=function(){this._sortDescriptions.sourceCollection=[];this.commitSort()};SortManager.prototype._getSortItem=function(e){var t=this.checkSortItemExists(e);if(t>-1)return this._sortDescriptions.items[t]};SortManager.prototype._cloneSortList=function(e){for(var t=[],o=0;o<e.length;o++)t[o]=e[o].clone();return t};SortManager.prototype._updateSortDescriptions=function(e,t,o){void 0===o&&(o=!0);var n,i;for(n=this._sortDescriptions.items.length-1;n>=0;n--){i=this._sortDescriptions.items[n];o?i.columnIndex>e&&(i.columnIndex+=t):i.columnIndex>=e+t?i.columnIndex-=t:i.columnIndex>=e&&this._sortDescriptions.remove(i)}};SortManager.prototype._handleColumnMoving=function(e,t){this._sortDescriptions.items.forEach((function(o){if(!(o.columnIndex<0))if(o.columnIndex===e)o.columnIndex=t;else{o.columnIndex>e&&o.columnIndex--;o.columnIndex>=t&&o.columnIndex++}}))};SortManager.prototype._isEmpty=function(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};return SortManager}();export{SortManager};var ColumnSortDescription=function(){function ColumnSortDescription(e,t){this._columnIndex=e;this._ascending=t}Object.defineProperty(ColumnSortDescription.prototype,"columnIndex",{get:function(){return this._columnIndex},set:function(e){this._columnIndex=+e},enumerable:!0,configurable:!0});Object.defineProperty(ColumnSortDescription.prototype,"ascending",{get:function(){return this._ascending},set:function(e){this._ascending=e},enumerable:!0,configurable:!0});ColumnSortDescription.prototype.clone=function(){return new ColumnSortDescription(this._columnIndex,this._ascending)};return ColumnSortDescription}();export{ColumnSortDescription};_addCultureInfo("FlexSheet",{insertRow:"Insert Row",deleteRow:"Delete Rows",insertCol:"Insert Column",deleteCol:"Delete Columns",convertTable:"Convert To Table",insertSheet:"Insert",deleteSheet:"Delete",renameSheet:"Rename",copyCells:"Copy Cells",fillSeries:"Fill Series",fillFormat:"Fill Formatting Only",fillWithoutFormat:"Fill Without Formatting"});var FlexSheetFunctions=[{name:"abs",description:"Returns the absolute value of a number."},{name:"acos",description:"Returns the arccosine of a number."},{name:"address",description:"Obtains the address of a cell in a worksheet by given specified row and column numbers."},{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:"concat",description:"Joins several text items into one text item."},{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:"exact",description:"Compares two text strings and returns TRUE if they are exactly the same, FALSE otherwise."},{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:"iferror",description:"Returns a value you specify if a formula evaluates to an error; otherwise, it returns the result of the formula."},{name:"index",description:"Uses an index to choose a value from a reference."},{name:"indirect",description:"Returns the reference specified by a text string. References are immediately evaluated to display their contents."},{name:"isblank",description:"Checks if value refers to an empty cell."},{name:"iserr",description:"Checks if value is an error (#VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!) excluding #N/A, and returns TRUE or FALSE."},{name:"iserror",description:"Checks if value is an error (#N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!), and returns TRUE or FALSE."},{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 current date and time formatted as a 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 current date formatted as a 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:"vlookup",description:"Looks in the first column of an array and returns the value of the indicated cell."},{name:"year",description:"Converts a serial number to a year."}],FlexSheet=function(e){__extends(FlexSheet,e);function FlexSheet(t,o){var n=e.call(this,t,o)||this;n._heights=[];n._selectedSheetIndex=-1;n._columnHeaderClicked=!1;n._addingSheet=!1;n._mouseMoveHdl=n._mouseMove.bind(n);n._clickHdl=n._click.bind(n);n._touchStartHdl=n._touchStart.bind(n);n._touchEndHdl=n._touchEnd.bind(n);n._keydownHdl=n._keydown.bind(n);n._isContextMenuKeyDown=!1;n._isClicking=!1;n._builtInTableStylesCache=null;n._needCopyToSheet=!0;n._isSorting=!1;n._fillingData=!1;n._enableDragDrop=!0;n._enableFormulas=!0;n._headerRowRemoved=!1;n._clearCalcCacheOnRefresh=!0;n._copyingTo=!1;n._ignoreBindGrid=!1;n._loadingFromWorkbook=!1;n.insertedColumnIndex=0;n.dropzonePrevHit=-1;n.selectedSheetChanged=new Event;n.draggingRowColumn=new Event;n.droppingRowColumn=new Event;n.beginDroppingRowColumn=new Event;n.endDroppingRowColumn=new Event;n.loaded=new Event;n.unknownFunction=new Event;n.sheetCleared=new Event;n.prepareChangingRow=new Event;n.prepareChangingColumn=new Event;n.rowChanged=new Event;n.columnChanged=new Event;n.autoFilling=new Event;n.autoFilled=new Event;n._updateScrollPos=!1;o&&null!=o.allowAutoFill||(n._allowAutoFill=!0);n._needCopyToSheet=!1;n._colorThemes=["FFFFFF","000000","EEECE1","1F497D","4F818D","C0504D","9BBB59","8064A2","4BACC6","F79646"];n._eCt.style.backgroundColor="white";addClass(n.hostElement,"wj-flexsheet");setCss(n.hostElement,{fontFamily:"Arial"});n._cf=new _FlexSheetCellFactory;n._bndSortConverter=n._sheetSortConverter.bind(n);n._selHdl=new _FlexSheetSelectionHandler(n);n.quickAutoSize=!1;n._init();n.showSort=!1;n.allowSorting=AllowSorting.None;n.showGroups=!1;n.showMarquee=!0;n.showSelectedHeaders=HeadersVisibility.All;n.allowResizing=AllowResizing.Both;n.allowDragging=AllowDragging.None;n.keyActionTab=KeyAction.CycleOut;n._needCopyToSheet=!0;return n}FlexSheet.prototype._getProductInfo=function(){return"R20I,FlexSheet"};Object.defineProperty(FlexSheet.prototype,"sheets",{get:function(){this._sheets||(this._sheets=new SheetCollection);return this._sheets},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"selectedSheetIndex",{get:function(){return this._selectedSheetIndex},set:function(e){if(e!==this._selectedSheetIndex){this._showSheet(e);this._sheets.selectedIndex=e}},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"selectedSheet",{get:function(){return this._selectedSheetIndex>=0?this._sheets[this._selectedSheetIndex]:null},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"isFunctionListOpen",{get:function(){return this._functionListHost&&"none"!==this._functionListHost.style.display},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"isTabHolderVisible",{get:function(){return this._tabHolder.visible},set:function(e){if(e!==this._tabHolder.visible){this._updateDivContainerHeight(e);e?this._eFocus.removeAttribute("tabindex"):this._eFocus.tabIndex=this._orgTabIndex;this._tabHolder.visible=e;this.invalidate()}},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"undoStack",{get:function(){return this._undoStack},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"sortManager",{get:function(){return this._sortManager},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"filter",{get:function(){return this._filter},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"showFilterIcons",{get:function(){return!!this._filter&&this._filter.showFilterIcons},set:function(e){this._filter&&this._filter.showFilterIcons!==e&&(this._filter.showFilterIcons=e)},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"calculationPrecision",{get:function(){var e=this._precision;return null==e?14:e},set:function(e){if(e!==this._precision){this._precision=e;this.invalidate()}},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"definedNames",{get:function(){this._defNames||(this._defNames=new DefinedNameCollection(this));return this._defNames},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"enableDragDrop",{get:function(){return this._enableDragDrop},set:function(e){this._enableDragDrop=e},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"enableFormulas",{get:function(){return this._enableFormulas},set:function(e){if(this._enableFormulas!==e){this._enableFormulas=e;this.refresh()}},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"allowAutoFill",{get:function(){return this._allowAutoFill},set:function(e){this._allowAutoFill=asBoolean(e)},enumerable:!0,configurable:!0});Object.defineProperty(FlexSheet.prototype,"_lastSelMovePos",{get:function(){return this._lsmPos},set:function(e){this._lsmPos=e?e.clone():null},enumerable:!0,configurable:!0});FlexSheet.prototype._setvalidateEdits=function(t){e.prototype._setvalidateEdits.call(this,t);for(var o=0;o<this.sheets.length;o++)this.sheets[o].grid&&(this.sheets[o].grid.validateEdits=t)};FlexSheet.prototype.onSelectedSheetChanged=function(e){this.selectedSheetChanged.raise(this,e)};FlexSheet.prototype.onDraggingRowColumn=function(e){this.draggingRowColumn.raise(this,e)};FlexSheet.prototype.onDroppingRowColumn=function(e){_deprecated("droppingRowColumn","beginDroppingRowColumn and endDroppingRowColumn");this.droppingRowColumn.raise(this,new EventArgs)};FlexSheet.prototype.onBeginDroppingRowColumn=function(e){this.beginDroppingRowColumn.raise(this,e)};FlexSheet.prototype.onEndDroppingRowColumn=function(e){this.endDroppingRowColumn.raise(this,e)};FlexSheet.prototype.onLoaded=function(e){var t=this;if(this._toRefresh){clearTimeout(this._toRefresh);this._toRefresh=null}this._toRefresh=setTimeout((function(){t._setFlexSheetToDirty();t.invalidate()}),10);this.loaded.raise(this,new EventArgs)};FlexSheet.prototype.onUnknownFunction=function(e){this.unknownFunction.raise(this,e)};FlexSheet.prototype.onSheetCleared=function(e){this.sheetCleared.raise(this,e)};FlexSheet.prototype.onPrepareChangingRow=function(e){this.prepareChangingRow.raise(this,e)};FlexSheet.prototype.onPrepareChangingColumn=function(e){this.prepareChangingColumn.raise(this,e)};FlexSheet.prototype.onRowChanged=function(e){this.rowChanged.raise(this,e)};FlexSheet.prototype.onColumnChanged=function(e){this.columnChanged.raise(this,e)};FlexSheet.prototype.onAutoFilling=function(e){this.autoFilling.raise(this,e)};FlexSheet.prototype.onAutoFilled=function(e){this.autoFilled.raise(this,e)};FlexSheet.prototype.refresh=function(t){void 0===t&&(t=!0);if(this.selectedSheet&&this.selectedSheet.grid.rows&&this._items&&this.selectedSheet.grid.rows.length<this._items.length)for(var o=this._items.length-this.selectedSheet.grid.rows.length,n=0;n<=o;n++)this.selectedSheet.grid.rows.push(new Row);this.hostElement&&!this.isUpdating&&this._updateDivContainerHeight(this.isTabHolderVisible);if(!this.preserveSelectedState&&this.selectedSheet){this.selectedSheet.selectionRanges.clear();this.selectedSheet.selectionRanges.push(this.selection)}if(t){this._clearCalcCacheOnRefresh&&this._clearCalcEngine();this._clearCalcCacheOnRefresh=!0}this._lastVisibleFrozenRow=-1;if(this.rows.frozen>0)for(n=this.rows.frozen-1;n>=0;n--)if(this.rows[n]&&this.rows[n].isVisible){this._lastVisibleFrozenRow=n;break}this._lastVisibleFrozenColumn=-1;if(this.columns.frozen>0)for(n=this.columns.frozen-1;n>=0;n--)if(this.columns[n]&&this.columns[n].isVisible){this._lastVisibleFrozenColumn=n;break}if(this.selectedSheet){if(this.selectedSheet._freezeHiddenRows&&this.selectedSheet._freezeHiddenRows.length>0)for(n=0;n<this.selectedSheet._freezeHiddenRows.length;n++){var i=this.rows[n];i instanceof HeaderRow||!this.selectedSheet._freezeHiddenRows[n]||(i.visible=!1)}if(this.selectedSheet._freezeHiddenCols&&this.selectedSheet._freezeHiddenCols.length>0)for(n=0;n<this.selectedSheet._freezeHiddenCols.length;n++)this.selectedSheet._freezeHiddenCols[n]&&(this.columns[n].visible=!1)}e.prototype.refresh.call(this,t);if(this.hostElement&&!this.isUpdating){this._tabHolder.adjustSize();this._tabHolder.isDisabled=this.isDisabled;this._tabHolder.sheetControl.isDisabled=this.isDisabled}};FlexSheet.prototype.setCellData=function(e,t,o,n,i,l){void 0===n&&(n=!1);void 0===i&&(i=!0);void 0===l&&(l=!1);var r=_isFormula(o);r&&this.evaluate(o,null,this.sheets[this.selectedSheetIndex]);this._clearCalcEngine();return this.cells.setCellData(e,t,o,n&&!r,i,l)||this._getHasValidation()};FlexSheet.prototype.containsFocus=function(){return this.isFunctionListOpen||e.prototype.containsFocus.call(this)};FlexSheet.prototype.addUnboundSheet=function(e,t,o,n,i){var l=this._addSheet(e,t,o,n,i);0===l.selectionRanges.length&&l.selectionRanges.push(this.selection);return l};FlexSheet.prototype.addBoundSheet=function(e,t,o,n){var i=this._addSheet(e,0,0,o,n);if(t){i.itemsSource=t;this.childItemsPath&&(i.grid.childItemsPath=this.childItemsPath)}0===i.selectionRanges.length&&i.selectionRanges.push(this.selection);return i};FlexSheet.prototype.applyCellsStyle=function(e,t,o){void 0===o&&(o=!1);var n,i,l,r,s,a=null!=t&&t.length>0,h=t||[this.selection];if(this.selectedSheet)if(e||!this._cloneStyle){if(h){if(t||o)o&&!this._cloneStyle&&(this._cloneStyle=this._cloneObject(this.selectedSheet._styledCells));else{this.undoStack.stackSize>0&&(s=new _CellStyleAction(this,this._cloneStyle));this._cloneStyle=null}for(r=0;r<h.length;r++)for(n=(l=h[r]).topRow;n<=l.bottomRow;n++)for(i=l.leftCol;i<=l.rightCol;i++)this._applyStyleForCell(n,i,e,a);if(s){s.saveNewState();this._undoStack._addAction(s)}}t||this.refresh(!1)}else{this.selectedSheet._styledCells=this._cloneObject(this._cloneStyle);this._cloneStyle=null;this.refresh(!1)}};FlexSheet.prototype.freezeAtCursor=function(){var e,t,o=this;if(this.selectedSheet){this.selectedSheet._freezeHiddenRows=null;this.selectedSheet._freezeHiddenCols=null;if(this.selection&&0===this.rows.frozen&&0===this.columns.frozen){if(this._ptScrl.y<0){this.selectedSheet._freezeHiddenRows=[];for(var n=0;n<this.selection.topRow-1;n++){var i=this.rows[n];if(!(i instanceof HeaderRow)){if(!(i._pos+this._ptScrl.y<0&&i.visible))break;i.visible=!1;this.selectedSheet._freezeHiddenRows[n]=!0}}}if(this._ptScrl.x<0){this.selectedSheet._freezeHiddenCols=[];for(n=0;n<this.selection.leftCol-1;n++){var l=this.columns[n];if(!(l._pos+this._ptScrl.x<0&&l.visible))break;l.visible=!1;this.selectedSheet._freezeHiddenCols[n]=!0}}e=this.selection.leftCol>0?this.selection.leftCol:0;t=this.selection.topRow>0?this.selection.topRow:0}else{for(n=0;n<this.rows.frozen-1&&n<this.rows.length;n++)this.rows[n].visible=!0;for(n=0;n<this.columns.frozen-1&&n<this.columns.length;n++)this.columns[n].visible=!0;this._filter.apply();e=0;t=0}this.rows.frozen=this.selectedSheet.grid.rows.frozen=t;this.columns.frozen=this.selectedSheet.grid.columns.frozen=e;setTimeout((function(){o._setFlexSheetToDirty();o.invalidate();o.scrollIntoView(o.selection.topRow,o.selection.leftCol)}),10)}};FlexSheet.prototype.showColumnFilter=function(){var e=this.selection.col>0?this.selection.col:0;this.columns.length>0&&this._filter.editColumnFilter(this.columns[e])};FlexSheet.prototype.clear=function(){this.beginUpdate();this.selection=new 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 Point;this._clearCalcEngine();this._defNames&&this._defNames.clear();this._builtInTableStylesCache=null;this._copiedRanges=null;this._copiedSheet=null;this._isCutting=!1;this._cutValue=null;this._reservedContent=null;this._lastVisibleFrozenRow=-1;this._lastVisibleFrozenColumn=-1;this._loadingFromWorkbook||this.addUnboundSheet();this.endUpdate()};FlexSheet.prototype.getSelectionFormatState=function(){var e,t,o=this.rows.length,n=this.columns.length,i={isBold:!1,isItalic:!1,isUnderline:!1,textAlign:"left",isMergedCell:!1,verticalAlign:"top"};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};FlexSheet.prototype.insertRows=function(e,t){var o,n,i,l,r,s=this,a=isNumber(e)&&e>=0?e:this.selection&&this.selection.topRow>-1?this.selection.topRow:0,h=isNumber(t)?t:1,u=this.rows[a];if(this.selectedSheet){this.rows.length>0?a>=this.rows.length&&(a=this.rows.length-1):a=0;var c=this.collectionView,d=this.editableCollectionView,_=c instanceof CollectionView?c:null;this._clearCalcEngine();this.finishEditing();d&&d.currentEditItem&&d.commitEdit();0===a&&u&&u.constructor===HeaderRow&&(a=1);this.onPrepareChangingRow(new RowColumnChangedEventArgs(a,h,!0,!1));this.undoStack.stackSize>0&&(i=new _RowsChangedAction(this,a,h,!0));this._updateCellsForUpdatingRow(this.rows.length,a,h);if(!this.collectionView||0===this.collectionView.sortDescriptions.length){l=this._updateAffectedFormula(a,h,!0,!0);r=this._updateAffectedNamedRanges(a,h,!0,!0)}if(i){i._affectedFormulas=l;i._affectedDefinedNameVals=r}var f=null==this.selectedSheet.grid.collectionView;this.beginUpdate();if(c){var g=this.itemsSource instanceof CollectionView,p=this.autoGenerateColumns,w=void 0;this.selectedSheet._dataView=this.collectionView._view.slice();this.autoGenerateColumns=!1;this.collectionView.beginUpdate();this.rows[0]instanceof _NewRowTemplate&&this.rows[1]instanceof HeaderRow?(o=this._heights).splice.apply(o,[2,0].concat(Array(h).map((function(){return null})))):(n=this._heights).splice.apply(n,[a,0].concat(Array(h).map((function(){return null}))));if(!g){w=this.selectedSheet.grid.autoGenerateColumns;this.selectedSheet.grid.autoGenerateColumns=!1;f||this.selectedSheet.grid.collectionView.beginUpdate()}var m=Math.max(a-this._getDataRowsOffset(),0);this.collectionView.moveCurrentToPosition(m);for(var C=0;C<h;C++){var S=_&&_.newItemCreator?_.newItemCreator():{};c.sourceCollection.splice(m,0,S);_&&_.trackChanges&&_.itemsAdded.push(S);if(!g){var b=this.selectedSheet.grid.itemsSource;b&&this.itemsSource!==b&&b.splice(m,0,S)}this.selectedSheet._dataView.splice(m,0,S)}this._updateItemIndexForInsertingRow(this.collectionView.sourceCollection,m,h);if(!g){f||this.selectedSheet.grid.collectionView.endUpdate(!0);this.selectedSheet.grid.autoGenerateColumns=w}var v=this.collectionView._idx;this.collectionView.endUpdate(!0);this.updateRowHeights();if(this.collectionView.sortDescriptions.length>0){this.collectionView._view=this.selectedSheet._dataView;this.collectionView._pgView=this.collectionView._getPageView();this.collectionView._idx=v;if(!g&&!f){this.selectedSheet.grid.collectionView._view=this.selectedSheet._dataView;this.selectedSheet.grid.collectionView._pgView=this.selectedSheet.grid.collectionView._getPageView();this.collectionView._idx=v}this._bindGrid(!1);this.selectedSheet.grid._bindGrid(!1)}setTimeout((function(){s._filter.apply()}));this.autoGenerateColumns=p}else{this.rows.beginUpdate();for(C=0;C<h;C++)this.rows.insert(a,new Row);var y=this.selectedSheet._freezeHiddenRows;if(y&&y.length)for(C=a+h;C<this.rows.length;C++)y[C]||(this.rows[C].visible=!0);this.rows.endUpdate()}this._updateTablesForUpdatingRow(a,h);this.selection&&-1!==this.selection.row&&-1!==this.selection.col||this.select(new CellRange(0,0),!1);if(i){i.saveNewState();this._undoStack._addAction(i)}this.onRowChanged(new RowColumnChangedEventArgs(a,h,!0,!1));this.endUpdate()}};FlexSheet.prototype.deleteRows=function(e,t){var o=this;if(this.selectedSheet&&!(this.rows.length<1)){var n=e,i=isArray(e);if(!i)if(isNumber(e)){if((t=isNumber(t)?t:1)<1)return;n=[new CellRange(e,-1,e+t-1,-1)]}else i=(n=this._selections()).length>1;var l=!!this.collectionView;if(l){var r=[];n.forEach((function(e){if(e.row>=0&&e.row2>=0)for(var t=e.topRow,n=e.bottomRow;t<=n;t++)(o.rows[t]instanceof HeaderRow||o.rows[t]instanceof _NewRowTemplate)&&r.push(t)}));r.forEach((function(e){return _RangesHelper.excludeRow(n,e)}))}if((n=_RangesHelper.validateRowRanges(n,this.rows.length)).length){n.forEach((function(e){e.col=e.col2=-1}));this._clearCalcEngine();this.finishEditing();var s,a=this.selection.topRow,h=i?new RowColumnChangedEventArgs(n,!1,!1):new RowColumnChangedEventArgs(n[0].topRow,n[0].rowSpan,!1,!1);this.onPrepareChangingRow(h);this.undoStack.stackSize>0&&(s=new _RowsChangedAction(this,null,null,!1));var u,c,d=l&&this.itemsSource instanceof CollectionView,_=null==this.selectedSheet.grid.collectionView,f=0;this.beginUpdate();this._isDeletingRows=!0;if(l){this.selectedSheet._dataView=this.collectionView._view.slice();u=this.autoGenerateColumns;this.autoGenerateColumns=!1;this.collectionView.beginUpdate();if(!d){c=this.selectedSheet.grid.autoGenerateColumns;this.selectedSheet.grid.autoGenerateColumns=!1;_||this.selectedSheet.grid.collectionView.beginUpdate()}}else this.rows.beginUpdate();for(var g=n.length-1;g>=0;g--){var p=n[g],w=void 0,m=new CellRangeEventArgs(this.cells,p);if(this.onDeletingRow(m)){if(s){(w=new _RowsChangedAction(this,p.topRow,p.rowSpan,!1))._affectedFormulas=this._updateAffectedFormula(p.bottomRow,p.rowSpan,!1,!0);w._affectedDefinedNameVals=this._updateAffectedNamedRanges(p.bottomRow,p.rowSpan,!1,!0);w._deletedTables=this._updateTablesForUpdatingRow(p.topRow,p.rowSpan,!0);s.addDeleteSubAction(w)}this._updateCellsForUpdatingRow(this.rows.length,p.topRow,p.rowSpan,!0);for(var C=p.bottomRow;C>=p.topRow;C--){var S=this.rows[C];if(!S||S.isVisible){f++;if(S.dataItem&&this.editableCollectionView){var b=void 0;this.editableCollectionView.remove(S.dataItem);var v=this.selectedSheet._dataView.indexOf(S.dataItem);this.selectedSheet._dataView.splice(v,1);var y=Array.from(this.rows).map((function(e){return e.height}));y.splice(C,1);this.setHeights(y);d||(b=this.itemsSource.indexOf(S.dataItem));this._updateItemIndexForRemovingRow(this.collectionView.sourceCollection,b)}else this.rows.removeAt(C)}}w&&w.saveNewState();this.onDeletedRow(m)}}if(l){if(!d){_||this.selectedSheet.grid.collectionView.endUpdate(f>0);this.selectedSheet.grid.autoGenerateColumns=c}this.collectionView.endUpdate(f>0);this.updateRowHeights();if(this.collectionView.sortDescriptions.length>0){this.collectionView._view=this.selectedSheet._dataView;this.collectionView._pgView=this.collectionView._getPageView();if(!d&&!_){this.selectedSheet.grid.collectionView._view=this.selectedSheet._dataView;this.selectedSheet.grid.collectionView._pgView=this.selectedSheet.grid.collectionView._getPageView()}this._bindGrid(!1);this.selectedSheet.grid._bindGrid(!1)}this.autoGenerateColumns=u}else this.rows.endUpdate();this.selectedSheet.selectionRanges.clear();var R,x=this.rows.length;if(0===x)R=new CellRange;else if(this.selection.topRow>=x)R=new CellRange(x-1,0,x-1,this.columns.length-1);else{var T=a;this.selection.topRow>=0&&(T=Math.min(T,this.selection.topRow));R=new CellRange(T,0,T,this.columns.length-1)}this.select(R,!1);0===x&&"move"===this.hostElement.style.cursor&&(this.hostElement.style.cursor="default");if(s){s.saveNewState();this._undoStack._addAction(s)}this.onRowChanged(h);this._isDeletingRows=!1;this.endUpdate()}}};FlexSheet.prototype.insertColumns=function(e,t){var o,n,i,l=this,r=isNumber(e)&&e>=0?e:this.selection&&this.selection.leftCol>-1?this.selection.leftCol:0,s=isNumber(t)?t:1;if(this.selectedSheet){this.columns.length>0?r>=this.columns.length&&(r=this.columns.length-1):r=0;this._clearCalcEngine();this.finishEditing();this.onPrepareChangingColumn(new RowColumnChangedEventArgs(r,s,!0,!0));this.undoStack.stackSize>0&&(o=new _ColumnsChangedAction(this,r,s,!0));this._updateCellsForUpdatingColumn(this.columns.length,r,s);n=this._updateAffectedFormula(r,s,!0,!1);i=this._updateAffectedNamedRanges(r,s,!0,!1);if(o){o._affectedFormulas=n;o._affectedDefinedNameVals=i}this.deferUpdate((function(){l.columns.beginUpdate();for(var e=0;e<s;e++){var t=new Column;t.isRequired=!1;if(l.itemsSource){t.binding=l._getUniqueColumnName();var n=l.rows[l._getDataRowsOffset()-1];if(n){n._ubv||(n._ubv={});n._ubv[t._hash]=FlexSheet._getHeaderRowText(t)}}l.columns.insert(r,t)}l.columns.endUpdate();l.selectedSheet._filterDefinition=l._filter.filterDefinition;l.selectedSheet.grid.columns._dirty=!1;l._sortManager._updateSortDescriptions(r,s);l._sortManager.commitSort(!1);l._updateTablesForUpdatingColumn(r,s);l.selection&&-1!==l.selection.row&&-1!==l.selection.col||l.select(new CellRange(0,0),!1);if(o){o.saveNewState();l._undoStack._addAction(o)}l.onColumnChanged(new RowColumnChangedEventArgs(r,s,!0,!0))}));this.updateRowHeights()}};FlexSheet.prototype.deleteColumns=function(e,t){if(this.selectedSheet){var o=e,n=isArray(e);if(!n)if(isNumber(e)){if((t=isNumber(t)?t:1)<1)return;o=[new CellRange(-1,e,-1,e+t-1)]}else n=(o=this._selections()).length>1;if((o=_RangesHelper.validateColumnRanges(o,this.columns.length)).length){var i=this.selection.leftCol,l=0;o.forEach((function(e){l+=e.columnSpan;e.row=e.row2=-1}));this._clearCalcEngine();this.finishEditing();var r,s=n?new RowColumnChangedEventArgs(o,!1,!0):new RowColumnChangedEventArgs(o[0].leftCol,o[0].columnSpan,!1,!0);this.onPrepareChangingColumn(s);this.undoStack.stackSize>0&&(r=new _ColumnsChangedAction(this,null,null,!1));this.beginUpdate();this._isDeletingColumns=!0;var a=this.filter?this.filter._filters:null,h=!1;this.columns.beginUpdate();for(var u=o.length-1;u>=0;u--){var c=o[u],d=void 0;if(r){(d=new _ColumnsChangedAction(this,c.leftCol,c.columnSpan,!1))._affectedFormulas=this._updateAffectedFormula(c.rightCol,c.columnSpan,!1,!1);d._affectedDefinedNameVals=this._updateAffectedNamedRanges(c.rightCol,c.columnSpan,!1,!1);d._deletedTables=this._updateTablesForUpdatingColumn(c.leftCol,c.columnSpan,!0);r._delSubActions.push(d)}this._updateCellsForUpdatingColumn(this.columns.length,c.leftCol,c.columnSpan,!0);for(var _=c.rightCol;_>=c.leftCol;_--){var f=this.columns[_];if(f.isVisible){if(a)for(var g=0;g<a.length;g++)if(a[g].column===f){a.splice(g,1);h=!0;break}this.columns.removeAt(_);this._sortManager.deleteSortLevel(_)}}this._sortManager._updateSortDescriptions(c.leftCol,c.columnSpan,!1)}this.columns.endUpdate();if(h){for(_=0;_<this.columns.length;_++)this.columns[_].isVisible&&this.filter._updateColumnFilter(this.columns[_]);this.filter.apply()}this.selectedSheet._filterDefinition=this._filter.filterDefinition;this.selectedSheet.grid.columns._dirty=!1;this._sortManager.commitSort(!1);this.selectedSheet.selectionRanges.clear();var p,w=this.columns.length;if(0===w){p=new CellRange;"move"===this.hostElement.style.cursor&&(this.hostElement.style.cursor="default")}else if(this.selection.leftCol>=w)p=new CellRange(0,w-1,this.rows.length-1,w-1);else{var m=i-l+1;m=Math.max(m,o[0].leftCol);m=Math.min(m,this.selection.leftCol);p=new CellRange(this.selection.row,m,this.selection.row2,m)}this.select(p,!1);if(r){this._undoStack._addAction(r);r._delSubActions.forEach((function(e){return e.saveNewState()}))}this.onColumnChanged(s);this._isDeletingColumns=!1;this.endUpdate();this.updateRowHeights()}}};FlexSheet.prototype.mergeRange=function(e,t){void 0===t&&(t=!1);var o,n,i,l,r,s=e||this.selection,a=-1,h=-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&&(r=new _CellMergeAction(this));this.hostElement.focus()}if(!this._resetMergedRange(s)){for(o=s.topRow;o<=s.bottomRow;o++)if((i=this.rows[o])&&i.isVisible){a=o;break}for(n=s.leftCol;n<=s.rightCol;n++)if((l=this.columns[n])&&l.isVisible){h=n;break}a>-1&&h>-1&&this.selectedSheet._mergedRanges.push(new CellRange(a,h,s.bottomRow,s.rightCol))}if(r){r.saveNewState();this._undoStack._addAction(r)}}e||this.refresh()}};FlexSheet.prototype.getMergedRange=function(t,o,n,i){void 0===i&&(i=!0);var l,r,s,a,h=this.selectedSheet?this.selectedSheet._getMergedRange(o,n):null;if(t===this.cells&&h){if(!h.isSingleCell&&(this.rows.frozen>0||this.columns.frozen>0)&&(h.topRow<this.rows.frozen&&h.bottomRow>=this.rows.frozen||h.leftCol<this.columns.frozen&&h.rightCol>=this.columns.frozen)){l=h.topRow;r=h.bottomRow;s=h.leftCol;a=h.rightCol;o>=this.rows.frozen&&h.topRow<this.rows.frozen&&(l=this.rows.frozen);o<this.rows.frozen&&h.bottomRow>=this.rows.frozen&&(r=this.rows.frozen-1);r>=this.rows.length&&(r=this.rows.length-1);n>=this.columns.frozen&&h.leftCol<this.columns.frozen&&(s=this.columns.frozen);n<this.columns.frozen&&h.rightCol>=this.columns.frozen&&(a=this.columns.frozen-1);a>=this.columns.length&&(a=this.columns.length-1);return new CellRange(l,s,r,a)}return h.bottomRow>=this.rows.length?new CellRange(h.topRow,h.leftCol,this.rows.length-1,h.rightCol):h.rightCol>=this.columns.length?new CellRange(h.topRow,h.leftCol,h.bottomRow,this.columns.length-1):h.clone()}return e.prototype.getMergedRange.call(this,t,o,n,i)};FlexSheet.prototype.evaluate=function(e,t,o,n){void 0===n&&(n=!0);var i=this._evaluate(e,t,o);return n&&null!=i&&!isPrimitive(i)?i instanceof FormulaError?i.error:i.value:i};FlexSheet.prototype.getCellValue=function(e,t,o,n){void 0===o&&(o=!1);var i=n&&n!==this.selectedSheet?n.grid.columns[t]:this.columns[t],l=this._getCellStyle(e,t,n),r=l&&l.format||null,s=n&&n!==this.selectedSheet?n.grid.getCellData(e,t,!1):this.getCellData(e,t,!1);if(isString(s)){var a=n||this.selectedSheet;if(a){var h=a.findTable(e,t);if(h&&h._isHeaderRow(e))return s}var u=_FormulaErrorHelper.asError(s);if(u)return u;if(_isFormula(s)&&(s=this._evaluate(s,null,n,e,t))instanceof FormulaError)return s}if(o){r||null==s||isPrimitive(s)||(r=s.format);s=this._formatEvaluatedResult(s,i,r)}else null==s||isPrimitive(s)||(s=s.value);return 0===o?s:null==s?"":s};FlexSheet.prototype.showFunctionList=function(e){var t=this;if(this._enableFormulas){this._functionTarget=tryCast(e,HTMLInputElement);if(this._functionTarget&&this._functionTarget.value&&"="===this._functionTarget.value[0]){this._functionList._cv.filter=function(e){var o,n=e.actualvalue.toLowerCase(),i=t._getCurrentFormulaIndex(t._functionTarget.value);-1===i&&(i=0);return(o=t._functionTarget.value.substr(i+1).trim().toLowerCase()).length>0&&0===n.indexOf(o)||"="===t._functionTarget.value};this._functionList.selectedIndex=0;var o=this._cumulativeOffset(e),n=this._cumulativeOffset(this._root),i=o.y+e.clientHeight+2+(hasClass(e,"wj-grid-editor")?this._ptScrl.y:0),l=o.x+(hasClass(e,"wj-grid-editor")?this._ptScrl.x:0);setCss(this._functionListHost,{height:this._functionList._cv.items.length>5?"218px":"auto",display:this._functionList._cv.items.length>0?"block":"none",top:"",left:""});this._functionListHost.scrollTop=0;this._functionListHost.offsetHeight+i>n.y+this._root.offsetHeight?i=i-e.clientHeight-this._functionListHost.offsetHeight-5:i+=5;this._functionListHost.offsetWidth+l>n.x+this._root.offsetWidth&&(l=n.x+this._root.offsetWidth-this._functionListHost.offsetWidth);setCss(this._functionListHost,{top:i,left:l})}else this.hideFunctionList()}};FlexSheet.prototype.hideFunctionList=function(){this._functionListHost.style.display="none"};FlexSheet.prototype.selectPreviousFunction=function(){this._functionList.selectedIndex>0&&this._functionList.selectedIndex--};FlexSheet.prototype.selectNextFunction=function(){this._functionList.selectedIndex<this._functionList.itemsSource.length&&this._functionList.selectedIndex++};FlexSheet.prototype.applyFunctionToCell=function(){if(this._functionTarget){var e=this._getCurrentFormulaIndex(this._functionTarget.value);-1===e?e=this._functionTarget.value.indexOf("="):e+=1;this._functionTarget.value=this._functionTarget.value.substring(0,e)+this._functionList.selectedValue+"(";"="!==this._functionTarget.value[0]&&(this._functionTarget.value="="+this._functionTarget.value);this._functionTarget.focus();this.hideFunctionList()}};FlexSheet.prototype.save=function(e,t){var o=this._saveToWorkbook(t);e&&o.save(e);return o};FlexSheet.prototype.saveAsync=function(e,t,o,n){var i=this._saveToWorkbook(n);i.saveAsync(e,t,o);return i};FlexSheet.prototype.saveToWorkbookOM=function(e){return this._saveToWorkbook(e)._serialize()};FlexSheet.prototype.load=function(e){var t=this;if(e instanceof Blob)_blobToBuffer(e,(function(o){e=null;var n=new mXlsx.Workbook;n.load(o);o=null;t._loadFromWorkbook(n);n=null}));else if(e instanceof mXlsx.Workbook){this._loadFromWorkbook(e);e=null}else{if(!(e instanceof ArrayBuffer||isString(e)))throw"Invalid workbook.";var o=new mXlsx.Workbook;o.load(e);e=null;this._loadFromWorkbook(o);o=null}};FlexSheet.prototype.loadAsync=function(e,t,o){var n=this;if(e instanceof Blob)_blobToBuffer(e,(function(i){e=null;var l=new mXlsx.Workbook;l.loadAsync(i,(function(){n._loadFromWorkbook(l);t&&t(l);i=null;l=null}),o)}));else if(e instanceof mXlsx.Workbook){this._loadFromWorkbook(e);t&&t(e);e=null}else{if(!(e instanceof ArrayBuffer||isString(e)))throw"Invalid workbook.";var i=new mXlsx.Workbook;i.loadAsync(e,(function(){e=null;n._loadFromWorkbook(i);t&&t(i);i=null}),o)}};FlexSheet.prototype.loadFromWorkbookOM=function(e){var t;e instanceof mXlsx.Workbook?t=e:(t=new mXlsx.Workbook)._deserialize(e);this._loadFromWorkbook(t)};FlexSheet.prototype.undo=function(){var e=this;setTimeout((function(){e._undoStack.undo()}),100)};FlexSheet.prototype.redo=function(){var e=this;setTimeout((function(){e._undoStack.redo()}),100)};FlexSheet.prototype.select=function(t,o){void 0===o&&(o=!0);var n,i,l;if(isNumber(t)&&isNumber(o)){t=new CellRange(t,o);this._lastSelMovePos=t;o=!0}else this._lastSelMovePos=null;if(t.rowSpan!==this.rows.length&&t.columnSpan!==this.columns.length)for(i=t.topRow;i<=t.bottomRow;i++)for(l=t.leftCol;l<=t.rightCol;l++)if((n=this.getMergedRange(this.cells,i,l))&&!t.equals(n)){if(t.row<=t.row2){t.row=Math.min(t.topRow,n.topRow);t.row2=Math.max(t.bottomRow,n.bottomRow)}else{t.row=Math.max(t.bottomRow,n.bottomRow);t.row2=Math.min(t.topRow,n.topRow)}if(t.col<=t.col2){t.col=Math.min(t.leftCol,n.leftCol);t.col2=Math.max(t.rightCol,n.rightCol)}else{t.col=Math.max(t.rightCol,n.rightCol);t.col2=Math.min(t.leftCol,n.leftCol)}}this._isPasting&&this.collectionView&&(this.collectionView._pendingRefresh=!1);!this._enableMulSel&&this.selectedSheet&&this.selectedSheet.selectionRanges.clear();return e.prototype.select.call(this,t,o)};FlexSheet.prototype.addCustomFunction=function(e,t,o,n,i){_deprecated("addCustomFunction","addFunction");this._calcEngine.addCustomFunction(e,t,n,i);this._addCustomFunctionDescription(e,o)};FlexSheet.prototype.addFunction=function(e,t,o,n,i){this._calcEngine.addFunction(e,t,n,i);this._addCustomFunctionDescription(e,o)};FlexSheet.prototype.dispose=function(){var t=window.navigator.userAgent;this._needCopyToSheet=!1;this.removeEventListener(document.body,"mousemove",this._mouseMoveHdl);this.removeEventListener(document.body,"keydown",this._keydownHdl);this.removeEventListener(document.body,"click",this._clickHdl);if(t.match(/iPad/i)||t.match(/iPhone/i)){this.removeEventListener(document.body,"touchstart",this._touchStartHdl);this.removeEventListener(document.body,"touchend",this._touchEndHdl)}this._filter&&this._filter.filterApplied.removeAllHandlers();this.hideFunctionList();if(!this.itemsSource){var o=this._selHdl.selection;o.row=o.row2=-1}e.prototype.dispose.call(this)};FlexSheet.prototype.getClipString=function(t){var o,n,i,l,r,s,a="",h=!0;if(!this.selectedSheet)return e.prototype.getClipString.call(this,t);this._isCutting=!1;if(!t)if(this.selectedSheet.selectionRanges.length>1){if(this._isMultipleRowsSelected()){a="";(o=this._selections()).sort(this._sortByRow);for(i=0;i<o.length;i++){a&&(a+="\n");a+=this.getClipString(o[i])}return a}if(this._isMultipleColumnsSelected()){a="";(o=this._selections()).sort(this._sortByColumn);for(n=(l=o[0]).topRow,h=!0;n<=l.bottomRow;n++){h||(a+="\n");h=!1;for(i=0,p=!0;i<o.length;i++){r=o[i];p||(a+="\t");p=!1;a+=this.getClipString(new CellRange(n,r.col,n,r.col2))}}return a}assert(!1,"Copy or Cut operation cannot be used on multiple selections.")}else{var u=this.selectionMode;if(u!=SelectionMode.ListBox)for(var c=this.rows,d=0;d<c.length;d++)if(c[d].isSelected){u=SelectionMode.ListBox;break}t=this.selection;switch(u){case SelectionMode.Row:case SelectionMode.RowRange:t.col=0;t.col2=this.columns.length-1;break;case SelectionMode.ListBox:t.col=0;t.col2=this.columns.length-1;for(var _=0;_<this.rows.length;_++)if(this.rows[_].isSelected&&this.rows[_].isVisible){t.row=t.row2=_;a&&(a+="\n");a+=this.getClipString(t)}return a}}if(!(t=asType(t,CellRange)).isValid)return"";var f=t.topRow;for(h=!0;f<=t.bottomRow;f++)if(this.rows[f].isVisible){h||(a+="\n");h=!1;for(var g=t.leftCol,p=!0;g<=t.rightCol;g++)if(this.columns[g].isVisible){p||(a+="\t");p=!1;(s=(s=this.getCellValue(f,g,!0).toString()).replace(/\t/g," ")).indexOf("\n")>-1&&(s='"'+s.replace(/"/g,'""')+'"');a+=s}}return a};FlexSheet.prototype.setClipString=function(t,o){var n=null==o,i=!1;if(this.selectedSheet){o=o?asType(o,CellRange):this.selection;var l=t=asString(t).replace(/\r\n/g,"\n").replace(/\r/g,"\n"),r=this._edtHdl._parseClipString(asString(t));n&&!o.isSingleCell&&r.length&&this._edtHdl._expandClipRows(r,o);var s=this._containsMultiLineText(r);if(this._copiedRanges&&0!==this._copiedRanges.length&&(l.trim()===this._getRangeString(this._copiedRanges,this._copiedSheet).trim()||this._containsRandFormula(this._copiedRanges,this._copiedSheet))&&!this._cutValue||s){if(this._copiedRanges){var a=this._getRangeString(this._copiedRanges,this._copiedSheet,!1)+"\r\n";a=asString(a).replace(/\r\n/g,"\n").replace(/\r/g,"\n");r=this._edtHdl._parseClipString(asString(a));n&&!o.isSingleCell&&r.length&&this._edtHdl._expandClipRows(r,o)}var h=o.topRow+r.length-1;h>=this.rows.length&&(h=this.rows.length-1);var u=o.leftCol;if(r.length)for(var c=u,d=0;c<this.columns.length&&d<r[0].length;c++){this.columns[c].visible&&d++;u=c}var _=new CellRange(o.topRow,o.leftCol,h,u);if(this.onPasting(new CellRangeEventArgs(this.cells,_,t))){this.beginUpdate();var f=r.length>1,g=this.editableCollectionView;g&&f&&g.beginUpdate();if(s||!this._copiedRanges||this._copiedRanges.length>1||0===this._copiedRanges.length)for(var p=0,w=(D=this._copiedRanges&&this._copiedRanges.length>1?this._copiedRanges[0]:new CellRange).topRow,m=(c=0,o.topRow);c<r.length&&m<this.rows.length;c++,m++){if((k=this.rows[m]).isVisible){if(!k.isReadOnly){var C=r[c],S=D.leftCol,b=k.dataItem;if(k instanceof _NewRowTemplate){f&&(k.dataItem=g.addNew());var v=this.newRowAtTop?f?0:c:m,y=new CellRangeEventArgs(this.cells,new CellRange(v,-1));if(!this.onRowEditStarting(y)){m--;f&&g.cancelNew();continue}this.onRowEditStarted(y)}for(var R=0,x=o.leftCol;R<C.length&&x<this.columns.length;R++,x++)if(this.columns[x].isVisible){if(!this.columns[x].isReadOnly){var T=C[R];if(!this.columns[x].isReadOnly&&!k.isReadOnly){var E=T.length;E>1&&'"'==T[0]&&'"'==T[E-1]&&T.indexOf("\n")>-1&&(T=T.substr(1,E-2));i=this._postSetClipStringProcess(b,T,m,x,p,w,S,g)||i;_.row2=Math.max(_.row2,m+p);_.col2=Math.max(_.col2,x)}S>=0&&S++}}else R--;w>=0&&w++;if(f&&k instanceof _NewRowTemplate){k.dataItem=null;m--;p++;y=new CellRangeEventArgs(this.cells,new CellRange(this.newRowAtTop?0:m,-1));this.onRowEditEnding(y);this.onRowEditEnded(y);g.commitNew()}}}else c--}else if(this._copiedRanges&&1===this._copiedRanges.length){var F=this.selectedSheet===this._copiedSheet?this:this._copiedSheet.grid,A=(p=0,0),D=this.selectionMode===SelectionMode.ListBox?this._getSelectionForListBoxMode(F):this._copiedRanges[0];for(c=0,m=o.topRow;c<r.length&&m<this.rows.length;c++,m++){var k,I=0;if((k=this.rows[m]).isVisible){if(!k.isReadOnly){for(;F.rows[D.topRow+A]&&!F.rows[D.topRow+A].isVisible;)A++;A>=D.rowSpan&&(A%=D.rowSpan);if(!F.rows[D.topRow+A])break;var M=m-D.topRow-A;C=r[c],b=k.dataItem;if(k instanceof _NewRowTemplate){f&&(k.dataItem=g.addNew());v=this.newRowAtTop?f?0:c:m,y=new CellRangeEventArgs(this.cells,new CellRange(v,-1));if(!this.onRowEditStarting(y)){m--;f&&g.cancelNew();continue}this.onRowEditStarted(y)}for(R=0,x=o.leftCol;R<C.length&&x<this.columns.length;R++,x++)if(this.columns[x]&&this.columns[x].isVisible){if(!this.columns[x].isReadOnly){I>=D.columnSpan&&(I%=D.columnSpan);if(!F.columns[D.leftCol+I])break;var N=x-D.leftCol-I;if(!this.columns[x].isReadOnly&&!k.isReadOnly){T=C[R];var V=this._getCellStyle(D.topRow+A,D.leftCol+I,this._copiedSheet);if(_isFormula(T)&&(0!==M||0!==N))try{var B=this._calcEngine.parse(T),H=new CellRange(D.topRow+A,D.leftCol+I),L=new CellRange(D.topRow+A+M,D.leftCol+I+N),P=!(this._isCutting&&!B._refersTo(D));B._moveCellRangeExp(this.selectedSheetIndex,H,L,!1,P)&&(T="="+B._getStringExpression())}catch(e){}F.columns[D.leftCol+I].format&&!this.columns[x].format&&(V?V.format||(V.format=F.columns[D.leftCol+I].format):V={format:F.columns[D.leftCol+I].format});i=this._postSetClipStringProcess(b,T,m,x,p,D.topRow+A,D.leftCol+I,g,V)||i;_.row2=Math.max(_.row2,m+p);_.col2=Math.max(_.col2,x)}I++}}else R--;A++;if(f&&k instanceof _NewRowTemplate){k.dataItem=null;m--;p++;y=new CellRangeEventArgs(this.cells,new CellRange(this.newRowAtTop?0:m,-1));this.onRowEditEnding(y);this.onRowEditEnded(y);g.commitNew()}}}else c--}}if(this._isCutting){this._delCutData(r.length,r[0].length);this._isCutting=!1;this._cutValue=l;this._copiedRanges=null;this._copiedSheet=null}if(g&&f){g.currentEditItem&&g.commitEdit();g.endUpdate(!0)}else if(g&&i){var O=g.currentAddItem;!O&&0===o.row&&this.newRowAtTop&&this.rows[0]instanceof _NewRowTemplate&&(O=this.rows[0].dataItem);if(O){g.editItem(O);this._edtHdl._edItem=O}g.refresh()}this.endUpdate();this.select(_);this.onPasted(new CellRangeEventArgs(this.cells,_))}else{this._cutValue=null;this._copiedRanges=null;this._copiedSheet=null}}else{if(l!==this._cutValue){this._cutValue=null;e.prototype.setClipString.call(this,t)}this._copiedRanges=null;this._copiedSheet=null}}else e.prototype.setClipString.call(this,t,o)};FlexSheet.prototype.getBuiltInTableStyle=function(e){var t;null==this._builtInTableStylesCache&&(this._builtInTableStylesCache={});if(null==(t=this._builtInTableStylesCache[e.toLowerCase()])){t=this._createBuiltInTableStyle(e);Object.freeze(t);this._builtInTableStylesCache[e.toLowerCase()]=t}return t};FlexSheet.prototype.onSortingColumn=function(e){return!1};FlexSheet.prototype._getCvIndex=function(t){return t>-1&&this.collectionView?this.rows[t]instanceof HeaderRow?t:e.prototype._getCvIndex.call(this,t):-1};FlexSheet.prototype._headerRowAtTop=function(){var e=this._getDataRowsOffset();return e>0&&this.rows[e-1]instanceof HeaderRow};FlexSheet.prototype._getDataRowsOffset=function(){var e=0;this.allowAddNew&&this.newRowAtTop&&e++;this.rows[e]instanceof HeaderRow&&e++;return e};FlexSheet.prototype._bindGrid=function(t){if(!this._ignoreBindGrid)if(this.itemsSource)e.prototype._bindGrid.call(this,t);else if(!this.rows.length){var o=this._selHdl.selection;o.row=o.row2=-1}};FlexSheet.prototype._init=function(){var e=this,t=window.navigator.userAgent,mouseUp=function(t){document.removeEventListener("mouseup",mouseUp);e._mouseUp(t)};this.hostElement.setAttribute("tabindex","-1");this._divContainer=this.hostElement.querySelector('[wj-part="container"]');this._tabHolder=new _TabHolder(this.hostElement.querySelector('[wj-part="tab-holder"]'),this);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._contextMenu=new _SheetContextMenu(this.hostElement.querySelector('[wj-part="context-menu"]'),this);this._tabHolder.addEventListener(this._tabHolder.hostElement,"mousedown",(function(){t.match(/iPad/i)||t.match(/iPhone/i)||e._hideContextMenu()}));this._gpCells=new FlexSheetPanel(this,CellType.Cell,this.rows,this.columns,this._eCt);this._gpCHdr=new FlexSheetPanel(this,CellType.ColumnHeader,this._hdrRows,this.columns,this._eCHdrCt);this._gpRHdr=new FlexSheetPanel(this,CellType.RowHeader,this.rows,this._hdrCols,this._eRHdrCt);this._gpTL=new FlexSheetPanel(this,CellType.TopLeft,this._hdrRows,this._hdrCols,this._eTLCt);this._syncSelection=this._flexSheetSyncSelection.bind(this);this._sortManager=new SortManager(this);this._filter=new FlexSheetFilter(this);this._filter.filterApplied.addHandler((function(){if(e.selectedSheet){e.selectedSheet._filterDefinition=e._filter.filterDefinition;if(e.selectedSheet.itemsSource){e.selectedSheet._storeRowSettings();e.selectedSheet._setRowSettings()}}}));this._calcEngine=new _CalcEngine(this);this._calcEngine.unknownFunction.addHandler((function(t,o){e.onUnknownFunction(o)}),this);this._initFuncsList();this._undoStack=new UndoStack(this);this.loadedRows.addHandler((function(){if(e.collectionView&&!(e.rows[0]instanceof HeaderRow)&&!e._headerRowRemoved){var t=new HeaderRow;t.isReadOnly=!0;for(var o=0;o<e.columns.length;o++){var n=e.columns[o];t._ubv||(t._ubv={});t._ubv[n._hash]=FlexSheet._getHeaderRowText(n)}e.rows[0]instanceof _NewRowTemplate&&e.newRowAtTop?e.rows.insert(1,t):e.rows.insert(0,t)}e._filter&&e._filter.apply()}));this.itemsSourceChanged.addHandler((function(){var t;for(t=0;t<e.columns.length;t++)e.columns[t].isRequired=!1;e.collectionView&&e.collectionView.currentChanged.removeHandler(null,e)}));this.copied.addHandler((function(t,o){var n;if(e.selectedSheet){e._copiedSheet=e.selectedSheet;e._needCopyToSheet=!0;if(e.selectedSheet.selectionRanges.length>1)if(e._isMultipleRowsSelected()){(n=e.selectedSheet.selectionRanges.slice(0)).sort(e._sortByRow);e._copiedRanges=n}else if(e._isMultipleColumnsSelected()){(n=e.selectedSheet.selectionRanges.slice(0)).sort(e._sortByColumn);e._copiedRanges=n}else assert(!1,"Copy operation cannot be used on multiple selections.");else e._copiedRanges=[o.range]}}));this.rows.collectionChanged.addHandler((function(t,o){e._clearForEmptySheet("rows");e.itemsSource||!e.selectedSheet||!e._needCopyToSheet||e._isCopying||e._isUndoing||o.item instanceof _NewRowTemplate||e._copyRowsToSelectedSheet();e.itemsSource&&e.selectedSheet&&o.action===NotifyCollectionChangedAction.Remove&&o.item instanceof HeaderRow&&!e._draggingSingleRow&&(e._headerRowRemoved=!0)}),this);this.columns.collectionChanged.addHandler((function(t,o){e._clearForEmptySheet("columns");e.selectedSheet&&e._needCopyToSheet&&!e._isCopying&&!e._isUndoing&&e._copyColumnsToSelectedSheet()}),this);this.addEventListener(this.hostElement,"mousedown",(function(t){document.addEventListener("mouseup",mouseUp);e._isDescendant(e._divContainer,t.target)&&e._mouseDown(t)}),!0);this.addEventListener(this.hostElement,"dragend",(function(){e._columnHeaderClicked=!1;e._htDown=null;e._enableMulSel=!1;e.selectedSheet._addSelection(e.selection)}));this.addEventListener(this.hostElement,"contextmenu",(function(t){if(!t.defaultPrevented&&e.selectedSheet){if(!e.activeEditor){var o=void 0,n=void 0,i=e.selection;if(e._isContextMenuKeyDown&&i.row>-1&&i.col>-1&&e.rows.length>0&&e.columns.length>0){var l=e.columns[i.col],r=e.rows[i.row],s=e._cumulativeOffset(e.hostElement),a=e._cumulativeScrollOffset(e.hostElement),h=l.pos+e._eCt.offsetLeft+s.x+l.renderSize/2+e._ptScrl.x,u=r.pos+e._eCt.offsetTop+s.y+r.renderSize/2+e._ptScrl.y;n=new Point(h-a.x,u-a.y);o=e.hitTest(h,u)}else o=e.hitTest(t);t.preventDefault();if(o&&o.cellType!==CellType.None){var c=e.columns.length-1,d=e.rows.length-1,_=void 0;switch(o.cellType){case CellType.TopLeft:_=new CellRange(Math.min(0,d),Math.min(0,c),d,c);break;case CellType.RowHeader:_=new CellRange(o.row,Math.min(0,c),o.row,c);break;case CellType.ColumnHeader:_=new CellRange(e.itemsSource&&e.rows[0]&&!e.rows[0].isVisible?1:Math.min(0,d),o.col,d,o.col);break;case CellType.Cell:_=new CellRange(o.row,o.col)}(_&&e.selection.contains(_)||o.cellType===CellType.RowHeader&&e._isRowSelected(o.row)||o.cellType===CellType.ColumnHeader&&e._isColumnSelected(o.col)||o.cellType===CellType.Cell&&e._isCellSelected(o.row,o.col))&&(_=null);if(_){if(e.selectedSheet){e.selectedSheet.selectionRanges.clear();e.selectedSheet.selectionRanges.push(_)}e.selection=_}e._contextMenu.show(t,n)}}e._isContextMenuKeyDown=!1}}));this.prepareCellForEdit.addHandler(this._prepareCellForEditHandler,this);this.cellEditEnded.addHandler((function(t,o){(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)&&setTimeout((function(){e.hideFunctionList()}),200)}));this.cellEditEnding.addHandler((function(t,o){if(!o.cancel&&(!o.data||46!==o.data.keyCode&&8!==o.data.keyCode)){var n=e.getCellData(o.row,o.col,!1),i=e.cellFactory.getEditorValue(e);if((null==n||""===n)&&null!=i&&""!==i&&!isNaN(+i)){var l=e._updateFormulaBoundaryForEditingCell(o.row,o.col);e._undoStack._pendingAction&&e._undoStack._pendingAction instanceof _EditAction&&(e._undoStack._pendingAction._affectedFormulas=l)}e._clearCalcEngine();e._clearCalcCacheOnRefresh=!1}}));this.rowEditEnding.addHandler((function(t,o){var n=e.collectionView;if(n&&e.selectedSheet){var i=n.sortDescriptions.length>0,l=e._filter&&e._filter._isActive();(i||e.selectedSheet._dataView||l)&&(e.selectedSheet._dataView=n._view.slice());i&&(e.selectedSheet._scrollPosition=e.scrollPosition)}}));this.rowEditEnded.addHandler((function(t,o){var n=e.collectionView;if(n&&e.selectedSheet){e.selectedSheet._dataView&&(e.selectedSheet._dataView=n._view.slice());var i=n.sortDescriptions.length>0,l=e._filter&&e._filter._isActive();if(i||l){n._view=e.selectedSheet._dataView;n._pgView=n._getPageView();if(!(e.itemsSource instanceof CollectionView)&&null!=e.selectedSheet.grid.collectionView){e.selectedSheet.grid.collectionView._view=e.selectedSheet._dataView;e.selectedSheet.grid.collectionView._pgView=e.selectedSheet.grid.collectionView._getPageView()}if(e.refreshOnEdit){e._isPasting||e._bindGrid(!1);e.selectedSheet.grid._bindGrid(!1)}}i&&(e.scrollPosition=e.selectedSheet._scrollPosition)}}));this.pasting.addHandler((function(){e._needCopyToSheet=!1;e._isPasting=!0}));this.pasted.addHandler((function(){var t=e.collectionView,o=e.selectedSheet;t&&o&&o._dataView&&o._dataView.length!==t._view.length&&(o._dataView=t._view.slice());e.selection;e._needCopyToSheet=!0;e._isPasting=!1;e._clearCalcEngine()}));this.resizingColumn.addHandler((function(){e._resizing=!0}));this.resizingRow.addHandler((function(){e._resizing=!0}));this.resizedColumn.addHandler((function(){e._resizing=!1}));this.resizedRow.addHandler((function(){e._resizing=!1}));this.selectionChanged.addHandler((function(){var t=e.selection;t.rightCol>=e.columns.length&&(e.selection=new 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()}));this.draggingRow.addHandler((function(){return e._draggingSingleRow=!0}));this.draggedRow.addHandler((function(){return e._draggingSingleRow=!1}));this.addEventListener(this.hostElement,"keydown",(function(t){var o,n,i=!1,l=!1;if(t.ctrlKey){if(89===t.keyCode){e.finishEditing();e.redo();t.preventDefault()}if(90===t.keyCode){e.finishEditing();e.undo();t.preventDefault()}if(e.selectedSheet&&65===t.keyCode){e._isClicking=!0;e.selectedSheet.selectionRanges.clear();e.selectedSheet.selectionRanges.push(e.selection);e._isClicking=!1}if(67===t.keyCode||45==t.keyCode){if(e.activeEditor){e._copiedRanges=null;e._copiedSheet=null}e._cutValue=null}if(88===t.keyCode&&!e.activeEditor){t.stopPropagation();if(e.selectionMode===SelectionMode.ListBox)for(var r=0;r<e.rows.length;r++)if(e.rows[r].isSelected)if(i){if(l)continue;assert(!1,"Cut operation cannot be used on multiple selections.")}else{i=!0;l=!0}else l&&(l=!1);if(e.selectedSheet.selectionRanges.length>1)assert(!1,"Cut operation cannot be used on multiple selections.");else{e.finishEditing();o=new CellRangeEventArgs(e.cells,e.selection);if(e.onCopying(o)){e._cutValue=null;n=e.getClipString();e._isCutting=!0;Clipboard.copy(n);e.onCopied(o)}}}t.keyCode!==Key.Space||!e.selection.isValid||e.selectionMode!==SelectionMode.CellRange&&e.selectionMode!==SelectionMode.MultiRange||e.select(new CellRange(0,e.selection.col,e.rows.length-1,e.selection.col))}t.keyCode===Key.Escape&&e._hideContextMenu();(93===t.keyCode||t.shiftKey&&121===t.keyCode)&&(e._contextMenu.visible&&!isFirefox()?e._isContextMenuKeyDown=!1:e._isContextMenuKeyDown=!0)}));this.addEventListener(document.body,"keydown",this._keydownHdl,!0);this.addEventListener(document.body,"click",this._clickHdl);this.addEventListener(document.body,"mousemove",this._mouseMoveHdl);this.draggedColumn.addHandler((function(t,o){e.sortManager._handleColumnMoving(o.data.col,o.col)}));if(t.match(/iPad/i)||t.match(/iPhone/i)){this.addEventListener(document.body,"touchstart",this._touchStartHdl);this.addEventListener(document.body,"touchend",this._touchEndHdl)}};FlexSheet.prototype._flexSheetSyncSelection=function(e){if(this.collectionView&&this.selectionMode!=SelectionMode.None){var t=this.selection,o=t.row>-1&&t.row<this.rows.length?this.rows[t.row]:null,n=o?o.dataItem:null;if(this.collectionView instanceof CollectionView&&this.collectionView.isUpdating)return;(o instanceof HeaderRow||this.newRowAtTop&&o instanceof _NewRowTemplate||n instanceof CollectionViewGroup)&&(n=null);if((n!=this.collectionView.currentItem||e)&&(!this.editableCollectionView||!this.editableCollectionView.currentAddItem)){var i=this._getRowIndex(this.collectionView.currentPosition);if(i!=t.row){t.row=t.row2=i;this.select(t,!1);this.selectionMode&&!this._copyingTo&&this.scrollIntoView(t.row,-1)}}}};FlexSheet.prototype._initFuncsList=function(){var e=this;this._functionListHost=document.createElement("div");addClass(this._functionListHost,"wj-flexsheet-formula-list");document.querySelector("body").appendChild(this._functionListHost);this._functionListHost.style.display="none";this._functionListHost.style.position="absolute";this._functionList=new mInput.ListBox(this._functionListHost);this._functionList.isContentHtml=!0;this._functionList.itemsSource=this._getFunctions();this._functionList.displayMemberPath="displayValue";this._functionList.selectedValuePath="actualvalue";this.addEventListener(this._functionListHost,"click",this.applyFunctionToCell.bind(this));this.addEventListener(this._functionListHost,"keydown",(function(t){if(t.keyCode===Key.Escape){e.hideFunctionList();e.hostElement.focus();t.preventDefault()}if(t.keyCode===Key.Enter){e.applyFunctionToCell();e.hostElement.focus();t.preventDefault();t.stopPropagation()}}))};FlexSheet.prototype._getFunctions=function(){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};FlexSheet.prototype._addCustomFunctionDescription=function(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,l=0;l<n.length;l++)if(n[l].actualvalue===e){i=l;break}i>-1?n.splice(i,1,o):n.push(o)};FlexSheet.prototype._getCurrentFormulaIndex=function(e){var t=-1;["+","-","*","/","^","(","&"].forEach((function(o){var n=e.lastIndexOf(o);"/"===o&&(n>=2&&"#N"===e.substr(n-2,2)||n>=4&&"#DIV"===e.substr(n-4,4))||n>t&&(t=n)}));return t};FlexSheet.prototype._prepareCellForEditHandler=function(){var e=this,t=this._edtHdl._edt;if(t){this.addEventListener(t,"keydown",(function(t){if(e.isFunctionListOpen)switch(t.keyCode){case Key.Up:e.selectPreviousFunction();t.preventDefault();t.stopPropagation();break;case Key.Down:e.selectNextFunction();t.preventDefault();t.stopPropagation();break;case Key.Tab:case Key.Enter:e.applyFunctionToCell();t.preventDefault();t.stopPropagation();break;case Key.Escape:e.hideFunctionList();t.preventDefault();t.stopPropagation()}}));this.addEventListener(t,"keyup",(function(o){(o.keyCode>40||o.keyCode<32)&&o.keyCode!==Key.Tab&&o.keyCode!==Key.Escape&&setTimeout((function(){e.showFunctionList(t)}),0)}))}};FlexSheet.prototype._addSheet=function(e,t,o,n,i){var l=new Sheet(this,i,e,t,o);l.name||l._setValidName(this.sheets.getUniqueNameOnInit());if("number"==typeof n){n<0&&(n=0);n>=this.sheets.length&&(n=this.sheets.length)}else n=this.sheets.length;this.sheets.insert(n,l);return l};FlexSheet.prototype._showSheet=function(e){if(!(!this.sheets||!this.sheets.length||e>=this.sheets.length||e<0||e===this.selectedSheetIndex||this.sheets[e]&&!this.sheets[e].visible)){this.beginUpdate();this.finishEditing();this._clearCalcEngine();this._isCopying=!0;if(this.selectedSheetIndex>-1&&this.selectedSheetIndex<this.sheets.length&&!this._sheets._exchangingPosition){this._copyingTo=!0;try{this._copyTo(this.sheets[this.selectedSheetIndex])}finally{this._copyingTo=!1}}if(this.sheets[e]){this._selectedSheetIndex=e;this._copyFrom(this.sheets[e])}this._isCopying=!1;this.endUpdate();this._filter.closeEditor()}};FlexSheet.prototype._selectedSheetChange=function(e,t){this.beginUpdate();this._showSheet(t.newValue);this._clearCalcCacheOnRefresh=!1;this.endUpdate();this.onSelectedSheetChanged(t)};FlexSheet.prototype._sourceChange=function(e,t){if(!this.sheets._exchangingPosition){this.beginUpdate();if(t.action===NotifyCollectionChangedAction.Add||t.action===NotifyCollectionChangedAction.Change){t.item._attachOwner(this);if(t.action===NotifyCollectionChangedAction.Add){this._addingSheet=!0;t.index<=this.selectedSheetIndex&&(this._selectedSheetIndex+=1)}else t.index===this.selectedSheetIndex&&this._copyFrom(t.item);this.selectedSheetIndex=t.index}else if(t.action===NotifyCollectionChangedAction.Reset){for(var o=0;o<this.sheets.length;o++)this.sheets[o]._attachOwner(this);if(this.sheets.length>0){0===this.selectedSheetIndex&&this._copyFrom(this.selectedSheet);this.selectedSheetIndex=0}else{this.rows.clear();this.columns.clear();this._selectedSheetIndex=-1}}else if(this.sheets.length>0){if(this.selectedSheetIndex===t.index){this._selectedSheetIndex=-1;this.sheets._setCurrentIdx(-1);this.selectedSheetIndex=t.index>this.sheets.length-1?this.sheets.length-1:t.index}else if(this.selectedSheetIndex>t.index){this._selectedSheetIndex--;this.sheets._setCurrentIdx(this._selectedSheetIndex)}}else{this.rows.clear();this.columns.clear();this._selectedSheetIndex=-1}this._updateDivContainerHeight(this.isTabHolderVisible);this.endUpdate()}};FlexSheet.prototype._sheetVisibleChange=function(e,t){t.item.visible||this._loadingFromWorkbook||t.index===this.selectedSheetIndex&&(this.selectedSheetIndex===this.sheets.length-1?this.selectedSheetIndex=t.index-1:this.selectedSheetIndex=t.index+1)};FlexSheet.prototype._applyStyleForCell=function(e,t,o,n){void 0===n&&(n=!1);var i=this.rows[e];if(!(null==i||i instanceof HeaderRow||!i.isVisible&&!n)){var l=e*this.columns.length+t,r=this.selectedSheet._getMergedRange(e,t);r&&(l=r.topRow*this.columns.length+r.leftCol);var s=this.selectedSheet._styledCells[l];s||(s=this.selectedSheet._styledCells[l]={});Object.keys(o).forEach((function(e){var t=o[e];("className"===e&&"normal"===t||("fontStyle"===e||"fontWeight"===e||"textDecoration"===e)&&"none"===t)&&(t="");s[e]=null===t||""===t?void 0:t||s[e]}))}};FlexSheet.prototype._checkCellFormat=function(e,t,o){var n,i,l=e*this.columns.length+t;if(this.selectedSheet){if(n=this.selectedSheet._getMergedRange(e,t)){o.isMergedCell=!0;l=n.topRow*this.columns.length+n.leftCol}if(i=this.selectedSheet._styledCells[l]){o.isBold=o.isBold||"bold"===i.fontWeight;o.isItalic=o.isItalic||"italic"===i.fontStyle;o.isUnderline=o.isUnderline||"underline"===i.textDecoration;o.verticalAlign=i.verticalAlign||"top"}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))}};FlexSheet.prototype._resetMergedRange=function(e){var t,o,n,i,l=!1;for(t=e.topRow;t<=e.bottomRow;t++)for(o=e.leftCol;o<=e.rightCol;o++)if(i=this.selectedSheet._getMergedRange(t,o)){l=!0;n=this.selectedSheet._mergedRanges.indexOf(i);this.selectedSheet._mergedRanges.splice(n,1)}return l};FlexSheet.prototype._updateCellsForUpdatingRow=function(e,t,o,n){var i,l,r,s,a,h,u,c=e*this.columns.length;if(n)for(l=i=t*this.columns.length;l<c;l++){r=l-o*this.columns.length;if(s=this.selectedSheet._styledCells[l]){l>=(t+o)*this.columns.length&&(this.selectedSheet._styledCells[r]=s);delete this.selectedSheet._styledCells[l]}}else{i=t*this.columns.length-1;for(l=c-1;l>i;l--){r=l+this.columns.length*o;if(s=this.selectedSheet._styledCells[l]){this.selectedSheet._styledCells[r]=s;delete this.selectedSheet._styledCells[l]}}}if(this.selectedSheet._mergedRanges.length>0)for(h=this.selectedSheet._mergedRanges.length-1;h>=0;h--){a=this.selectedSheet._mergedRanges[h];if(n)if((u=t+o-1)<a.topRow){a.row-=o;a.row2-=o}else if(u>=a.topRow&&u<=a.bottomRow)if(t<=a.topRow&&u>=a.bottomRow)this.selectedSheet._mergedRanges.splice(h,1);else if(t<a.topRow)if(a.row<=a.row2){a.row+=t-a.topRow;a.row2-=o}else{a.row2+=t-a.topRow;a.row-=o}else t===a.topRow&&o===a.rowSpan?this.selectedSheet._mergedRanges.splice(h,1):a.row<=a.row2?a.row2-=o:a.row-=o;else 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);else if(t<=a.topRow){a.row+=o;a.row2+=o}else t>a.topRow&&t<=a.bottomRow&&(a.row<=a.row2?a.row2+=o:a.row+=o)}};FlexSheet.prototype._updateCellsForUpdatingColumn=function(e,t,o,n){var i,l,r,s,a,h,u,c=this.rows.length*e;if(n)for(i=t;i<c;i++){l=i-o*(Math.floor(i/e)+((s=i%e)>=t?1:0));if(r=this.selectedSheet._styledCells[i]){(s<t||s>=t+o)&&(this.selectedSheet._styledCells[l]=r);delete this.selectedSheet._styledCells[i]}}else for(i=c-1;i>=t;i--){l=Math.floor(i/e)*o+i+((s=i%e)>=t?o:0);if(r=this.selectedSheet._styledCells[i]){this.selectedSheet._styledCells[l]=r;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];if(n)if((u=t+o-1)<a.leftCol){a.col-=o;a.col2-=o}else if(u>=a.leftCol&&u<=a.rightCol)if(t<=a.leftCol&&u>=a.rightCol)this.selectedSheet._mergedRanges.splice(h,1);else if(t<a.leftCol)if(a.col<=a.col2){a.col+=t-a.leftCol;a.col2-=o}else{a.col2+=t-a.leftCol;a.col-=o}else t===a.leftCol&&o===a.columnSpan?this.selectedSheet._mergedRanges.splice(h,1):a.col<=a.col2?a.col2-=o:a.col-=o;else 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);else if(t<=a.leftCol){a.col+=o;a.col2+=o}else t>a.leftCol&&t<=a.rightCol&&(a.col<=a.col2?a.col2+=o:a.col+=o)}};FlexSheet.prototype._cloneObject=function(e){var t;if(null==e||!isObject(e))return e;t={};for(var o in e)e.hasOwnProperty(o)&&null!=e[o]&&(e[o].clone?t[o]=e[o].clone():t[o]=this._cloneObject(e[o]));return t};FlexSheet.prototype._evaluate=function(e,t,o,n,i){if(e&&e.length>1&&this._enableFormulas){e="="===e[0]?e:"="+e;var l=this._calcEngine.evaluate(e,t,o,n,i);isPrimitive(l)?isNumber(l)&&(l=this._calcEngine.round(l)):l&&isNumber(l.value)&&(l.value=this._calcEngine.round(l.value));return l}return e};FlexSheet.prototype._clearAndCheckItemsOwner=function(e){if(e&&e.length){var t=e[0]._list;e.clear();this._checkCollectionOwner(t)}};FlexSheet.prototype._checkCollectionOwner=function(e,t){void 0===t&&(t=!0);if(e&&e.length&&(!e[0]._list||!t&&e[0]._list!=e))for(var o=0,n=e.length;o<n;o++)e[o]._setList(e)};FlexSheet.prototype._checkCollectionsOwner=function(){this._checkCollectionOwner(this.columns,!1);this._checkCollectionOwner(this.rows,!1);this._checkCollectionOwner(this.columnFooters.columns,!1);this._checkCollectionOwner(this.columnFooters.rows,!1);this._checkCollectionOwner(this.columnHeaders.columns,!1);this._checkCollectionOwner(this.columnHeaders.rows,!1);this._checkCollectionOwner(this.rowHeaders.columns,!1);this._checkCollectionOwner(this.rowHeaders.rows,!1)};FlexSheet.prototype._copyTo=function(e){var t,o=e.grid.autoGenerateColumns;this.beginUpdate();e._storeRowSettings();this._selHdl.extendedSelection.clear();t=this.selection.clone();e.grid.select(new CellRange,!1);this._clearAndCheckItemsOwner(e.grid.rows);this._clearAndCheckItemsOwner(e.grid.columns);this._clearAndCheckItemsOwner(e.grid.columnHeaders.columns);this._clearAndCheckItemsOwner(e.grid.rowHeaders.rows);e._ownerHeaderRowRemoved=this._headerRowRemoved;if(this.itemsSource){e.grid.autoGenerateColumns=!1;e.itemsSource=this.itemsSource;this.collectionView.sortDescriptions.length>0&&(e._dataView=this.collectionView._view.slice());e.grid.collectionView.beginUpdate()}else{e.itemsSource=null;for(var n=0;n<this.rows.length;n++)e.grid.rows.push(this.rows[n])}e._sortList=this.sortManager._committedList.slice();e._getFilterSetting();for(var i=0;i<this.columns.length;i++)e.grid.columns.push(this.columns[i]);if(e.grid.collectionView){this._resetMappedColumns(e.grid);e.grid.collectionView.endUpdate(!0)}e.grid.autoGenerateColumns=o;e.grid.rows.frozen=this.rows.frozen;e.grid.columns.frozen=this.columns.frozen;e.grid.allowAddNew=this.allowAddNew;null!=this.newRowAtTop&&(e.grid.newRowAtTop=this.newRowAtTop);e.grid.select(t,!1);e._scrollPosition=this.scrollPosition;this._setFlexSheetToDirty();this.endUpdate()};FlexSheet.prototype._copyFrom=function(e,t){var o=this;void 0===t&&(t=!0);var n,i=this.autoGenerateColumns;this._isCopying=!0;this._dragable=!1;t&&this.beginUpdate();this.itemsSource=null;this._clearAndCheckItemsOwner(this.rows);this._clearAndCheckItemsOwner(this.columns);this._clearAndCheckItemsOwner(this.columnHeaders.columns);this._clearAndCheckItemsOwner(this.rowHeaders.rows);n=e.grid.selection.clone();this._selHdl.select(new CellRange,!1);e.selectionRanges.length>1&&(this.selectionMode===SelectionMode.CellRange||this.selectionMode===SelectionMode.MultiRange)&&(this._enableMulSel=!0);this._headerRowRemoved=e._ownerHeaderRowRemoved;if(e.itemsSource){this.autoGenerateColumns=!1;this._ignoreBindGrid=isArray(e.itemsSource)||e.itemsSource instanceof CollectionView;this.itemsSource=e.itemsSource;this._ignoreBindGrid=!1;this.collectionView.beginUpdate()}else for(var l=0;l<e.grid.rows.length;l++)this.rows.push(e.grid.rows[l]);for(var r=0;r<e.grid.columns.length;r++){var s=e.grid.columns[r];s.isRequired=!1;this.columns.push(s)}this.sortManager.sortDescriptions.sourceCollection=e._sortList.slice();this.sortManager._committedList=e._sortList.slice();if(this.collectionView){if(e.grid.collectionView){this.collectionView.sortDescriptions.clear();e.grid.collectionView.sortDescriptions.forEach((function(e){return o.collectionView.sortDescriptions.push(e)}))}this.collectionView.moveCurrentToPosition(this._getCvIndex(n.row));this._resetMappedColumns(this);this.collectionView.endUpdate(!0);if(e._dataView){this.collectionView._view=e._dataView;this.collectionView._pgView=this.collectionView._getPageView();if(!(this.itemsSource instanceof CollectionView)){e.grid.collectionView._view=e._dataView;e.grid.collectionView._pgView=e.grid.collectionView._getPageView()}this._bindGrid(!1);e.grid._bindGrid(!1)}this.collectionView.collectionChanged.addHandler((function(e,t){t.action===NotifyCollectionChangedAction.Reset&&setTimeout((function(){o.invalidate()}),10)}),this)}if(this.rows.length&&this.columns.length){this._selHdl.select(n,!1);if(this.selectionMode===SelectionMode.MultiRange){this._selHdl.extendedSelection.beginUpdate();for(var a=0;a<e.selectionRanges.length;a++)this.selection.equals(e.selectionRanges[a])||this._selHdl.extendedSelection.push(e.selectionRanges[a]);this._selHdl.extendedSelection.endUpdate()}}e._applyFilterSetting();for(l=0;l<this.rows.length;l++){var h=e._rowSettings[l];if(h){var u=this.rows[l],c=u instanceof HeaderRow;u.height=h.height;u.allowMerging=h.allowMerging;u.visible=h.visible;u instanceof GroupRow&&(u.isCollapsed=!!h.isCollapsed);u.isSelected=!!h.isSelected;u.isReadOnly=c||!!h.readOnly}}this.autoGenerateColumns=i;this.rows.frozen=e.grid.rows.frozen;this.columns.frozen=e.grid.columns.frozen;this._isCopying=!1;if(t){this.cells.hostElement.style.overflow="hidden";this._setFlexSheetToDirty();this.endUpdate();if(this._addingSheet){clearTimeout(this._toRefresh);this._toRefresh=setTimeout((function(){o._setFlexSheetToDirty();o.invalidate()}),Control._REFRESH_INTERVAL);this._addingSheet=!1}}this._updateScrollPos=!0};FlexSheet.prototype.onUpdatedLayout=function(t){if(this._updateScrollPos){this.cells.hostElement.style.overflow="";this._updateScrollPos=!1;var o=this.selectedSheet;if(o){this.scrollPosition=o._scrollPosition;this._ptScrl=o._scrollPosition}}e.prototype.onUpdatedLayout.call(this,t)};FlexSheet.prototype._resetMappedColumns=function(e){var t,o,n=0;e._mappedColumns=null;if(e.collectionView){o=e.collectionView.sortDescriptions;for(;n<o.length;n++)if((t=e.columns.getColumn(o[n].property))&&t.dataMap){e._mappedColumns||(e._mappedColumns={});e._mappedColumns[t.binding]=t.dataMap}}};FlexSheet.prototype._loadFromWorkbook=function(e){var t=this;if(null!=e.sheets&&0!==e.sheets.length){this._loadingFromWorkbook=!0;this.beginUpdate();this.clear();this._reservedContent=e.reservedContent;if(e.colorThemes&&e.colorThemes.length>0)for(var o=0;o<this._colorThemes.length;o++)this._colorThemes[o]=e.colorThemes[o];o=0;for(var n=e.sheets.length;o<n;o++){this.addUnboundSheet("",0,0);var i=this.selectedSheet,l=i.grid,r=l.wj_sheetInfo={};FlexGridXlsxConverter.load(l,e,{sheetIndex:o,includeColumnHeaders:!1});i.name=r.name;i.visible=r.visible;i._styledCells=r.styledCells;if(r.mergedRanges){for(var s=0;s<r.mergedRanges.length;s++)i._mergedRanges[s]=r.mergedRanges[s];r.mergedRanges=i._mergedRanges}this._copyFrom(i);if(r.tables&&r.tables.length>0)for(var a=0;a<r.tables.length;a++)this._parseFromWorkbookTable(r.tables[a],i)}null!=e.activeWorksheet&&e.activeWorksheet>-1&&e.activeWorksheet<this.sheets.length?this.selectedSheetIndex=e.activeWorksheet:this.selectedSheetIndex=0;e.definedNames&&e.definedNames.forEach((function(e){t.definedNames.push(new DefinedName(t,e.name,e.value,e.sheetName))}));this.endUpdate();this._loadingFromWorkbook=!1;this.onLoaded()}};FlexSheet.prototype._saveToWorkbook=function(e){var t=this;if(0===this.sheets.length)throw"The flexsheet is empty.";for(var o=!(!e||!e.includeFormulaValues),n=e&&e.convertHtmlEntities,i=this._saveSheetToWorkbook(0,o,n),l=1;l<this.sheets.length;l++){var r=this._saveSheetToWorkbook(l,o,n);i._addWorkSheet(r.sheets[0],l)}i.sheets.forEach((function(e){return e.rightToLeft=t.rightToLeft}));i.activeWorksheet=this.selectedSheetIndex;i.reservedContent=this._reservedContent;for(l=0;l<this.definedNames.length;l++){var s=this.definedNames[l],a=new mXlsx.DefinedName;a.name=s.name;a.value=s.value;a.sheetName=s.sheetName;i.definedNames.push(a)}var h=this._colorThemes;if(h&&h.length>0)for(l=0;l<h.length;l++)i.colorThemes[l]=h[l];return i};FlexSheet.prototype._saveSheetToWorkbook=function(e,t,o){var n=this,i=this.sheets[e],l=i.grid.wj_sheetInfo;t&&(l.evaluateFormula=function(e){return n.evaluate(e,null,i)});if(this.selectedSheetIndex===e){i._storeRowSettings();this._copyRowsToSelectedSheet()}i._setRowSettings();if(i.tables.length>0){l.tables=[];for(var r=0;r<i.tables.length;r++)l.tables.push(this._parseToWorkbookTable(i.tables[r]))}var s=FlexGridXlsxConverter.save(i.grid,{sheetName:i.name,sheetVisible:i.visible,includeColumnHeaders:!1,convertHtmlEntities:o});this._checkTableHeaderRow(i.tables,s);l.evaluateFormula=null;return s};FlexSheet.prototype._mouseDown=function(e){var t,o,n=window.navigator.userAgent,i=this.hitTest(e);this.selectedSheet&&(this.selectedSheet._scrollPosition=this.scrollPosition);i.cellType!==CellType.None&&(this._isClicking=!0);if(this._dragable){this._isDragging=!0;this.createDropzone(e);this.onDraggingRowColumn(new DraggingRowColumnEventArgs(this.selection.clone(),this._draggingRow,e.shiftKey));e.preventDefault()}else if("crosshair"!==this.hostElement.style.cursor||null!=this._fillingMarker){if(this.selectionMode===SelectionMode.CellRange||this.selectionMode===SelectionMode.MultiRange){if(e.ctrlKey){if(!this._enableMulSel){this._enableMulSel=!0;0===this.selectedSheet.selectionRanges.length&&this.selectedSheet.selectionRanges.push(this.selection)}}else if(i.cellType!==CellType.None){if(this.selectedSheet)if(i.cellType===CellType.TopLeft){this.selectedSheet.selectionRanges.clear();this.selectedSheet._addSelection(new CellRange(0,0,this.rows.length-1,this.columns.length-1))}else 3===e.which&&this._isCellSelected(i.row,i.col)||this.selectedSheet.selectionRanges.clear();this._enableMulSel&&this.refresh(!1);this._enableMulSel=!1}}else{this._enableMulSel=!1;this.selectedSheet&&this.selectedSheet.selectionRanges.clear()}this._htDown=i;if(0!==this.rows.length&&0!==this.columns.length){n.match(/iPad/i)||n.match(/iPhone/i)||this._hideContextMenu();if(3!==e.which&&(this.selectionMode===SelectionMode.CellRange||this.selectionMode===SelectionMode.MultiRange)&&(i.cellType===CellType.ColumnHeader||i.cellType===CellType.None)&&!(i.col>-1&&this.columns[i.col].isSelected)&&hasClass(e.target,"wj-cell")&&!i.edgeRight){this._columnHeaderClicked=!0;o=this.itemsSource&&this.rows[0]&&!this.rows[0].isVisible?1:0;e.target.focus();if(e.shiftKey)this._multiSelectColumns(i);else{t=new CellRange(o,i.col,this.rows.length-1,i.col);if(3===e.which&&this.selection.contains(t))return;this.select(t)}this._eCt.children[o]&&this._eCt.children[o].children[i.col]&&this._eCt.children[o].children[i.col].focus()}}}else{this.finishEditing();this._fillingData=!0;this._fillingPoint=new Point(e.clientX-this.scrollPosition.x,e.clientY-this.scrollPosition.y);this._fillingSource=this.selection.clone();this._fillingMarker=document.createElement("div");setCss(this._fillingMarker,{position:"absolute",display:"none",border:"2px dashed"});this._root.appendChild(this._fillingMarker);this._fillingTooltip=new Tooltip;e.preventDefault()}};FlexSheet.prototype._mouseMove=function(e){var t,o=this.hitTest(e),n=this.selection.clone(),i=this.rows.length,l=this.columns.length,r=this.hostElement.style.cursor;if(0!==this.rows.length&&0!==this.columns.length)if(this._isDragging){this.hostElement.style.cursor="move";this.updateDropzone(e)}else if(!this._isClicking&&o.edgeBottom&&o.edgeRight&&o.row===n.bottomRow&&o.col===n.rightCol&&this.allowAutoFill)this.hostElement.style.cursor="crosshair";else if(this._fillingData){this.hostElement.style.cursor="crosshair";this._showFillMarker(e)}else{t=this.itemsSource?0===n.topRow||1===n.topRow:0===n.topRow;if(!this._isClicking&&n&&o.cellType!==CellType.None&&!this.itemsSource&&!this.isReadOnly&&this._enableDragDrop&&(!this._filter||!this._filter._isEditorOpened())){this._draggingColumn=t&&n.bottomRow===i-1;this._draggingRow=0===n.leftCol&&n.rightCol===l-1;if(o.cellType===CellType.Cell){this._draggingColumn&&((o.col===n.leftCol-1||o.col===n.rightCol)&&o.edgeRight||o.row===i-1&&o.edgeBottom)&&(r="move");this._draggingRow&&!this._containsGroupRows(n)&&((o.row===n.topRow-1||o.row===n.bottomRow)&&o.edgeBottom||o.col===l-1&&o.edgeRight)&&(r="move")}else o.cellType===CellType.ColumnHeader?o.edgeBottom&&(this._draggingColumn&&o.col>=n.leftCol&&o.col<=n.rightCol?r="move":this._draggingRow&&0===n.topRow&&(r="move")):o.cellType===CellType.RowHeader&&o.edgeRight&&(this._draggingColumn&&0===n.leftCol?r="move":this._draggingRow&&o.row>=n.topRow&&o.row<=n.bottomRow&&!this._containsGroupRows(n)&&(r="move"));this._dragable="move"===r;this.hostElement.style.cursor=r}if(this._htDown&&this._htDown.panel){o=new HitTestInfo(this._htDown.panel,e);this._multiSelectColumns(o);o.cellType===CellType.Cell&&this.scrollIntoView(o.row,o.col)}}else{this._dragable=!1;o.cellType===CellType.Cell&&(this.hostElement.style.cursor="default")}};FlexSheet.prototype._mouseUp=function(e){var t=this;try{if(this._isDragging){if(this._dropRange&&!this._draggingCells.equals(this._dropRange)){var o=new DroppingRowColumnEventArgs(this._dropRange.clone(),this._draggingRow),n=new CancelEventArgs;this.onBeginDroppingRowColumn(o);n.cancel=o.cancel;o.cancel||this._handleDropping(e);this.onEndDroppingRowColumn(n)}}else if(this._fillingData){var i=AutoFillOperation.CopyContent,l=this._fillingRange,r=this._fillingSource;this._orgCellSettings=null;if(this._fillingRange&&this._fillingRange.isValid){assert(this._canDoFillOperation(),"To do this, all the merged cells need be the same size.");r.leftCol===l.leftCol&&r.rightCol===l.rightCol?r.row!==r.row2&&(i=AutoFillOperation.FillSeries):r.col!==r.col2&&(i=AutoFillOperation.FillSeries);this._orgCellSettings=this._getCellSettingsForFill();var s=new _FillAction(this,this._fillingSource);this._undoStack._addAction(s);i=AutoFillOperation.CopyFormat|i;if(this._fillData(i))var a=this._root.appendChild(document.createElement("div")),h=new _SmartTag(a,this,i,{operationSelected:function(e){t._fillData(e.operation)},cancelled:function(){a.parentElement.removeChild(a);h.dispose();h=null;s.saveNewState();t.focus()}})}}}finally{this._draggingSingleRow=!1;if(this._isDragging){this._draggingCells=null;this._dropRange=null;this.destroyDropzone(e);this._isDragging=!1;this._draggingColumn=!1;this._draggingRow=!1}if(this._htDown&&this._htDown.cellType!==CellType.None&&this.selectedSheet){this.selection.isValid&&this.selectedSheet._addSelection(this.selection);this._enableMulSel=!1}if(this._fillingData){this._fillingData=!1;this._fillingPoint=null;this._fillingRange=null;this._root.removeChild(this._fillingMarker);this._fillingMarker=null;this._fillingTooltip.hide();this._fillingTooltip=null;this.hostElement.style.cursor="default"}this._isClicking=!1;this._columnHeaderClicked=!1;this._htDown=null}};FlexSheet.prototype._click=function(){var e=this,t=window.navigator.userAgent;t.match(/iPad/i)||t.match(/iPhone/i)||this._hideContextMenu();setTimeout((function(){e.hideFunctionList()}),200)};FlexSheet.prototype._touchStart=function(e){var t=this;hasClass(e.target,"wj-context-menu-item")||this._hideContextMenu();this._longClickTimer=setTimeout((function(){var o;if(t._isDescendant(t._divContainer,e.target)&&(o=t.hitTest(e))&&o.cellType!==CellType.None&&!t._resizing){if(o.cellType===CellType.TopLeft){t.selection=new CellRange(0,0,t.rows.length-1,t.columns.length-1);if(t.selectedSheet){t.selectedSheet.selectionRanges.clear();t.selectedSheet.selectionRanges.push(t.selection)}}t._contextMenu.show(null,new Point(e.pageX+10,e.pageY+10))}}),500)};FlexSheet.prototype._touchEnd=function(){clearTimeout(this._longClickTimer)};FlexSheet.prototype._keydown=function(e){if(!e.defaultPrevented){if((this._isDescendant(this.hostElement,e.target)||this.hostElement===e.target)&&!this._edtHdl.activeEditor&&!(e.target instanceof HTMLInputElement)&&this.selectedSheet&&(e.keyCode===Key.Delete||e.keyCode===Key.Back)){this._delSeletionContent(e);e.preventDefault()}var t=this._contextMenu.visible?this._contextMenu:this._tabHolder.sheetControl._contextMenu.visible?this._tabHolder.sheetControl._contextMenu:null;if(t){e.keyCode===Key.Down&&t.moveToNext();e.keyCode===Key.Up&&t.moveToPrev();e.keyCode===Key.Home&&t.moveToFirst();e.keyCode===Key.End&&t.moveToLast();e.keyCode===Key.Enter&&t.handleContextMenu();e.preventDefault()}}};FlexSheet.prototype.createDropzone=function(e){var t=new Tooltip({gap:0}),o=document.createElement("div");o.style.position="absolute";o.style.display="block";o.style.borderStyle="dotted";o.style.cursor="move";o.style.zIndex="1";o.style.opacity="0.5";this.dropzoneMarker=o;this._draggingTooltip=t;this._draggingCells=this.selection;this._root.appendChild(o);this.selectedSheet&&this.selectedSheet.selectionRanges.clear()};FlexSheet.prototype.updateDropzoneArea=function(e){var t=this._draggingColumn,o=this._root,n=this.dropzoneMarker,i={col:0,row:0};t?i.col=e.hit<this.dropzonePrevHit?e.start:e.end:i.row=e.hit<this.dropzonePrevHit?e.start:e.end;this.scrollIntoView(i.row,i.col);var l,r=t?{start:this.cells.getCellBoundingRect(0,e.start),hit:this.cells.getCellBoundingRect(0,e.hit),end:this.cells.getCellBoundingRect(0,e.end)}:{start:this.cells.getCellBoundingRect(e.start,0),hit:this.cells.getCellBoundingRect(e.hit,0),end:this.cells.getCellBoundingRect(e.end,0)},s={};if(t){l=FlexSheet.convertNumberToAlpha(e.start)+" : "+FlexSheet.convertNumberToAlpha(e.end);s={top:this._eCHdr.offsetHeight,left:o.scrollLeft,height:this.cells.height};r.hit.top=r.hit.bottom+o.scrollTop+8;if(this.rightToLeft){s.left=r.end.left-this.controlRect.left+o.scrollLeft;s.width=r.start.right-r.end.left}else{s.left+=r.start.left-this.controlRect.left;s.width=r.end.right-r.start.left}}else{l=e.start+1+" : "+(e.end+1);s={top:r.start.top-this.controlRect.top+o.scrollTop,width:this.cells.width,height:r.end.bottom-r.start.top};r.hit.top=r.hit.bottom;this.rightToLeft?s.right=this._eRHdr.offsetWidth:s.left=this._eRHdr.offsetWidth}if(this._dropRange)if(t){this._dropRange.col=e.start;this._dropRange.col2=e.end}else{this._dropRange.row=e.start;this._dropRange.row2=e.end}else this._dropRange=t?new CellRange(0,e.start,this.rows.length-1,e.end):new CellRange(e.start,0,e.end,this.columns.length-1);setCss(n,s);this._draggingTooltip.show(this.hostElement,l,r.hit);this.dropzonePrevHit=e.hit};FlexSheet.prototype.updateDropzone=function(e){var t=this,o=new HitTestInfo(this.cells,e),n=this.rightToLeft,i=this._draggingColumn,l=i?o.col:o.row,r=this.dropzonePrevHit,s=this.selection,a=i?this.columns.length:this.rows.length;if(-1!==l&&l!==r){this.dropzone||(this.dropzone=i?{left:l-s.leftCol,right:s.rightCol-l}:{left:l-s.topRow,right:s.bottomRow-l});var h={start:l-this.dropzone.left,hit:l,end:l+this.dropzone.right};if(!(h.start<0||h.end>a-1)){var u,c=i?n?{start:this.cells.getCellBoundingRect(0,h.end),end:this.cells.getCellBoundingRect(0,h.start)}:{start:this.cells.getCellBoundingRect(0,h.start),end:this.cells.getCellBoundingRect(0,h.end)}:{start:this.cells.getCellBoundingRect(h.start,0),end:this.cells.getCellBoundingRect(h.end,0)},d={top:this.controlRect.top+this._eCHdr.offsetHeight,right:this.controlRect.right,bottom:this.controlRect.bottom,left:this.controlRect.left};if(i){n?d.right-=this._eRHdr.offsetWidth:d.left+=this._eRHdr.offsetWidth;(d.left>=c.start.right||d.right<=c.end.left)&&(u=!0)}else(d.top>=c.start.bottom||d.bottom<=c.end.top)&&(u=!0);clearTimeout(this.dropzoneTimeout);u?this.dropzoneTimeout=setTimeout((function(){t.updateDropzoneArea(h);t.updateDropzone(e)}),100):this.updateDropzoneArea(h)}}};FlexSheet.prototype.destroyDropzone=function(e){if(this.dropzoneMarker){this._root.removeChild(this.dropzoneMarker);this.dropzoneMarker=null}if(this.dropzoneTimeout){clearTimeout(this.dropzoneTimeout);this.dropzoneTimeout=null}if(this._draggingTooltip){this._draggingTooltip.hide();this._draggingTooltip=null}this.dropzone=null;this.dropzonePrevHit=-1};FlexSheet.prototype._showFillMarker=function(e){var t=new HitTestInfo(this.cells,e);if(t.row>-1&&t.col>-1){var o=e.clientX-this.scrollPosition.x-this._fillingPoint.x,n=e.clientY-this.scrollPosition.y-this._fillingPoint.y,i=void 0,l=void 0,r=void 0,s=void 0;if(Math.abs(o)>=Math.abs(n)){i=this._fillingSource.topRow;r=this._fillingSource.bottomRow;l=o>=0?this._fillingSource.leftCol:t.col;s=o>=0?t.col:this._fillingSource.rightCol}else{i=n>=0?this._fillingSource.topRow:t.row;r=n>=0?t.row:this._fillingSource.bottomRow;l=this._fillingSource.leftCol;s=this._fillingSource.rightCol}this._fillingRange=new CellRange(i,l,r,s);this._updateFillingMarquee();this.scrollIntoView(t.row,t.col);this._showFillTooltip()}};FlexSheet.prototype._updateMarquee=function(){e.prototype._updateMarquee.call(this);this._updateFillingMarquee()};FlexSheet.prototype._updateFillingMarquee=function(){var e=this._fillingMarker,t=this._fillingRange;if(e&&t){var o=this.cells.getCellBoundingRect(t.row,t.col,!0),n=this.cells.getCellBoundingRect(t.row2,t.col2,!0);if(this.rows.frozen){var i=Math.min(this.rows.length,this.rows.frozen),l=this.cells.getCellBoundingRect(i-1,0,!0);t.topRow>=i&&o.top<l.bottom&&(o.top=l.bottom);t.bottomRow>=i&&n.bottom<l.bottom&&(n.height=l.bottom-n.top)}if(this.columns.frozen){var r=Math.min(this.columns.length,this.columns.frozen);l=this.cells.getCellBoundingRect(0,r-1,!0);if(this.rightToLeft){t.leftCol>=r&&o.right>l.left&&(o.left=l.left-o.width);t.rightCol>=r&&n.left>l.left&&(n.left=l.left)}else{t.leftCol>=r&&o.left<l.right&&(o.left=l.right);t.rightCol>=r&&n.right<l.right&&(n.width=l.right-n.left)}}var s=this.cells.hostElement;setCss(e,{left:o.left+s.offsetLeft,top:o.top+s.offsetTop,width:n.right-o.left,height:n.bottom-o.top,display:"",zIndex:this.rows.frozen||this.columns.frozen?"3":""})}};FlexSheet.prototype._showFillTooltip=function(){var e,t,o,n,i,l,r,s,a,h,u,c,d=this._fillingSource,_=this._fillingRange;this._fillingTooltip.hide();if(!_.equals(d)&&!d.contains(_)){if(t=d.leftCol===_.leftCol&&d.rightCol===_.rightCol){if(_.bottomRow>d.bottomRow){(e=this.cells.getCellBoundingRect(_.bottomRow,_.rightCol)).top=e.bottom+10;o=_.bottomRow-d.topRow}else{(e=this.cells.getCellBoundingRect(_.topRow,_.rightCol)).top+=10;o=_.topRow-d.topRow}e.left=e.right;(n=o%d.rowSpan)<0&&(n+=d.rowSpan);d.row===d.row2&&(i=!0);a=this.selectedSheet.getCellStyle(d.topRow+n,d.leftCol);h=this.getMergedRange(this.cells,d.topRow+n,d.leftCol);u=this.columns[d.leftCol];c=a&&a.format?a.format:u.format;if(i)s=_isFormula(s=this.getCellData(h?h.topRow:d.topRow+n,d.leftCol,!1))?"":Globalize.format(s,c);else{l=this.getCellData(d.topRow+n,d.leftCol,!1);if(isNumber(l)||isDate(l))if(r=this._getFillSeries(t,0,n)){s=this._getFillData(n,o,d,t,r,!0);s=Globalize.format(s,c)}else s="";else _isFormula(s=l)&&(s="")}}else{if(_.rightCol>d.rightCol){e=this.cells.getCellBoundingRect(_.bottomRow,_.rightCol);o=_.rightCol-d.leftCol}else{e=this.cells.getCellBoundingRect(_.bottomRow,_.leftCol);o=_.leftCol-d.leftCol}e.top=e.bottom+10;(n=o%d.columnSpan)<0&&(n+=d.columnSpan);d.col===d.col2&&(i=!0);a=this.selectedSheet.getCellStyle(d.topRow,d.leftCol+n);h=this.getMergedRange(this.cells,d.topRow,d.leftCol+n);u=this.columns[d.leftCol+n];c=a&&a.format?a.format:u.format;if(i)s=_isFormula(s=this.getCellData(d.topRow,h?h.leftCol:d.leftCol+n,!1))?"":Globalize.format(s,c);else{l=this.getCellData(d.topRow,d.leftCol+n,!1);if(isNumber(l)||isDate(l))if(r=this._getFillSeries(t,0,n)){s=this._getFillData(n,o,d,t,r,!0);s=Globalize.format(s,c)}else s="";else _isFormula(s=l)&&(s="")}}e.top+=this.cells.hostElement.offsetTop;this._fillingTooltip.show(this.hostElement,s,e)}};FlexSheet.prototype._selections=function(){var e=[];if(!this.selectedSheet)return e;if(this.selectionMode==SelectionMode.ListBox)for(var t=0,o=this.rows.length,n=this.columns.length-1;t<o;t++)this.rows[t].isSelected&&e.push(new CellRange(t,0,t,n));else e=this.selectedSheet.selectionRanges.slice();return e.length?e:[this.selection]};FlexSheet.prototype._isCellSelected=function(e,t){return this._selections().some((function(o){return o.contains(e,t)}))};FlexSheet.prototype._isColumnSelected=function(e){var t=this;return this._selections().some((function(o){return o.containsColumn(e)&&0===o.row&&o.row2===t.rows.length-1}))};FlexSheet.prototype._isRowSelected=function(e){var t=this;return this._selections().some((function(o){return o.containsRow(e)&&0===o.col&&o.col2===t.columns.length-1}))};FlexSheet.prototype._handleDropping=function(e){var t,o,n,i,l,r,s;if(this.selectedSheet&&this._draggingCells&&this._dropRange&&!this._containsMergedCells(this._draggingCells)&&!this._containsMergedCells(this._dropRange)){this._clearCalcEngine();if(this._draggingColumn&&this._draggingCells.leftCol>this._dropRange.leftCol||this._draggingRow&&this._draggingCells.topRow>this._dropRange.topRow)if(e.shiftKey){if(!this._allowExchangeCells(this._draggingRow,!0)){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.");return}if(this._draggingColumn){i=this._dropRange.leftCol;for(o=this._draggingCells.leftCol;o<=this._draggingCells.rightCol;o++){this.columns.moveElement(o,i);i++}this._exchangeTableColumns(!0)}else if(this._draggingRow){n=this._dropRange.topRow;for(t=this._draggingCells.topRow;t<=this._draggingCells.bottomRow;t++){this.rows.moveElement(t,n);n++}}this._exchangeCellStyle(!0)}else{this.undoStack.stackSize>0&&(l=new _MoveCellsAction(this,this._draggingCells,this._dropRange,e.ctrlKey));n=this._dropRange.topRow;for(t=this._draggingCells.topRow;t<=this._draggingCells.bottomRow;t++){i=this._dropRange.leftCol;for(o=this._draggingCells.leftCol;o<=this._draggingCells.rightCol;o++){this._moveCellContent(t,o,n,i,e.ctrlKey);if(this._draggingColumn&&n===this._dropRange.topRow){this.columns[i].dataType=this.columns[o].dataType?this.columns[o].dataType:DataType.Object;this.columns[i].align=this.columns[o].align;this.columns[i].format=this.columns[o].format;if(!e.ctrlKey){this.columns[o].dataType=DataType.Object;this.columns[o].align=null;this.columns[o].format=null}}i++}n++}if(this._draggingColumn&&!e.ctrlKey){i=this._dropRange.leftCol;for(o=this._draggingCells.leftCol;o<=this._draggingCells.rightCol;o++){this._updateColumnFiler(o,i);i++}}}else if(this._draggingColumn&&this._draggingCells.leftCol<this._dropRange.leftCol||this._draggingRow&&this._draggingCells.topRow<this._dropRange.topRow)if(e.shiftKey){if(!this._allowExchangeCells(this._draggingRow,!1)){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.");return}if(this._draggingColumn){i=this._dropRange.rightCol;for(o=this._draggingCells.rightCol;o>=this._draggingCells.leftCol;o--){this.columns.moveElement(o,i);i--}this._exchangeTableColumns(!1)}else if(this._draggingRow){n=this._dropRange.bottomRow;for(t=this._draggingCells.bottomRow;t>=this._draggingCells.topRow;t--){this.rows.moveElement(t,n);n--}}this._exchangeCellStyle(!1)}else{this.undoStack.stackSize>0&&(l=new _MoveCellsAction(this,this._draggingCells,this._dropRange,e.ctrlKey));n=this._dropRange.bottomRow;for(t=this._draggingCells.bottomRow;t>=this._draggingCells.topRow;t--){i=this._dropRange.rightCol;for(o=this._draggingCells.rightCol;o>=this._draggingCells.leftCol;o--){this._moveCellContent(t,o,n,i,e.ctrlKey);if(this._draggingColumn&&n===this._dropRange.bottomRow){this.columns[i].dataType=this.columns[o].dataType?this.columns[o].dataType:DataType.Object;this.columns[i].align=this.columns[o].align;this.columns[i].format=this.columns[o].format;if(!e.ctrlKey){this.columns[o].dataType=DataType.Object;this.columns[o].align=null;this.columns[o].format=null}}i--}n--}if(this._draggingColumn&&!e.ctrlKey){i=this._dropRange.rightCol;for(o=this._draggingCells.rightCol;o>=this._draggingCells.leftCol;o--){this._updateColumnFiler(o,i);i--}}}if(!e.ctrlKey){r=this._updateFormulaForDropping(e.shiftKey);s=this._updateNamedRangesForDropping(e.shiftKey)}if(l&&l.saveNewState()){l._affectedFormulas=r;l._affectedDefinedNameVals=s;this._undoStack._addAction(l)}if(this._undoStack._pendingAction){this._undoStack._pendingAction._affectedFormulas=r;this._undoStack._pendingAction._affectedDefinedNameVals=s}this.select(this._dropRange);this.selectedSheet._addSelection(this.selection);this.hostElement.focus()}};FlexSheet.prototype._moveCellContent=function(e,t,o,n,i){var l,r=this.getCellData(e,t,!1),s=e*this.columns.length+t,a=o*this.columns.length+n,h=this.selectedSheet._styledCells[s],u=!0,c=this.selectedSheet.findTable(o,n);if(c&&c._isHeaderRow(o)){var d=c.getRange(),_=c.getColumns(),f=n-d.leftCol;l=_[f].name;null==r||""===r?u=!1:_[f].name=r+""}if(u){if(i&&_isFormula(r)&&a-s!=0)try{var g=this._calcEngine.parse(r);g._moveCellRangeExp(this.selectedSheetIndex,new CellRange(e,t),new CellRange(o,n),!1,!0)&&(r="="+g._getStringExpression())}catch(e){}this.setCellData(o,n,r)}else u=!0;h?this.selectedSheet._styledCells[a]=this._cloneObject(h):delete this.selectedSheet._styledCells[a];if(i){if(p=this.selectedSheet.findTable(e,t)){w=p._getTableRange();if(p===c&&e===o&&p._isHeaderRow(e)){m=t-w.leftCol;p._updateColumnName(m,r)}}}else{delete this.selectedSheet._styledCells[s];var p;if(p=this.selectedSheet.findTable(e,t)){var w=p._getTableRange();if(p===c&&e===o&&p._isHeaderRow(e)){var m=t-w.leftCol;p._updateColumnName(m,l);return}if(p.showHeaderRow&&e===w.topRow)return}this.setCellData(e,t,null)}};FlexSheet.prototype._allowExchangeCells=function(e,t){for(var o=this.selectedSheet.tables,n=0;n<o.length;n++){var i=o[n],l=void 0,r=void 0,s=void 0;if(e){l=i.getRange(TableSection.Data);this._draggingCells.rowSpan;r=new CellRange(this._draggingCells.topRow,l.leftCol,this._draggingCells.bottomRow,l.rightCol);s=new CellRange(this._dropRange.topRow,l.leftCol,this._dropRange.bottomRow,l.rightCol)}else{l=i.getRange();this._draggingCells.columnSpan;r=new CellRange(l.topRow,this._draggingCells.leftCol,l.bottomRow,this._draggingCells.rightCol);s=new CellRange(l.topRow,this._dropRange.leftCol,l.bottomRow,this._dropRange.rightCol)}if(l.intersects(r)&&!l.contains(r)||l.intersects(s)&&!l.contains(s)||l.contains(r)&&!l.contains(s)||!l.contains(r)&&l.contains(s))return!1}return!0};FlexSheet.prototype._exchangeTableColumns=function(e){for(var t=this.selectedSheet.tables,o=0;o<t.length;o++){var n=t[o],i=n.getRange();if(i.leftCol<=this._draggingCells.leftCol&&i.rightCol>=this._draggingCells.rightCol)for(var l=(e?this._draggingCells.leftCol:this._draggingCells.rightCol)-i.leftCol,r=(e?this._dropRange.leftCol:this._dropRange.rightCol)-i.leftCol,s=0;s<this._draggingCells.columnSpan;s++){n._moveColumns(l,r);if(e){l++;r++}else{l--;r--}}}};FlexSheet.prototype._exchangeCellStyle=function(e){for(var t=[],o=this._draggingCells.topRow;o<=this._draggingCells.bottomRow;o++)for(var n=this._draggingCells.leftCol;n<=this._draggingCells.rightCol;n++){var i=o*this.columns.length+n;if(this.selectedSheet._styledCells[i]){t.push(this._cloneObject(this.selectedSheet._styledCells[i]));delete this.selectedSheet._styledCells[i]}else t.push(void 0)}if(e){if(this._draggingColumn){var l=this._draggingCells.rightCol-this._draggingCells.leftCol+1;for(n=this._draggingCells.leftCol-1;n>=this._dropRange.leftCol;n--)for(o=0;o<this.rows.length;o++){i=o*this.columns.length+n;var r=o*this.columns.length+n+l;if(this.selectedSheet._styledCells[i]){this.selectedSheet._styledCells[r]=this._cloneObject(this.selectedSheet._styledCells[i]);delete this.selectedSheet._styledCells[i]}else delete this.selectedSheet._styledCells[r]}}else if(this._draggingRow)for(l=this._draggingCells.bottomRow-this._draggingCells.topRow+1,o=this._draggingCells.topRow-1;o>=this._dropRange.topRow;o--)for(n=0;n<this.columns.length;n++){i=o*this.columns.length+n,r=(o+l)*this.columns.length+n;if(this.selectedSheet._styledCells[i]){this.selectedSheet._styledCells[r]=this._cloneObject(this.selectedSheet._styledCells[i]);delete this.selectedSheet._styledCells[i]}else delete this.selectedSheet._styledCells[r]}}else if(this._draggingColumn)for(l=this._draggingCells.rightCol-this._draggingCells.leftCol+1,n=this._draggingCells.rightCol+1;n<=this._dropRange.rightCol;n++)for(o=0;o<this.rows.length;o++){i=o*this.columns.length+n,r=o*this.columns.length+n-l;if(this.selectedSheet._styledCells[i]){this.selectedSheet._styledCells[r]=this._cloneObject(this.selectedSheet._styledCells[i]);delete this.selectedSheet._styledCells[i]}else delete this.selectedSheet._styledCells[r]}else if(this._draggingRow)for(l=this._draggingCells.bottomRow-this._draggingCells.topRow+1,o=this._draggingCells.bottomRow+1;o<=this._dropRange.bottomRow;o++)for(n=0;n<this.columns.length;n++){i=o*this.columns.length+n,r=(o-l)*this.columns.length+n;if(this.selectedSheet._styledCells[i]){this.selectedSheet._styledCells[r]=this._cloneObject(this.selectedSheet._styledCells[i]);delete this.selectedSheet._styledCells[i]}else delete this.selectedSheet._styledCells[r]}o=this._dropRange.topRow;for(var s=0;o<=this._dropRange.bottomRow;o++)for(n=this._dropRange.leftCol;n<=this._dropRange.rightCol;n++){i=o*this.columns.length+n;t[s]?this.selectedSheet._styledCells[i]=t[s]:delete this.selectedSheet._styledCells[i];s++}};FlexSheet.prototype._containsMergedCells=function(e,t){if(!(t=t||this.selectedSheet))return!1;for(var o=0;o<t._mergedRanges.length;o++){var n=t._mergedRanges[o];if(e.intersects(n))return!0}return!1};FlexSheet.prototype._multiSelectColumns=function(e){if(e&&this._columnHeaderClicked){var t=new CellRange(e.row,e.col);t.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)}};FlexSheet.prototype._cumulativeOffset=function(e){var t=0,o=0;do{t+=e.offsetTop||0;o+=e.offsetLeft||0;e=e.offsetParent}while(e);return new Point(o,t)};FlexSheet.prototype._cumulativeScrollOffset=function(e){var t=0,o=0;do{t+=e.scrollTop||0;o+=e.scrollLeft||0;e=e.offsetParent}while(e&&!(e instanceof HTMLBodyElement));t+=document.body.scrollTop||document.documentElement.scrollTop;o+=document.body.scrollLeft||document.documentElement.scrollLeft;return new Point(o,t)};FlexSheet.prototype._checkHitWithinSelection=function(e){if(null!=e&&e.cellType===CellType.Cell){var t=this.getMergedRange(this.cells,e.row,e.col);if(t&&t.contains(this.selection))return!0;if(this.selection.row===e.row&&this.selection.col===e.col)return!0}return!1};FlexSheet.prototype._clearForEmptySheet=function(e){if(this.selectedSheet&&0===this[e].length&&!0!==this._isCopying&&!0!==this._isUndoing&&!0!==this._isSorting){this.selectedSheet._mergedRanges.length=0;this.selectedSheet._styledCells=null;this._isDeletingRows||this.select(new CellRange)}};FlexSheet.prototype._containsGroupRows=function(e){for(var t=e.topRow;t<=e.bottomRow;t++){if(this.rows[t]instanceof GroupRow)return!0}return!1};FlexSheet.prototype._delSeletionContent=function(e){if(!this.isReadOnly)if(this.allowDelete&&this.selection.isValid&&0===this.selection.leftCol&&this.selection.rightCol===this.columns.length-1)this.deleteRows(this._selections());else{var t,o=this.editableCollectionView,n=!1,i=!1,l=this.scrollPosition;this.beginUpdate();var r=new _EditAction(this);this.undoStack.stackSize>0&&(r=new _EditAction(this));for(var s=this._selections(),a=0;a<s.length;a++){t=s[a];var h=new CellRange,u=new CellEditEndingEventArgs(this.cells,h,e),c=this.selectedSheet.tables.length;if(c>0)for(var d=c-1;d>=0;d--){var _=this.selectedSheet.tables[d];if(t.contains(_.getRange())){r&&r._storeDeletedTables(_);this.selectedSheet.tables.remove(_)}}for(var f=t.topRow;f<=t.bottomRow;f++){var g=this.rows[f];if(g&&!g.isReadOnly&&(g.visible||this.selectedSheet._freezeHiddenRows&&this.selectedSheet._freezeHiddenRows[f]))for(var p=t.leftCol;p<=t.rightCol;p++){var w=this._getBindingColumn(this.cells,f,this.columns[p]);if(w&&!w.isReadOnly&&(!1===w.isRequired||null==w.isRequired&&w.dataType==DataType.String)&&(w.visible||this.selectedSheet._freezeHiddenCols&&this.selectedSheet._freezeHiddenCols[p])){var m=this.getCellData(f,p,!1);if(null!=m){h.setRange(f,p);u.cancel=!1;u.previousData=m;if(this.onBeginningEdit(u)){if(o){if(!n){n=!0;o.beginUpdate()}o.editItem(g.dataItem);this._edtHdl._edItem=o.currentEditItem}this.setCellData(f,p,void 0,!1);i=!0;this.onCellEditEnding(u);this.onCellEditEnded(u)}}}}}if(n){o.endUpdate(!0);o._pendingRefresh=!1;t.rowSpan>1&&o.commitEdit()}}if(i&&r){r.saveNewState();this._undoStack._addAction(r)}this.selection=t;this.scrollPosition=l;this.endUpdate()}};FlexSheet.prototype._updateAffectedFormula=function(e,t,o,n,i){var l=[],r=[],s=this.selection.clone();this.selectedSheet._storeRowSettings();this.beginUpdate();for(var a=0;a<this.sheets.length;a++)for(var h=this.sheets[a],u=h.grid,c=0;c<u.rows.length;c++)for(var d=0;d<u.columns.length;d++){var _=u.getCellData(c,d,!1);if(_isFormula(_)){var f=this._updateCellRef(_,a,e,t,o,n,i);if(f){l.push({sheet:h,point:new Point(c,d),formula:_});var g=c,p=d;if(a===this.selectedSheetIndex){n?c>=e&&(o?g+=t:g-=t):d>=e&&(o?p+=t:p-=t);if(!o&&(n&&c<=e&&c>=e-t+1||!n&&d<=e&&d>=e-t+1))continue}u.setCellData(c,d,f,!1);r.push({sheet:h,point:new Point(g,p),formula:f})}}}this.select(s,!1);this.endUpdate();return{oldFormulas:l,newFormulas:r}};FlexSheet.prototype._updateAffectedNamedRanges=function(e,t,o,n){for(var i=this,l=[],r=[],s=[],a=0;a<this.definedNames.length;a++){var h=this.definedNames[a],u=h.value;if(u&&isString(u)){var c=this._updateCellRef(u,this.selectedSheetIndex,e,t,o,n);if("object"==typeof c&&null!==c)s.push(c.name);else if(c){l.push({name:h.name,value:u});h.value=c;r.push({name:h.name,value:c})}}}s.forEach((function(e){return i.definedNames.remove(i.definedNames.find((function(t){return t.name==e})))}));return{oldDefinedNameVals:l,newDefinedNameVals:r}};FlexSheet.prototype._updateFormulaBoundaryForEditingCell=function(e,t){var o=[],n=[];this.beginUpdate();for(var i=e;i<this.rows.length;i++){if(_isFormula(r=this.getCellData(i,t,!1))){if(s=this._updateCellBoundary(r,e,t)){o.push({point:new Point(i,t),formula:r});this.setCellData(i,t,s,!1);n.push({point:new Point(i,t),formula:s})}}}for(var l=t;l<this.columns.length;l++){var r;if(_isFormula(r=this.getCellData(e,l,!1))){var s;if(s=this._updateCellBoundary(r,e,t)){o.push({point:new Point(e,l),formula:r});this.setCellData(e,l,s,!1);n.push({point:new Point(e,l),formula:s})}}}this.endUpdate();return{oldFormulas:o,newFormulas:n}};FlexSheet.prototype._updateColumnFiler=function(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)};FlexSheet.prototype._isDescendant=function(e,t){for(var o=t.parentNode;null!=o;){if(o===e)return!0;o=o.parentNode}return!1};FlexSheet.prototype._clearCalcEngine=function(){this._calcEngine.clearExpressionCache()};FlexSheet.prototype._getRangeString=function(e,t,o){void 0===o&&(o=!0);var n,i,l,r,s,a="",h=!0,u=t&&t!==this.selectedSheet?t.grid:this;if(isArray(e))if(e.length>1){if(this._isMultipleRowsSelected(e,t)){a="";for(i=0;i<e.length;i++){a&&(a+="\n");a+=this._getRangeString(e[i],t)}return a}if(!this._isMultipleColumnsSelected(e,t))return"";a="";for(n=0,h=!0;n<u.rows.length;n++){h||(a+="\n");h=!1;for(i=0,f=!0;i<e.length;i++){(l=e[i].clone()).row=l.row2=n;f||(a+="\t");f=!1;a+=this._getRangeString(e[i],t)}return a}}else{s=e[0];switch(this.selectionMode){case SelectionMode.Row:case SelectionMode.RowRange:s.col=0;s.col2=t.grid.columns.length-1;break;case SelectionMode.ListBox:s.col=0;s.col2=t.grid.columns.length-1;for(var c=0;c<t.grid.rows.length;c++)if(t.grid.rows[c].isSelected&&t.grid.rows[c].isVisible){s.row=s.row2=c;a&&(a+="\n");a+=this._getRangeString(s,t)}return a}}for(var d=(s=asType(isArray(e)?e[0]:e,CellRange)).topRow;d<=s.bottomRow;d++)if(u.rows[d]&&u.rows[d].isVisible){h||(a+="\n");h=!1;for(var _=s.leftCol,f=!0;_<=s.rightCol;_++)if(u.columns[_]&&u.columns[_].isVisible){f||(a+="\t");f=!1;var g=this._getCellStyle(d,_,t),p=g?g.format:"",w=u.columns[_];if(o){_isFormula(r=u.getCellData(d,_,!1))&&(r=this._evaluate(r,null,t,d,_));r=this._formatEvaluatedResult(r,w,p)}else{r=u.getCellData(d,_,!1);isDate(r)&&(r=Globalize.format(r,p||w.format));w.dataMap&&(r=w.dataMap.getDisplayValue(r))}(r=(r=null==r?"":r.toString()).replace(/\t/g," ")).indexOf("\n")>-1&&(r='"'+r.replace(/"/g,'""')+'"');a+=r}}return a};FlexSheet.prototype._getSelectionForListBoxMode=function(e){for(var t,o=0;o<e.rows.length;o++)e.rows[o].isSelected&&(t?t.row2=o:t=new CellRange(o,0,o,e.columns.length-1));return t};FlexSheet.prototype._containsRandFormula=function(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 l=n.leftCol;l<=n.rightCol&&l<t.grid.columns.length;l++){var r=t.grid.getCellData(i,l,!1);if(_isFormula(r)&&-1!==r.search(/rand/i))return!0}return!1};FlexSheet.prototype._isMultipleRowsSelected=function(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 l=1;l<i.length;l++)if((n=i[l]).leftCol!==o.leftCol||n.rightCol!==o.rightCol)return!1;return!0};FlexSheet.prototype._isMultipleColumnsSelected=function(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 l=0;l<i.length;l++)if((n=i[l]).topRow!==o.topRow||n.bottomRow!==o.bottomRow)return!1;return!0};FlexSheet.prototype._postSetClipStringProcess=function(e,t,o,n,i,l,r,s,a){var h,u=new CellRangeEventArgs(this.cells,new CellRange(o+i,n),t);if(this.onPastingCell(u)){if(l>=0&&r>=0&&this._copiedSheet&&(h=this._copiedSheet._getMergedRange(l,r))&&h.topRow===l&&h.leftCol===r){var c=o+h.rowSpan-1;c=c<this.rows.length?c:this.rows.length-1;var d=n+h.columnSpan-1;d=d<this.columns.length?d:this.columns.length-1;for(var _=new CellRange(o,n,c,d),f=_.topRow;f<=_.bottomRow;f++)for(var g=_.leftCol;g<=_.rightCol;g++){var p=this.getMergedRange(this.cells,f,g);if(null!=p&&!p.equals(_)){console.error("We can't paste the merged cell to another merged cell.");return!1}}this.mergeRange(new CellRange(o,n,c,d),!0)}s&&s.editItem(e);var w=this.cells.setCellData(o,n,a&&a.format?new _ValWithFormat(u.data,a.format):u.data);if(w){if(isString(u.data)&&"\n"!==u.data){var m=u.data.match(/\n/g);if(m&&m.length>0){a?a.whiteSpace="pre":a={whiteSpace:"pre"};this.rows[o].height=this.rows.defaultSize*(m.length+1)}}var C=o*this.columns.length+n;this.selectedSheet._styledCells[C]=a?this._cloneObject(a):void 0;this.onPastedCell(u)}}return w};FlexSheet.prototype._delCutData=function(e,t){for(var o,n=this._copiedSheet===this.selectedSheet?this:this._copiedSheet.grid,i=this.selection,l=(o=this.selectionMode===SelectionMode.ListBox?this._getSelectionForListBoxMode(n):this._copiedRanges[0]).topRow;l<=o.bottomRow;l++)if(null!=n.rows[l]&&!n.rows[l].isReadOnly)for(var r=o.leftCol;r<=o.rightCol;r++)if(this._copiedSheet!==this.selectedSheet||l<i.topRow||l>i.topRow+e-1||r<i.leftCol||r>i.leftCol+t-1||n.rows[i.topRow]instanceof _NewRowTemplate){var s=n._getBindingColumn(n.cells,l,n.columns[r]);s.isReadOnly||0!=s.isRequired&&(null!=s.isRequired||s.dataType!=DataType.String)||n.getCellData(l,r,!0)&&(s.dataMap||n.rows[l].dataMap?n.setCellData(l,r,null,!0):n.setCellData(l,r,"",!0))}};FlexSheet.prototype._containsMultiLineText=function(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};FlexSheet.prototype._sortByRow=function(e,t){return e.topRow>t.topRow?1:e.topRow<t.topRow?-1:0};FlexSheet.prototype._sortByColumn=function(e,t){return e.leftCol>t.leftCol?1:e.leftCol<t.leftCol?-1:0};FlexSheet.prototype._setFlexSheetToDirty=function(){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};FlexSheet.convertNumberToAlpha=function(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};FlexSheet.prototype._updateFormulaForReorderingRows=function(e,t,o){void 0===o&&(o=!1);var n,i,l=o?e-t:t-e;this.beginUpdate();for(var r=0;r<this.columns.length;r++)if(_isFormula(n=this.getCellData(t,r,!1))&&0!==l){try{i=this._calcEngine.parse(n)}catch(e){continue}i._updateCellRangeExpForReorderingRows(l)&&this.setCellData(t,r,"="+i._getStringExpression())}this.endUpdate()};FlexSheet.prototype._updateFormulaForDropping=function(e){var t,o,n,i,l,r,s,a,h,u=[],c=[];this.beginUpdate();for(n=0;n<this.sheets.length;n++){o=(t=this.sheets[n]).grid;for(i=0;i<o.rows.length;i++)for(r=0;r<o.columns.length;r++)if(_isFormula(a=o.getCellData(i,r,!1))&&(h=this._updateCellRefForDropping(a,n,e))){o.setCellData(i,r,h,!1);if(e&&n===this.selectedSheetIndex){l=o.rows[i];s=o.columns[r];u.push({sheet:t,row:l,column:s,formula:a});c.push({sheet:t,row:l,column:s,formula:h})}else{u.push({sheet:t,point:new Point(i,r),formula:a});c.push({sheet:t,point:new Point(i,r),formula:h})}}}this.endUpdate();return{oldFormulas:u,newFormulas:c}};FlexSheet.prototype._updateNamedRangesForDropping=function(e){var t,o,n,i,l=[],r=[];for(t=0;t<this.definedNames.length;t++)if((n=(o=this.definedNames[t]).value)&&isString(n)&&(i=this._updateCellRefForDropping(n,this.selectedSheetIndex,e))){l.push({name:o.name,value:n});o.value=i;r.push({name:o.name,value:i})}return{oldDefinedNameVals:l,newDefinedNameVals:r}};FlexSheet.prototype._updateCellRefForDropping=function(e,t,o){void 0===o&&(o=!1);var n;try{n=this._calcEngine.parse(e)}catch(e){return null}return n._moveCellRangeExp(t,this._draggingCells,this._dropRange,o)?"="+n._getStringExpression():null};FlexSheet.prototype._updateCellStyleForReorderingRows=function(e,t,o){var n,i,l=this.columns.length;for(n=0;n<l;n++)(i=this._getCellStyle(e,n))&&(o[t*l+n]=i)};FlexSheet.prototype._scanFormulas=function(){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);_isFormula(n)&&e.push({row:t,column:o,formula:n})}return e};FlexSheet.prototype._resetFormulas=function(e){var t=this;e&&this.deferUpdate((function(){for(var o=0;o<e.length;o++){var n=e[o];t.setCellData(n.row,n.column,n.formula)}}))};FlexSheet.prototype._getCellStyle=function(e,t,o){return(o=o||this.selectedSheet)?o.getCellStyle(e,t):null};FlexSheet.prototype._getSheet=function(e){if(null==e)return null;e=e.toLowerCase();for(var t=0;t<this.sheets.length;t++){var o=this.sheets[t];if(o.name.toLowerCase()===e)return o}return null};FlexSheet.prototype._validateSheetName=function(e){return!!this._getSheet(e)};FlexSheet.prototype._sheetNameChanged=function(e,t){if(!this._loadingFromWorkbook){this.definedNames._updateSheetName(e,t);this._updateFormulasWithNameUpdating(e,t)}};FlexSheet.prototype._updateFormulasTableColumn=function(e,t,o,n){if(o!==n){this.beginUpdate();for(var i=new RegExp(e.name+"\\["+o+"\\]","g"),l=e.name+"["+n+"]",r=new RegExp("\\["+o+"\\]","g"),s="["+o+"]",a="["+n+"]",h=0;h<this.sheets.length;h++)for(var u=this.sheets[h],c=u.grid,d=0;d<c.rows.length;d++)for(var _=0;_<c.columns.length;_++){var f=c.getCellData(d,_,!1);if(_isFormula(f)&&f.indexOf("[")>=0){if((f=f.replace(i,l)).indexOf(s)>=0){var g=u.findTable(d,_);g&&g.name===e.name&&(f=f.replace(r,a))}c.setCellData(d,_,f,!1)}}e._updateColumnName(t-e._getTableRange().leftCol,n,!1);this.endUpdate()}};FlexSheet.prototype._updateFormulasWithNameUpdating=function(e,t,o){void 0===o&&(o=!1);if(this.sheets.length){var n=o?/\[/:/\w/,i=this.selection.clone();this.selectedSheet._storeRowSettings();this.beginUpdate();for(var l=0;l<this.sheets.length;l++)for(var r=this.sheets[l].grid,s=0;s<r.rows.length;s++)for(var _loop_1=function(i){var l=r.getCellData(s,i,!1);if(_isFormula(l)){for(var a=!1,h=l.indexOf(e),u=new RegExp(e,"g");h>-1;){var c="",d="";h>0&&(c=l[h-1]);h+e.length<l.length&&(d=l[h+e.length]);if(!/\w/.test(c)&&(o&&n.test(d)||!o&&!n.test(d))){l=l.replace(u,(function(o,n){return n===h?t:e}));a=!0}h=l.indexOf(e,h+e.length)}a&&r.setCellData(s,i,l,!1)}},a=0;a<r.columns.length;a++)_loop_1(a);this.selection=i;this.endUpdate()}};FlexSheet.prototype._updateTablesForUpdatingRow=function(e,t,o){var n,i,l,r,s;if(this.selectedSheet.tables.length>0)for(n=this.selectedSheet.tables.length-1;n>=0;n--){l=(i=this.selectedSheet.tables[n]).getRange();if(o){if((r=e+t-1)<l.topRow)i._updateTableRange(-t,-t,0,0);else if(r>=l.topRow&&r<=l.bottomRow){if(e<=l.topRow&&r===l.bottomRow){null==s&&(s=[]);s.push(i);this.selectedSheet.tables.remove(i);continue}if(e<l.topRow){i.showHeaderRow&&(i._showHeaderRow=!1);i._updateTableRange(e-l.topRow,-t,0,0)}else{e===l.topRow&&i.showHeaderRow&&(i._showHeaderRow=!1);r===l.bottomRow&&i.showTotalRow&&(i._showTotalRow=!1);i._updateTableRange(0,-t,0,0)}}else if(e<=l.topRow){null==s&&(s=[]);s.push(i);this.selectedSheet.tables.remove(i)}else if(e<=l.bottomRow){i.showTotalRow&&(i._showTotalRow=!1);i._updateTableRange(0,e-l.bottomRow-1,0,0)}}else e<=l.topRow?i._updateTableRange(t,t,0,0):e>l.topRow&&e<=l.bottomRow&&i._updateTableRange(0,t,0,0)}return s};FlexSheet.prototype._updateTablesForUpdatingColumn=function(e,t,o){var n,i,l,r,s,a,h,u;if(this.selectedSheet.tables.length>0)for(n=this.selectedSheet.tables.length-1;n>=0;n--){l=(i=this.selectedSheet.tables[n]).getRange();if(o){if((r=e+t-1)<l.leftCol)i._updateTableRange(0,0,-t,-t);else if(r>=l.leftCol&&r<=l.rightCol){if(e<=l.leftCol&&r===l.rightCol){null==u&&(u=[]);u.push(i);this.selectedSheet.tables.remove(i);continue}if(e<l.leftCol){s=t-l.leftCol+e;a=l.leftCol;i._updateTableRange(0,0,e-l.leftCol,-t)}else{s=t;a=e;i._updateTableRange(0,0,0,-s)}i._columns.splice(a-l.leftCol,s)}else if(e<=l.leftCol){null==u&&(u=[]);u.push(i);this.selectedSheet.tables.remove(i)}else if(e<=l.rightCol){s=l.rightCol-e+1;i._updateTableRange(0,0,0,-s);i._columns.splice(e,s)}}else if(e<=l.leftCol)i._updateTableRange(0,0,t,t);else if(e>l.leftCol&&e<=l.rightCol){i._updateTableRange(0,0,0,t);a=e-l.leftCol;for(h=0;h<t;h++)i._addColumn(a+h)}}return u};FlexSheet.prototype._updateDivContainerHeight=function(e){var t=this._divContainer.parentElement.clientHeight;e&&(t-=this._tabHolder.getSheetBlanketSize());this._divContainer.style.height=t+"px"};FlexSheet.prototype._isDisableDeleteRow=function(e,t){var o,n,i;if(this.selectedSheet.tables.length>0)for(o=0;o<this.selectedSheet.tables.length;o++){i=(n=this.selectedSheet.tables[o]).getRange();if(n.showHeaderRow&&i.topRow>=e&&i.topRow<=t)return!0}return!1};FlexSheet.prototype._copy=function(t,o){var n,i;if("columns"==t){e.prototype._copy.call(this,t,o);if(this.itemsSource&&(n=this.rows[0])instanceof HeaderRow){n._ubv=null;n._ubv={};for(var l=0;l<this.columns.length;l++){i=this.columns[l];n._ubv[i._hash]=FlexSheet._getHeaderRowText(i)}}return!0}return!1};FlexSheet.prototype._getTableSheetIndex=function(e,t){this.sheets;for(var o=0;o<e.length;o++)if(e[o].indexOf(t)>-1)return o;return-1};FlexSheet.prototype._sheetSortConverter=function(t,o,n,i){_isFormula(n=e.prototype._sortConverter.call(this,t,o,n,i))&&(n=this.evaluate(n));return n};FlexSheet.prototype._formatEvaluatedResult=function(e,t,o){if(isPrimitive(e)){t.dataMap&&(e=t.dataMap.getDisplayValue(e));var n=o||t.format;if(!isInt(e)||n||t.dataMap){isDate(e)&&_isExclusiveNumericFormat(n)?e=FlexSheet._toOADate(e):n&&"@"!==n&&isString(e)&&(+e).toString()===e&&(e=+e);e=null!=e?Globalize.format(e,n):""}else e=e.toString()}else if(e){if(e instanceof FormulaError)return e.error;n=o||e.format||t.format;if(!isInt(e.value)||n||t.dataMap){isDate(e.value)&&_isExclusiveNumericFormat(n)?e.value=FlexSheet._toOADate(e.value):isString(e.value)&&(+e.value).toString()===e.value&&(e.value=+e.value);e=null!=e.value?Globalize.format(e.value,n):""}else e=e.value.toString()}return e};FlexSheet.prototype._updateCellRef=function(e,t,o,n,i,l,r){var s;try{s=this._calcEngine.parse(e)}catch(e){return null}var a=s;if(!i&&this._isDeletingColumns&&this.definedNames&&this.definedNames.length&&a._cells){var h=this.selection,u=(h._col,h._col2,a._cells),c=u._col,d=u._col2,_=[o,o-n+1],f=_[0],g=_[1],p=[Math.max(c,d),Math.min(c,d)];if(p[1]>=g&&p[0]<=f){var w=this.definedNames.find((function(t){return t.value==e}));if(w){var m=this.sheets[this.selectedSheetIndex].name,C=w.sheetName;if(C&&C===m||null==C&&w.value.includes(m))return{name:w.name}}}}return s._updateCellRangeExp(t,o,n,i,l,r)?"="+s._getStringExpression():null};FlexSheet.prototype._updateCellBoundary=function(e,t,o){var n;try{n=this._calcEngine.parse(e)}catch(e){return null}return n instanceof _FunctionExpression&&n._updateCellBoundary(t,o)?"="+n._getStringExpression():null};FlexSheet.prototype._fillData=function(e){void 0===e&&(e=AutoFillOperation.CopyFormat|AutoFillOperation.FillSeries);var t=this._fillingRange||this.selection,o=this._fillingSource,n=0!=(e&AutoFillOperation.CopyFormat),i=0!=(e&AutoFillOperation.CopyContent),l=0!=(e&AutoFillOperation.FillSeries),r=o.leftCol===t.leftCol&&o.rightCol===t.rightCol,s=[],a=new AutoFillingEventArgs(t,e);this.onAutoFilling(a);if(a.cancel)return!1;this.beginUpdate();this._resetCellsForFillRange(e);for(var h=0;h<t.rowSpan;h++){var u=t.topRow+h,c=u-o.topRow,d=c%o.rowSpan;if(this.rows[u].visible){d<0&&(d+=o.rowSpan);for(var _=0;_<t.columnSpan;_++){var f=t.leftCol+_,g=f-o.leftCol;if(!(c>=0&&c<o.rowSpan&&g>=0&&g<o.columnSpan)){var p=g%o.columnSpan;p<0&&(p+=o.columnSpan);var w=!1,m=this.getMergedRange(this.cells,o.topRow+d,o.leftCol+p);if(m&&(w=m.topRow===o.topRow+d&&m.leftCol===o.leftCol+p)){this.getMergedRange(this.cells,u,f)||this.mergeRange(new CellRange(u,f,u+m.rowSpan-1,f+m.columnSpan-1))}if(n){var C=this.selectedSheet.getCellStyle(o.topRow+d,o.leftCol+p),S=C?this._cloneObject(C):null,b=u*this.columns.length+f;this.selectedSheet._styledCells[b]=S}if((!m||w)&&!this.isReadOnly&&!this.rows[u].isReadOnly&&!this.columns[f].isReadOnly){var v=void 0;if(i)_isFormula(v=this.getCellData(o.topRow+d,o.leftCol+p,!1))?this._fillFormula(v,o.topRow+d,o.leftCol+p,u,f):this.setCellData(u,f,v);else if(l){var y=void 0,R=void 0;if(r){y=_;R=d}else{y=h;R=p}if(null==(v=this.getCellData(o.topRow+d,o.leftCol+p,!1))||isString(v)){_isFormula(v)?this._fillFormula(v,o.topRow+d,o.leftCol+p,u,f):this.setCellData(u,f,v);s[y]=null}else{s[y]||(s[y]=this._getFillSeries(r,y,R));var x=s[y];if(x){if(r){v=this._getFillData(d,c,o,r,x,null!=e||0===y);x.endIndex===o.topRow+d&&(s[y]=null)}else{v=this._getFillData(p,g,o,r,x,null!=e||0===y);x.endIndex===o.leftCol+p&&(s[y]=null)}this.setCellData(u,f,v)}}}}}}}}this._fillingRange&&this.select(this._fillingRange,!1);this.endUpdate();this.onAutoFilled(a);return!0};FlexSheet.prototype._getFillData=function(e,t,o,n,i,l){var r,s,a=i.items;if(1===a.length&&!l)return a[0];r=n?Math.floor(t/o.rowSpan)*i.itemIndexes[i.itemIndexes.length-1]+o.topRow+e-i.startIndex+1:Math.floor(t/o.columnSpan)*i.itemIndexes[i.itemIndexes.length-1]+o.leftCol+e-i.startIndex+1;s=this._getLinearBestFitTrendData(a,i.itemIndexes,r);"date"===i.type&&(s=FlexSheet._fromOADate(s));return s};FlexSheet.prototype._fillFormula=function(e,t,o,n,i){var l,r,s;try{l=this._calcEngine.parse(e);r=new CellRange(t,o);s=new CellRange(n,i);l._moveCellRangeExp(this.selectedSheetIndex,r,s,!1,!0)&&(e="="+l._getStringExpression())}catch(e){}finally{this.setCellData(n,i,e)}};FlexSheet.prototype._getFillSeries=function(e,t,o){var n,i,l,r,s,a,h,u,c=this._fillingSource,d=[],_=[];if(e){o=c.topRow+o;r=0;for(s=c.topRow;s<=c.bottomRow;s++){if(a=this.getMergedRange(this.cells,s,c.leftCol+t))if(h&&!a.equals(h)){r+=h.rowSpan;h=a;if(a.leftCol!==c.leftCol+t)continue}else{if(a.topRow!==s||a.leftCol!==c.leftCol+t)continue;r+=1;h=a}else if(h){r+=h.rowSpan;h=null}else r+=1;if(null!=(u=this.getCellData(s,c.leftCol+t,!1))&&""!==u)if(isNumber(u)||isDate(u)){n=isNumber(u)?"number":"date";isDate(u)&&(u=FlexSheet._toOADate(u));if(0===d.length){l=s;i=n;d.push(u);_.push(r)}else if(n===i){d.push(u);_.push(r)}else{if(o>=l&&o<=s)return{type:i,startIndex:l,endIndex:s-1,items:d,itemIndexes:_};d.splice(0,d.length);_.splice(0,_.length)}}else if(d.length>0){if(o>=l&&o<=s)return{type:i,startIndex:l,endIndex:s-1,items:d,itemIndexes:_};d.splice(0,d.length);_.splice(0,_.length)}}}else{o=c.leftCol+o;r=0;for(s=c.leftCol;s<=c.rightCol;s++){if(a=this.getMergedRange(this.cells,c.topRow+t,s))if(h&&!a.equals(h)){r+=h.columnSpan;h=a;if(a.topRow!==c.topRow+t)continue}else{if(a.leftCol!==s||a.topRow!==c.topRow+t)continue;r+=1;h=a}else if(h){r+=h.columnSpan;h=null}else r+=1;if(null!=(u=this.getCellData(c.topRow+t,s,!1))&&""!==u)if(isNumber(u)||isDate(u)){n=isNumber(u)?"number":"date";isDate(u)&&(u=FlexSheet._toOADate(u));if(0===d.length){l=s;i=n;d.push(u);_.push(r)}else if(n===i){d.push(u);_.push(r)}else{if(o>=l&&o<=s)return{type:i,startIndex:l,endIndex:s-1,items:d,itemIndexes:_};d.splice(0,d.length);_.splice(0,_.length)}}else if(d.length>0){if(o>=l&&o<=s)return{type:i,startIndex:l,endIndex:s-1,items:d,itemIndexes:_};d.splice(0,d.length);_.splice(0,_.length)}}}return d.length>0?{type:i,startIndex:l,endIndex:s-1,items:d,itemIndexes:_}:null};FlexSheet.prototype._getLinearBestFitTrendData=function(e,t,o){var n,i,l,r,s=0,a=0,h=0,u=0;if(1===(r=e.length))return e[0]+o-1;for(n=0;n<t.length;n++){s+=i=t[n];h+=i*i;a+=l=e[n];u+=i*l}return o*((r*u-s*a)/(r*h-s*s))+(a*h-s*u)/(r*h-s*s)};FlexSheet.prototype._getCellSettingsForFill=function(e,t){var o,n,i,l,r,s;e||(e=this._fillingSource);t||(t=this._fillingRange);r=[];for(o=t.topRow;o<=t.bottomRow;o++)for(n=t.leftCol;n<=t.rightCol;n++)if(!(o>=e.topRow&&o<=e.bottomRow&&n>=e.leftCol&&n<=e.rightCol)){i=this.getCellData(o,n,!1);l=this._cloneObject(this.selectedSheet.getCellStyle(o,n));(s=this.getMergedRange(this.cells,o,n))&&s.topRow===o&&s.leftCol===n||(s=null);r.push({row:o,col:n,value:i,style:l,mergedCell:s?s.clone():null})}return r};FlexSheet.prototype._resetCellsForFillRange=function(e){var t=0!=(e&AutoFillOperation.CopyFormat),o=0!=(e&AutoFillOperation.CopyContent),n=0!=(e&AutoFillOperation.FillSeries);if(this._orgCellSettings&&this._orgCellSettings.length>0)for(var i=0;i<this._orgCellSettings.length;i++){var l=this._orgCellSettings[i],r=l.row,s=l.col;if(!t){var a=r*this.columns.length+s;this.selectedSheet._styledCells[a]=l.style}o||n||this.setCellData(r,s,l.value)}};FlexSheet.prototype._canDoFillOperation=function(){var e,t,o,n,i,l,r,s,a,h,u,c,d,_,f,g=this._fillingSource,p=this._fillingRange,w=!1;for(e=g.topRow;e<=g.bottomRow;e++)for(t=g.leftCol;t<=g.rightCol;t++){h=this.getMergedRange(this.cells,e,t);if(u){if(!h||!u.equals(h)){w=!0;break}}else u=h}for(o=p.topRow;o<=p.bottomRow;o++){(n=(i=o-g.topRow)%g.rowSpan)<0&&(n+=g.rowSpan);n+=g.topRow;for(l=p.leftCol;l<=p.rightCol;l++){s=l-g.leftCol;if(!(i>=0&&i<g.rowSpan&&s>=0&&s<g.columnSpan)){(r=s%g.columnSpan)<0&&(r+=g.columnSpan);r+=g.leftCol;h=this.getMergedRange(this.cells,n,r);if(a=this.getMergedRange(this.cells,o,l)){if(w||!h)return!1;c=a?o-a.topRow:NaN;d=a?l-a.leftCol:NaN;_=h?n-h.topRow:NaN;f=h?r-h.leftCol:NaN;if(c!==_||d!==f)return!1}}}}return!0};FlexSheet.prototype._updateItemIndexForInsertingRow=function(e,t,o){for(var n=0;n<e.length;n++){var i=e[n];i&&null!=i._itemIdx&&i._itemIdx>=t&&(i._itemIdx+=o)}};FlexSheet.prototype._updateItemIndexForRemovingRow=function(e,t){for(var o=0;o<e.length;o++){var n=e[o];n&&null!=n._itemIdx&&n._itemIdx>=t&&(n._itemIdx-=1)}};FlexSheet.prototype._copyRowsToSelectedSheet=function(){var e=this;if(this.selectedSheet){this.selectedSheet.grid.rows.clear();for(var t=0;t<this.rows.length;t++){var o=this.rows[t];this.selectedSheet.grid.rows.push(o);o._list=this.rows}setTimeout((function(){e._setFlexSheetToDirty();e.invalidate()}),10)}};FlexSheet.prototype._copyColumnsToSelectedSheet=function(){var e=this;if(this.selectedSheet){this.selectedSheet.grid.columns.clear();for(var t=0;t<this.columns.length;t++){var o=this.columns[t];this.selectedSheet.grid.columns.push(o);o._setList(this.columns)}setTimeout((function(){e._setFlexSheetToDirty();e.invalidate()}),10)}};FlexSheet.prototype._getUniqueColumnName=function(){for(var e=this.insertedColumnIndex+1;null!=this.columns.getColumn("col"+e);)e++;return"col"+(this.insertedColumnIndex=e)};FlexSheet.prototype._hideContextMenu=function(){this._contextMenu.hide();this._tabHolder.sheetControl._contextMenu.hide()};FlexSheet.prototype._parseFromWorkbookTable=function(e,t){var o,n,i,l,r,s,a,h,u,c,d,_=t===this.selectedSheet?this:t.grid;i=(n=e.range.split(":"))[0];l=n[1];r=mXlsx.Workbook.tableAddress(i);o=new CellRange(r.row,r.col);s=mXlsx.Workbook.tableAddress(l);o.row2=s.row;o.col2=s.col;if(o.bottomRow>=t.rowCount){d=o.bottomRow-t.rowCount+1;for(f=0;f<d;f++)_.rows.push(new Row)}if(o.rightCol>=t.columnCount){d=o.rightCol-t.columnCount+1;for(f=0;f<d;f++)_.columns.push(new Column)}if(e.columns&&e.columns.length>0){a=[];for(var f=0;f<e.columns.length;f++){h=e.columns[f];a[f]=new TableColumn(h.name,h.totalRowLabel,h.totalRowFunction,h.showFilterButton)}}null!=e.style&&(u=this._isBuiltInStyleName(e.style.name)?this.getBuiltInTableStyle(e.style.name):this._parseFromWorkbookTableStyle(e.style));c=new Table(e.name,o,u,a,{showHeaderRow:e.showHeaderRow,showTotalRow:e.showTotalRow,showBandedColumns:e.showBandedColumns,showBandedRows:e.showBandedRows,alterFirstColumn:e.alterFirstColumn,alterLastColumn:e.alterLastColumn});t.tables.push(c);return c};FlexSheet.prototype._parseFromWorkbookTableStyle=function(e){var t=new TableStyle(e.name);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));return t};FlexSheet.prototype._parseFromWorkbookTableStyleElement=function(e){var t;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:""};if(e.borders){if(e.borders.left){FlexGridXlsxConverter._parseBorderStyle(e.borders.left.style,"Left",t);t.borderLeftColor=e.borders.left.color}if(e.borders.right){FlexGridXlsxConverter._parseBorderStyle(e.borders.right.style,"Right",t);t.borderRightColor=e.borders.right.color}if(e.borders.top){FlexGridXlsxConverter._parseBorderStyle(e.borders.top.style,"Top",t);t.borderTopColor=e.borders.top.color}if(e.borders.bottom){FlexGridXlsxConverter._parseBorderStyle(e.borders.bottom.style,"Bottom",t);t.borderBottomColor=e.borders.bottom.color}if(e.borders.vertical){FlexGridXlsxConverter._parseBorderStyle(e.borders.vertical.style,"Vertical",t);t.borderVerticalColor=e.borders.vertical.color}if(e.borders.horizontal){FlexGridXlsxConverter._parseBorderStyle(e.borders.horizontal.style,"Horizontal",t);t.borderHorizontalColor=e.borders.horizontal.color}}null!=e.size&&(t.size=e.size);return t};FlexSheet.prototype._parseToWorkbookTable=function(e){var t,o,n=new mXlsx.WorkbookTable,i=e.getRange(),l=e.getColumns();n.name=e.name;t=mXlsx.Workbook.xlsxAddress(i.topRow,i.leftCol);o=mXlsx.Workbook.xlsxAddress(i.bottomRow,i.rightCol);n.range=t+":"+o;if(null!=e.style)if(e.style.isBuiltIn){n.style=new mXlsx.WorkbookTableStyle;n.style.name=e.style.name}else 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 r=0;r<l.length;r++){var s=l[r],a=new mXlsx.WorkbookTableColumn;a.name=s.name;a.totalRowLabel=s.totalRowLabel;a.totalRowFunction=s.totalRowFunction;a.showFilterButton=s.showFilterButton;n.columns.push(a)}return n};FlexSheet.prototype._parseToWorkbookTableStyle=function(e){var t=new mXlsx.WorkbookTableStyle;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));return t};FlexSheet.prototype._parseToWorkbookTableStyleElement=function(e,t){void 0===t&&(t=!1);var o,n=FlexGridXlsxConverter._parseCellStyle(e,!0);t?(o=new mXlsx.WorkbookTableBandedStyle).size=e.size:o=new mXlsx.WorkbookTableCommonStyle;o._deserialize(n);return o};FlexSheet.prototype._isBuiltInStyleName=function(e){var t;if(0===e.search(/TableStyleLight/i)){t=+e.substring(15);if(!isNaN(t)&&t>=1&&t<=21)return!0}else if(0===e.search(/TableStyleMedium/i)){t=+e.substring(16);if(!isNaN(t)&&t>=1&&t<=28)return!0}else if(0===e.search(/TableStyleDark/i)){t=+e.substring(14);if(!isNaN(t)&&t>=1&&t<=11)return!0}return!1};FlexSheet.prototype._getTable=function(e){e=e.substr(e.lastIndexOf("!")+1);for(var t=0;t<this.sheets.length;t++)for(var o=this.sheets[t].tables,n=0;n<o.length;n++){var i=o[n];if(i.name.toLowerCase()===e.toLowerCase())return i}return null};FlexSheet.prototype._checkTableHeaderRow=function(e,t){e.forEach((function(e){if(e.showHeaderRow)for(var o=e.getRange(TableSection.Header),n=o.row,i=o.leftCol;i<=o.rightCol;i++){var l=t.sheets[0].rows[n].cells[i];l.isDate=!1;if(null==l.value||""===l.value){var r=i-o.leftCol;l.value=e._getColumns()[r].name}}}))};FlexSheet.prototype._getThemeColor=function(e,t){var o,n=this._colorThemes[e];if(null!=t){(o=new Color("#"+n).getHsl())[2]=t<0?o[2]*(1+t):o[2]*(1-t)+(1-1*(1-t));return Color.fromHsl(o[0],o[1],o[2]).toString()}return"#"+n};FlexSheet.prototype._createBuiltInTableStyle=function(e){var t;if(0===e.search(/TableStyleLight/i)){t=+e.substring(15);if(!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)){t=+e.substring(16);if(!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);if(!isNaN(t)&&t>=1&&t<=11)return t<=7?this._generateTableDarkStyle1(t-1,e):this._generateTableDarkStyle2(t-8,e)}return null};FlexSheet.prototype._generateTableLightStyle1=function(e,t,o){var n=new TableStyle(t,!0),i=0===e?1:e+3,l=o?"1px":"2px",r=o?"solid":"double",s=o?"1px":"3px";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:l,fontWeight:"bold"};n.totalRowStyle={borderTopColor:this._getThemeColor(i),borderTopStyle:r,borderTopWidth:s,fontWeight:"bold"};if(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)}}else{if(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)}else{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)}}if(!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"}return n};FlexSheet.prototype._generateTableLightStyle2=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;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)};return o};FlexSheet.prototype._generateTableMediumStyle1=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;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)};if(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)}}else{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)};return o};FlexSheet.prototype._generateTableMediumStyle2=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;o.wholeTableStyle={borderVerticalStyle:"solid",borderVerticalWidth:"1px",borderVerticalColor:this._getThemeColor(0),borderHorizontalStyle:"solid",borderHorizontalWidth:"1px",borderHorizontalColor:this._getThemeColor(0),color:this._getThemeColor(1)};if(0===e){o.wholeTableStyle.backgroundColor=this._getThemeColor(0,-.15);o.firstBandedRowStyle={backgroundColor:this._getThemeColor(0,-.35)};o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(0,-.35)}}else{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)};return o};FlexSheet.prototype._generateTableMediumStyle3=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;o.wholeTableStyle={borderTopStyle:"solid",borderTopWidth:"2px",borderTopColor:this._getThemeColor(1),borderBottomStyle:"solid",borderBottomWidth:"2px",borderBottomColor:this._getThemeColor(1),color:this._getThemeColor(1)};if(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"};return o};FlexSheet.prototype._generateTableMediumStyle4=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3;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)};if(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)}}else{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)};return o};FlexSheet.prototype._generateTableDarkStyle1=function(e,t){var o=new TableStyle(t,!0),n=0===e?1:e+3,i=0===e?.25:-.25;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)};if(0===e){o.wholeTableStyle.backgroundColor=this._getThemeColor(n,.5);o.totalRowStyle.backgroundColor=this._getThemeColor(n,.15)}else{o.wholeTableStyle.backgroundColor=this._getThemeColor(n);o.totalRowStyle.backgroundColor=this._getThemeColor(n,-.5)}return o};FlexSheet.prototype._generateTableDarkStyle2=function(e,t){var o=new TableStyle(t,!0),n=0===e?0:2*e+2,i=0===e?1:2*e+3,l=0===e?-.15:.8;o.wholeTableStyle={backgroundColor:this._getThemeColor(n,l)};o.firstBandedRowStyle={backgroundColor:this._getThemeColor(n,l-.2)};o.firstBandedColumnStyle={backgroundColor:this._getThemeColor(n,l-.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)};return o};FlexSheet._getHeaderRowText=function(e){var t=e.binding,o=e._hdr;null!=o&&""!=o.trim()||(o=toHeaderCase(t||""));return o};FlexSheet._toOADate=function(e){var t,o=new Date(1900,0,0),n=Date.UTC(1900,0,0),i=o.getTime()-n-6e4*o.getTimezoneOffset(),l=6e4*(e.getTimezoneOffset()-o.getTimezoneOffset());t=(e.getTime()-o.getTime()-(0!==l?l-i:0))/864e5;return t+=t>59?1:0};FlexSheet._fromOADate=function(e){var t,o,n,i=new Date(1900,0,0),l=Date.UTC(1900,0,0),r=i.getTime()-l-6e4*i.getTimezoneOffset();o=e>59?1:0;return 0!==(t=6e4*((n=new Date(i.getTime()+864e5*(e-o))).getTimezoneOffset()-i.getTimezoneOffset()))?new Date(i.getTime()+t-r+864e5*(e-o)):n};FlexSheet.prototype.setHeights=function(e){this._heights=e};FlexSheet.prototype.updateRowHeights=function(){if(this.collectionView)for(var e=0;e<this._heights.length;e++)this._heights[e]&&this.rows[e]&&(this.rows[e].height=this._heights[e])};FlexSheet.controlTemplate='<div style="width:100%;height:100%"><div wj-part="container" style="width:100%; max-width: 100vw;">'+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>';return FlexSheet}(FlexGrid);export{FlexSheet};var DraggingRowColumnEventArgs=function(e){__extends(DraggingRowColumnEventArgs,e);function DraggingRowColumnEventArgs(t,o,n){var i=e.call(this)||this;i._draggingRange=t;i._isDraggingRows=o;i._isShiftKey=n;return i}Object.defineProperty(DraggingRowColumnEventArgs.prototype,"draggingRange",{get:function(){return this._draggingRange},enumerable:!0,configurable:!0});Object.defineProperty(DraggingRowColumnEventArgs.prototype,"isDraggingRows",{get:function(){return this._isDraggingRows},enumerable:!0,configurable:!0});Object.defineProperty(DraggingRowColumnEventArgs.prototype,"isShiftKey",{get:function(){return this._isShiftKey},enumerable:!0,configurable:!0});return DraggingRowColumnEventArgs}(EventArgs);export{DraggingRowColumnEventArgs};var DroppingRowColumnEventArgs=function(e){__extends(DroppingRowColumnEventArgs,e);function DroppingRowColumnEventArgs(t,o){var n=e.call(this)||this;n._droppingRange=t;n._isDroppingRows=o;return n}Object.defineProperty(DroppingRowColumnEventArgs.prototype,"droppingRange",{get:function(){return this._droppingRange},enumerable:!0,configurable:!0});Object.defineProperty(DroppingRowColumnEventArgs.prototype,"isDroppingRows",{get:function(){return this._isDroppingRows},enumerable:!0,configurable:!0});return DroppingRowColumnEventArgs}(CancelEventArgs);export{DroppingRowColumnEventArgs};var UnknownFunctionEventArgs=function(e){__extends(UnknownFunctionEventArgs,e);function UnknownFunctionEventArgs(t,o){var n=e.call(this)||this;n._funcName=t;n._params=o;return n}Object.defineProperty(UnknownFunctionEventArgs.prototype,"funcName",{get:function(){return this._funcName},enumerable:!0,configurable:!0});Object.defineProperty(UnknownFunctionEventArgs.prototype,"params",{get:function(){return this._params},enumerable:!0,configurable:!0});return UnknownFunctionEventArgs}(EventArgs);export{UnknownFunctionEventArgs};var RowColumnChangedEventArgs=function(e){__extends(RowColumnChangedEventArgs,e);function RowColumnChangedEventArgs(t,o,n,i){var l=e.call(this)||this;if(isArray(t)){l._ranges=t;l._added=o;if(1===t.length){var r=t[0];if(n){l._index=r.leftCol;l._count=r.columnSpan}else{l._index=r.topRow;l._count=r.rowSpan}}else{l._index=-1;l._count=-1}}else{l._index=t;l._count=o;l._added=n;l._ranges=i?[new CellRange(-1,l._index,-1,l._index+l._count-1)]:[new CellRange(l._index,-1,l._index+l._count-1,-1)]}return l}Object.defineProperty(RowColumnChangedEventArgs.prototype,"ranges",{get:function(){return this._ranges},enumerable:!0,configurable:!0});Object.defineProperty(RowColumnChangedEventArgs.prototype,"index",{get:function(){return this._index},enumerable:!0,configurable:!0});Object.defineProperty(RowColumnChangedEventArgs.prototype,"count",{get:function(){return this._count},enumerable:!0,configurable:!0});Object.defineProperty(RowColumnChangedEventArgs.prototype,"added",{get:function(){return this._added},enumerable:!0,configurable:!0});Object.defineProperty(RowColumnChangedEventArgs.prototype,"isAdd",{get:function(){_deprecated("RowColumnChangedEventArgs.isAdd","RowColumnChangedEventArgs.added");return this._added},enumerable:!0,configurable:!0});return RowColumnChangedEventArgs}(EventArgs);export{RowColumnChangedEventArgs};var AutoFillingEventArgs=function(e){__extends(AutoFillingEventArgs,e);function AutoFillingEventArgs(t,o){var n=e.call(this)||this;n._range=t;n._op=o;return n}Object.defineProperty(AutoFillingEventArgs.prototype,"range",{get:function(){return this._range},enumerable:!0,configurable:!0});Object.defineProperty(AutoFillingEventArgs.prototype,"operation",{get:function(){return this._op},enumerable:!0,configurable:!0});return AutoFillingEventArgs}(CancelEventArgs);export{AutoFillingEventArgs};var AutoFilledEventArgs=function(e){__extends(AutoFilledEventArgs,e);function AutoFilledEventArgs(t,o){var n=e.call(this)||this;n._range=t;n._op=o;return n}Object.defineProperty(AutoFilledEventArgs.prototype,"range",{get:function(){return this._range},enumerable:!0,configurable:!0});Object.defineProperty(AutoFilledEventArgs.prototype,"operation",{get:function(){return this._op},enumerable:!0,configurable:!0});return AutoFilledEventArgs}(EventArgs);export{AutoFilledEventArgs};var FlexSheetPanel=function(e){__extends(FlexSheetPanel,e);function FlexSheetPanel(t,o,n,i,l){var r=e.call(this,t,o,n,i,l)||this;r._drkColors={};return r}FlexSheetPanel.prototype.getSelectedState=function(t,o,n){if(this.grid){var i=this.grid.selectedSheet,l=i?i.selectionRanges:null,r=l?l.length:0,s=e.prototype.getSelectedState.call(this,t,o,n);if(s===SelectedState.None&&r>0)for(var a=this.grid.getMergedRange(this,t,o),h=this.columns.length-1,u=this.rows.length-1,c=0;c<l.length;c++){var d=l[c];if(d&&d instanceof CellRange){if(this.cellType===CellType.Cell){if(a){if(a.contains(d.row,d.col))return c!==r-1||this.grid._isClicking?SelectedState.Selected:this.grid.showMarquee?SelectedState.None:SelectedState.Cursor;if(a.intersects(d))return SelectedState.Selected}if(d.row===t&&d.col===o)return c!==r-1||this.grid._isClicking?SelectedState.Selected:this.grid.showMarquee?SelectedState.None:SelectedState.Cursor;if(d.contains(t,o))return SelectedState.Selected}if(this.cellType===CellType.RowHeader&&this.grid.showSelectedHeaders&HeadersVisibility.Row&&o===h&&d.containsRow(t))return SelectedState.Selected;if(this.cellType===CellType.ColumnHeader&&this.grid.showSelectedHeaders&HeadersVisibility.Column&&t===u&&d.containsColumn(o))return SelectedState.Selected}}return s}};FlexSheetPanel.prototype.getCellData=function(t,o,n){if(isString(o)&&(o=this.columns.indexOf(o))<0)throw"Invalid column name or binding.";if(t>=this.rows.length||asNumber(o,!1,!0)>=this.columns.length)return null;if(this.cellType===CellType.RowHeader)return t+1+"";var i=this.columns[asNumber(o,!1,!0)],l=this.grid?this.grid._getBindingColumn(this,t,i):i,r=this.grid;if(this.cellType===CellType.ColumnHeader){var s=this.rows[t];if(s&&s._ubv&&null!=s._ubv[i._hash])return e.prototype.getCellData.call(this,t,o,n);var a=l.header;return null==l._hdr||l._hdr==l._orgHdr||a===l.binding||a===toHeaderCase(l.binding)?FlexSheet.convertNumberToAlpha(o):a}if(n&&(!l||!l.dataMap)){if(_isEditingCell(this.grid,t,o)){var h=e.prototype.getCellData.call(this,t,o,!1);return Globalize.format(h,null)}var u=r&&r._getCellStyle(t,o);if(u&&u.format){h=e.prototype.getCellData.call(this,t,o,!1);if(isDate(h)||isNumber(h))return Globalize.format(h,u.format)}}return e.prototype.getCellData.call(this,t,o,n)};FlexSheetPanel.prototype.setCellData=function(t,o,n,i,l,r){void 0===i&&(i=!0);void 0===l&&(l=!0);void 0===r&&(r=!1);if(t>=this.rows.length||o>=this.columns.length)return!1;var s,a=this.grid,h=a?a._getBindingColumn(this,t,this.columns[o]):this.columns[o],u=this.rows[t];if(n instanceof _ValWithFormat){s=n.format;n=n.value}a&&a._isPasting&&(i=!0);var c=isString(n);if(a&&a.selectedSheet){var d=a.selectedSheet.findTable(t,o);if(d&&d._isHeaderRow(t)){if(null==n||c&&isNullOrWhiteSpace(n)&&!h.dataMap)return;if(!(u instanceof HeaderRow)){n=h.dataType===DataType.Boolean&&isBoolean(n)?n:n.toString();d._attached&&a._updateFormulasTableColumn(d,o,this.getCellData(t,o,!1)+"",n+"");return e.prototype.setCellData.call(this,t,o,n,!1,l,r)}u._ubv[h._hash]=n.toString()}}var _=c&&"'"===n[0],f=c&&_isFormula(n);if(i&&n&&h.dataType!==DataType.String&&c&&!_&&!f){var g=culture.Globalize;if(this.getCellData(t,o,!0)===n)return!0;var p=a?a._getCellStyle(t,o):null,w=s||p&&p.format||h.format,m=null;w&&/[yYMhsmt\:-]/.test(w)&&!/[pc]/.test(w)&&(m=Globalize.parseDate(n,w));null==m&&n.indexOf(g.calendar["/"])>=0&&(m=Globalize.parseDate(n,null));if(m)n=m;else{var C=!1,S=!1;if(isNullOrWhiteSpace(n)||!(S="%"===n[n.length-1])&&!(C=n.indexOf(g.numberFormat.currency.symbol)>=0)&&/[^-\d,\.]/.test(n))h.dataType===DataType.Boolean&&(n=changeType(n,DataType.Boolean,null));else{var b=changeType(n,DataType.Number,"");if(isNumber(b)){n=b;w||h.dataType&&h.dataType!==DataType.Number||(C?a.applyCellsStyle({format:"C"+(isInt(n)?"0":"")},[new CellRange(t,o)]):S&&a.applyCellsStyle({format:"P"+(isInt(100*n)?"0":"")},[new CellRange(t,o)]))}else i=!1}}}(f||_||!h.dataType&&n)&&(i=!1);if(""===n&&i&&h.dataType!==DataType.String&&!h.dataMap&&!u.dataMap){n=null;i=!1}if(!(u instanceof HeaderRow))return e.prototype.setCellData.call(this,t,o,n,i,l,r);u._ubv[h._hash]=n};FlexSheetPanel.prototype._renderCell=function(t,o,n,i,l,r){var s=o*this.grid.columns.length+n,a=this.grid.getMergedRange(this,o,n),h=e.prototype._renderCell.call(this,t,o,n,i,l,r);if(this.cellType!==CellType.Cell)return h;if(a&&s>a.topRow*this.grid.columns.length+a.leftCol)return h;if(this.columns[n].renderSize<=0&&(!a||a.getRenderSize(this).width<=0))return h;var u=t.childNodes[r];if(u){var c=this.grid.selectedSheet;if(c&&!_isEditingCell(this.grid,o,n)){var d=c.findTable(o,n);d&&d._updateCell(o,n,u)}var _=c?c._styledCells[s]:null,f=void 0;if(hasClass(u,"wj-state-selected")||(f=hasClass(u,"wj-state-multi-selected"))){_&&_.backgroundColor&&(u.style.backgroundColor="");_&&_.color&&(u.style.color="");f&&_&&_.backgroundColor&&(u.style.backgroundColor=this._darker(_.backgroundColor))}else if(_){""!==_.backgroundColor&&(u.style.backgroundColor=_.backgroundColor);""!==_.color&&(u.style.color=_.color)}}return h};FlexSheetPanel.prototype._darker=function(e){var t=this._drkColors[e];if(!t){var o=new Color(e).getHsl();this._drkColors[e]=t=Color.fromHsl(o[0],o[1],.75*o[2]).toString()}return t};return FlexSheetPanel}(GridPanel);export{FlexSheetPanel};var HeaderRow=function(e){__extends(HeaderRow,e);function HeaderRow(){var t=e.call(this)||this;t.isReadOnly=!0;return t}return HeaderRow}(Row);export{HeaderRow};export function _isFormula(e){return e&&"string"==typeof e&&e.length>1&&"="===e[0]&&"="!==e[1]}export function _isEditingCell(e,t,o){var n=e.editRange;return n&&n.contains(t,o)}function _isExclusiveNumericFormat(e){if(e){var t=e.match(/^[cdefgnprx](\d?)/i);if(t){var o=t[0][0].toLowerCase();return"d"!==o&&"e"!==o&&"f"!==o&&"g"!==o||!!t[1]}}return!1}export var AutoFillOperation;!function(e){e[e.CopyFormat=1]="CopyFormat";e[e.CopyContent=2]="CopyContent";e[e.FillSeries=4]="FillSeries"}(AutoFillOperation||(AutoFillOperation={}));var _RangesHelper=function(){function _RangesHelper(){}_RangesHelper.validateRowRanges=function(e,t){return this._validateCellRanges(e,t,"topRow","bottomRow","row2")};_RangesHelper.excludeRow=function(e,t){if(e&&e.length)for(var o=0;o<e.length;o++){var n=e[o];if(n.containsRow(t))if(1===n.rowSpan){e.splice(o);o--}else if(n.topRow===t)n.setRange(n.topRow+1,n.col,n.bottomRow,n.col2);else if(n.bottomRow===t)n.setRange(n.topRow,n.col,n.bottomRow-1,n.col2);else{e.splice(o,1,new CellRange(n.topRow,n.col,t-1,n.col2),new CellRange(t+1,n.col,n.bottomRow,n.col2));o++}}};_RangesHelper.validateColumnRanges=function(e,t){return this._validateCellRanges(e,t,"leftCol","rightCol","col2")};_RangesHelper._validateCellRanges=function(e,t,o,n,i){var l=(e=e.filter((function(e){return e&&e[o]>=0&&e[n]>=0&&e[o]<t&&e[n]<t}))).length;if(l>1){for(var r=[],s=(e=e.sort((function(e,t){return t[o]>=e[o]&&t[n]<=e[n]?-1:e[o]-t[o]})))[0].clone(),a=1;a<l;a++){var h=e[a];if(h[o]>=s[o]&&h[n]<=s[n]);else if(h[o]<=s[n]+1)s[i]=h[n];else{r.push(s);s=h.clone()}a===l-1&&r.push(s)}e=r}return e};return _RangesHelper}(),_ValWithFormat=function _ValWithFormat(e,t){this.value=e;this.format=t},UndoStack=function(){function UndoStack(e){var t=this;this.MAX_STACK_SIZE=500;this._stack=[];this._pointer=-1;this._resizingTriggered=!1;this.undoStackChanged=new Event;var o=this;o._owner=e;o._owner.prepareCellForEdit.addHandler(o._initCellEditAction,o);o._owner.cellEditEnded.addHandler((function(e,t){o._pendingAction&&(!t.data||46!==t.data.keyCode&&8!==t.data.keyCode)&&o._pendingAction instanceof _EditAction&&!o._pendingAction.isPaste&&o._afterProcessCellEditAction(o)}),o);o._owner.pasting.addHandler(o._initCellEditActionForPasting,o);o._owner.pastingCell.addHandler((function(e,t){o._pendingAction&&(o._pendingAction instanceof _EditAction?o._pendingAction.updateForPasting(t.range):o._pendingAction instanceof _CutAction&&o._pendingAction.updateForPasting(t.range))}),o);o._owner.pasted.addHandler((function(){if(o._pendingAction)if(o._pendingAction instanceof _EditAction&&o._pendingAction.isPaste)o._afterProcessCellEditAction(o);else if(o._pendingAction instanceof _CutAction){o._pendingAction.saveNewState();o._addAction(o._pendingAction);o._pendingAction=null}}),o);o._owner.resizingColumn.addHandler((function(e,t){if(0!==o.stackSize&&o._owner.selectedSheet&&!o._resizingTriggered){o._pendingAction=new _ColumnResizeAction(o._owner,t.panel,t.col);o._resizingTriggered=!0}}),o);o._owner.resizedColumn.addHandler((function(e,t){o._pendingAction instanceof _ColumnResizeAction&&o._pendingAction.saveNewState()&&o._addAction(o._pendingAction);o._pendingAction=null;o._resizingTriggered=!1}),o);o._owner.resizingRow.addHandler((function(e,t){if(0!==o.stackSize&&o._owner.selectedSheet&&!o._resizingTriggered){o._pendingAction=new _RowResizeAction(o._owner,t.panel,t.row);o._resizingTriggered=!0}}),o);o._owner.resizedRow.addHandler((function(e,t){o._pendingAction instanceof _RowResizeAction&&o._pendingAction.saveNewState()&&o._addAction(o._pendingAction);o._pendingAction=null;o._resizingTriggered=!1}),o);o._owner.draggingRowColumn.addHandler((function(e,t){0!==o.stackSize&&o._owner.selectedSheet&&t.isShiftKey&&(t.isDraggingRows?o._pendingAction=new _RowsChangedAction(o._owner):o._pendingAction=new _ColumnsChangedAction(o._owner))}),o);o._owner.endDroppingRowColumn.addHandler((function(e,t){!t.cancel&&o._pendingAction&&o._pendingAction.saveNewState()&&o._addAction(o._pendingAction);o._pendingAction=null}),o);o._owner.sheets.collectionChanged.addHandler((function(e,o){if(o.action===NotifyCollectionChangedAction.Remove){for(var n=0;n<t._stack.length;n++)if(t._stack[n].sheetUid===o.item._uid){t._stack.splice(n,1);n--}t._pointer=Math.min(t._pointer,t._stack.length-1)}}));o._owner.sheets.sheetCleared.addHandler((function(){return t.clear()}))}Object.defineProperty(UndoStack.prototype,"stackSize",{get:function(){return null==this._stackSize?this.MAX_STACK_SIZE:this._stackSize},set:function(e){isNumber(e)&&(e<0?this._stackSize=0:e>this.MAX_STACK_SIZE?this._stackSize=this.MAX_STACK_SIZE:this._stackSize=Math.floor(e))},enumerable:!0,configurable:!0});Object.defineProperty(UndoStack.prototype,"canUndo",{get:function(){return this._pointer>-1&&this._pointer<this._stack.length},enumerable:!0,configurable:!0});Object.defineProperty(UndoStack.prototype,"canRedo",{get:function(){return this._pointer+1>-1&&this._pointer+1<this._stack.length},enumerable:!0,configurable:!0});UndoStack.prototype.onUndoStackChanged=function(e){this.undoStackChanged.raise(this,e)};UndoStack.prototype.undo=function(){if(this.canUndo){var e=this._stack[this._pointer];this._beforeUndoRedo(e);e.undo();this._pointer--;this.onUndoStackChanged()}};UndoStack.prototype.redo=function(){if(this.canRedo){this._pointer++;var e=this._stack[this._pointer];this._beforeUndoRedo(e);e.redo();this.onUndoStackChanged()}};UndoStack.prototype.clear=function(){this._stack.length=0;this._pointer=-1};UndoStack.prototype._addAction=function(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()};UndoStack.prototype._pop=function(){var e;if(this._pointer<0)return null;e=this._stack[this._pointer];this._pointer--;return e};UndoStack.prototype._initCellEditAction=function(e,t){0!==this.stackSize&&this._owner.selectedSheet&&(this._pendingAction=new _EditAction(this._owner,t.range))};UndoStack.prototype._initCellEditActionForPasting=function(){if(0!==this.stackSize&&this._owner.selectedSheet)if(this._owner._isCutting)this._pendingAction=new _CutAction(this._owner);else{this._pendingAction=new _EditAction(this._owner);this._pendingAction.markIsPaste()}};UndoStack.prototype._afterProcessCellEditAction=function(e){if(e._pendingAction){e._pendingAction instanceof _EditAction&&e._pendingAction.saveNewState()&&e._addAction(this._pendingAction);e._pendingAction=null}};UndoStack.prototype._beforeUndoRedo=function(e){for(var t=this._owner.sheets,o=0;o<t.length;o++)if(t[o]._uid===e.sheetUid){this._owner.selectedSheetIndex=o;break}};return UndoStack}();export{UndoStack};var FlexSheetValueFilterEditor=function(e){__extends(FlexSheetValueFilterEditor,e);function FlexSheetValueFilterEditor(){return null!==e&&e.apply(this,arguments)||this}FlexSheetValueFilterEditor.prototype.updateEditor=function(){var t=this,o=this.filter.column,n=o.grid;if(this.filter.uniqueValues||null!=n.itemsSource&&null!=n.childItemsPath)e.prototype.updateEditor.call(this);else{var i=n.filter._getValueFilters(o),l=this.filter.showValues;if(l&&0!=Object.keys(l).length){for(var r in l)for(s=0;s<i.length;s++)if(l[r]&&""!==i[s].cellRef&&i[s].cellRef===l[r].cellRef){l[i[s].text]={show:!0,cellRef:i[s].cellRef};i[s].show=!0;i[s].text!=r&&delete l[r]}else if(i[s].text==r){i[s].show=!0;break}}else for(var s=0;s<i.length;s++)i[s].show=!0;this._lbValues.isContentHtml=o.isContentHtml;this._cmbFilter.text=this.filter.filterText;var a=this._filterText=this._cmbFilter.text.toLowerCase();this._rxFilter=a?new RegExp(escapeRegExp(a),this._getCaseSensitive()?"":"i"):null;this._view.pageSize=this.filter.maxValues;this._view.sourceCollection=i;setTimeout((function(){t._adjustWidths()}),0)}};FlexSheetValueFilterEditor.prototype.updateFilter=function(){var e=null,t=this._getItems();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};return FlexSheetValueFilterEditor}(ValueFilterEditor);export{FlexSheetValueFilterEditor};var FlexSheetConditionFilter=function(e){__extends(FlexSheetConditionFilter,e);function FlexSheetConditionFilter(t){return e.call(this,t)||this}FlexSheetConditionFilter.prototype.apply=function(e){var t,o,n,i,l=this.column,r=l.grid,s=this.condition1,a=this.condition2;if(!(r instanceof FlexSheet))return!0;if(!this.isActive)return!0;if(r.rows[e]instanceof _NewRowTemplate)return!0;""===(t=r.getCellValue(e,l.index))&&l.dataType!==DataType.String&&(t=null);o=n=t;if(i=this.dataMap||l.dataMap)o=n=t=i.getDisplayValue(t);else if(isDate(t))(isString(s.value)||isString(a.value))&&(o=n=t=r.getCellValue(e,l.index,!0));else if(isNumber(t)){o=n=t=Globalize.parseFloat(r.getCellValue(e,l.index,!0));if(0===t&&!l.dataType){s.isActive&&""===s.value&&(o=t.toString());a.isActive&&""===a.value&&(n=n.toString())}}else if(null==t){s.isActive&&isNumber(s.value)&&(o=NaN);a.isActive&&isNumber(a.value)&&(n=NaN)}var h=s.apply(o),u=a.apply(n);return s.isActive&&a.isActive?this.and?h&&u:h||u:s.isActive?h:!a.isActive||u};return FlexSheetConditionFilter}(ConditionFilter);export{FlexSheetConditionFilter};var FlexSheetValueFilter=function(e){__extends(FlexSheetValueFilter,e);function FlexSheetValueFilter(t){return e.call(this,t)||this}FlexSheetValueFilter.prototype.apply=function(e){var t,o=this.column.grid;if(!(o instanceof FlexSheet))return!0;if(!this.showValues||!Object.keys(this.showValues).length)return!0;if(o.rows[e]instanceof _NewRowTemplate)return!0;e=(t=this.dataMap||this.column.dataMap)?t.getDisplayValue(o.getCellValue(e,this.column.index)):o.getCellValue(e,this.column.index,!0);return null!=this.showValues[e]};return FlexSheetValueFilter}(ValueFilter);export{FlexSheetValueFilter};var FlexSheetColumnFilter=function(e){__extends(FlexSheetColumnFilter,e);function FlexSheetColumnFilter(t,o){var n=e.call(this,t,o)||this;n._valueFilter=new FlexSheetValueFilter(o);n._valueFilter.exclusiveValueSearch=t.exclusiveValueSearch;n._conditionFilter=new FlexSheetConditionFilter(o);return n}return FlexSheetColumnFilter}(ColumnFilter);export{FlexSheetColumnFilter};var FlexSheetColumnFilterEditor=function(e){__extends(FlexSheetColumnFilterEditor,e);function FlexSheetColumnFilterEditor(t,o,n){void 0===n&&(n=!0);var i=e.call(this,t,o,n)||this,l=i;n&&(i._divSort.style.display="");i._btnSortAsc=i.cloneElement(i._btnAsc);i._btnSortDsc=i.cloneElement(i._btnDsc);i._btnAsc.parentNode.replaceChild(i._btnSortAsc,i._btnAsc);i._btnDsc.parentNode.replaceChild(i._btnSortDsc,i._btnDsc);i._btnSortAsc.addEventListener("click",(function(e){l._sortBtnClick(e,!0)}));i._btnSortDsc.addEventListener("click",(function(e){l._sortBtnClick(e,!1)}));i._updateSortButtonStateUnbound();return i}FlexSheetColumnFilterEditor.prototype._showFilter=function(t){var o=this;if(t==FilterType.Value&&null==this._edtVal){this._edtVal=new FlexSheetValueFilterEditor(this._divEdtVal,this.filter.valueFilter);this._edtVal.canApplyChanged.addHandler((function(e){enable(o._btnApply,o._edtVal.canApply)}))}e.prototype._showFilter.call(this,t)};FlexSheetColumnFilterEditor.prototype._sortBtnClick=function(e,t){var o,n,i=this.filter.column,l=i.grid.sortManager;e.preventDefault();e.stopPropagation();if((o=l.checkSortItemExists(i.index))>-1){l.sortDescriptions.moveCurrentToPosition(o);l.sortDescriptions.currentItem.ascending=t;n=-o}else{l.addSortLevel(i.index,t);n=-(l.sortDescriptions.items.length-1)}l.moveSortLevel(n);l.commitSort();this.onButtonClicked()};FlexSheetColumnFilterEditor.prototype.cloneElement=function(e){for(var t=e.cloneNode();e.firstChild;)t.appendChild(e.lastChild);return t};FlexSheetColumnFilterEditor.prototype._updateSortButtonStateUnbound=function(){var e=this.filter.column;if(e&&e.grid&&e.grid.selectedSheet)for(var t=e.grid.selectedSheet._unboundSortDesc,o=0;o<t.length;o++)if(t[o].column===e){toggleClass(this._btnSortAsc,"wj-state-active",!0===t[o].ascending);toggleClass(this._btnSortDsc,"wj-state-active",!1===t[o].ascending);break}};return FlexSheetColumnFilterEditor}(ColumnFilterEditor);export{FlexSheetColumnFilterEditor};var FlexSheetFilter=function(e){__extends(FlexSheetFilter,e);function FlexSheetFilter(){return null!==e&&e.apply(this,arguments)||this}Object.defineProperty(FlexSheetFilter.prototype,"filterDefinition",{get:function(){for(var e={filters:[]},t=0;t<this._filters.length;t++){var o=this._filters[t];if(o&&o.column&&this.grid.columns.indexOf(o.column)>-1)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:function(e){var t=JSON.parse(asString(e));this.clear();for(var o=0;o<t.filters.length;o++){var n=t.filters[o],i=this.grid.columns[n.columnIndex],l=this.getColumnFilter(i,!0);if(l)switch(n.type){case"condition":var r=l.conditionFilter;r.condition1.value=i.dataType==DataType.Date?changeType(n.condition1.value,i.dataType,null):n.condition1.value;r.condition1.operator=n.condition1.operator;r.and=n.and;r.condition2.value=i.dataType==DataType.Date?changeType(n.condition2.value,i.dataType,null):n.condition2.value;r.condition2.operator=n.condition2.operator;break;case"value":var s=l.valueFilter;s.filterText=n.filterText;s.showValues=n.showValues}}this.apply()},enumerable:!0,configurable:!0});FlexSheetFilter.prototype.apply=function(){var e=this;e.grid.deferUpdate((function(){for(var t,o,n,i=-1,l=0;l<e.grid.rows.length;l++)if(!((t=e.grid.rows[l])instanceof HeaderRow||l<=i)){i=-1;o=e._filter(l);if(t instanceof GroupRow){n=t.getCellRange();if(null==t.dataItem||t.dataItem instanceof CollectionViewGroup)t.visible=e._checkGroupVisible(n);else{t.visible=o;i=n.bottomRow;if(n.isValid)for(var r=n.topRow;r<=n.bottomRow;r++)e.grid.rows[r].visible=o}}else t.visible=o}e.grid._isCopying||e.grid._isUndoing||e.grid._isSorting||e.onFilterApplied()}))};FlexSheetFilter.prototype.editColumnFilter=function(e,t){var o=this,n=o.grid;o.closeEditor();e=o._asColumn(e);var i=document.createElement("div"),l=o.getColumnFilter(e),r=new FlexSheetColumnFilterEditor(i,l,o.showSortButtons);addClass(i,"wj-dropdown-panel");o._divEdt=i;o._edtCol=e;var s=new CellRangeEventArgs(n.cells,new CellRange(-1,e.index));o.onFilterChanging(s);if(s.cancel){o._divEdt=null;o._edtCol=null}else{s.cancel=!0;n.undoStack.stackSize>0&&(o._undoAcion=new _FilteringAction(n));n.rightToLeft&&(i.dir="rtl");r.filterChanged.addHandler((function(){s.cancel=!1;o._filterChanged=!0;setTimeout((function(){if(!s.cancel){o.apply();if(o._undoAcion){o._undoAcion.saveNewState();n.undoStack._addAction(o._undoAcion);o._undoAcion=null}}}))}));r.buttonClicked.addHandler((function(){o.closeEditor();n.focus();o.onFilterChanged(s)}));r.lostFocus.addHandler((function(){setTimeout((function(){var e=Control.getControl(o._divEdt);e&&!e.containsFocus()&&o.closeEditor()}),10)}));n._edtHdl._commitRowEdits();n.scrollIntoView(-1,e.index,!0);var a=o.grid.columnHeaders,h=t?t.row:a.rows.length-1,u=t?t.col:e.index,c=a.getCellBoundingRect(h,u),d=document.elementFromPoint(c.left+c.width/2,c.top+c.height/2);(d=closest(d,".wj-cell"))?showPopup(i,d,!1,!1,!1):showPopup(i,c);o._setAriaExpanded(d,!0);o._setAriaExpanded(n.cells.getCellElement(-1,u),!0);for(var _=r.hostElement.querySelectorAll("input"),f=0;f<_.length;f++){var g=_[f];if(g.offsetHeight>0&&g.tabIndex>-1&&!g.disabled){g.focus();break}}r.containsFocus()||r.focus()}};FlexSheetFilter.prototype._updateColumnFilter=function(e){e=this._asColumn(e);var t=this.getColumnFilter(e,!1),o=null!=t?t.valueFilter:null;if(o&&o.isActive){var n=this._getValueFilters(e),i=o.showValues;if(n&&n.length>0){for(var l in i)for(var r=0;r<n.length;r++){if(i[l]&&isSameRow(n[r].cellRef,i[l].cellRef)){i[n[r].text]={show:!0,cellRef:n[r].cellRef};n[r].text!=l&&delete i[l];break}if(n[r].text==l){i[l].show=!0;break}}o.showValues=i}}function isSameRow(e,t){return""!=e&&""!=e&&e.split("_")[0]==t.split("_")[0]}};FlexSheetFilter.prototype._getValueFilters=function(e){var t=this.getColumnFilter(e,!1),o=t.valueFilter,n=e.grid,i=e.index,l=[],r={},s=o.showValues,a=t.conditionFilter,h=a.condition1.operator,u=a.condition2.operator;if(o.uniqueValues||null!=n.itemsSource&&null!=n.childItemsPath)l=o.getUniqueValues(!0);else for(var c=0;c<n.rows.length;c++){var d=n.rows[c];if(!(d instanceof HeaderRow||d instanceof GroupRow||d instanceof _NewRowTemplate)){o.showValues=null;a.condition1.operator=null;a.condition2.operator=null;var _=n.filter._filter(c);o.showValues=s;a.condition1.operator=h;a.condition2.operator=u;if((d.visible||_)&&(d.visible||!o.apply(c)||!a.apply(c))){var f=c,g=i,p=n.getMergedRange(n.cells,f,g);if(p){if(p.leftCol!==i)continue;f=p.topRow;g=p.leftCol}var w=n.getCellValue(f,g),m=void 0;m=o.dataMap?o.dataMap.getDisplayValue(w):n.getCellValue(f,g,!0);w=""===w?null:w;var C=n.getCellData(f,g,!0),S=void 0;if(!r[m]){r[m]=!0;S=C&&"="===C[0]?c+"_"+i:"";l.push({value:w,text:m,cellRef:S})}}}}return l};FlexSheetFilter.prototype.closeEditor=function(){this._undoAcion&&!this._filterChanged&&(this._undoAcion=null);e.prototype.closeEditor.call(this)};FlexSheetFilter.prototype.getColumnFilter=function(e,t){void 0===t&&(t=!0);if(e=this._asColumn(e)){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);this._filters.push(n);return n}}return null};FlexSheetFilter.prototype._isActive=function(){var e=this;return this._filters.some((function(t){return t.column&&(t.conditionFilter.isActive||t.valueFilter.isActive)&&e.grid.columns.indexOf(t.column)>=0}))};FlexSheetFilter.prototype._isEditorOpened=function(){return!!this._divEdt};FlexSheetFilter.prototype._checkGroupVisible=function(e){for(var t,o=!0,n=e.topRow+1;n<=e.bottomRow;n++)if(t=this.grid.rows[n])if(t instanceof GroupRow)o=this._checkGroupVisible(t.getCellRange());else if(o=this._filter(n))break;return o};return FlexSheetFilter}(FlexGridFilter);export{FlexSheetFilter};var _SmartTag=function(e){__extends(_SmartTag,e);function _SmartTag(t,o,n,i){var l=e.call(this,t)||this;l.CopyCells=AutoFillOperation.CopyFormat|AutoFillOperation.CopyContent;l.FillSeries=AutoFillOperation.CopyFormat|AutoFillOperation.FillSeries;l.FillFormat=AutoFillOperation.CopyFormat;l.FillWithoutFormat=AutoFillOperation.FillSeries;l.FullWidth=32;l.CompactWidth=18;l._uiEventHdl=l._onUIEvent.bind(l);l.operationSelected=new Event;l.cancelled=new Event;l._owner=o;l._op=n;var r=l.getTemplate();l.applyTemplate("wj-flexsheet-smart-tag",r,{_icon:"icon",_btnMenu:"btn-menu"});var s=l._getPos();setCss(l.hostElement,{left:s.x,top:s.y});l.addEventListener(l.hostElement,"mouseover",(function(){l.hostElement.style.width=l.FullWidth+"px";l._btnMenu.style.display=""}));l.addEventListener(l.hostElement,"mouseleave",(function(){if(!l._menu){l.hostElement.style.width=l.CompactWidth+"px";l._btnMenu.style.display="none"}}));l.addEventListener(l.hostElement,"mousedown",(function(e){e.preventDefault();l._showFillOpMenu()}),!0);l.addEventListener(document.body,"mousedown",l._uiEventHdl,!0);l.addEventListener(document.body,"keydown",l._uiEventHdl,!0);l.initialize(i);return l}_SmartTag.prototype.dispose=function(){this.removeEventListener(document.body,"mousedown",this._uiEventHdl,!0);this.removeEventListener(document.body,"keydown",this._uiEventHdl,!0);e.prototype.dispose.call(this)};Object.defineProperty(_SmartTag.prototype,"operation",{get:function(){return this._op},enumerable:!0,configurable:!0});_SmartTag.prototype.onOperationSelected=function(e){this.operationSelected.raise(this,e)};_SmartTag.prototype.onCancelled=function(e){this.cancelled.raise(this,e)};_SmartTag.prototype._getPos=function(){var e=this._owner,t=e._root,o=e.selection,n=e.cells.getCellBoundingRect(o.bottomRow,o.rightCol,!0),i=e.cells.hostElement,l=n.right+i.offsetLeft,r=n.bottom+i.offsetTop;l+e._ptScrl.x+32+(i.offsetHeight>t.offsetHeight?17:0)>t.offsetWidth&&(l-=32);r+e._ptScrl.y+18+(i.offsetWidth>t.offsetWidth?17:0)>t.offsetHeight&&(r-=18);return new Point(l,r)};_SmartTag.prototype._showFillOpMenu=function(){var e=this,t=culture.FlexSheet;this._menu=new Menu(document.createElement("div"),{displayMemberPath:"item",selectedValuePath:"op",dropDownCssClass:"wj-flexsheet-fill-menu",openOnHover:!1,closeOnLeave:!1,itemsSource:[{item:t.copyCells,op:this.CopyCells,checked:this._op===this.CopyCells},{item:t.fillSeries,op:this.FillSeries,checked:this._op===this.FillSeries},{item:t.fillFormat,op:this.FillFormat,checked:this._op===this.FillFormat},{item:t.fillWithoutFormat,op:this.FillWithoutFormat,checked:this._op===this.FillWithoutFormat}],selectedValue:this._op,itemClicked:function(t){e._op=t.selectedValue;e.onOperationSelected()}});this._menu.listBox.checkedMemberPath="checked";this._menu.show(this.hostElement);this._menu.selectedValue=this._op};_SmartTag.prototype._onUIEvent=function(e){var t=e.target,o=contains(this.hostElement,t),n=this._menu&&contains(this._menu.listBox.hostElement,t),i=o||n;i&&e instanceof KeyboardEvent&&(i=n&&(e.keyCode==Key.Down||e.keyCode==Key.Up||e.keyCode==Key.Enter||e.keyCode==Key.Escape));i||this.onCancelled()};_SmartTag.controlTemplate='<img wj-part="icon" style="float:left; height: 18; margin: 0" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAAFJJREFUeNrclEEKACAIBOfp/Xy7i4WSRnRYBIVRVhFJVIhyEAxllQa5E/wBSnsU6Rza2nugqNmASi57C/KKNg/Iqn+iVWzx6M4bOdUEAAD//wMAAYRMfiNaiqEAAAAASUVORK5CYII=" /><img wj-part="btn-menu" style="float:left; height: 18; margin: 0; display: none" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAASCAYAAACXScT7AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVN3WJP3Fj7f92UPVkLY8LGXbIEAIiOsCMgQWaIQkgBhhBASQMWFiApWFBURnEhVxILVCkidiOKgKLhnQYqIWotVXDjuH9yntX167+3t+9f7vOec5/zOec8PgBESJpHmomoAOVKFPDrYH49PSMTJvYACFUjgBCAQ5svCZwXFAADwA3l4fnSwP/wBr28AAgBw1S4kEsfh/4O6UCZXACCRAOAiEucLAZBSAMguVMgUAMgYALBTs2QKAJQAAGx5fEIiAKoNAOz0ST4FANipk9wXANiiHKkIAI0BAJkoRyQCQLsAYFWBUiwCwMIAoKxAIi4EwK4BgFm2MkcCgL0FAHaOWJAPQGAAgJlCLMwAIDgCAEMeE80DIEwDoDDSv+CpX3CFuEgBAMDLlc2XS9IzFLiV0Bp38vDg4iHiwmyxQmEXKRBmCeQinJebIxNI5wNMzgwAABr50cH+OD+Q5+bk4eZm52zv9MWi/mvwbyI+IfHf/ryMAgQAEE7P79pf5eXWA3DHAbB1v2upWwDaVgBo3/ldM9sJoFoK0Hr5i3k4/EAenqFQyDwdHAoLC+0lYqG9MOOLPv8z4W/gi372/EAe/tt68ABxmkCZrcCjg/1xYW52rlKO58sEQjFu9+cj/seFf/2OKdHiNLFcLBWK8ViJuFAiTcd5uVKRRCHJleIS6X8y8R+W/QmTdw0ArIZPwE62B7XLbMB+7gECiw5Y0nYAQH7zLYwaC5EAEGc0Mnn3AACTv/mPQCsBAM2XpOMAALzoGFyolBdMxggAAESggSqwQQcMwRSswA6cwR28wBcCYQZEQAwkwDwQQgbkgBwKoRiWQRlUwDrYBLWwAxqgEZrhELTBMTgN5+ASXIHrcBcGYBiewhi8hgkEQcgIE2EhOogRYo7YIs4IF5mOBCJhSDSSgKQg6YgUUSLFyHKkAqlCapFdSCPyLXIUOY1cQPqQ28ggMor8irxHMZSBslED1AJ1QLmoHxqKxqBz0XQ0D12AlqJr0Rq0Hj2AtqKn0UvodXQAfYqOY4DRMQ5mjNlhXIyHRWCJWBomxxZj5Vg1Vo81Yx1YN3YVG8CeYe8IJAKLgBPsCF6EEMJsgpCQR1hMWEOoJewjtBK6CFcJg4Qxwicik6hPtCV6EvnEeGI6sZBYRqwm7iEeIZ4lXicOE1+TSCQOyZLkTgohJZAySQtJa0jbSC2kU6Q+0hBpnEwm65Btyd7kCLKArCCXkbeQD5BPkvvJw+S3FDrFiOJMCaIkUqSUEko1ZT/lBKWfMkKZoKpRzame1AiqiDqfWkltoHZQL1OHqRM0dZolzZsWQ8ukLaPV0JppZ2n3aC/pdLoJ3YMeRZfQl9Jr6Afp5+mD9HcMDYYNg8dIYigZaxl7GacYtxkvmUymBdOXmchUMNcyG5lnmA+Yb1VYKvYqfBWRyhKVOpVWlX6V56pUVXNVP9V5qgtUq1UPq15WfaZGVbNQ46kJ1Bar1akdVbupNq7OUndSj1DPUV+jvl/9gvpjDbKGhUaghkijVGO3xhmNIRbGMmXxWELWclYD6yxrmE1iW7L57Ex2Bfsbdi97TFNDc6pmrGaRZp3mcc0BDsax4PA52ZxKziHODc57LQMtPy2x1mqtZq1+rTfaetq+2mLtcu0W7eva73VwnUCdLJ31Om0693UJuja6UbqFutt1z+o+02PreekJ9cr1Dund0Uf1bfSj9Rfq79bv0R83MDQINpAZbDE4Y/DMkGPoa5hpuNHwhOGoEctoupHEaKPRSaMnuCbuh2fjNXgXPmasbxxirDTeZdxrPGFiaTLbpMSkxeS+Kc2Ua5pmutG003TMzMgs3KzYrMnsjjnVnGueYb7ZvNv8jYWlRZzFSos2i8eW2pZ8ywWWTZb3rJhWPlZ5VvVW16xJ1lzrLOtt1ldsUBtXmwybOpvLtqitm63Edptt3xTiFI8p0in1U27aMez87ArsmuwG7Tn2YfYl9m32zx3MHBId1jt0O3xydHXMdmxwvOuk4TTDqcSpw+lXZxtnoXOd8zUXpkuQyxKXdpcXU22niqdun3rLleUa7rrStdP1o5u7m9yt2W3U3cw9xX2r+00umxvJXcM970H08PdY4nHM452nm6fC85DnL152Xlle+70eT7OcJp7WMG3I28Rb4L3Le2A6Pj1l+s7pAz7GPgKfep+Hvqa+It89viN+1n6Zfgf8nvs7+sv9j/i/4XnyFvFOBWABwQHlAb2BGoGzA2sDHwSZBKUHNQWNBbsGLww+FUIMCQ1ZH3KTb8AX8hv5YzPcZyya0RXKCJ0VWhv6MMwmTB7WEY6GzwjfEH5vpvlM6cy2CIjgR2yIuB9pGZkX+X0UKSoyqi7qUbRTdHF09yzWrORZ+2e9jvGPqYy5O9tqtnJ2Z6xqbFJsY+ybuIC4qriBeIf4RfGXEnQTJAntieTE2MQ9ieNzAudsmjOc5JpUlnRjruXcorkX5unOy553PFk1WZB8OIWYEpeyP+WDIEJQLxhP5aduTR0T8oSbhU9FvqKNolGxt7hKPJLmnVaV9jjdO31D+miGT0Z1xjMJT1IreZEZkrkj801WRNberM/ZcdktOZSclJyjUg1plrQr1zC3KLdPZisrkw3keeZtyhuTh8r35CP5c/PbFWyFTNGjtFKuUA4WTC+oK3hbGFt4uEi9SFrUM99m/ur5IwuCFny9kLBQuLCz2Lh4WfHgIr9FuxYji1MXdy4xXVK6ZHhp8NJ9y2jLspb9UOJYUlXyannc8o5Sg9KlpUMrglc0lamUycturvRauWMVYZVkVe9ql9VbVn8qF5VfrHCsqK74sEa45uJXTl/VfPV5bdra3kq3yu3rSOuk626s91m/r0q9akHV0IbwDa0b8Y3lG19tSt50oXpq9Y7NtM3KzQM1YTXtW8y2rNvyoTaj9nqdf13LVv2tq7e+2Sba1r/dd3vzDoMdFTve75TsvLUreFdrvUV99W7S7oLdjxpiG7q/5n7duEd3T8Wej3ulewf2Re/ranRvbNyvv7+yCW1SNo0eSDpw5ZuAb9qb7Zp3tXBaKg7CQeXBJ9+mfHvjUOihzsPcw83fmX+39QjrSHkr0jq/dawto22gPaG97+iMo50dXh1Hvrf/fu8x42N1xzWPV56gnSg98fnkgpPjp2Snnp1OPz3Umdx590z8mWtdUV29Z0PPnj8XdO5Mt1/3yfPe549d8Lxw9CL3Ytslt0utPa49R35w/eFIr1tv62X3y+1XPK509E3rO9Hv03/6asDVc9f41y5dn3m978bsG7duJt0cuCW69fh29u0XdwruTNxdeo94r/y+2v3qB/oP6n+0/rFlwG3g+GDAYM/DWQ/vDgmHnv6U/9OH4dJHzEfVI0YjjY+dHx8bDRq98mTOk+GnsqcTz8p+Vv9563Or59/94vtLz1j82PAL+YvPv655qfNy76uprzrHI8cfvM55PfGm/K3O233vuO+638e9H5ko/ED+UPPR+mPHp9BP9z7nfP78L/eE8/sl0p8zAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAGCSURBVHjafNFPKKRxHAbw5/v7GYdBYUQjLm5SkoNykCQHtcx431/KgdKumJvSrAO7Nwc3RQ5kd3OkHJC/hUJREluonVcToqRh3sRFPA6M1Mbhc3z6Pj1fkMRHQNJL0uPeul731lU37o1y49cqHr8GvvgWQRLBsmpM/P0j4XAXiooKcXl1CZDEzl4EJBEwAZBUwWAQsVgsFSRR11gmM8trimSa3WypzZ31l5v2/vfk/4oAcv9aSGyUSz4gg/AIAOET0YQswIQWaNrnH+2OeSaY0BJN2+wDTi/OpCrwkxX1vW8q63p5cnaaB+Z/09u7x0nFJTVMiEajPsNCQaC6Ryb8THKcw/Tikho6zj//0RGUNV6gMZ1H8fmpH5iTHDlwsiOhO7FrN5RdP6aBIUj/pvJ2bkFbkxAzBzELELNCQQqgrJ5ST1/jqmYOJcHa7dYYGV5TrQ3d+vfUU+b7IfrOIRCGBYD0o1VGmaHaB6DZkqvMD2hUfF1UAISkvE/+yqbCZ89+HgBtwgFOrBUzJgAAAABJRU5ErkJggg==" />';return _SmartTag}(Control);export{_SmartTag};var _FlexSheetSelectionHandler=function(e){__extends(_FlexSheetSelectionHandler,e);function _FlexSheetSelectionHandler(t){var o=this,n=t.selectionMode;(o=e.call(this,t)||this)._mode=n;o._fs=t;return o}_FlexSheetSelectionHandler.prototype.moveSelection=function(t,o,n){var i=this._fs;!n&&i._lastSelMovePos&&this.selection.copy(i._lastSelMovePos);i._lastSelMovePos=null;e.prototype.moveSelection.call(this,t,o,n)};return _FlexSheetSelectionHandler}(_SelectionHandler);export{_FlexSheetSelectionHandler};var DefinedName=function(){function DefinedName(e,t,o,n){this._owner=e;this._name=t;this._value=o;if(null!=n){if(!e._validateSheetName(n))throw"The sheet name:("+n+") does not exist in FlexSheet.";this._sheetName=n}}Object.defineProperty(DefinedName.prototype,"name",{get:function(){return this._name},set:function(e){if(this._name!==e){if(this._owner.definedNames._find(e,this._sheetName,-1,!0))throw"The "+e+" already existed in definedNames.";var t=this._name;this._name=e;this._owner._updateFormulasWithNameUpdating(t,this._name)}},enumerable:!0,configurable:!0});Object.defineProperty(DefinedName.prototype,"value",{get:function(){return this._value},set:function(e){this._value!==e&&(this._value=e)},enumerable:!0,configurable:!0});Object.defineProperty(DefinedName.prototype,"sheetName",{get:function(){return this._sheetName},enumerable:!0,configurable:!0});return DefinedName}();export{DefinedName};var DefinedNameCollection=function(e){__extends(DefinedNameCollection,e);function DefinedNameCollection(t){var o=e.call(this)||this;o._owner=t;o.collectionChanged.addHandler((function(e,t){if(t.action===NotifyCollectionChangedAction.Add||t.action===NotifyCollectionChangedAction.Change){var n=t.action===NotifyCollectionChangedAction.Add?"inserted":"updated";if(!(t.item instanceof DefinedName)){o.remove(t.item);throw"Invalid defined name item object was "+n+". The DefinedName instance should be "+n+" in the definedNames array."}if(!t.item||!t.item.name||null==t.item.value){o.remove(t.item);throw"Invalid defined name was "+n+"."}if(null!=t.item.sheetName&&!o._owner._validateSheetName(t.item.sheetName)){o.remove(t.item);throw"The sheet name ("+t.item.sheetName+") does not exist in FlexSheet."}if(o._find(t.item.name,t.item.sheetName,t.index,!0)){o.remove(t.item);throw"The "+t.item.name+" already existed in definedNames."}}}));return o}DefinedNameCollection.prototype._find=function(e,t,o,n){void 0===o&&(o=-1);void 0===n&&(n=!1);var i=null;t=t?t.toLowerCase():t;e=e?e.toLowerCase():e;for(var l=0;l<this.length;l++){var r=this[l];if(r.name.toLowerCase()===e&&l!==o)if(r.sheetName){if(r.sheetName.toLowerCase()===t)return r}else{if(n&&t)continue;i=r}}return i};DefinedNameCollection.prototype._getIndexByName=function(e){for(var t=0;t<this.length;t++)if(this[t].name===e)return t;return-1};DefinedNameCollection.prototype._updateSheetName=function(e,t){for(var o=e.toLowerCase(),n=0;n<this.length;n++){var i=this[n];null!=i.sheetName&&i.sheetName.toLowerCase()===o&&(i._sheetName=t);var l=i.value.match(/(\w+)\!\$?[A-Za-z]+\$?\d+/g);if(l&&l.length>0)for(var r=0;r<l.length;r++){var s=l[r];s.substring(0,s.indexOf("!"))===e&&(i.value=i.value.replace(s,s.replace(e,t)))}}};return DefinedNameCollection}(ObservableArray);export{DefinedNameCollection};var _ContextMenu=function(e){__extends(_ContextMenu,e);function _ContextMenu(t,o){var n=e.call(this,t)||this;n._idx=-1;n._owner=o;return n}Object.defineProperty(_ContextMenu.prototype,"visible",{get:function(){return"none"!==this.hostElement.style.display},enumerable:!0,configurable:!0});_ContextMenu.prototype.show=function(e,t){if(this._owner.selectedSheet){this._owner.finishEditing();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";n+this.hostElement.clientHeight>window.innerHeight+(e?window.pageYOffset:0)&&(n-=this.hostElement.clientHeight);o+this.hostElement.clientWidth>window.innerWidth+(e?window.pageXOffset:0)&&(o-=this.hostElement.clientWidth);this.hostElement.style.top=n+"px";this.hostElement.style.left=o+"px"}};_ContextMenu.prototype.hide=function(){this._idx=-1;var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e);this.hostElement.style.display="none"};_ContextMenu.prototype.moveToNext=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e);this._idx++;for(;e[this._idx]&&("none"===e[this._idx].style.display||hasClass(e[this._idx],"wj-state-disabled"));)this._idx++;this._idx>=e.length&&(this._idx=0);addClass(e[this._idx],"wj-context-menu-item-selected")};_ContextMenu.prototype.moveToPrev=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e);this._idx--;this._idx<0&&(this._idx=e.length-1);for(;this._idx>0&&("none"===e[this._idx].style.display||hasClass(e[this._idx],"wj-state-disabled"));)this._idx--;addClass(e[this._idx],"wj-context-menu-item-selected")};_ContextMenu.prototype.moveToFirst=function(){var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._removeSelectedState(e);this._idx=0;addClass(e[this._idx],"wj-context-menu-item-selected")};_ContextMenu.prototype.moveToLast=function(){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--;addClass(e[this._idx],"wj-context-menu-item-selected")};_ContextMenu.prototype.handleContextMenu=function(){if(-1===this._idx)this.moveToNext();else{var e=this.hostElement.querySelectorAll(".wj-context-menu-item");this._handleMenuItemOperation(e);this.hide();this._owner.hostElement.focus()}};_ContextMenu.prototype.refresh=function(t){void 0===t&&(t=!0);e.prototype.refresh.call(this,t);this._localize()};_ContextMenu.prototype._init=function(){var e=this,t=e.hostElement.querySelectorAll(".wj-context-menu-item");e.hostElement.style.zIndex="9999";document.body.appendChild(e.hostElement);e.addEventListener(document.body,"mousemove",(function(){e._removeSelectedState(t)}));e.addEventListener(e.hostElement,"contextmenu",(function(e){e.preventDefault()}));this._localize()};_ContextMenu.prototype._handleMenuItemOperation=function(e){};_ContextMenu.prototype._localize=function(){};_ContextMenu.prototype._removeSelectedState=function(e){for(var t=0;t<e.length;t++)removeClass(e[t],"wj-context-menu-item-selected")};return _ContextMenu}(Control);export{_ContextMenu};var _SheetContextMenu=function(e){__extends(_SheetContextMenu,e);function _SheetContextMenu(t,o){var n=e.call(this,t,o)||this;n._isDisableDelRow=!1;n._isDisableConvertTable=!1;n.applyTemplate("",n.getTemplate(),{_insRows:"insert-rows",_delRows:"delete-rows",_insCols:"insert-columns",_delCols:"delete-columns",_splitter:"splitter",_convertTable:"convert-table"});n._init();return n}_SheetContextMenu.prototype.show=function(t,o){if(this._owner.selectedSheet){if(this._owner._isDisableDeleteRow(this._owner.selection.topRow,this._owner.selection.bottomRow)){this._isDisableDelRow=!0;addClass(this._delRows,"wj-state-disabled")}this._showTableOperation();if(!this._owner.selection.isValid){this._isDisableConvertTable=!0;addClass(this._convertTable,"wj-state-disabled")}e.prototype.show.call(this,t,o)}};_SheetContextMenu.prototype.hide=function(){e.prototype.hide.call(this);this._isDisableDelRow=!1;this._isDisableConvertTable=!1;removeClass(this._delRows,"wj-state-disabled");removeClass(this._convertTable,"wj-state-disabled")};_SheetContextMenu.prototype._init=function(){e.prototype._init.call(this);var t=this;t.addEventListener(t._insRows,"click",(function(e){t._owner.insertRows();t.hide();t._owner.hostElement.focus()}));t.addEventListener(t._delRows,"click",(function(e){t._isDisableDelRow||t._owner.deleteRows();t.hide();t._owner.hostElement.focus()}));t.addEventListener(t._insCols,"click",(function(e){t._owner.insertColumns();t.hide();t._owner.hostElement.focus()}));t.addEventListener(t._delCols,"click",(function(e){t._owner.deleteColumns();t.hide();t._owner.hostElement.focus()}));t.addEventListener(t._convertTable,"click",(function(e){t._isDisableConvertTable||t._addTable();t.hide();t._owner.hostElement.focus()}))};_SheetContextMenu.prototype._handleMenuItemOperation=function(e){switch(e[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()}};_SheetContextMenu.prototype._localize=function(){e.prototype._localize.call(this);var t=culture.FlexSheet;this._insRows.textContent=t.insertRow;this._delRows.textContent=t.deleteRow;this._insCols.textContent=t.insertCol;this._delCols.textContent=t.deleteCol;this._convertTable.textContent=t.convertTable};_SheetContextMenu.prototype._showTableOperation=function(){for(var e=this._owner.selection,t=e.topRow;t<=e.bottomRow;t++)for(var o=e.leftCol;o<=e.rightCol;o++){if(null!=this._owner.selectedSheet.findTable(t,o)){this._convertTable.style.display="none";this._splitter.style.display="none";return}}if(e.isSingleCell||this._owner._containsMergedCells(e)){this._convertTable.style.display="none";this._splitter.style.display="none"}else{this._convertTable.style.display="";this._splitter.style.display=""}};_SheetContextMenu.prototype._addTable=function(){var e=this._owner.selectedSheet._addTable(this._owner.selection);if(e){if(0===this._owner.undoStack.stackSize)return;var t=new _TableAction(this._owner,e);this._owner.undoStack._addAction(t)}};_SheetContextMenu.controlTemplate='<div class="wj-context-menu wj-control wj-flexsheet-context-menu" width="150px"><div class="wj-context-menu-item" wj-part="insert-rows"></div><div class="wj-context-menu-item" wj-part="delete-rows"></div><div class="wj-context-menu-item" wj-part="insert-columns"></div><div class="wj-context-menu-item" wj-part="delete-columns"></div><div class="wj-state-disabled" wj-part="splitter" style="width:100%;height:1px;background-color:lightgray;"></div><div class="wj-context-menu-item" wj-part="convert-table"></div></div>';return _SheetContextMenu}(_ContextMenu);export{_SheetContextMenu};var _SheetTabContextMenu=function(e){__extends(_SheetTabContextMenu,e);function _SheetTabContextMenu(t,o){var n=e.call(this,t,o)||this;n.applyTemplate("",n.getTemplate(),{_insSheet:"insert-sheet",_delSheet:"delete-sheet",_renameSheet:"rename-sheet"});n._init();return n}_SheetTabContextMenu.prototype._init=function(){var t=culture.FlexSheet,o=this;o._insSheet.textContent=t.insertSheet;o._delSheet.textContent=t.deleteSheet;o._renameSheet.textContent=t.renameSheet;e.prototype._init.call(this);o.addEventListener(o._insSheet,"click",(function(e){o._owner.addUnboundSheet(null,null,null,o._owner.selectedSheetIndex);o.hide();o._owner.hostElement.focus()}));o.addEventListener(o._delSheet,"click",(function(e){o._owner.sheets.removeAt(o._owner.selectedSheetIndex);o.hide();o._owner.hostElement.focus()}));o.addEventListener(o._renameSheet,"click",(function(e){o._owner._tabHolder.sheetControl._startEditingSheetName(o._owner.selectedSheetIndex);o.hide()}))};_SheetTabContextMenu.prototype._handleMenuItemOperation=function(e){switch(e[this._idx]){case this._insSheet:this._owner.addUnboundSheet(null,null,null,this._owner.selectedSheetIndex);break;case this._delSheet:this._owner.sheets.removeAt(this._owner.selectedSheetIndex);break;case this._renameSheet:this._owner._tabHolder.sheetControl._startEditingSheetName(this._owner.selectedSheetIndex)}};_SheetTabContextMenu.prototype._localize=function(){e.prototype._localize.call(this);var t=culture.FlexSheet;this._insSheet.textContent=t.insertSheet;this._delSheet.textContent=t.deleteSheet;this._renameSheet.textContent=t.renameSheet};_SheetTabContextMenu.controlTemplate='<div class="wj-context-menu wj-control wj-flexsheet-context-menu" width="150px"><div class="wj-context-menu-item" wj-part="insert-sheet"></div><div class="wj-context-menu-item" wj-part="delete-sheet"></div><div class="wj-context-menu-item" wj-part="rename-sheet"></div><div>';return _SheetTabContextMenu}(_ContextMenu);export{_SheetTabContextMenu};var Sheet=function(){function Sheet(e,t,o,n,i){this._visible=!0;this._unboundSortDesc=new ObservableArray;this._currentStyledCells={};this._currentMergedRanges=[];this._isEmptyGrid=!1;this._rowSettings=[];this._scrollPosition=new Point;this._ownerHeaderRowRemoved=!1;this.workingAs="";this.nameChanged=new Event;this.visibleChanged=new Event;var l=this;this._uuid=Sheet.GenId++;l._owner=e;l._name=o;l._sortList=[new ColumnSortDescription(-1,!0)];n=isNumber(n)&&!isNaN(n)&&n>=0?n:200;i=isNumber(i)&&!isNaN(i)&&i>=0?i:20;if(t){t.columns.forEach((function(e){return e._orgHdr=e._hdr}));l._grid=t;l._addHeaderRow(!0)}else{l._grid=this._createGrid(n,i);l._owner&&(l._grid.validateEdits=l._owner.validateEdits)}l._grid.loadedRows.addHandler((function(){l._owner&&l._owner._checkCollectionsOwner();l._addHeaderRow();l._setRowSettings()}));l._grid.refreshed.addHandler((function(){l._owner&&l._owner._checkCollectionsOwner()}));l._grid.itemsSourceChanged.addHandler(this._gridItemsSourceChanged,this);l._unboundSortDesc.collectionChanged.addHandler((function(){for(var e=l._unboundSortDesc,t={},o=0;o<e.length;o++){if(!tryCast(e[o],_UnboundSortDescription))throw"sortDescriptions array must contain SortDescription objects."}if(l._owner){l._owner.rows.beginUpdate();l._owner.rows.sort(l._compareRows());if(!l._owner._isUndoing){for(o=0;o<l._owner.rows.length;o++){var n=l._owner.rows[o];o!==n._idx&&l._owner._updateFormulaForReorderingRows(n._idx,o);l._owner._updateCellStyleForReorderingRows(n._idx,o,t)}l._currentStyledCells=t}l._owner.rows.endUpdate();l._owner.rows._dirty=!0;l._owner.rows._update();if(l._owner.selectedSheet){l._owner._copyTo(l._owner.selectedSheet);l._owner._copyFrom(l._owner.selectedSheet)}}}));l.tables.collectionChanged.addHandler((function(e,t){if(null!=t.item&&!(t.item instanceof Table))throw"The tables only allows to handle Table instance.";if(l._owner)if(t.action===NotifyCollectionChangedAction.Add||t.action===NotifyCollectionChangedAction.Change){if(t.item){var o=t.item,n=o._getTableRange(),i=l===l._owner.selectedSheet?l._owner:l.grid;try{if(n.topRow>=i.rows.length||n.leftCol>=i.columns.length)throw"";if(n.leftCol+n.columnSpan>i.columns.length)throw"";if(n.topRow+n.rowSpan>i.rows.length)throw"";for(var r=n.topRow;r<=n.bottomRow;r++)for(var s=n.leftCol;s<=n.rightCol;s++){if(l.findTable(r,s)!==o)throw""}o._attachSheet(l)}catch(e){l.tables.removeAt(t.index)}}}else t.action===NotifyCollectionChangedAction.Remove&&t.item&&t.item._detachSheet()}))}Object.defineProperty(Sheet.prototype,"grid",{get:function(){null==this._grid.wj_sheetInfo&&(this._grid.wj_sheetInfo={});return this._grid},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"name",{get:function(){return this._name},set:function(e){if(!isNullOrWhiteSpace(e)&&(this._name&&this._name.toLowerCase()!==e.toLowerCase()||!this._name)){var t=new PropertyChangedEventArgs("sheetName",this._name,e);this._name=e;this.grid.wj_sheetInfo.name=e;this.onNameChanged(t)}},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"visible",{get:function(){return this._visible},set:function(e){if(this._visible!==e){this._visible=e;this.grid.wj_sheetInfo.visible=e;this.onVisibleChanged(new EventArgs)}},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"rowCount",{get:function(){return null!=this._grid?this._grid.rows.length:0},set:function(e){if(!this.itemsSource){var t=this.grid.rows.length;if(isNumber(e)&&!isNaN(e)&&e>=0&&t!==e){if(t<e)for(var o=0;o<e-t;o++)this.grid.rows.push(new Row);else this.grid.rows.splice(e,t-e);this._currentStyledCells=this._adjustStylesDict(this._currentStyledCells);this._owner&&this._owner.selectedSheet&&this._name===this._owner.selectedSheet.name&&this._owner._copyFrom(this)}}},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"columnCount",{get:function(){return null!=this._grid?this._grid.columns.length:0},set:function(e){if(!this.itemsSource){var t=this.grid.columns.length;if(isNumber(e)&&!isNaN(e)&&e>=0&&t!==e){if(t<e)for(var o=0;o<e-t;o++)this._grid.columns.push(new Column);else this._grid.columns.splice(e,t-e);this._currentStyledCells=this._adjustStylesDict(this._currentStyledCells);this._owner&&this._owner.selectedSheet&&this._name===this._owner.selectedSheet.name&&this._owner._copyFrom(this)}}},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"selectionRanges",{get:function(){var e=this;if(!this._selectionRanges){this._selectionRanges=new ObservableArray;this._selectionRanges.collectionChanged.addHandler((function(){if(e._owner&&!e._owner._isClicking){var t=e._selectionRanges.length;if(t>0){var o=e._selectionRanges[t-1];o&&o instanceof CellRange&&(e._owner.selection=o)}if(t>1){e._owner._enableMulSel=!0;e._owner.refresh(!1)}e._owner._enableMulSel=!1}}),this)}return this._selectionRanges},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"itemsSource",{get:function(){return null!=this._grid?this._grid.itemsSource:null},set:function(e){if(!this._grid||this._grid.itemsSource!=e){this._owner&&this._owner._isCopying||(this._dataView=null);this._isEmptyGrid&&this._clearGrid();this._grid.itemsSource=e}},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"filterSetting",{get:function(){this._owner&&this===this._owner.selectedSheet&&this._getFilterSetting();return this._filterSetting},set:function(e){this._filterSetting=e;this._owner&&this===this._owner.selectedSheet&&this._applyFilterSetting()},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"tables",{get:function(){null==this._tables&&(this._tables=new ObservableArray);return this._tables},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"_styledCells",{get:function(){this._currentStyledCells||(this._currentStyledCells={});this._currentStyledCells.columnCount=this.columnCount;this._currentStyledCells.rowCount=this.rowCount;return this._currentStyledCells},set:function(e){this._currentStyledCells=e},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"_uid",{get:function(){return this._uuid},enumerable:!0,configurable:!0});Object.defineProperty(Sheet.prototype,"_mergedRanges",{get:function(){this._currentMergedRanges||(this._currentMergedRanges=[]);return this._currentMergedRanges},enumerable:!0,configurable:!0});Sheet.prototype.onNameChanged=function(e){this.nameChanged.raise(this,e)};Sheet.prototype.onVisibleChanged=function(e){this.visibleChanged.raise(this,e)};Sheet.prototype.dispose=function(){this._clearGrid();this._grid.wj_sheetInfo=null;this._grid.dispose();this._grid=null;if(null!=this._tables){for(var e=0;e<this._tables.length;e++)this._tables[e]=null;this._tables=null}};Sheet.prototype.getCellStyle=function(e,t){var o=this._grid.rows.length,n=this._grid.columns.length;if(e>=o||t>=n)return null;var i=e*n+t;return this._styledCells[i]};Sheet.prototype.addTableFromArray=function(e,t,o,n,i,l,r,s){void 0===s&&(s=!0);var a=!1;if(this._owner){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;for(var h=null==(r&&r.showHeaderRow)||r.showHeaderRow,u=!(!r||!r.showTotalRow),c=e+(h?1:0),d=c+o.length-1+(u?1:0),_=[],f=this._flex,g=0;g<n.length;g++){var p=n[g],w=new TableColumn(p);0===g?w._totalRowLabel="Total":g===n.length-1&&(w._totalRowFunction="Sum");_.push(w)}var m=new CellRange(e,t,d,t+n.length-1),C=this._needShiftForTable(m);if(0!==C){if(!s)return null;if(!this._canShiftCells(m))return null;var S=this._needAddRowCountForAddTable(C,m);if(f.collectionView){var b=f.itemsSource instanceof CollectionView;f.collectionView.beginUpdate();for(var v=0;v<S;v++)b?f.itemsSource.sourceCollection.push({}):f.itemsSource.push({});f.collectionView.endUpdate(!0)}else for(v=0;v<S;v++)f.rows.push(new Row);a=!0}if(t+n.length>=f.columns.length){if(!s)return null;var y=t+n.length-f.columns.length+1;if(this.itemsSource&&y>0)return null;f.columns.beginUpdate();for(v=0;v<y;v++)f.columns.push(new Column);f.columns.endUpdate()}f.beginUpdate();a&&this._moveDownCells(C,m);if(h)for(g=0;g<n.length;g++){p=n[g];f.setCellData(e,t+g,p)}for(var R=0;R<o.length;R++)for(g=0;g<n.length;g++){p=n[g];f.setCellData(c+R,t+g,o[R][p])}f.endUpdate();return this._addTable(m,i,l,_,r)}};Sheet.prototype.findTable=function(e,t){var o,n=this._tables;if(n&&(o=n.length)>0)for(var i=0;i<o;i++){var l=n[i],r=l._getTableRange();if(e>=r.topRow&&e<=r.bottomRow&&t>=r.leftCol&&t<=r.rightCol)return l}return null};Sheet.prototype._attachOwner=function(e){var t=this;if(this._owner!==e){this._owner=e;if(this._owner){var o=!1;this._owner.loadedRows.addHandler((function(){if(!o){o=!0;t._addHeaderRow()}}))}}};Sheet.prototype._setValidName=function(e){this._name=e;this.grid.wj_sheetInfo.name=e};Sheet.prototype._storeRowSettings=function(){if(this._owner){this._rowSettings=[];for(var e=0;e<this._grid.rows.length;e++){var t=this._owner.rows[e];t&&(this._rowSettings[e]={height:t.height,allowMerging:t.allowMerging,isCollapsed:t instanceof GroupRow?t.isCollapsed:null,visible:t.visible,isSelected:t.isSelected,readOnly:t.isReadOnly&&!(t instanceof HeaderRow)})}}};Sheet.prototype._setRowSettings=function(){for(var e=0;e<this._rowSettings.length;e++){var t=this._rowSettings[e];if(t){var o=this._grid.rows[e];if(o){var n=o instanceof HeaderRow;o.height=t.height;o.allowMerging=t.allowMerging;o.visible=t.visible;o instanceof GroupRow&&(o.isCollapsed=!!t.isCollapsed);o.isSelected=!!t.isSelected;o.isReadOnly=n||!!t.readOnly}}}};Sheet.prototype._addTable=function(e,t,o,n,i){if(!e.isValid||!this._owner)return null;var l;null!=t&&null==this._owner._getTable(t)||(t=this._getUniqueTableName());l=new Table(t,e,o,n,i);this.tables.push(l);return l};Sheet.prototype._addSelection=function(e){var t=this.selectionRanges;t.beginUpdate();for(var o=t.length-1;o>=0;o--)e.contains(t[o])&&t.removeAt(o);e.isValid&&t.push(e);t.endUpdate()};Object.defineProperty(Sheet.prototype,"_flex",{get:function(){return this===this._owner.selectedSheet?this._owner:this.grid},enumerable:!0,configurable:!0});Sheet.prototype._compareRows=function(){var e=this,t=this._unboundSortDesc;return function(o,n){for(var i=0;i<t.length;i++){var l=t[i],r=o._ubv&&l.column?o._ubv[l.column._hash]:"",s=n._ubv&&l.column?n._ubv[l.column._hash]:"";_isFormula(r)&&(r=e._owner.evaluate(r));_isFormula(s)&&(s=e._owner.evaluate(s));r!=r&&(r=null);s!=s&&(s=null);isString(r)&&(r=r.toLowerCase()+r);isString(s)&&(s=s.toLowerCase()+s);if(""===r||null==r)return 1;if(""===s||null==s)return-1;var a=r<s?-1:r>s?1:0;isString(r)&&isNumber(s)&&(a=1);isString(s)&&isNumber(r)&&(a=-1);if(0!==a)return l.ascending?+a:-a}return 0}};Sheet.prototype._createGrid=function(e,t){var o=document.createElement("div");this._isEmptyGrid=!0;o.style.visibility="hidden";document.body.appendChild(o);var n=new FlexGrid(o);document.body.removeChild(o);for(var i=0;i<e;i++)n.rows.push(new Row);for(var l=0;l<t;l++){var r=new Column;r.isRequired=!1;n.columns.push(r)}n.wj_sheetInfo={name:this.name,visible:this.visible,styledCells:this._styledCells,mergedRanges:this._mergedRanges};return n};Sheet.prototype._clearGrid=function(){this._grid.rows.clear();this._grid.columns.clear();this._grid.columnHeaders.columns.clear();this._grid.rowHeaders.rows.clear()};Sheet.prototype._gridItemsSourceChanged=function(){var e=this;if(this._owner&&!this._owner._isCopying&&this._owner.selectedSheet&&this._name===this._owner.selectedSheet.name){this._owner.filter.clear();this._owner._copyFrom(this,!1);setTimeout((function(){e._owner._setFlexSheetToDirty();e._owner.invalidate()}),10)}};Sheet.prototype._addHeaderRow=function(e){void 0===e&&(e=!1);if(this._needAddHeaderRow()||e){var t=new HeaderRow;t.isReadOnly=!0;for(var o=0;o<this._grid.columns.length;o++){var n=this._grid.columns[o];t._ubv||(t._ubv={});t._ubv[n._hash]=FlexSheet._getHeaderRowText(n)}this._grid.rows.insert(0,t)}};Sheet.prototype._needAddHeaderRow=function(){var e=this._grid.allowAddNew&&this._grid.newRowAtTop?this._grid.rows[1]:this._grid.rows[0];return!(!this._grid.collectionView||e instanceof HeaderRow)&&(null==this._owner||!this._owner.rows.length||((this._owner.allowAddNew&&this._owner.newRowAtTop?this._owner.rows[1]:this._owner.rows[0])instanceof HeaderRow||!this._ownerHeaderRowRemoved))};Sheet.prototype._getUniqueTableName=function(){for(var e="Table1",t=2;;){if(null==this._owner._getTable(e))break;e="Table"+t;t++}return e};Sheet.prototype._needShiftForTable=function(e){for(var t=0,o=0,n=this._flex,i=e.topRow;i<=e.bottomRow;i++){if(i>=n.rows.length)return t=e.rowSpan-o;for(var l=e.leftCol;l<=e.rightCol&&l<n.columns.length;l++){var r=n.getCellData(i,l,!1);if(null!=r&&""!==r)return t=e.rowSpan-o}o++}return t};Sheet.prototype._needAddRowCountForAddTable=function(e,t){for(var o=this._flex,n=1;n<=e;n++)for(var i=o.rows.length-n,l=t.leftCol;l<=t.rightCol&&l<o.columns.length;l++){var r=o.getCellData(i,l,!1),s=this.getCellStyle(i,l);if(null!=r&&""!==r||null!=s)return e-n+1}return 0};Sheet.prototype._moveDownTable=function(e){for(var t=e._getTableRange(),o=this._flex,n=t.bottomRow;n>=t.topRow;n--)for(var i=t.leftCol;i<=t.rightCol;i++){var l=null!=o.columns[i].dataMap,r=o.getCellData(n,i,l);o.setCellData(n+1,i,r);o.setCellData(n,i,"")}e._updateTableRange(1,1,0,0)};Sheet.prototype._moveDownCells=function(e,t){for(var o=this._flex,n=o.rows.length-1-e;n>=t.topRow;n--)for(var i=t.leftCol;i<=t.rightCol&&i<o.columns.length;i++){var l=null!=o.columns[i].dataMap,r=o.getCellData(n,i,l);o.setCellData(n+e,i,r);o.setCellData(n,i,"");var s=this.getCellStyle(n,i),a=(n+e)*o.columns.length+i,h=n*o.columns.length+i;if(s){this._styledCells[a]=s;this._styledCells[h]=null}var u=this._mergedRanges[h];if(u){u.row+=e;u.row2+=e;this._mergedRanges[a]=u;this._mergedRanges[h]=null}var c=this.findTable(n,i);if(c){var d=c._getTableRange();d.topRow===n&&d.leftCol===i&&c._updateTableRange(e,e,0,0)}}};Sheet.prototype._moveUpCells=function(e,t){for(var o=this._flex,n=t.topRow;n<o.rows.length;n++)for(var i=t.leftCol;i<=t.rightCol&&i<o.columns.length;i++){var l=null!=o.columns[i].dataMap,r=o.getCellData(n,i,l);o.setCellData(n-e,i,r);o.setCellData(n,i,"");var s=this.getCellStyle(n,i),a=(n-e)*o.columns.length+i,h=n*o.columns.length+i;if(s){this._styledCells[a]=s;this._styledCells[h]=null}var u=this._mergedRanges[h];if(u){u.row-=e;u.row2-=e;this._mergedRanges[a]=u;this._mergedRanges[h]=null}var c=this.findTable(n,i);if(c){var d=c._getTableRange();d.topRow===n&&d.leftCol===i&&c._updateTableRange(-e,-e,0,0)}}};Sheet.prototype._moveDownCellsWithinTable=function(e,t,o){for(var n=this._flex,i=o.bottomRow;i>o.topRow+e;i--)for(var l=o.leftCol;l<=o.rightCol;l++){var r=null!=n.columns[l].dataMap,s=n.getCellData(i,l,r);n.setCellData(i+t,l,s);n.setCellData(i,l,"")}};Sheet.prototype._moveUpCellsWithinTable=function(e,t,o){for(var n=o.topRow+e,i=this._flex,l=n;l<=o.bottomRow;l++)for(var r=o.leftCol;r<=o.rightCol;r++){if(l>=n+t){var s=null!=i.columns[r].dataMap,a=i.getCellData(l,r,s);i.setCellData(l-t,r,a)}i.setCellData(l,r,"")}};Sheet.prototype._canShiftCells=function(e){for(var t=this._flex,o=e.topRow;o<t.rows.length;o++)for(var n=e.leftCol;n<=e.rightCol&&n<t.columns.length;n++){var i=this.findTable(o,n);if(i){var l=i._getTableRange();if(l.leftCol<e.leftCol||l.rightCol>e.rightCol)return!1}var r=o*t.columns.length+n,s=this._mergedRanges[r];if(s&&(s.leftCol<e.leftCol||s.rightCol>e.rightCol))return!1}return!0};Sheet.prototype._needMoveDownTable=function(e){var t=e.getRange();if(0===t.topRow)return!0;for(var o=e.getColumns(),n=this._flex,i=0;i<o.length;i++){var l=n.getCellData(t.topRow-1,t.leftCol+i,!1);if(null!=l&&""!==l)return!0}return!1};Sheet.prototype._needAddRowCountForInsertTableRows=function(e,t){for(var o=this._flex,n=1;n<=e;n++){var i=o.rows.length-n;if(i<=t.bottomRow)return e;for(var l=t.leftCol;l<=t.rightCol&&l<o.columns.length;l++){var r=o.getCellData(i,l,!1),s=this.getCellStyle(i,l);if(null!=r&&""!==r||null!=s)return e-n+1}}return 0};Sheet.prototype._getFilterSetting=function(){this._filterDefinition=this._owner.filter.filterDefinition;this._filterSetting={};this._filterSetting.filterColumns=this._owner.filter.filterColumns;this._filterSetting.columnFilterSettings||(this._filterSetting.columnFilterSettings=[]);for(var e=0;e<this._owner.filter._filters.length;e++){var t=this._owner.filter._filters[e];t&&this._filterSetting.columnFilterSettings.push({column:t.column,filterType:t.filterType,dataMap:t.dataMap,valueFilterSetting:{maxValues:t.valueFilter.maxValues,uniqueValues:t.valueFilter.uniqueValues,sortValues:t.valueFilter.sortValues,dataMap:t.valueFilter.dataMap,exclusiveValueSearch:t.valueFilter.exclusiveValueSearch},conditionFilterSetting:{dataMap:t.conditionFilter.dataMap}})}};Sheet.prototype._applyFilterSetting=function(){if(null==this._filterSetting)this._clearFilterSetting();else{this._owner.filter.filterColumns=this._filterSetting.filterColumns;this._filterDefinition&&(this._owner.filter.filterDefinition=this._filterDefinition);var e=this._filterSetting.columnFilterSettings;if(!e||!e.length)return;for(var t=0;t<e.length;t++){var o=e[t];if(o&&null!=o.column){var n=this._owner.filter.getColumnFilter(o.column);if(n){var i=n.valueFilter.showValues,l=n.valueFilter.filterText,r={operator:n.conditionFilter.condition1.operator,value:n.conditionFilter.condition1.value},s={operator:n.conditionFilter.condition2.operator,value:n.conditionFilter.condition2.value},a=n.conditionFilter.and;null!=o.dataMap&&(n.dataMap=o.dataMap);null!=o.filterType&&(n.filterType=o.filterType);var h=o.valueFilterSetting;if(h){h.dataMap&&(n.valueFilter.dataMap=h.dataMap);null!=h.maxValues&&(n.valueFilter.maxValues=h.maxValues);null!=h.sortValues&&(n.valueFilter.sortValues=h.sortValues);h.uniqueValues&&(n.valueFilter.uniqueValues=h.uniqueValues);n.valueFilter.exclusiveValueSearch=h.exclusiveValueSearch}var u=o.conditionFilterSetting;u&&u.dataMap&&(n.conditionFilter.dataMap=u.dataMap);n.valueFilter.showValues=i;n.valueFilter.filterText=l;n.conditionFilter.condition1.operator=r.operator;n.conditionFilter.condition1.value=r.value;n.conditionFilter.condition2.operator=s.operator;n.conditionFilter.condition2.value=s.value;n.conditionFilter.and=a}}}}};Sheet.prototype._cloneMergedCells=function(){for(var e=[],t=0;t<this._mergedRanges.length;t++){var o=this._mergedRanges[t];e.push(o.clone())}return e};Sheet.prototype._getMergedRange=function(e,t){for(var o=0;o<this._mergedRanges.length;o++){var n=this._mergedRanges[o];if(e>=n.topRow&&e<=n.bottomRow&&t>=n.leftCol&&t<=n.rightCol)return n}return null};Sheet.prototype._clearFilterSetting=function(){this._owner.filter._filters=[];this._owner.filter.filterColumns=null;this._filterDefinition&&(this._owner.filter.filterDefinition=this._filterDefinition)};Sheet.prototype._adjustStylesDict=function(e){if(e){var t=e.columnCount,o=e.rowCount,n=this.columnCount,i=this.rowCount;if(t&&t!=n||o&&o!=i){var l={};Object.keys(e).forEach((function(o){var r=+o;if(!isNaN(r)){var s=Math.floor(r/t),a=r%t;s<i&&a<n&&(l[s*n+a]=e[o]);delete e[o]}}));e=l}e.columnCount=n;e.rowCount=i;return e}};Sheet.GenId=0;return Sheet}();export{Sheet};var SheetCollection=function(e){__extends(SheetCollection,e);function SheetCollection(){var t=null!==e&&e.apply(this,arguments)||this;t._current=-1;t.sheetCleared=new Event;t.selectedSheetChanged=new Event;t.sheetNameChanged=new Event;t.sheetVisibleChanged=new Event;return t}SheetCollection.prototype.onSheetCleared=function(){this.sheetCleared.raise(this)};Object.defineProperty(SheetCollection.prototype,"selectedIndex",{get:function(){return this._current},set:function(e){this._moveCurrentTo(+e)},enumerable:!0,configurable:!0});SheetCollection.prototype.onSelectedSheetChanged=function(e){this.selectedSheetChanged.raise(this,e)};SheetCollection.prototype.push=function(){for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];for(var n=0;n<t.length;n++){var i=t[n].name?this.getValidSheetName(t[n]):this._getUniqueName();i!==t[n].name&&(t[n].name=i);e.prototype.push.call(this,t[n]);this._postprocessSheet(t[n])}return this.length};SheetCollection.prototype.splice=function(t,o){for(var n=this,i=[],l=2;l<arguments.length;l++)i[l-2]=arguments[l];i.forEach((function(e){if(e instanceof Sheet&&"Angular"===e.workingAs)requestAnimationFrame((function(){e.name=e.name?n.getValidSheetName(e):n._getUniqueName();n._postprocessSheet(e)}));else{e.name=e.name?n.getValidSheetName(e):n._getUniqueName();n._postprocessSheet(e)}}));return e.prototype.splice.apply(this,[t,o].concat(i))};SheetCollection.prototype.onCollectionChanged=function(t){this._current>=this.length&&(this._current=this.length-1);e.prototype.onCollectionChanged.call(this,t)};SheetCollection.prototype.onSheetNameChanged=function(e){this.sheetNameChanged.raise(this,e)};SheetCollection.prototype.onSheetVisibleChanged=function(e){this.sheetVisibleChanged.raise(this,e)};SheetCollection.prototype.selectFirst=function(){return this._moveCurrentTo(0)};SheetCollection.prototype.selectLast=function(){return this._moveCurrentTo(this.length-1)};SheetCollection.prototype.selectPrevious=function(){return this._moveCurrentTo(this._current-1)};SheetCollection.prototype.selectNext=function(){return this._moveCurrentTo(this._current+1)};SheetCollection.prototype.hide=function(e){if(e<0&&e>=this.length)return!1;if(!this[e].visible)return!1;this[e].visible=!1;return!0};SheetCollection.prototype.show=function(e){if(e<0&&e>=this.length)return!1;this[e].visible=!0;this._moveCurrentTo(e);return!0};SheetCollection.prototype.clear=function(){for(var t=0;t<this.length;t++){var o=this[t];o.dispose();o=null}e.prototype.clear.call(this);this._current=-1;this.onSheetCleared()};SheetCollection.prototype.isValidSheetName=function(e){var t=this._getSheetIndexFrom(e.name),o=this.indexOf(e);return-1===t||t===o};SheetCollection.prototype.getValidSheetName=function(e){for(var t=e.name,o=1,n=this.indexOf(e);;){var i=this._getSheetIndexFrom(t);if(-1===i||i===n)break;t=e.name.concat((o+1).toString());o++}return t};SheetCollection.prototype.getUniqueNameOnInit=function(){for(var e="Sheet1",t=1;;){if(-1===this._getSheetIndexFrom(e))break;e="Sheet"+t;t++}return e};SheetCollection.prototype._setCurrentIdx=function(e){this._current=e};SheetCollection.prototype._moveCurrentTo=function(e){var t=e;if(e<0||e>=this.length)return!1;if(this._current<t||0===t)for(;t<this.length&&!this[t].visible;)t++;else if(this._current>t)for(;t>=0&&!this[t].visible;)t--;if(t===this.length){t=e;for(;t>=0&&!this[t].visible;)t--}if(t<0)return!1;if(t!==this._current){var o=new PropertyChangedEventArgs("sheetIndex",this._current,t);this._current=t;this.onSelectedSheetChanged(o)}return!0};SheetCollection.prototype._getSheetIndexFrom=function(e){if(!e)return-1;e=e.toLowerCase();for(var t=0;t<this.length;t++){var o=this[t];if((o.name?o.name.toLowerCase():"")===e)return t}return-1};SheetCollection.prototype._postprocessSheet=function(e){e.nameChanged.removeHandler(this._shNameChanged,this);e.nameChanged.addHandler(this._shNameChanged,this);e.visibleChanged.removeHandler(this._shVisibleChanged,this);e.visibleChanged.addHandler(this._shVisibleChanged,this)};SheetCollection.prototype._shNameChanged=function(e,t){this.isValidSheetName(e)||e._setValidName(this.getValidSheetName(e));e._owner&&e._owner._sheetNameChanged(t.oldValue,e.name);var o=this._getSheetIndexFrom(e.name),n=new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Change,e,isNumber(o)?o:this.length-1);this.onSheetNameChanged(n)};SheetCollection.prototype._shVisibleChanged=function(e,t){var o=this._getSheetIndexFrom(e.name),n=new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Change,e,isNumber(o)?o:this.length-1);this.onSheetVisibleChanged(n)};SheetCollection.prototype._getUniqueName=function(){for(var e="Sheet1",t=2;;){if(-1===this._getSheetIndexFrom(e))break;e="Sheet"+t;t++}return e};return SheetCollection}(ObservableArray);export{SheetCollection};var _SheetTabs=function(e){__extends(_SheetTabs,e);function _SheetTabs(t,o,n){var i=e.call(this,t,n)||this;i._rtl=!1;i._sheetTabClicked=!1;i._owner=o;i._sheets=o.sheets;i._rtl="rtl"==getComputedStyle(o.hostElement).direction;i._initControl();i.deferUpdate((function(){i.initialize(n)}));return i}_SheetTabs.prototype.refresh=function(e){this._tabContainer.innerHTML="";this._tabContainer.innerHTML=this._getSheetTabs();this._rtl&&this._adjustSheetsPosition();this._adjustSize()};_SheetTabs.prototype._sourceChanged=function(e,t){void 0===t&&(t=NotifyCollectionChangedEventArgs.reset);var o=t;switch(o.action){case NotifyCollectionChangedAction.Add:var n=o.index-1;n<0&&(n=0);this._tabContainer.innerHTML="";this._tabContainer.innerHTML=this._getSheetTabs();this._rtl&&this._adjustSheetsPosition();this._adjustSize();break;case NotifyCollectionChangedAction.Remove:this._tabContainer.removeChild(this._tabContainer.children[o.index]);this._adjustSize();break;default:this.invalidate()}};_SheetTabs.prototype._selectedSheetChanged=function(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()};_SheetTabs.prototype._initControl=function(){var e=this,t=e.hostElement;e.applyTemplate("",e.getTemplate(),{_sheetContainer:"sheet-container",_tabContainer:"container",_sheetPage:"sheet-page",_newSheet:"new-sheet",_contextMenuHost:"context-menu"});e._contextMenu=new _SheetTabContextMenu(e._contextMenuHost,e._owner);if(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(t,"mousedown",(function(){e._owner._mouseHdl._htDown=null}));e.addEventListener(t,"dragstart",(function(t){t.dataTransfer.setData("text","foo");t.target instanceof HTMLLIElement&&e._owner._isDescendant(e._tabContainer,t.target)?e._dragSrcIdx=e._getItemIndex(e._tabContainer,t.target):e._dragSrcIdx=-1}));e.addEventListener(t,"dragover",(function(e){e.dataTransfer.dropEffect="move";e.preventDefault();e.stopPropagation()}));e.addEventListener(t,"drop",(function(t){if(e._dragSrcIdx>-1){var o;if(t.target instanceof HTMLLIElement&&e._owner._isDescendant(e._tabContainer,t.target))o=e._getItemIndex(e._tabContainer,t.target);else{var n=e._tabContainer.getBoundingClientRect();o=t.clientX<n.left?0:t.clientX>n.right?e._sheets.length-1:-1}if(o!==e._dragSrcIdx){var i=e._sheets[e._dragSrcIdx],l=e._owner.selection.clone();e._sheets._exchangingPosition=!0;e._sheets.deferUpdate((function(){i.grid._selHdl.select(l,!1,!1);e._sheets.splice(e._dragSrcIdx,1);e._sheets.splice(o,0,i)}));e._owner.selectedSheetIndex=o;e._sheets._exchangingPosition=!1}}e._dragSrcIdx=-1;t.preventDefault();t.stopPropagation()}));e.addEventListener(e._newSheet,"click",(function(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()};_SheetTabs.prototype._initSheetTab=function(){var e=this;e.addEventListener(e._tabContainer,"mousedown",(function(t){var o,n=t.target;if(n instanceof HTMLLIElement){e._sheetTabClicked=!0;o=e._getItemIndex(e._tabContainer,n);e._scrollSheetTabContainer(n);o>-1&&(e._sheets.selectedIndex=o)}}));e.addEventListener(e._tabContainer,"dblclick",(function(t){var o,n=t.target;if(n instanceof HTMLLIElement){o=e._getItemIndex(e._tabContainer,n);e._scrollSheetTabContainer(n);o>-1&&e._startEditingSheetName(o)}}));e.addEventListener(e._tabContainer,"contextmenu",(function(t){t.preventDefault();e._contextMenu.show(t)}))};_SheetTabs.prototype._initSheetPage=function(){var e=this;e.hostElement.querySelector("div.wj-sheet-page").addEventListener("click",(function(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()}}))};_SheetTabs.prototype._getSheetTabs=function(){for(var e="",t=0;t<this._sheets.length;t++)e+=this._getSheetElement(this._sheets[t],this._sheets.selectedIndex===t);return e};_SheetTabs.prototype._getSheetElement=function(e,t){void 0===t&&(t=!1);var o="<li";e.visible?t&&(o+=' class="active"'):o+=' class="hidden"';return o+=' draggable="true">'+e.name+"</li>"};_SheetTabs.prototype._updateTabActive=function(e,t){e>=0&&e<this._tabContainer.children.length&&toggleClass(this._tabContainer.children[e],"active",t)};_SheetTabs.prototype._updateTabShown=function(e,t){if(!(t.index<0||t.index>=this._tabContainer.children.length)){t.item.visible?removeClass(this._tabContainer.children[t.index],"hidden"):addClass(this._tabContainer.children[t.index],"hidden");this._adjustSize()}};_SheetTabs.prototype._adjustSize=function(){var e,t=0;if("none"!==this.hostElement.style.display){e=this._tabContainer.parentElement.scrollLeft;this._tabContainer.parentElement.style.width="";this._tabContainer.style.width="";this._sheetPage.parentElement.style.width="";for(var o=0,n=this._tabContainer.childElementCount;o<n;o++)t+=this._tabContainer.children[o].offsetWidth+1;var i=this.hostElement.offsetWidth-this._sheetPage.offsetWidth-this._newSheet.offsetWidth-2;this._tabContainer.parentElement.style.width=(t>i?i:t)+"px";this._tabContainer.style.width=t+"px";this._sheetPage.parentElement.style.width=this._sheetPage.offsetWidth+this._newSheet.offsetWidth+this._tabContainer.parentElement.offsetWidth+3+"px";this._tabContainer.parentElement.scrollLeft=e}};_SheetTabs.prototype._getItemIndex=function(e,t){for(var o=0;o<e.children.length;o++)if(e.children[o]===t)return o;return-1};_SheetTabs.prototype._updateSheetName=function(e,t){this._tabContainer.querySelectorAll("li")[t.index].textContent=t.item.name;this._adjustSize()};_SheetTabs.prototype._scrollSheetTabContainer=function(e){var t=this._tabContainer.parentElement.scrollLeft,o=this._tabContainer.parentElement.offsetWidth;if(this._rtl)switch(FlexGrid._getRtlMode()){case"rev":var n=-this._tabContainer.offsetLeft;n+e.offsetLeft+e.offsetWidth>o+t?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:n+e.offsetLeft<t&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth);break;case"neg":e.offsetLeft<t?this._tabContainer.parentElement.scrollLeft-=e.offsetWidth:e.offsetLeft+e.offsetWidth>o+t&&(this._tabContainer.parentElement.scrollLeft+=e.offsetWidth);break;default:var i=this._newSheet.offsetWidth;e.offsetLeft-i+t<0?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:e.offsetLeft+e.offsetWidth-i+t>o&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth)}else{var l=this._sheetPage.offsetWidth;e.offsetLeft+e.offsetWidth-l>o+t?this._tabContainer.parentElement.scrollLeft+=e.offsetWidth:e.offsetLeft-l<t&&(this._tabContainer.parentElement.scrollLeft-=e.offsetWidth)}};_SheetTabs.prototype._adjustSheetsPosition=function(){for(var e=this._tabContainer.querySelectorAll("li"),t=0,o=0;o<e.length;o++){var n=e[o];n.style.cssFloat="right";n.style.right=t+"px";t+=e[o].clientWidth}};_SheetTabs.prototype._scrollToActiveSheet=function(e,t){var o=this._tabContainer.querySelectorAll("li"),n=0;this._tabContainer.clientWidth>this._tabContainer.parentElement.clientWidth&&(n=this._tabContainer.clientWidth-this._tabContainer.parentElement.clientWidth);if(o.length>0&&e<o.length&&t<o.length){if(0===e&&!this._rtl||e===o.length-1&&this._rtl){if(this._rtl)switch(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===o.length-1&&!this._rtl){if(this._rtl)switch(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(var i=t+1;i<=e;i++){var l=o[i];this._scrollSheetTabContainer(l)}else for(i=t-1;i>=e;i--){l=o[i];this._scrollSheetTabContainer(l)}}};_SheetTabs.prototype._adjustNavigationButtons=function(e){var t=this.hostElement.querySelectorAll(".wj-sheet-page button");if(t&&4===t.length){var o=void 0;if(e){o=t[0].querySelector("span");removeClass(o,"wj-glyph-step-backward");addClass(o,"wj-glyph-step-forward");o=t[1].querySelector("span");removeClass(o,"wj-glyph-left");addClass(o,"wj-glyph-right");o=t[2].querySelector("span");removeClass(o,"wj-glyph-right");addClass(o,"wj-glyph-left");o=t[3].querySelector("span");removeClass(o,"wj-glyph-step-forward");addClass(o,"wj-glyph-step-backward")}else{o=t[0].querySelector("span");removeClass(o,"wj-glyph-step-forward");addClass(o,"wj-glyph-step-backward");o=t[1].querySelector("span");removeClass(o,"wj-glyph-right");addClass(o,"wj-glyph-left");o=t[2].querySelector("span");removeClass(o,"wj-glyph-left");addClass(o,"wj-glyph-right");o=t[3].querySelector("span");removeClass(o,"wj-glyph-step-backward");addClass(o,"wj-glyph-step-forward")}}};_SheetTabs.prototype._startEditingSheetName=function(e){var t,o=this,n=o._tabContainer.children[e],i=n.textContent;o._editingSheetTab=n;o._measureEle=document.createElement("span");o._measureEle.setAttribute(FlexGrid._WJS_MEASURE,"true");o._measureEle.style.visibility="hidden";o.hostElement.appendChild(o._measureEle);n.innerHTML='<input type="text" style="width: '+(n.offsetWidth-40)+'px;"/>';t=n.children[0];addClass(t,"wj-sheet-name-editor wj-form-control");t.value=i;setSelectionRange(t,0,i.length);o.addEventListener(t,"keydown",(function(e){e.keyCode===Key.Enter?o._commitSheetName():o._measureInputWidth(e.key)}));o.addEventListener(t,"blur",o._commitSheetName.bind(o))};_SheetTabs.prototype._commitSheetName=function(){if(this._editingSheetTab){var e=this._editingSheetTab.children[0];this.removeEventListener(e);var t=e.value,o=this._getItemIndex(this._tabContainer,this._editingSheetTab);if(null!=t&&""!==t&&-1===this._sheets._getSheetIndexFrom(t)){this._sheets[o].name=t;this._editingSheetTab.textContent=t}else this._editingSheetTab.textContent=this._sheets[o].name;this._editingSheetTab=null;removeChild(this._measureEle);this._measureEle=null;this._adjustSize()}};_SheetTabs.prototype._measureInputWidth=function(e){if(this._editingSheetTab&&!(e.length>1)){var t=this._editingSheetTab.children[0],o=t.selectionStart,n=t.selectionEnd,i=t.value;if(null!=(i=i.substring(0,o)+e+i.substring(n))&&""!==i){this._measureEle.textContent=i;t.style.width=this._measureEle.offsetWidth+"px";this._adjustSize()}}};_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 wj-part="context-menu" style="display:none;z-index:100"></div></div>';return _SheetTabs}(Control);export{_SheetTabs};var _UnboundSortDescription=function(){function _UnboundSortDescription(e,t){this._column=e;this._ascending=t}Object.defineProperty(_UnboundSortDescription.prototype,"column",{get:function(){return this._column},enumerable:!0,configurable:!0});Object.defineProperty(_UnboundSortDescription.prototype,"ascending",{get:function(){return this._ascending},enumerable:!0,configurable:!0});return _UnboundSortDescription}();export{_UnboundSortDescription};var _TabHolder=function(e){__extends(_TabHolder,e);function _TabHolder(t,o){var n=e.call(this,t)||this;n._splitterMousedownHdl=n._splitterMousedownHandler.bind(n);n._owner=o;n.applyTemplate("",n.getTemplate(),{_divSheet:"left",_divSplitter:"splitter",_divRight:"right"});n._init();return n}Object.defineProperty(_TabHolder.prototype,"sheetControl",{get:function(){return this._sheetControl},enumerable:!0,configurable:!0});Object.defineProperty(_TabHolder.prototype,"visible",{get:function(){return"none"!==this.hostElement.style.display},set:function(e){this.hostElement.style.display=e?"block":"none";this._divSheet.style.display=e?"block":"none"},enumerable:!0,configurable:!0});_TabHolder.prototype.getSheetBlanketSize=function(){return 20};_TabHolder.prototype.adjustSize=function(){var e=this._owner.scrollSize.width-this._owner.clientSize.width,t=(this._owner.scrollSize.height,this._owner.clientSize.height,this._divSplitter.parentElement);if(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)}else{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()};_TabHolder.prototype._init=function(){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)};_TabHolder.prototype._splitterMousedownHandler=function(e){this._startPos=e.pageX;document.addEventListener("mousemove",this._splitterMousemoveHandler.bind(this),!0);document.addEventListener("mouseup",this._funSplitterMousedown,!0);e.preventDefault()};_TabHolder.prototype._splitterMousemoveHandler=function(e){null!==this._startPos&&void 0!==this._startPos&&this._adjustDis(e.pageX-this._startPos)};_TabHolder.prototype._splitterMouseupHandler=function(e){document.removeEventListener("mousemove",this._splitterMousemoveHandler,!0);document.removeEventListener("mouseup",this._funSplitterMousedown,!0);this._adjustDis(e.pageX-this._startPos);this._startPos=null};_TabHolder.prototype._adjustDis=function(e){var t=this._divRight.offsetWidth-e,o=this._divSheet.offsetWidth+e;if(t<=100){t=100;e=this._divRight.offsetWidth-t;o=this._divSheet.offsetWidth+e}else if(o<=100){e=(o=100)-this._divSheet.offsetWidth;t=this._divRight.offsetWidth-e}if(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>';return _TabHolder}(Control);export{_TabHolder};var _Expression=function(){function _Expression(e,t){this._evaluated=!1;this._rounder=e;this._token=t?t instanceof _Token?t:new _Token(t,_TokenID.ATOM,_TokenType.LITERAL):new _Token(null,_TokenID.ATOM,_TokenType.IDENTIFIER)}Object.defineProperty(_Expression.prototype,"token",{get:function(){return this._token},enumerable:!0,configurable:!0});Object.defineProperty(_Expression.prototype,"evaluated",{get:function(){return this._evaluated},enumerable:!0,configurable:!0});Object.defineProperty(_Expression.prototype,"evaluatedValue",{get:function(){return this._evaluated?this._evaluatedValue:void 0},set:function(e){this._evaluatedValue=e;this._evaluated=!0},enumerable:!0,configurable:!0});_Expression.prototype.evaluate=function(e,t,o,n,i,l){void 0===n&&(n=!0);void 0===i&&(i=!1);void 0===l&&(l=!0);if(this._token.tokenType===_TokenType.ERROR){if(l)throw this._token.value;return this._token.value}if(this._token.tokenType!==_TokenType.LITERAL)throw new SyntaxError(_ErrorMessages.BadExpression);return this._token.value};_Expression.toString=function(e,t,o,n){var i=e.evaluate(t,o,n);if(i instanceof FormulaError)throw i;(null==i||e instanceof _CellRangeExpression&&e._isEmpty)&&(i="");i&&!isPrimitive(i)&&(i=i.value);isString(i)&&"'"===i[0]&&(i=i.substr(1));isDate(i)&&(i=i.valueOf());return null!=i?i.toString():""};_Expression.toNumber=function(e,t,o,n){var i=e.evaluate(t,o,n);(null==i||e instanceof _CellRangeExpression&&e._isEmpty)&&(i=0);if(i instanceof FormulaError)throw i;i&&!isPrimitive(i)&&(i=i.value);if(isNumber(i))return i;if(isBoolean(i))return i?1:0;if(isDate(i))return FlexSheet._toOADate(i);if(isString(i)){"'"===i[0]&&(i=i.substr(1));if(i=i.trim()){if(!isNaN(+i))return+i;if(this.isDateValue(i))return FlexSheet._toOADate(new Date(i))}}return changeType(i,DataType.Number)};_Expression.toBoolean=function(e,t,o,n){var i=e.evaluate(t,o,n);(null==i||e instanceof _CellRangeExpression&&e._isEmpty)&&(i=0);if(i instanceof FormulaError)throw i;i&&!isPrimitive(i)&&(i=i.value);if(isBoolean(i))return i;if(isNumber(i))return 0!==i;isString(i)&&"'"===i[0]&&(i=i.substr(1));return changeType(i,DataType.Boolean,"")};_Expression.toDate=function(e,t,o,n){var i=e.evaluate(t,o,n);(null==i||e instanceof _CellRangeExpression&&e._isEmpty)&&(i=0);if(i instanceof FormulaError)throw i;i&&!isPrimitive(i)&&(i=i.value);if(isDate(i))return i;if(isNumber(i))return FlexSheet._fromOADate(i);isString(i)&&"'"===i[0]&&(i=i.substr(1));return changeType(i,DataType.Date,"")};_Expression.isDateValue=function(e){var t,o=["January","February","March","April","May","June","July","August","September","October","November","December","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];!e||e instanceof FormulaError||isPrimitive(e)||(e=e.value);if(!(t=isDate(e))&&isString(e)){"'"===e[0]&&(e=e.substr(1));if(!isNullOrWhiteSpace(e)&&isNaN(e)&&(e.indexOf("/")>0||e.indexOf("-")>0)&&!(t=!isNaN(Date.parse(e))))for(var n in o)if(e.indexOf(o[n])>-1){t=!0;break}}return t};_Expression.prototype._refersTo=function(e){return!1};_Expression.prototype._updateCellRangeExp=function(e,t,o,n,i,l){return!1};_Expression.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1);void 0===i&&(i=!1);return!1};_Expression.prototype._updateCellRangeExpForReorderingRows=function(e){return!1};_Expression.prototype._updateCellBoundary=function(e,t){return!1};_Expression.prototype._getStringExpression=function(){return null==this._token.value?"":isString(this._token.value)?'"'+this._token.value+'"':this._token.value.toString()};return _Expression}();export{_Expression};var _UnaryExpression=function(e){__extends(_UnaryExpression,e);function _UnaryExpression(t,o,n){var i=e.call(this,t,o)||this;i._expr=n;return i}_UnaryExpression.prototype.evaluate=function(e,t,o,n,i,l){void 0===n&&(n=!0);void 0===i&&(i=!1);void 0===l&&(l=!0);if(this._expr.token.tokenType===_TokenType.ERROR){if(l)throw this._expr.token.value;return this._expr.token.value}if(this.token.tokenID===_TokenID.SUB){if(!this.evaluated){var r=_Expression.toNumber(this._expr,e,t,o);this.evaluatedValue=isString(r)?NaN:-r}return this.evaluatedValue}if(this.token.tokenID===_TokenID.ADD){if(!this.evaluated){r=_Expression.toNumber(this._expr,e,t,o);this.evaluatedValue=isString(r)?NaN:+r}return this.evaluatedValue}throw new SyntaxError(_ErrorMessages.BadExpression)};_UnaryExpression.prototype._refersTo=function(e){return this._expr._refersTo(e)};_UnaryExpression.prototype._updateCellRangeExp=function(e,t,o,n,i,l){return this._expr._updateCellRangeExp(e,t,o,n,i,l)};_UnaryExpression.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1);void 0===i&&(i=!1);return this._expr._moveCellRangeExp(e,t,o,n,i)};_UnaryExpression.prototype._updateCellRangeExpForReorderingRows=function(e){return this._expr._updateCellRangeExpForReorderingRows(e)};_UnaryExpression.prototype._getStringExpression=function(){return this.token.tokenID===_TokenID.SUB?(this._inGroup?"(":"")+"-"+this._expr._getStringExpression()+(this._inGroup?")":""):this.token.tokenID===_TokenID.ADD?(this._inGroup?"(":"")+"+"+this._expr._getStringExpression()+(this._inGroup?")":""):""};return _UnaryExpression}(_Expression);export{_UnaryExpression};var _BinaryExpression=function(e){__extends(_BinaryExpression,e);function _BinaryExpression(t,o,n,i){var l=e.call(this,t,o)||this;l._leftExpr=n;l._rightExpr=i;return l}_BinaryExpression.prototype.evaluate=function(e,t,o,n,i,l){void 0===n&&(n=!0);void 0===i&&(i=!1);void 0===l&&(l=!0);var r,s,a,h;if(this.evaluated)return this.evaluatedValue;if(this._leftExpr.token.tokenType===_TokenType.ERROR){if(l)throw this._leftExpr.token.value;return this._leftExpr.token.value}if(this._rightExpr.token.tokenType===_TokenType.ERROR){if(l)throw this._rightExpr.token.value;return this._rightExpr.token.value}var u=_Expression.toString(this._leftExpr,e,t,o),c=_Expression.toString(this._rightExpr,e,t,o);if(this.token.tokenType===_TokenType.CONCAT)return this.evaluatedValue=u+c;var d=this._leftExpr.evaluate(e,t,o),_=this._rightExpr.evaluate(e,t,o);if(d&&!isPrimitive(d)){r=d.format;d=d.value}if(_&&!isPrimitive(_)){s=_.format;_=_.value}var f=_Expression.isDateValue(d),g=_Expression.isDateValue(_),p=f||g;if(p){a=isDate(d)?FlexSheet._toOADate(d):isNumber(d)?d:FlexSheet._toOADate(new Date(d));h=isDate(_)?FlexSheet._toOADate(_):isNumber(_)?_:FlexSheet._toOADate(new Date(_))}else{a=_Expression.toNumber(this._leftExpr,e,t,o);h=_Expression.toNumber(this._rightExpr,e,t,o)}if(this.token.tokenType===_TokenType.COMPARE){var w=void 0;this._leftExpr instanceof _CellRangeExpression&&this._leftExpr._isEmpty&&(d=null);this._rightExpr instanceof _CellRangeExpression&&this._rightExpr._isEmpty&&(_=null);var m=null==d,C=null==_;if(m!==C)w=m&&!_||C&&!d?0:m?-1:1;else{var S=typeof d,b=typeof _;if(i&&S!==b){if(this.token.tokenID===_TokenID.NE)return this.evaluatedValue=!0;if(this.token.tokenID!==_TokenID.EQ||"number"!==b&&!g)return this.evaluatedValue=!1}var v="boolean"===S;if(v!==("boolean"===b))w=v?1:-1;else{var y="string"===S;if(n&&y!==("string"===b))w=y?1:-1;else if(0!==d&&isNullOrWhiteSpace(d)||0!==_&&isNullOrWhiteSpace(_))w=d===_?0:d<=_?-1:1;else{isNumber(a)&&(a=this._rounder.round(a));isNumber(h)&&(h=this._rounder.round(h));w=a-h}}}switch(this.token.tokenID){case _TokenID.GT:return this.evaluatedValue=w>0;case _TokenID.LT:return this.evaluatedValue=w<0;case _TokenID.GE:return this.evaluatedValue=w>=0;case _TokenID.LE:return this.evaluatedValue=w<=0;case _TokenID.EQ:return isNaN(w)?this.evaluatedValue=u.toLowerCase()===c.toLowerCase():this.evaluatedValue=0===w;case _TokenID.NE:return isNaN(w)?this.evaluatedValue=u.toLowerCase()!==c.toLowerCase():this.evaluatedValue=0!==w}}if(isString(a)||isString(h))throw new ValueError;switch(this.token.tokenID){case _TokenID.ADD:this.evaluatedValue=a+h;break;case _TokenID.SUB:this.evaluatedValue=a-h;break;case _TokenID.MUL:this.evaluatedValue=a*h;break;case _TokenID.DIV:case _TokenID.PERCENT:if(0===h)throw this.evaluatedValue=new DivideByZeroError;this.evaluatedValue=a/h;break;case _TokenID.DIVINT:if(0===h)throw this.evaluatedValue=new DivideByZeroError;this.evaluatedValue=Math.floor(a/h);break;case _TokenID.MOD:if(0===h)throw this.evaluatedValue=new DivideByZeroError;this.evaluatedValue=Math.floor(a%h);break;case _TokenID.POWER:switch(h){case 0:this.evaluatedValue=1;break;case.5:this.evaluatedValue=Math.sqrt(a);break;case 1:this.evaluatedValue=a;break;case 2:this.evaluatedValue=a*a;break;case 3:this.evaluatedValue=a*a*a;break;case 4:this.evaluatedValue=a*a*a*a;break;default:this.evaluatedValue=Math.pow(a,h)}break;default:this.evaluatedValue=NaN}if(!isNaN(this.evaluatedValue)){p&&(this.evaluatedValue={value:FlexSheet._fromOADate(this.evaluatedValue),format:r||s});return this.evaluatedValue}throw new SyntaxError(_ErrorMessages.BadExpression)};_BinaryExpression.prototype._refersTo=function(e){return this._leftExpr._refersTo(e)||this._rightExpr._refersTo(e)};_BinaryExpression.prototype._updateCellRangeExp=function(e,t,o,n,i,l){var r,s=!1;r=this._leftExpr._updateCellRangeExp(e,t,o,n,i,l);s=s||r;r=this._rightExpr._updateCellRangeExp(e,t,o,n,i,l);return s||r};_BinaryExpression.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1);void 0===i&&(i=!1);var l,r=!1;l=this._leftExpr._moveCellRangeExp(e,t,o,n,i);r=r||l;l=this._rightExpr._moveCellRangeExp(e,t,o,n,i);return r||l};_BinaryExpression.prototype._updateCellRangeExpForReorderingRows=function(e){var t,o=!1;t=this._leftExpr._updateCellRangeExpForReorderingRows(e);o=o||t;t=this._rightExpr._updateCellRangeExpForReorderingRows(e);return o||t};_BinaryExpression.prototype._getStringExpression=function(){var e=_OpMap[this.token.tokenID]||"",t=this._leftExpr._getStringExpression(),o=this.token.tokenID!==_TokenID.PERCENT?this._rightExpr._getStringExpression():"";return(this._inGroup?"(":"")+t+e+o+(this._inGroup?")":"")};return _BinaryExpression}(_Expression);export{_BinaryExpression};var _CellRangeExpression=function(e){__extends(_CellRangeExpression,e);function _CellRangeExpression(t,o,n,i,l,r,s,a,h,u){void 0===l&&(l=!0);void 0===r&&(r=!1);void 0===s&&(s=!1);void 0===a&&(a=!1);void 0===h&&(h=!1);var c=e.call(this,t)||this;c._cells=new CellRange(o.topRow,o.leftCol,o.bottomRow,o.rightCol);c._sheetRef=n;c._flex=i;c._evalutingRange={};c._isCellRange=l;c._absRow=r;c._absCol=s;c._absRow2=a;c._absCol2=h;c._isWholeRow=u;return c}_CellRangeExpression.prototype.evaluate=function(e,t,o,n,i,l){void 0===n&&(n=!0);void 0===i&&(i=!1);void 0===l&&(l=!0);if(!this.evaluated){var r=this._extendRange(o),s=this._getCellValue(r,o,e,t,l,!0);this._isEmpty=null==s;this.evaluatedValue=s}return null==this.evaluatedValue?0:this.evaluatedValue};_CellRangeExpression.prototype.getValues=function(e,t,o,n){void 0===e&&(e=!0);void 0===n&&(n=!0);var i=[];if(!(o=this._getSheet()||o||this._flex.selectedSheet))return null;for(var l=this._extendRange(o),r=null==t||isNaN(+t)?l.leftCol:t,s=null==t||isNaN(+t)?l.rightCol:t,a=new CellRange,h=l.topRow;h<=l.bottomRow&&h<o.grid.rows.length;h++)if(e||!1!==o.grid.rows[h].isVisible)for(var u=r;u<=s&&u<o.grid.columns.length;u++){a.setRange(h,u);var c=this._getCellValue(a,o,void 0,void 0,n);!c||c instanceof FormulaError||isPrimitive(c)||(c=c.value);i.push(c)}return i};_CellRangeExpression.prototype.getValuesWithTwoDimensions=function(e,t){void 0===e&&(e=!0);var o,n,i,l,r,s=[],a=0,h=0;if(!(t=this._getSheet()||t||this._flex.selectedSheet))return null;for(i=(r=this._extendRange(t)).topRow;i<=r.bottomRow&&i<t.grid.rows.length;i++)if(e||!1!==t.grid.rows[i].isVisible){n=[];h=0;for(l=r.leftCol;l<=r.rightCol&&l<t.grid.columns.length;l++)if(e||!1!==t.grid.columns[l].isVisible){!(o=this._getCellValue(new CellRange(i,l),t))||o instanceof FormulaError||isPrimitive(o)||(o=o.value);n[h]=o;h++}else h++;s[a]=n;a++}else a++;return s};Object.defineProperty(_CellRangeExpression.prototype,"cells",{get:function(){return this._cells},enumerable:!0,configurable:!0});Object.defineProperty(_CellRangeExpression.prototype,"sheetRef",{get:function(){return this._sheetRef},enumerable:!0,configurable:!0});_CellRangeExpression.prototype._getCellValue=function(e,t,o,n,i,l){void 0===i&&(i=!0);var r,s,a;if(!(t=this._getSheet()||t||this._flex.selectedSheet))return null;for(var h=0,u=t._currentMergedRanges;h<u.length;h++){var c=u[h];if(e._row>=c._row&&e._row2<=c._row2&&e._col>=c._col&&e._col2<=c._col2&&(e._row!==c._row||e._col!==c._col))return null}if(e.isSingleCell){s=e.row;a=e.col}else{if(null!=o&&o>=e.topRow&&o<=e.bottomRow&&e.col===e.col2){s=o;a=e.col}if(null!=n&&n>=e.leftCol&&n<=e.rightCol&&e.row===e.row2){s=e.row;a=n}}if(null==s||null==a)throw new ReferenceError(_ErrorMessages.InvalidCellRef);r=t.name+":"+s+","+a+"-"+s+","+a;if(this._evalutingRange[r])throw new SyntaxError(_ErrorMessages.CircRef);try{if(this._flex){this._evalutingRange[r]=!0;var d=t===this._flex.selectedSheet?this._flex:t.grid;if(s<d.rows.length&&a<d.columns.length){var _=t.grid.columns[a],f=this._flex.getCellValue(s,a,!!l&&0,t);if(f instanceof FormulaError){if(i)throw f;return f}_.dataMap&&!l&&(f=_.dataMap.getDisplayValue(f));return f}return 0}}finally{delete this._evalutingRange[r]}};_CellRangeExpression.prototype._getSheet=function(){if(!this._sheetRef)return null;var e=this._flex._getSheet(this._sheetRef);if(!e)throw new ReferenceError(_ErrorMessages.InvalidSheetRef);return e};_CellRangeExpression.prototype._refersTo=function(e){return e.contains(this.cells)};_CellRangeExpression.prototype._updateCellRangeExp=function(e,t,o,n,i,l){var r=this._cells,s=!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;if(i){if(null==this._isWholeRow||this._isWholeRow){if(l&&(r.leftCol>l.rightCol||r.rightCol<l.leftCol))return!1;if(n){if(r.topRow>=t){r.row+=o;r.row2+=o;s=!0}else if(r.topRow<t&&r.bottomRow>=t){r.row2+=o;s=!0}}else if(r.topRow>t){r.row-=o;r.row2-=o;s=!0}else if(r.isSingleCell){if(r.row>=t-o+1){r.row=t-o+1;r.row2=t-o+1;s=!0}}else if(r.topRow>=t-o+1){r.row=t-o+1;r.row2-=o;s=!0}else if(r.topRow<t-o+1&&r.bottomRow>=t-o+1){r.bottomRow>t?r.row2-=o:r.row2=t-o;s=!0}}}else if(null==this._isWholeRow||!this._isWholeRow){if(l&&(r.topRow>l.bottomRow||r.bottomRow<l.topRow))return!1;if(n){if(r.leftCol>=t){r.col+=o;r.col2+=o;s=!0}else if(r.leftCol<t&&r.rightCol>=t){r.col2+=o;s=!0}}else if(r.leftCol>t){r.col-=o;r.col2-=o;s=!0}else if(r.isSingleCell){if(r.col>=t-o+1){r.col=t-o+1;r.col2=t-o+1;s=!0}}else if(r.leftCol>=t-o+1){r.col=t-o+1;r.col2-=o;s=!0}else if(r.leftCol<t-o+1&&r.rightCol>=t-o+1){r.rightCol>t?r.col2-=o:r.col2=t-o;s=!0}}return s};_CellRangeExpression.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1);void 0===i&&(i=!1);var l,r,s=this._cells,a=!1;if(this._tableParams&&this._tableParams.length>0)return!1;if(this._flex.selectedSheetIndex!=e&&(!this._sheetRef||this._sheetRef.toLowerCase()!==this._flex.selectedSheet.name.toLowerCase()))return!1;if(!i&&this._flex.selectedSheetIndex==e&&this._sheetRef&&this._sheetRef.toLowerCase()!==this._flex.selectedSheet.name.toLowerCase())return!1;l=o.topRow-t.topRow;r=o.leftCol-t.leftCol;if(i){if(0!==l&&(null==this._isWholeRow||this._isWholeRow)){s.row+=i&&this._absRow?0:l;s.row2+=this._isCellRange?i&&this._absRow2?0:l:i&&this._absRow?0:l;a=!0}if(0!==r&&(null==this._isWholeRow||!this._isWholeRow)){s.col+=i&&this._absCol?0:r;s.col2+=this._isCellRange?i&&this._absCol2?0:r:i&&this._absCol?0:r;a=!0}return a}if(t.contains(s)){if(0!==l&&(null==this._isWholeRow||this._isWholeRow)){s.row+=l;s.row2+=l;a=!0}if(0!==r&&(null==this._isWholeRow||!this._isWholeRow)){s.col+=r;s.col2+=r;a=!0}}else if(t.intersects(s)){if(t.intersectsRow(s)){var h=t.topRow>=s.topRow&&t.bottomRow<=s.bottomRow;if(0!==l&&(null==this._isWholeRow||this._isWholeRow))if(t.topRow<=s.topRow){if(l<0){s.row+=l;a=!0}else if(l>0){var u=h&&o.bottomRow<s.bottomRow;if(n&&!u){t.topRow<s.topRow&&(s.row-=s.topRow-t.topRow);s.row2-=t.rowSpan;a=!0}}}else if(t.bottomRow>=s.bottomRow){if(l>0){s.row2+=l;a=!0}else if(l<0){var c=h&&o.topRow>s.topRow;if(n&&!c){t.bottomRow>s.bottomRow&&(s.row2+=t.bottomRow-s.bottomRow);s.row+=t.rowSpan;a=!0}}}else if(n){l<0&&o.topRow<=s.topRow&&(s.row+=t.rowSpan);l>0&&o.bottomRow>=s.bottomRow&&(s.row2-=t.rowSpan);a=!0}}if(t.intersectsColumn(s)&&0!==r&&(null==this._isWholeRow||!this._isWholeRow))if(t.leftCol<=s.leftCol){if(r<0){s.col+=r;a=!0}else if(r>0&&n){t.leftCol<s.leftCol&&(s.col-=s.leftCol-t.leftCol);s.col2-=t.columnSpan;a=!0}}else if(t.rightCol>=s.rightCol){if(r>0){s.col2+=r;a=!0}else if(r<0&&n){t.rightCol>s.rightCol&&(s.col2+=t.rightCol-s.rightCol);s.col+=t.columnSpan;a=!0}}else if(n){r<0?s.col+=t.columnSpan:s.col2-=t.columnSpan;a=!0}}else if(n){if(null==this._isWholeRow||this._isWholeRow)if(s.row!==s.row2&&s.containsRow(o.topRow)){l<0?s.row2+=o.rowSpan:s.row=Math.max(0,s.row-o.rowSpan);a=!0}else{if(s.topRow>=o.topRow&&s.topRow<t.topRow&&l<0){s.row+=o.rowSpan;s.row2+=o.rowSpan;a=!0}if(s.topRow>t.bottomRow&&s.bottomRow<=o.bottomRow&&l>0){s.row-=o.rowSpan;s.row2-=o.rowSpan;a=!0}}if(null==this._isWholeRow||!this._isWholeRow)if(s.col!==s.col2&&s.containsColumn(o.leftCol)){r<0?s.col2+=o.columnSpan:s.col=Math.max(0,s.col-o.columnSpan);a=!0}else{if(s.leftCol>=o.leftCol&&s.leftCol<t.leftCol&&r<0){s.col+=o.columnSpan;s.col2+=o.columnSpan;a=!0}if(s.leftCol>t.rightCol&&s.rightCol<=o.rightCol&&r>0){s.col-=o.columnSpan;s.col2-=o.columnSpan;a=!0}}}return a};_CellRangeExpression.prototype._updateCellRangeExpForReorderingRows=function(e){var t,o=this._cells;if(null==this._isWholeRow||this._isWholeRow){(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}return!0};_CellRangeExpression.prototype._updateCellBoundary=function(e,t){var o=this._cells;if(this._sheetRef&&this._sheetRef.toLowerCase()!==this._flex.selectedSheet.name.toLowerCase())return!1;if(o.row===o.row2&&o.row===e&&t===o.col2+1){o.col2+=1;return!0}if(o.col===o.col2&&o.col===t&&e===o.row2+1){o.row2+=1;return!0}return!1};_CellRangeExpression.prototype._getStringExpression=function(){if(this._tableParams&&this._tableParams.length>0)return this._getTableParamsStringExpression();var e=this._quoteName(this._sheetRef);return this._definedName?this._definedName:(e?e+"!":"")+Workbook.xlsxAddress(this._cells.row,this._cells.col,this._absRow,this._absCol,this._isWholeRow)+(this._isCellRange?":"+Workbook.xlsxAddress(this._cells.row2,this._cells.col2,this._absRow2,this._absCol2,this._isWholeRow):"")};_CellRangeExpression.prototype._quoteName=function(e){e&&(/[\s\-!\$]/.test(e)||/^\d/.test(e))&&(e="'"+e+"'");return e};_CellRangeExpression.prototype._getTableParamsStringExpression=function(){var e,t=0,o="",n=this._tableParams.length,i=!1;if(!this._defTableParameterProvided){for(;t<n;t++)if("#"===(e=this._tableParams[t])[0]){o+="["+e+"]";t<n-1&&(o+=", ")}else if(i)o+=": ["+e+"]";else{o+="["+e+"]";i=!0}n>1&&(o="["+o+"]")}this._tableName&&(o=this._tableName+o);return o};_CellRangeExpression.prototype._extendRange=function(e){var t=this._cells.clone();if(null!=this._isWholeRow)if(this._isWholeRow){t.col=0;t.col2=e?e.grid.columns.length-1:this._flex.columns.length-1}else{t.row=0;t.row2=e?e.grid.rows.length-1:this._flex.rows.length-1}return t};return _CellRangeExpression}(_Expression);export{_CellRangeExpression};var _FunctionExpression=function(e){__extends(_FunctionExpression,e);function _FunctionExpression(t,o,n,i,l){void 0===l&&(l=!0);var r=e.call(this,t)||this;r._funcId=o;r._funcDefinition=n;r._params=i;r._needCacheEvaluatedVal=l;return r}_FunctionExpression.prototype.evaluate=function(e,t,o){if(!this._needCacheEvaluatedVal)return this._funcDefinition.func(this._params,o,e,t);this.evaluated||(this.evaluatedValue=this._funcDefinition.func(this._params,o,e,t));return this.evaluatedValue};_FunctionExpression.prototype._refersTo=function(e){if(this._params)for(var t=0;t<this._params.length;t++)if(this._params[t]._refersTo(e))return!0;return!1};_FunctionExpression.prototype._updateCellRangeExp=function(e,t,o,n,i,l){var r,s,a=!1;if(this._params&&this._params.length>0)for(r=0;r<this._params.length;r++){s=this._params[r]._updateCellRangeExp(e,t,o,n,i,l);a||(a=a||s)}return a};_FunctionExpression.prototype._moveCellRangeExp=function(e,t,o,n,i){void 0===n&&(n=!1);void 0===i&&(i=!1);var l,r,s=!1;if(this._params&&this._params.length>0)for(l=0;l<this._params.length;l++){r=this._params[l]._moveCellRangeExp(e,t,o,n,i);s||(s=s||r)}return s};_FunctionExpression.prototype._updateCellRangeExpForReorderingRows=function(e){var t,o,n=!1;if(this._params&&this._params.length>0)for(t=0;t<this._params.length;t++){o=this._params[t]._updateCellRangeExpForReorderingRows(e);n||(n=n||o)}return n};_FunctionExpression.prototype._updateCellBoundary=function(e,t){var o;return!!(this._params&&1===this._params.length&&(o=this._params[0])instanceof _CellRangeExpression)&&o._updateCellBoundary(e,t)};_FunctionExpression.prototype._getStringExpression=function(){return"true"===this._funcId||"false"===this._funcId?this._funcId.toUpperCase():this._funcId+this._parseParamsExpToString()};_FunctionExpression.prototype._parseParamsExpToString=function(){var e,t;if(this._params&&this._params.length>0){t="";for(e=0;e<this._params.length;e++){0===e&&(t+="(");t+=this._params[e]._getStringExpression();e<this._params.length-1?t+=", ":t+=")"}return t}return"()"};return _FunctionExpression}(_Expression);export{_FunctionExpression};var _CalcEngine=function(){function _CalcEngine(e){this._expressionCache={};this._idChars="_$:!";this._functionTable={};this._cacheSize=0;this._tableRefStart=!1;this.unknownFunction=new Event;this._owner=e;this._buildSymbolTable();this._registerAggregateFunction();this._registerMathFunction();this._registerLogicalFunction();this._registerTextFunction();this._registerDateFunction();this._registLookUpReferenceFunction();this._registFinacialFunction();this._registAddressRelatedFunction();this._registerIsFunctions()}_CalcEngine.prototype.onUnknownFunction=function(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)}n=new UnknownFunctionEventArgs(e,o);this.unknownFunction.raise(this,n);if(null!=n.value)return new _Expression(this,n.value);throw new NameError(_ErrorMessages.UnkFuncName(e))};_CalcEngine.prototype.evaluate=function(e,t,o,n,i,l,r){void 0===l&&(l=!0);void 0===r&&(r=!1);var s,a;if(!this._owner.enableFormulas)return e;try{if(_isFormula(e)){this._containsCellRef=!1;this._rowIndex=n;this._columnIndex=i;this._sheet=o||this._owner.selectedSheet;a=(s=this._checkCache(e,l,r)).evaluate(n,i,o,l,r);for(;a instanceof _Expression;)a=a.evaluate(n,i,o,l,r);return t&&isPrimitive(a)?Globalize.format(a,t):a}return e||""}catch(e){var h=e instanceof FormulaError?e:new UnknownError(e);s&&(s.evaluatedValue=h);return h}};_CalcEngine.prototype.addCustomFunction=function(e,t,o,n){var i=this;e=e.toLowerCase();this._functionTable[e]=new _FunctionDefinition((function(e){var o,n=[];if(e&&e.length>0)for(var l=0;l<e.length;l++){o=e[l];n[l]=o instanceof _CellRangeExpression?o.cells:o.evaluate(i._rowIndex,i._columnIndex)}return t.apply(i,n)}),n,o)};_CalcEngine.prototype.addFunction=function(e,t,o,n){var i=this;e=e.toLowerCase();this._functionTable[e]=new _FunctionDefinition((function(e){var o,n=[];if(e&&e.length>0)for(var l=i._sheet,r=0;r<e.length;r++){o=e[r];n[r]=o instanceof _CellRangeExpression?o.getValuesWithTwoDimensions(void 0,l):[[o.evaluate(i._rowIndex,i._columnIndex)]]}return t.apply(i,n)}),n,o)};_CalcEngine.prototype.clearExpressionCache=function(){this._expressionCache=null;this._expressionCache={};this._cacheSize=0};_CalcEngine.prototype.round=function(e){var t=this._owner.calculationPrecision;if(e.toString().indexOf(".")<0)return e;if(t<0)return e;t>20&&(t=20);var o=_CalcEngine.PowOf10[t];return e>=0?Math.round(e*o)/o:-Math.round(Math.abs(e)*o)/o};_CalcEngine.prototype.parse=function(e){if(isNumber(e)){this._token=new _Token(e,_TokenID.END,_TokenType.GROUP);return new _Expression(this,new _Token(e,_TokenID.ATOM,_TokenType.LITERAL))}this._expression=e;this._expressLength=e?e.length:0;this._pointer=0;this._expressLength>0&&"="===this._expression[0]&&this._pointer++;return this._parseExpression()};_CalcEngine.prototype._buildSymbolTable=function(){if(!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.PERCENT,_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)}};_CalcEngine.prototype._registerAggregateFunction=function(){var e=this;e._functionTable.sum=new _FunctionDefinition((function(t,o){return e._getAggregateResult(Aggregate.Sum,t,o)}));e._functionTable.average=new _FunctionDefinition((function(t,o){return e._getAggregateResult(Aggregate.Avg,t,o)}));e._functionTable.max=new _FunctionDefinition((function(t,o){return e._getAggregateResult(Aggregate.Max,t,o)}));e._functionTable.min=new _FunctionDefinition((function(t,o){return e._getAggregateResult(Aggregate.Min,t,o)}));e._functionTable.var=new _FunctionDefinition((function(t,o){return e._getAggregateResult(Aggregate.Var,t,o)}));e._functionTable.varp=new _FunctionDefinition((function(t,o){return e._getAggregateResult(Aggregate.VarPop,t,o)}));e._functionTable.stdev=new _FunctionDefinition((function(t,o){return e._getAggregateResult(Aggregate.Std,t,o)}));e._functionTable.stdevp=new _FunctionDefinition((function(t,o){return e._getAggregateResult(Aggregate.StdPop,t,o)}));e._functionTable.count=new _FunctionDefinition((function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.Count,t,o)}));e._functionTable.counta=new _FunctionDefinition((function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.CountA,t,o)}));e._functionTable.countblank=new _FunctionDefinition((function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.CountBlank,t,o)}));e._functionTable.countif=new _FunctionDefinition((function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.CountIf,t,o)}),2,2);e._functionTable.countifs=new _FunctionDefinition((function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.CountIfs,t,o)}),254,2);e._functionTable.sumif=new _FunctionDefinition((function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.SumIf,t,o)}),3,2);e._functionTable.sumifs=new _FunctionDefinition((function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.SumIfs,t,o)}),255,2);e._functionTable.rank=new _FunctionDefinition((function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.Rank,t,o)}),3,2);e._functionTable.product=new _FunctionDefinition((function(t,o){return e._getFlexSheetAggregateResult(_FlexSheetAggregate.Product,t,o)}),255,1);e._functionTable.subtotal=new _FunctionDefinition((function(t,o){return e._handleSubtotal(t,o)}),255,2);e._functionTable.dcount=new _FunctionDefinition((function(t,o){return e._handleDCount(t,o)}),3,3);e._functionTable.sumproduct=new _FunctionDefinition((function(t,o){return e._getSumProduct(t,o)}),255,1)};_CalcEngine.prototype._registerMathFunction=function(){var e=this;e._functionTable.pi=new _FunctionDefinition((function(){return Math.PI}),0,0);e._functionTable.rand=new _FunctionDefinition((function(){return Math.random()}),0,0);e._functionTable.power=new _FunctionDefinition((function(t,o){return 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((function(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 new DivideByZeroError(_ErrorMessages.Atan2ArgsLessThanZero);return Math.atan2(i,n)}),2,2);e._functionTable.mod=new _FunctionDefinition((function(t,o){var n=_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o),i=_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o),l=Math.abs(i);if(0===l)throw new DivideByZeroError;var r=Math.abs(n)%l;i<0&&(r=-r);return r}),2,2);e._functionTable.trunc=new _FunctionDefinition((function(t,o){var n,i,l,r=_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o),s=2===t.length?_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o):0;if(0===s){l="n0";i=r>=0?Math.floor(r):Math.ceil(r)}else{l="n"+((s=s>0?Math.floor(s):Math.ceil(s))>0?s:0);n=Math.pow(10,s);i=r>=0?Math.floor(r*n)/n:Math.ceil(r*n)/n}if(null!=i)return{value:i,format:l}}),2,1);["ceiling","floor"].forEach((function(t){e._functionTable[t]=new _FunctionDefinition((function(o,n){var i,l,r=_Expression.toNumber(o[0],e._rowIndex,e._columnIndex,n),s=2===o.length?_Expression.toNumber(o[1],e._rowIndex,e._columnIndex,n):1;if(isNaN(r))throw new ValueError(_ErrorMessages.InvalidParameter("number"));if(isNaN(s))throw new ValueError(_ErrorMessages.InvalidParameter("significance"));if(r>0&&s<0)throw new NumericError(_ErrorMessages.InvalidParameter("significance"));if(0===r||0===s)return 0;l=1;if(0!==(i=s-Math.floor(s)))for(;i<1;){l*=10;i*=10}return s*l*("ceiling"===t?Math.ceil(r/s):Math.floor(r/s))/l}),2,1)}));["round","rounddown","roundup"].forEach((function(t){e._functionTable[t]=new _FunctionDefinition((function(o,n){var i,l,r,s=_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=s>=0?Math.floor(s):Math.ceil(s);break;case"roundup":i=s>=0?Math.ceil(s):Math.floor(s);break;case"round":i=(s>=0?1:-1)*Math.round(Math.abs(s));break;default:i=Math.floor(s)}l="n0"}else{a=a>0?Math.floor(a):Math.ceil(a);r=Math.pow(10,a);switch(t){case"rounddown":i=s>=0?Math.floor(s*r)/r:Math.ceil(s*r)/r;break;case"roundup":i=s>=0?Math.ceil(s*r)/r:Math.floor(s*r)/r;break;case"round":i=(s>=0?1:-1)*Math.round(Math.abs(s)*r)/r}l="n"+(a>0?a:0)}if(null!=i)return{value:i,format:l}}),2,2)}));["abs","acos","asin","atan","cos","exp","ln","sin","sqrt","tan"].forEach((function(t){e._functionTable[t]=new _FunctionDefinition((function(o,n){return"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)}))};_CalcEngine.prototype._registerLogicalFunction=function(){var e=this;e._functionTable.and=new _FunctionDefinition((function(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((function(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((function(t,o){return!_Expression.toBoolean(t[0],e._rowIndex,e._columnIndex,o)}),1,1);e._functionTable.if=new _FunctionDefinition((function(t,o){return 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((function(){return!0}),0,0);e._functionTable.false=new _FunctionDefinition((function(){return!1}),0,0)};_CalcEngine.prototype._registerTextFunction=function(){var e=this;e._functionTable.char=new _FunctionDefinition((function(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((function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.charCodeAt(0):-1}),1,1);var t=new _FunctionDefinition((function(t,o){var n="";t.forEach((function(t){if(t instanceof _CellRangeExpression){var i=t.getValues(!0,void 0,o);n=n.concat(i.reduce((function(e,t){return e+""+t}),""))}else n=n.concat(_Expression.toString(t,e._rowIndex,e._columnIndex,o))}));return n}),Number.MAX_VALUE,1);e._functionTable.concat=t;e._functionTable.concatenate=t;e._functionTable.left=new _FunctionDefinition((function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),i=null==t[1]?1:Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o));return n&&n.length>0?n.slice(0,i):null}),2,1);e._functionTable.right=new _FunctionDefinition((function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),i=null==t[1]?1:Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o));return n&&n.length>0?i?n.slice(-i):"":null}),2,1);e._functionTable.find=new _FunctionDefinition((function(t,o){var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),l=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o),r=null!=t[2]?asInt(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o)):0;return null!=l&&null!=i&&(n=!isNaN(r)&&r>0&&r<=l.length?l.indexOf(i,r-1):l.indexOf(i))>-1?n+1:-1}),3,2);e._functionTable.search=new _FunctionDefinition((function(t,o){var n,i,l,r=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),s=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o),a=null!=t[2]?asInt(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o)):0;if(null!=s&&null!=r){i=new RegExp(r,"i");if(!isNaN(a)&&a>0&&a<s.length){s=s.substring(a-1);n=a}else n=1;if((l=s.search(i))>-1)return l+n}return-1}),3,2);e._functionTable.len=new _FunctionDefinition((function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return null!=n?n.length:-1}),1,1);e._functionTable.mid=new _FunctionDefinition((function(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)),l=Math.floor(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o));return n&&n.length>0&&i>0?n.substr(i-1,l):null}),3,3);e._functionTable.lower=new _FunctionDefinition((function(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((function(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((function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);if(n&&n.length>0){n=(n=n.toLowerCase())[0].toUpperCase()+n.substring(1);for(var i=1;i<n.length;i++)if(rgLetter.test(n[i])&&!rgLetter.test(n[i-1])){n=n.substr(0,i)+n[i].toUpperCase()+n.substring(i+1);i++}return n}return null}),1,1);e._functionTable.trim=new _FunctionDefinition((function(t,o){var n=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);return n&&n.length>0?n.trim().replace(/\s+/gm," "):null}),1,1);e._functionTable.replace=new _FunctionDefinition((function(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)),l=Math.floor(_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o)),r=_Expression.toString(t[3],e._rowIndex,e._columnIndex,o);return n&&n.length>0&&i>0?n.substring(0,i-1)+r+n.slice(i-1+l):null}),4,4);e._functionTable.substitute=new _FunctionDefinition((function(t,o){var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),l=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o),r=_Expression.toString(t[2],e._rowIndex,e._columnIndex,o),s=4===t.length?_Expression.toNumber(t[3],e._rowIndex,e._columnIndex,o):null,a=0;if(null!=s&&s<1||isNaN(s))throw new ValueError(_ErrorMessages.InvalidParameter("instance_num"));if(i&&i.length>0&&l&&l.length>0){n=new RegExp(l,"g");return i.replace(n,(function(e){a++;if(null!=s){s=Math.floor(s);return a===s?r:e}return r}))}return null}),4,3);e._functionTable.rept=new _FunctionDefinition((function(t,o){var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o),l=Math.floor(_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o)),r="";if(i&&i.length>0&&l>0)for(n=0;n<l;n++)r=r.concat(i);return r}),2,2);e._functionTable.text=new _FunctionDefinition((function(t,o){var n,i=t[0].evaluate(e._rowIndex,e._columnIndex,o),l=_Expression.toString(t[1],e._rowIndex,e._columnIndex,o);i&&!isPrimitive(i)&&(i=i.value);if(isDate(i))l=Workbook._fromXlsxDateFormat(l);else{var r=_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o);if(!isNumber(r)||isNaN(r))return i;if((n=l.match(/^(\d+)(\.\d+)?\E\+(\d+)(\.\d+)?$/))&&5===n.length)return e._parseToScientificValue(r,n[1],n[2],n[3],n[4]);if(/M{1,4}|d{1,4}|y{1,4}/i.test(l)){l=Workbook._fromXlsxDateFormat(l);i=FlexSheet._fromOADate(r)}else l&&!/[ncpfdg]\d?/i.test(l)&&(l=Workbook.fromXlsxFormat(l)[0])}if(isDate(i))switch(l){case"d":return i.getDate();case"M":return i.getMonth()+1;case"y":l="yy";break;case"yyy":l="yyyy"}return Globalize.format(i,l)}),2,2);e._functionTable.value=new _FunctionDefinition((function(t,o){var n,i=_Expression.toString(t[0],e._rowIndex,e._columnIndex,o);if((i=i.replace(/(\,\d{3})/g,(function(e){return e.substring(1)}))).length>0){if(i[0]===culture.Globalize.numberFormat.currency.symbol)return+(i=i.substring(1));if("%"===i[i.length-1])return+(i=i.substring(0,i.length-1))/100}n=+i;return isNaN(n)?_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o):n}),1,1);e._functionTable.exact=new _FunctionDefinition((function(t,o){return _Expression.toString(t[0],e._rowIndex,e._columnIndex,o)==_Expression.toString(t[1],e._rowIndex,e._columnIndex,o)}),2,2)};_CalcEngine.prototype._registerDateFunction=function(){var e=this;e._functionTable.now=new _FunctionDefinition((function(){return{value:new Date,format:"M/d/yyyy h:mm"}}),0,0);e._functionTable.today=new _FunctionDefinition((function(){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((function(t,o){if(!_Expression.toString(t[0],e._rowIndex,e._columnIndex,o).trim())return 1900;var n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o);return n&&!isPrimitive(n)?n.value:isDate(n)?n.getFullYear():1900}),1,1);e._functionTable.month=new _FunctionDefinition((function(t,o){if(!_Expression.toString(t[0],e._rowIndex,e._columnIndex,o).trim())return 1;var n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o);return!isPrimitive(n)&&n?n.value:isDate(n)?n.getMonth()+1:1}),1,1);e._functionTable.day=new _FunctionDefinition((function(t,o){if(!_Expression.toString(t[0],e._rowIndex,e._columnIndex,o))return 0;var n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o);return n&&!isPrimitive(n)?n.value:isDate(n)?n.getDate():0}),1,1);e._functionTable.hour=new _FunctionDefinition((function(t,o){var n=t[0].evaluate(e._rowIndex,e._columnIndex,o);if(isNumber(n)&&!isNaN(n))return Math.floor(24*(n-Math.floor(n)));if(isDate(n))return n.getHours();(n=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o))&&!isPrimitive(n)&&(n=n.value);if(isDate(n))return n.getHours();throw new ValueError(_ErrorMessages.InvalidParameter("serial_number"))}),1,1);e._functionTable.time=new _FunctionDefinition((function(t,o){var n=t[0].evaluate(e._rowIndex,e._columnIndex,o),i=t[1].evaluate(e._rowIndex,e._columnIndex,o),l=t[2].evaluate(e._rowIndex,e._columnIndex,o);if(isNumber(n)&&isNumber(i)&&isNumber(l)){n%=24;i%=60;l%=60;return{value:new Date(0,0,0,n,i,l),format:"h:mm tt"}}throw new ValueError(_ErrorMessages.InvalidParameters)}),3,3);e._functionTable.date=new _FunctionDefinition((function(t,o){var n=t[0].evaluate(e._rowIndex,e._columnIndex,o),i=t[1].evaluate(e._rowIndex,e._columnIndex,o),l=t[2].evaluate(e._rowIndex,e._columnIndex,o);if(isNumber(n)&&isNumber(i)&&isNumber(l))return{value:new Date(n,i-1,l),format:"M/d/yyyy"};throw new ValueError(_ErrorMessages.InvalidParameters)}),3,3);e._functionTable.datedif=new _FunctionDefinition((function(t,o){var n,i,l,r,s,a=_Expression.toDate(t[0],e._rowIndex,e._columnIndex,o),h=_Expression.toDate(t[1],e._rowIndex,e._columnIndex,o),u=t[2].evaluate(e._rowIndex,e._columnIndex,o);a&&!isPrimitive(a)&&(a=a.value);h&&!isPrimitive(h)&&(h=h.value);if(isDate(a)&&isDate(h)&&isString(u)){if((n=a.getTime())>(i=h.getTime()))throw new NumericError(_ErrorMessages.InvalidParameter("start_date"));l=h.getDate()-a.getDate();r=h.getMonth()-a.getMonth();s=h.getFullYear()-a.getFullYear();switch(u.toUpperCase()){case"Y":return r>0?s:r<0?s-1:l>=0?s:s-1;case"M":return l>=0?12*s+r:12*s+r-1;case"D":return(i-n)/864e5;case"YM":return(r=l>=0?12*s+r:12*s+r-1)%12;case"YD":return r>0?(new Date(a.getFullYear(),h.getMonth(),h.getDate()).getTime()-a.getTime())/864e5:r<0?(new Date(a.getFullYear()+1,h.getMonth(),h.getDate()).getTime()-a.getTime())/864e5:l>=0?l:(new Date(a.getFullYear()+1,h.getMonth(),h.getDate()).getTime()-a.getTime())/864e5;case"MD":return l>=0?l:l=new Date(h.getFullYear(),h.getMonth(),0).getDate()-new Date(h.getFullYear(),h.getMonth()-1,1).getDate()+1+l;default:throw new NumericError(_ErrorMessages.InvalidParameter("unit"))}}throw new ValueError(_ErrorMessages.InvalidParameters)}),3,3)};_CalcEngine.prototype._registLookUpReferenceFunction=function(){var e=this,t=this;t._functionTable.column=new _FunctionDefinition((function(e,o,n,i){var l;if(null==e)return i+1;l=e[0];if((l=t._ensureNonFunctionExpression(l,o))instanceof _CellRangeExpression)return l.cells.col+1;throw new SyntaxError(_ErrorMessages.InvalidCellRef)}),1,0);t._functionTable.columns=new _FunctionDefinition((function(e,o){var n=e[0];if((n=t._ensureNonFunctionExpression(n,o))instanceof _CellRangeExpression)return n.cells.columnSpan;throw new SyntaxError(_ErrorMessages.InvalidCellRef)}),1,1);t._functionTable.row=new _FunctionDefinition((function(e,o,n,i){var l;if(null==e)return n+1;l=e[0];if((l=t._ensureNonFunctionExpression(l,o))instanceof _CellRangeExpression)return l.cells.row+1;throw new SyntaxError(_ErrorMessages.InvalidCellRef)}),1,0);t._functionTable.rows=new _FunctionDefinition((function(e,o){var n=e[0];if((n=t._ensureNonFunctionExpression(n,o))instanceof _CellRangeExpression)return n.cells.rowSpan;throw new SyntaxError(_ErrorMessages.InvalidCellRef)}),1,1);t._functionTable.choose=new _FunctionDefinition((function(e,o){var n=_Expression.toNumber(e[0],t._rowIndex,t._columnIndex,o);if(isNaN(n))throw new ValueError(_ErrorMessages.InvalidParameter("index_num"));if(n<1||n>=e.length)throw new ValueError(_ErrorMessages.ParameterIsOutOfRange("index_num"));return e[n=Math.floor(n)].evaluate(t._rowIndex,t._columnIndex,o)}),255,2);t._functionTable.index=new _FunctionDefinition((function(o,n){var i,l=o[0],r=_Expression.toNumber(o[1],t._rowIndex,t._columnIndex,n),s=null!=o[2]?_Expression.toNumber(o[2],t._rowIndex,t._columnIndex,n):0;if(isNaN(r)||r<0)throw new ValueError(_ErrorMessages.InvalidParameter("row_num"));if(isNaN(s)||s<0)throw new ValueError(_ErrorMessages.InvalidParameter("column_num"));if((l=t._ensureNonFunctionExpression(l,n))instanceof _CellRangeExpression){if(r>(i=l.cells).rowSpan)throw new ReferenceError(_ErrorMessages.ParameterIsOutOfRange("row_num"));if(s>i.columnSpan)throw new ReferenceError(_ErrorMessages.ParameterIsOutOfRange("column_num"));if(r>0&&s>0)return t._owner.getCellValue(i.topRow+r-1,i.leftCol+s-1,!0,n);if(0===r&&0===s)return l;if(0===r)return new _CellRangeExpression(e,new CellRange(i.topRow,i.leftCol+s-1,i.bottomRow,i.leftCol+s-1),l.sheetRef,t._owner);if(0===s)return new _CellRangeExpression(e,new CellRange(i.topRow+r-1,i.leftCol,i.topRow+r-1,i.rightCol),l.sheetRef,t._owner)}throw new SyntaxError(_ErrorMessages.InvalidCellRef)}),4,2);t._functionTable.hlookup=new _FunctionDefinition((function(e,o){return t._handleHLookup(e,o)}),4,3);t._functionTable.vlookup=new _FunctionDefinition((function(e,o){return t._handleVLookup(e,o)}),4,3)};_CalcEngine.prototype._registFinacialFunction=function(){var e=this;e._functionTable.rate=new _FunctionDefinition((function(t,o){return{value:e._calculateRate(t,o),format:"p2"}}),6,3)};_CalcEngine.prototype._registAddressRelatedFunction=function(){var e=this;e._functionTable.indirect=new _FunctionDefinition((function(t,o){var n,i,l,r,s,a,h,u=e._ensureNonFunctionExpression(t[0],o);if(u instanceof _CellRangeExpression){n=u.cells;i=u.evaluate(n.row,n.col,o)}else i=u instanceof _Expression?u.evaluate(e._rowIndex,e._columnIndex,o):u;if(isString(i)){if(2===(l=i.split("!")).length){r=l[0].toLowerCase();s=l[1].toLowerCase()}else s=l[0].toLowerCase();var c=e._owner.definedNames._find(s,r||e._sheet.name);o=o||e._owner.selectedSheet;if(c){if(c.sheetName&&c.sheetName.toLowerCase()!==o.name.toLowerCase())throw new ReferenceError(_ErrorMessages.InvalidCellRef);i=c.value}if(a=e._getCellRange(i)){if(a.sheetRef){for(var d=0;d<e._owner.sheets.length;d++)if(e._owner.sheets[d].name.toLowerCase()===a.sheetRef.toLowerCase()){h=e._owner.sheets[d];break}}else h=e._owner.selectedSheet;if(h)return e._owner.getCellValue(a.cellRef.cellRange.row,a.cellRef.cellRange.col,!0,o)}}throw new SyntaxError(_ErrorMessages.InvalidCellRef)}),2,1);e._functionTable.address=new _FunctionDefinition((function(t,o){var n,i,l=_Expression.toNumber(t[0],e._rowIndex,e._columnIndex,o),r=_Expression.toNumber(t[1],e._rowIndex,e._columnIndex,o),s=!1,a=!1;if(isNaN(l)||!isInt(l)||l<1||l>1048576)throw new ValueError(_ErrorMessages.InvalidParameter("row_num"));if(isNaN(r)||!isInt(r)||r<1||r>16384)throw new ValueError(_ErrorMessages.InvalidParameter("column_num"));if(null!=t[2]){n=_Expression.toNumber(t[2],e._rowIndex,e._columnIndex,o);if(isNaN(n)||!isInt(n)||n<1||n>4)throw new ValueError(_ErrorMessages.InvalidParameter("abs_num"))}null!=t[4]&&(i=_Expression.toString(t[4],e._rowIndex,e._columnIndex,o));if(null==n||1===n){s=!0;a=!0}else 2===n?s=!0:3===n&&(a=!0);return(null!=i?i+"!":"")+(a?"$":"")+e._numAlpha(r)+(s?"$":"")+l.toString()}),5,2)};_CalcEngine.prototype._registerIsFunctions=function(){var e=this,getError=function(t,o){var n;try{n=t.evaluate(e._rowIndex,e._columnIndex,o)}catch(e){e instanceof FormulaError&&(n=e)}return n};this._functionTable.isblank=new _FunctionDefinition((function(t,o){var n=!1,i=t[0];if(i instanceof _CellRangeExpression){i.evaluate(e._rowIndex,e._columnIndex,o);n=!!i._isEmpty}return n}),1,1);this._functionTable.iserror=new _FunctionDefinition((function(e,t){return getError(e[0],t)instanceof FormulaError}),1,1);this._functionTable.iserr=new _FunctionDefinition((function(e,t){var o=getError(e[0],t);return o instanceof FormulaError&&!(o instanceof NotAvailableError)}),1,1);this._functionTable.iferror=new _FunctionDefinition((function(t,o){var n=getError(t[0],o);return n instanceof FormulaError?t[1].evaluate(e._rowIndex,e._columnIndex,o):n}),2,2)};_CalcEngine.prototype._addToken=function(e,t,o){var n=new _Token(e,t,o);this._tokenTable[e]=n};_CalcEngine.prototype._parseExpression=function(){this._getToken();return this._parseCompareOrConcat()};_CalcEngine.prototype._parseCompareOrConcat=function(){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(this,e,o,t)}return o};_CalcEngine.prototype._parseAddSub=function(){for(var e,t,o=this._parseMulDiv();this._token.tokenType===_TokenType.ADDSUB;){e=this._token;this._getToken();t=this._parseMulDiv();o=new _BinaryExpression(this,e,o,t)}return o};_CalcEngine.prototype._parseMulDiv=function(){for(var e,t,o=this._parsePower();this._token.tokenType===_TokenType.MULDIV;){if(this._token.tokenID===_TokenID.PERCENT){e=new _Token("%",_TokenID.PERCENT,_TokenType.MULDIV);this._token=new _Token(100,_TokenID.ATOM,_TokenType.LITERAL)}else{e=this._token;this._getToken()}t=this._parsePower();o=new _BinaryExpression(this,e,o,t)}return o};_CalcEngine.prototype._parsePower=function(){for(var e,t,o=this._parseUnary();this._token.tokenType===_TokenType.POWER;){e=this._token;this._getToken();t=this._parseUnary();o=new _BinaryExpression(this,e,o,t)}return o};_CalcEngine.prototype._parseUnary=function(){var e,t;if(this._token.tokenID===_TokenID.ADD||this._token.tokenID===_TokenID.SUB){e=this._token;this._getToken();t=this._parseAtom();return new _UnaryExpression(this,e,t)}return this._parseAtom()};_CalcEngine.prototype._parseAtom=function(){var e=null;switch(this._token.tokenType){case _TokenType.LITERAL:case _TokenType.ERROR:e=new _Expression(this,this._token);break;case _TokenType.IDENTIFIER:var t=this._token.value.toString(),o=t.toLowerCase(),n=this._functionTable[0===o.indexOf("_xlfn.")?o.substr(6):o];if(n){var i=this._getParameters();if(this._token.tokenType===_TokenType.GROUP&&this._token.tokenID===_TokenID.CLOSE){var l=i?i.length:0;if(-1!==n.paramMin&&l<n.paramMin)throw new SyntaxError(_ErrorMessages.TooFewParameters);if(-1!==n.paramMax&&l>n.paramMax)throw new SyntaxError(_ErrorMessages.TooManyParameters);"rand"!==o&&("column"!==o&&"row"!==o||0!==l)||(this._containsCellRef=!0);e=new _FunctionExpression(this,o,n,i);break}if("true"===o||"false"===o){e=new _FunctionExpression(this,o,n,i,!1);break}}var r=o.split("!"),s=void 0,a=void 0;if(2===r.length){a=r[0];s=r[1]}else s=r[0];var h=this._owner.definedNames._find(s,a||this._sheet.name);if(h){if(h.sheetName&&h.sheetName.toLowerCase()!==this._sheet.name.toLowerCase()&&h.sheetName.toLowerCase()!==a)throw new NameError(_ErrorMessages.DefNameInvalidSheet(h.sheetName));var u=this._pointer,c=this._expressLength,d=this._expression;this._pointer=0;(e=this._checkCache(h.value))._definedName=h.name;this._pointer=u;this._expressLength=c;this._expression=d;break}a="";var _=this._owner._getTable(o);if(null!=_){if(""===(a=_.sheet.name))throw new NameError(_ErrorMessages.InvalidTable(o));var f=this._pointer,g=this._token;this._getToken();if(this._token.tokenType===_TokenType.SQUAREBRACKETS&&this._token.tokenID===_TokenID.OPEN){this._tableRefStart=!0;e=this._getTableReference(_,a,!0)}else{e=this._getTableReference(_,a,!1);this._pointer=f;this._token=g}break}var p=this._getCellRange(t);if(p){this._containsCellRef=!0;e=new _CellRangeExpression(this,p.cellRef.cellRange,p.sheetRef,this._owner,t.indexOf(":")>-1,p.cellRef.absRow,p.cellRef.absCol,p.cellRef.absRow2,p.cellRef.absCol2,p.isWholeRow);break}e=this.onUnknownFunction(o,this._getParameters());break;case _TokenType.GROUP:if(this._token.tokenID!==_TokenID.OPEN)throw new SyntaxError(_ErrorMessages.ExpressionExpected);this._getToken();e=this._parseCompareOrConcat();if(this._token.tokenID!==_TokenID.CLOSE)throw new SyntaxError(_ErrorMessages.UnbalancedParenthesis);e._inGroup=!0;break;case _TokenType.SQUAREBRACKETS:if(this._token.tokenID!==_TokenID.OPEN)throw new ValueError(_ErrorMessages.TableReferencesExpected);if(null!=(_=this._sheet.findTable(this._rowIndex,this._columnIndex))){a=_.sheet.name;this._tableRefStart=!0;e=this._getTableReference(_,a,!0,!1)}}if(null==e)throw new SyntaxError(_ErrorMessages.BadExpression);this._getToken();return e};_CalcEngine.prototype._getToken=function(){for(var e,t,o,n,i,l,r="",s="",a=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{l=(t=this._expression[this._pointer])>="0"&&t<="9"||"."==t;if(!(i=t>="a"&&t<="z"||t>="A"&&t<="Z"||a.test(t))&&!l){var h=this._tokenTable[t];if(h){this._token=h;this._pointer++;if(this._pointer<this._expressLength&&(">"===t||"<"===t)&&(h=this._tokenTable[this._expression.substring(this._pointer-1,this._pointer+1)])){this._token=h;this._pointer++}return}}if(l){n=this._pointer;this._parseDigit();if(":"!==this._expression[this._pointer])return;this._pointer=n}if('"'!==t){if(("'"!==t||(s=this._parseSheetRef()))&&("#"!==t||!this._parseError()))if("#"!==t){if(!i&&!l&&this._idChars.indexOf(t)<0&&!s)throw new SyntaxError(_ErrorMessages.IdentifierExpected);for(e=1;e+this._pointer<this._expressLength;e++){i=(t=this._expression[this._pointer+e])>="a"&&t<="z"||t>="A"&&t<="Z"||a.test(t);l=t>="0"&&t<="9";if("'"!==t||":"!==o){o=t;if(!i&&!l&&"."!==t&&this._idChars.indexOf(t)<0)break}else{r=s+this._expression.substring(this._pointer,this._pointer+e);this._pointer+=e;s=this._parseSheetRef();e=0}}r+=s+this._expression.substring(this._pointer,this._pointer+e);this._pointer+=e;this._token=new _Token(r,_TokenID.ATOM,_TokenType.IDENTIFIER)}else this._parseDate()}else this._parseString()}};_CalcEngine.prototype._getTableToken=function(){for(var e,t,o,n="",i=!1;this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;if("@"===(t=this._expression[this._pointer])){n=t;this._pointer++}"["===(t=this._expression[this._pointer])&&(i=!0);for(e=1;e+this._pointer<this._expressLength;e++){t=this._expression[this._pointer+e];if(i&&","===t)throw new SyntaxError(_ErrorMessages.InvalidTableRef);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)};_CalcEngine.prototype._parseDigit=function(){var e,t,o=-1,n=!1,i=0;for(e=0;e+this._pointer<this._expressLength;e++)if((t=this._expression[this._pointer+e])>="0"&&t<="9"){i=10*i+(+t-0);o>-1&&(o*=10)}else if("."===t&&o<0)o=1;else{if("E"!==t&&"e"!==t||n)break;n=!0;"+"!==(t=this._expression[this._pointer+e+1])&&"-"!==t||e++}n?i=+this._expression.substring(this._pointer,this._pointer+e):o>1&&(i/=o);this._token=new _Token(i,_TokenID.ATOM,_TokenType.LITERAL);this._pointer+=e};_CalcEngine.prototype._parseString=function(){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 new SyntaxError(_ErrorMessages.CantFindFinalQuote);o=this._expression.substring(this._pointer+1,this._pointer+e);this._pointer+=e+1;if("!"===this._expression[this._pointer])throw new SyntaxError(_ErrorMessages.IllegalCrossSheetReference);this._token=new _Token(o.replace('""','"'),_TokenID.ATOM,_TokenType.LITERAL)};_CalcEngine.prototype._parseDate=function(){var e,t,o;for(e=1;e+this._pointer<this._expressLength&&"#"!==(t=this._expression[this._pointer+e]);e++);if("#"!==t)throw new SyntaxError(_ErrorMessages.CantFindFinalDateDelimiter);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)};_CalcEngine.prototype._parseError=function(){var e,t=this._pointer;for(e=t+1;e<this._expressLength;e++){var o=this._expression[e],n=this._expression[e-1];if(!(o>="a"&&o<="z"||o>="A"&&o<="Z"||("0"===o||"?"===o||"!"===o||"/"===o)&&(n>="a"&&n<="z"||n>="A"&&n<="Z"||"/"===n||"0"===n)))break}var i=e-t;if(i>3){var l=this._expression.substring(t,t+i),r=_FormulaErrorHelper.asError(l);if(r){this._token=new _Token(r,_TokenID.ATOM,_TokenType.ERROR);this._pointer+=i;return!0}}return!1};_CalcEngine.prototype._parseSheetRef=function(){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 new SyntaxError(_ErrorMessages.CantFindFinalQuote);o=this._expression.substring(this._pointer+1,this._pointer+e);this._pointer+=e+1;return"!"===this._expression[this._pointer]?o.replace(/\'\'/g,"'"):""};_CalcEngine.prototype._getCellRange=function(e){var t,o,n,i,l;if(e&&(t=e.split(":")).length>0&&t.length<3){if(null==(o=this._parseCell(t[0])).cellRef)return null;i=o.cellRef.cellRange;if(null!=o.cellRef.isWholeRow&&1===t.length)return null;if(i&&2===t.length){l=(n=this._parseCell(t[1])).cellRef.cellRange;if(null!=o.cellRef.isWholeRow&&o.cellRef.isWholeRow!==n.cellRef.isWholeRow)return null;o.sheetRef&&!n.sheetRef&&(n.sheetRef=o.sheetRef);if(o.sheetRef!==n.sheetRef)throw new ReferenceError(_ErrorMessages.CellRefMustBeInSameSheet);if(l){i.col2=l.col;i.row2=l.row}else 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,isWholeRow:o.cellRef.isWholeRow}};_CalcEngine.prototype._parseCellRange=function(e){var t,o,n,i,l=-1,r=-1,s=!1,a=!1;for(t=0;t<e.length;t++)if("$"!==(n=e[t])||s){if(!(n>="a"&&n<="z"||n>="A"&&n<="Z"))break;l<0&&(l=0);l=26*l+(n.toUpperCase().charCodeAt(0)-"A".charCodeAt(0)+1)}else s=!0;for(;t<e.length;t++)if("$"!==(n=e[t])||a){if(!(n>="0"&&n<="9"))break;r<0&&(r=0);r=10*r+(+n-0)}else a=!0;if(t<e.length)return null;if(r>-1&&l>-1){if(0===r)throw new NameError(_ErrorMessages.InvalidCellRef);o=new CellRange(r-1,l-1)}else if(-1===l){i=!0;o=new CellRange(r-1,0)}else if(-1===r){i=!1;o=new CellRange(0,l-1)}return{cellRange:o,absRow:a,absCol:s,isWholeRow:i}};_CalcEngine.prototype._parseCell=function(e){var t,o,n;if((t=e.lastIndexOf("!"))>0&&t<e.length-1){n=e.substring(0,t);o=e.substring(t+1)}else{if(!(t<=0))return null;o=e}return{cellRef:this._parseCellRange(o),sheetRef:n}};_CalcEngine.prototype._getParameters=function(){var e,t,o=this._pointer,n=this._token;this._getToken();if(this._token.tokenType!==_TokenType.SQUAREBRACKETS||this._token.tokenID!==_TokenID.OPEN){if(this._token.tokenID!==_TokenID.OPEN){this._pointer=o;this._token=n;return null}o=this._pointer;this._getToken();if(this._token.tokenID===_TokenID.CLOSE)return null;this._pointer=o;e=new Array;t=this._parseExpression();e.push(t);for(;this._token.tokenID===_TokenID.COMMA;){t=this._parseExpression();e.push(t)}if(this._token.tokenID!==_TokenID.CLOSE)throw new SyntaxError(_ErrorMessages.SyntaxError);return e}};_CalcEngine.prototype._getTableReference=function(e,t,o,n){void 0===n&&(n=!0);var i=[],l=o?this._getTableParameter():null,r=!1,s=!1;if(null==l){i.push("#Data");s=!0}else{i.push(l);for(;this._tableRefStart&&(this._token.tokenID===_TokenID.COMMA||":"===this._token.value);){":"===this._token.value&&(r=!0);if(null==(l=this._getTableParameter()))throw new SyntaxError(_ErrorMessages.InvalidTableRef);if(r){i[i.length-1]+=":"+l;r=!1}else i.push(l)}if(this._token.tokenType!==_TokenType.SQUAREBRACKETS||this._token.tokenID!==_TokenID.CLOSE)throw new SyntaxError(_ErrorMessages.UnbalancedSquareBrackets);this._tableRefStart=!1}var a=this._getTableRange(e,i);this._containsCellRef=!0;var h=new _CellRangeExpression(this,a,t.toLowerCase(),this._owner);h._tableParams=i;n&&(h._tableName=e.name);s&&(h._defTableParameterProvided=!0);return h};_CalcEngine.prototype._getTableParameter=function(){var e;for(this._pointer;this._pointer<this._expressLength&&" "===this._expression[this._pointer];)this._pointer++;if("]"===this._expression[this._pointer]){this._getToken();this._tableRefStart=!1;return null}this._getTableToken();e=this._token.value;this._getToken();return e};_CalcEngine.prototype._getTableRange=function(e,t){for(var o,n,i,l,r,s,a=0;a<t.length;a++){if(n)throw new ValueError(_ErrorMessages.InvalidTableRef);r=null;if("#"===(o=t[a].toLowerCase())[0]){switch(o){case"#all":r=e.getRange();break;case"#data":r=e.getRange(TableSection.Data);break;case"#headers":r=e.getRange(TableSection.Header);break;case"#totals":r=e.getRange(TableSection.Footer);break;case"#this row":l=e.getRange();if(!(this._rowIndex>=l.topRow&&this._rowIndex<=l.bottomRow))throw new ValueError(_ErrorMessages.RowIsOutOfTableRange(e.name));r=new CellRange(this._rowIndex,l.leftCol,this._rowIndex,l.rightCol);break;default:throw new ValueError(_ErrorMessages.InvalidTableRef)}if(null==r)throw new ValueError(_ErrorMessages.InvalidTableRef);if(null==i)i=r;else{i.row=i.topRow<r.topRow?i.topRow:r.topRow;i.row2=i.bottomRow>r.bottomRow?i.bottomRow:r.bottomRow}}else{n=!0;s=o.split(":");for(var h=0;h<s.length;h++){if(s.length>2)throw new ValueError(_ErrorMessages.InvalidTableColRef);if("@"===(o=s[h])[0]){if(null==(r=e.getRange(TableSection.Data,o.substring(1))))throw new ValueError(_ErrorMessages.InvalidTableRef);if(!(this._rowIndex>=r.topRow&&this._rowIndex<=r.bottomRow))throw new ValueError(_ErrorMessages.RowIsOutOfTableRange(e.name));r.row=this._rowIndex;r.row2=this._rowIndex}else if(null==(r=e.getRange(TableSection.Data,o)))throw new ValueError(_ErrorMessages.InvalidTableRef);0===h&&(null==i?i=r:i.col=r.col);i.col2=r.col;r=null}}}return i};_CalcEngine.prototype._getAggregate=function(e,t){for(var o=0,n=0,i=0,l=null,r=null,s=0;s<t.length;s++){var a=t[s];if(null!=a&&"number"==typeof a&&!isNaN(a)){(null==l||a<l)&&(l=a);(null==r||a>r)&&(r=a);o++;n+=a;i+=a*a}}var h=0==o?0:n/o;switch(e){case Aggregate.Avg:return h;case Aggregate.Max:return r;case Aggregate.Min:return l;case Aggregate.Sum:return n;case Aggregate.VarPop:return o<=1?0:i/o-h*h;case Aggregate.StdPop:return o<=1?0:Math.sqrt(i/o-h*h);case Aggregate.Var:return o<=1?0:(i/o-h*h)*o/(o-1);case Aggregate.Std:return o<=1?0:Math.sqrt((i/o-h*h)*o/(o-1))}throw"Invalid aggregate type."};_CalcEngine.prototype._getAggregateResult=function(e,t,o){var n,i=this._getItemList(t,o);n=this._getAggregate(e,i.items);i.isDate&&(n={value:n=new Date(n),format:i.format||"M/d/yyyy"});return n};_CalcEngine.prototype._getFlexSheetAggregateResult=function(e,t,o){var n,i;switch(e){case _FlexSheetAggregate.Count:n=this._getItemList(t,o,!1,void 0,void 0,!1);return this._countNumberCells(n.items);case _FlexSheetAggregate.CountA:return(n=this._getItemList(t,o,!1,void 0,void 0,!1)).items.length;case _FlexSheetAggregate.CountBlank:n=this._getItemList(t,o,!0,void 0,void 0,!1);return this._countBlankCells(n.items);case _FlexSheetAggregate.Rank:var l=_Expression.toNumber(t[0],this._rowIndex,this._columnIndex,o),r=t[2]?_Expression.toNumber(t[2],this._rowIndex,this._columnIndex,o):0;if(isNaN(l))throw new ValueError(_ErrorMessages.InvalidParameter("number"));if(isNaN(r))throw new ValueError(_ErrorMessages.InvalidParameter("order"));t[1]=this._ensureNonFunctionExpression(t[1],o);if(t[1]instanceof _CellRangeExpression){n=this._getItemList([t[1]],o);return this._getRankOfCellRange(l,n.items,r)}throw new SyntaxError(_ErrorMessages.InvalidCellRef);case _FlexSheetAggregate.CountIf:t[0]=this._ensureNonFunctionExpression(t[0],o);if(t[0]instanceof _CellRangeExpression){n=this._getItemList([t[0]],o,void 0,void 0,void 0,!1);return this._countCellsByCriteria([n.items],[t[1]],o)}throw new SyntaxError(_ErrorMessages.InvalidCellRef);case _FlexSheetAggregate.CountIfs:return this._handleCountIfs(t,o);case _FlexSheetAggregate.SumIf:t[0]=this._ensureNonFunctionExpression(t[0],o);if(t[0]instanceof _CellRangeExpression){var s=!1;t[2]=this._ensureNonFunctionExpression(t[2],o);null!=t[2]&&t[2]instanceof _CellRangeExpression&&(i=this._getItemList([t[2]],o,s=!0));n=this._getItemList([t[0]],o,s);return this._sumCellsByCriteria([n.items],[t[1]],i?i.items:null,o)}throw new SyntaxError(_ErrorMessages.InvalidCellRef);case _FlexSheetAggregate.SumIfs:return this._handleSumIfs(t,o);case _FlexSheetAggregate.Product:n=this._getItemList(t,o);return this._getProductOfNumbers(n.items)}throw"Invalid aggregate type."};_CalcEngine.prototype._getItemList=function(e,t,o,n,i,l){void 0===o&&(o=!1);void 0===n&&(n=!0);void 0===l&&(l=!0);var r,s,a,h,u,c,d,_,f,g,p=new Array;for(s=0;s<e.length;s++){u=e[s];if((u=this._ensureNonFunctionExpression(u,t))instanceof _CellRangeExpression){_=u._getSheet()||t||this._sheet;h=u.getValues(n,i,_,l);if(0===s){(f=_.getCellStyle(u.cells.topRow,u.cells.leftCol))&&(d=f.format);d||(g=_.grid.columns[u.cells.leftCol])&&(d=g.format)}e:for(a=0;a<h.length;a++){r=h[a];if(null==c&&null!=r&&!isString(r)){c=isDate(r);break e}}for(a=0;a<h.length;a++){r=h[a];(o||null!=r&&""!==r)&&(isDate(r)?p.push(+r):p.push(r))}}else{!(r=u instanceof _Expression?u.evaluate(this._rowIndex,this._columnIndex,t,void 0,void 0,l):u)||r instanceof FormulaError||isPrimitive(r)||(r=r.value);if(!o&&(null==r||""===r))continue;var w=+r;isNaN(w)||(r=w);p.push(r);null==c&&p.length>0&&(c=r instanceof Date)}}0===p.length&&(c=!1);return{isDate:c,items:p,format:d}};_CalcEngine.prototype._countBlankCells=function(e){for(var t,o=0,n=0;o<e.length;o++)(null==(t=e[o])||isString(t)&&""===t||isNumber(t)&&isNaN(t))&&n++;return n};_CalcEngine.prototype._countNumberCells=function(e){for(var t,o=0,n=0;o<e.length;o++)null!=(t=e[o])&&isNumber(t)&&!isNaN(t)&&n++;return n};_CalcEngine.prototype._getRankOfCellRange=function(e,t,o){void 0===o&&(o=0);var n,i=0,l=0;o?t.sort((function(e,t){return isNaN(e)||isNaN(t)?-1:e-t})):t.sort((function(e,t){return isNaN(e)||isNaN(t)?1:t-e}));for(;i<t.length;i++){n=t[i];if(!isNaN(n)&&isNumber(n)){l++;if(e===n)return l}}throw new ValueError(_ErrorMessages.ParameterIsOutOfRange("number"))};_CalcEngine.prototype._handleCountIfs=function(e,t){var o,n,i,l,r=0,s=[],a=[];if(e.length%2!=0)throw new ValueError(_ErrorMessages.InvalidParameters);for(;r<e.length/2;r++){n=e[2*r];if(!((n=this._ensureNonFunctionExpression(n,t))instanceof _CellRangeExpression))throw new SyntaxError(_ErrorMessages.InvalidCellRef);if(0===r){if(!n.cells)throw new SyntaxError(_ErrorMessages.InvalidCellRef);i=n.cells.rowSpan;l=n.cells.columnSpan}else{if(!n.cells)throw new SyntaxError(_ErrorMessages.InvalidCellRef);if(n.cells.rowSpan!==i||n.cells.columnSpan!==l)throw new ValueError(_ErrorMessages.RangesMustBeTheSame)}o=this._getItemList([n],t,void 0,void 0,void 0,!1);s[r]=o.items;a[r]=e[2*r+1]}return this._countCellsByCriteria(s,a,t)};_CalcEngine.prototype._countCellsByCriteria=function(e,t,o,n){for(var i,l=0,r=e[0].length,s=[],a=0;a<t.length;a++){"*"===(u=_Expression.toString(t[a],this._rowIndex,this._columnIndex,o))?s.push(u):s.push(this._parseRightExpr(u))}for(var h=0;h<r;h++){i=!1;for(a=0;a<e.length;a++){var u,c=e[a][h];if("string"==typeof(u=s[a])){if("*"!==u&&(null==c||""===c)){i=!1;break}if((i="*"===u||this.evaluate(this._combineExpr(c,u),null,o,this._rowIndex,this._columnIndex,!1,!0))instanceof FormulaError||!i)break}else if(!(i=i=u.reg.test(c.toString())===u.checkMathces))break}if(i&&!(i instanceof FormulaError))if(n){var d=n[h];null!=d&&isNumber(d)&&!isNaN(d)&&l++}else l++}return l};_CalcEngine.prototype._handleSumIfs=function(e,t){var o,n,i,l,r,s,a=1,h=[],u=[],c=!1;if(e.length%2!=1)throw new ValueError(_ErrorMessages.InvalidParameters);i=e[0];if(!((i=this._ensureNonFunctionExpression(i,t))instanceof _CellRangeExpression))throw new ValueError(_ErrorMessages.InvalidParameter("Sum_range"));if(!i.cells)throw new ValueError(_ErrorMessages.InvalidParameter("Sum_range"));r=i.cells.rowSpan;s=i.cells.columnSpan;n=this._getItemList([i],t,c=!0);for(;a<(e.length+1)/2;a++){l=e[2*a-1];if(!((l=this._ensureNonFunctionExpression(l,t))instanceof _CellRangeExpression))throw new ValueError(_ErrorMessages.InvalidParameter("Criteria_range"+a));if(!l.cells)throw new ValueError(_ErrorMessages.InvalidParameter("Criteria_range"+a));if(l.cells.rowSpan!==r||l.cells.columnSpan!==s)throw new ValueError(_ErrorMessages.RangesMustBeTheSame);o=this._getItemList([l],t,c);h[a-1]=o.items;u[a-1]=e[2*a]}return this._sumCellsByCriteria(h,u,n.items,t)};_CalcEngine.prototype._sumCellsByCriteria=function(e,t,o,n){var i,l,r,s,a=0,h=0,u=0,c=e[0].length,d=[];null==o&&(o=e[0]);for(;h<t.length;h++)"*"===(s=_Expression.toString(t[h],this._rowIndex,this._columnIndex,n))?d.push(s):d.push(this._parseRightExpr(s));for(;a<c;a++){l=!1;i=o[a];for(h=0;h<e.length;h++){r=e[h][a];if("string"==typeof(s=d[h])){if("*"!==s&&null==r){l=!1;break}if((l="*"===s||this.evaluate(this._combineExpr(r,s),null,n,this._rowIndex,this._columnIndex,!1))instanceof FormulaError||!l)break}else if(!(l=s.reg.test(r.toString())===s.checkMathces))break}l&&isNumber(i)&&!isNaN(i)&&(u+=i)}return u};_CalcEngine.prototype._getProductOfNumbers=function(e){var t,o=0,n=1,i=!1;if(e)for(;o<e.length;o++){t=e[o];if(isNumber(t)&&!isNaN(t)){n*=t;i=!0}}return i?n:0};_CalcEngine.prototype._handleSubtotal=function(e,t){var o,n,i,l,r=!0,s=!0;if((o=_Expression.toNumber(e[0],this._rowIndex,this._columnIndex,t))>=1&&o<=11||o>=101&&o<=111){o>=101&&o<=111&&(r=!1);(o=asEnum(o,_SubtotalFunction))!==_SubtotalFunction.CountA&&o!==_SubtotalFunction.CountAWithoutHidden||(s=!1);n=this._getItemList(e.slice(1),t,s,r);switch(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=Aggregate.Avg;break;case _SubtotalFunction.Max:case _SubtotalFunction.MaxWithoutHidden:i=Aggregate.Max;break;case _SubtotalFunction.Min:case _SubtotalFunction.MinWithoutHidden:i=Aggregate.Min;break;case _SubtotalFunction.Std:case _SubtotalFunction.StdWithoutHidden:i=Aggregate.Std;break;case _SubtotalFunction.StdPop:case _SubtotalFunction.StdPopWithoutHidden:i=Aggregate.StdPop;break;case _SubtotalFunction.Sum:case _SubtotalFunction.SumWithoutHidden:i=Aggregate.Sum;break;case _SubtotalFunction.Var:case _SubtotalFunction.VarWithoutHidden:i=Aggregate.Var;break;case _SubtotalFunction.VarPop:case _SubtotalFunction.VarPopWithoutHidden:i=Aggregate.VarPop}l=this._getAggregate(i,n.items);n.isDate&&(l=new Date(l));return l}throw new ValueError(_ErrorMessages.InvalidParameter("Function_num"))};_CalcEngine.prototype._handleDCount=function(e,t){var o,n,i,l=e[0],r=e[2];l=this._ensureNonFunctionExpression(l,t);r=this._ensureNonFunctionExpression(r,t);if(l instanceof _CellRangeExpression&&r instanceof _CellRangeExpression){o=e[1].evaluate(this._rowIndex,this._columnIndex,t);n=this._getColumnIndexByField(l,o);return(i=this._getItemList([l],t,!1,!0,n,!1)).items&&i.items.length>1?this._DCountWithCriteria(i.items.slice(1),l,r):0}throw new ValueError(_ErrorMessages.InvalidParameter("Database"))};_CalcEngine.prototype._DCountWithCriteria=function(e,t,o){var n,i,l,r,s,a,h,u,c,d,_,f=o.cells,g=0;n=this._owner._getSheet(t.sheetRef);i=this._owner._getSheet(o.sheetRef);if(f.rowSpan>1){l=f.topRow;for(r=f.bottomRow;r>f.topRow;r--){d=[];_=[];for(s=f.leftCol;s<=f.rightCol;s++)if(null!=(h=this._owner.getCellValue(r,s,!1,i))&&""!==h){_.push(new _Expression(this,h));u=this._owner.getCellValue(l,s,!1,i);a=this._getColumnIndexByField(t,u);if(!(null!=(c=this._getItemList([t],n,!1,!0,a,!1)).items&&c.items.length>1))throw new ValueError("Criteria");d.push(c.items.slice(1))}g+=this._countCellsByCriteria(d,_,n,e)}return g}throw new ValueError("Criteria")};_CalcEngine.prototype._getColumnIndexByField=function(e,t){var o,n,i,l,r;if(-1===(r=(o=e.cells).topRow))throw new ValueError(_ErrorMessages.InvalidParameter("Database"));if(isInt(t)&&!isNaN(t)){if(t>=1&&t<=o.columnSpan)return i=o.leftCol+t-1}else{n=this._owner._getSheet(e.sheetRef);for(i=o.leftCol;i<=o.rightCol;i++){l=this._owner.getCellValue(r,i,!1,n);if((t=isString(t)?t.toLowerCase():t)===(l=isString(l)?l.toLowerCase():l))return i}}throw new ValueError(_ErrorMessages.InvalidParameter("Field"))};_CalcEngine.prototype._getSumProduct=function(e,t){var o,n,i,l=0,r=this._getItemListForSumProduct(e,t);if(r.length>0){n=r[0].length;i=r.length;for(var s=0;s<n;s++){o=1;for(var a=0;a<i;a++)o*=r[a][s];l+=o}}return l};_CalcEngine.prototype._getItemListForSumProduct=function(e,t){var o,n,i,l,r,s,a=[new Array];for(i=0;i<e.length;i++){s=e[i];o=new Array;if((s=this._ensureNonFunctionExpression(s,t))instanceof _CellRangeExpression){r=s.getValues(!0,null,t);for(l=0;l<r.length;l++){n=r[l];o.push(+n)}}else{n=s instanceof _Expression?s.evaluate(this._rowIndex,this._columnIndex,t):s;o.push(+n)}if(i>0&&o.length!==a[0].length)throw new ValueError(_ErrorMessages.RangesMustBeTheSame);a[i]=o}return a};_CalcEngine.prototype._parseRightExpr=function(e){var t,o,n=!1;if(e.indexOf("?")>-1||e.indexOf("*")>-1){if(null==(t=e.match(/=?([\?\*]*)(\w*)([\?\*]*)(\w*)([\?\*]*)/))||6!==t.length)throw new ValueError(_ErrorMessages.InvalidParameter("Criteria"));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;return{reg:o,checkMathces:n}}var i=void 0;if(isNaN(+e))if("true"===(i=e.toLowerCase())||"false"===i)e="="+e;else if(/^\w/.test(e))e='="'+e+'"';else{if(!/^[<>=]{1,2}\s*-?.+$/.test(e))throw new ValueError(_ErrorMessages.InvalidParameter("Criteria"));e=e.replace(/([<>=]{1,2})\s*(-?.+)/,(function(e,t,o){var n=o.toLowerCase();return t+(isNaN(+o)&&"true"!==n&&"false"!==n?'"'+o+'"':o)}))}else e="="+ +e;return e};_CalcEngine.prototype._combineExpr=function(e,t){(isString(e)||isDate(e))&&(e='"'+e+'"');return(e="="+e)+t};_CalcEngine.prototype._parseRegCriteria=function(e){for(var t=0,o=0,n="";t<e.length;t++)if("*"===e[t]){if(o>0){n+="\\w{"+o+"}";o=0}n+="\\w*"}else"?"===e[t]&&o++;o>0&&(n+="\\w{"+o+"}");return n};_CalcEngine.prototype._calculateRate=function(e,t){var o,n,i,l,r,s,a,h,u,c,d=0,_=0;i=_Expression.toNumber(e[0],this._rowIndex,this._columnIndex,t);l=_Expression.toNumber(e[1],this._rowIndex,this._columnIndex,t);r=_Expression.toNumber(e[2],this._rowIndex,this._columnIndex,t);s=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?r*(1+i*n)+l*(1+n*a)*i+s:r*(h=Math.exp(i*Math.log(1+n)))+l*(1/n+a)*(h-1)+s;u=r+l*i+s;c=r*h+l*(1/n+a)*(h-1)+s;o=n;for(;Math.abs(u-c)>1e-7&&d<20;){n=(c*_-u*o)/(c-u);_=o;o=n;u=c;c=Math.abs(n)<1e-7?r*(1+i*n)+l*(1+n*a)*i+s:r*(h=Math.exp(i*Math.log(1+n)))+l*(1/n+a)*(h-1)+s;++d}if(Math.abs(u-c)>1e-7&&20===d)throw new NumericError(_ErrorMessages.RateCriteriaFails);return n};_CalcEngine.prototype._handleHLookup=function(e,t){var o=this;return this._handleLookup(e,t,{base:function(e){return e.topRow},span:function(e){return e.rowSpan},iterStart:function(e){return e.leftCol},iterEnd:function(e){return e.rightCol},getValue:function(e,t,n){return o._owner.getCellValue(e,t,0,n)}})};_CalcEngine.prototype._handleVLookup=function(e,t){var o=this;return this._handleLookup(e,t,{base:function(e){return e.leftCol},span:function(e){return e.columnSpan},iterStart:function(e){return e.topRow},iterEnd:function(e){return e.bottomRow},getValue:function(e,t,n){return o._owner.getCellValue(t,e,0,n)}})};_CalcEngine.prototype._handleLookup=function(e,t,o){var n=e[0].evaluate(this._rowIndex,this._columnIndex,t),i=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==n||""===n)throw new NotAvailableError(_ErrorMessages.InvalidParameter("Lookup_value"));if(isNaN(l)||l<0)throw new ValueError(_ErrorMessages.InvalidParameter("index_num"));if((i=this._ensureNonFunctionExpression(i,t))instanceof _CellRangeExpression){t=i._getSheet()||t||this._sheet;var s,a=i.cells;if(l>o.span(a))throw new ReferenceError(_ErrorMessages.ParameterIsOutOfRange("index_num"));r?-1===(s=this._exactMatch(n,a,!1,o,t))&&(s=this._approximateMatch(n,a,o,t)):s=this._exactMatch(n,a,!0,o,t);if(-1===s)throw new NotAvailableError;var h=o.getValue(o.base(a)+l-1,s,t);if(null==h)throw new NotAvailableError;return h}throw new SyntaxError(_ErrorMessages.InvalidCellRef)};_CalcEngine.prototype._exactMatch=function(e,t,o,n,i){var l,r=n.base(t);isString(e)&&(e=e.toLowerCase());if(o&&isString(e)&&(e.indexOf("?")>-1||e.indexOf("*")>-1)){var s=e.match(/([\?\*]*)(\w+)([\?\*]*)(\w+)([\?\*]*)/);if(null==s||6!==s.length)throw new ValueError(_ErrorMessages.InvalidParameter("Lookup_value"));l=new RegExp("^"+(s[1].length>0?this._parseRegCriteria(s[1]):"")+s[2]+(s[3].length>0?this._parseRegCriteria(s[3]):"")+s[4]+(s[5].length>0?this._parseRegCriteria(s[5]):"")+"$","i")}for(var a=n.iterStart(t);a<=n.iterEnd(t);a++){var h=n.getValue(r,a,i);if(null!=l){if(l.test(h))return a}else{isString(h)&&(h=h.toLowerCase());if(e===h)return a}}return-1};_CalcEngine.prototype._approximateMatch=function(e,t,o,n){var i=o.base(t),l=[];isString(e)&&(e=e.toLowerCase());for(var r=o.iterStart(t);r<=o.iterEnd(t);r++){var s=o.getValue(i,r,n);s=isNaN(+s)?s:+s;l.push({value:s,index:r})}l.sort((function(e,t){isString(e.value)&&(e.value=e.value.toLowerCase());isString(t.value)&&(t.value=t.value.toLowerCase());return e.value>t.value?-1:e.value===t.value?t.index-e.index:1}));for(var a=0;a<l.length;a++){s=l[a];isString(s.value)&&(s.value=s.value.toLowerCase());if(e>s.value)return s.index}throw new NotAvailableError};_CalcEngine.prototype._parseToScientificValue=function(e,t,o,n,i){var l,r,s,a,h=0;if(Math.abs(e)>=1){r="+";l=Math.pow(10,t.length);for(;e>l;){e/=l;h+=t.length}}else{r="-";l=Math.pow(10,t.length);for(;e*l<l;){e*=l;h+=t.length}}s=Globalize.format(e,"D"+t.length);if(o){if((s+=Globalize.format(e-Math.floor(e),t+o).substring(1)).indexOf(".")>-1)a=s.length-1-s.indexOf(".");else{s+=".";a=0}for(;a<o.length-1;){s+="0";a++}}s+="E"+r+Globalize.format(h,"D"+n.length);if(i){s+=".";for(var u=1;u<i.length;u++)s+="0"}return s};_CalcEngine.prototype._checkCache=function(e,t,o,n,i,l){void 0===t&&(t=!0);void 0===o&&(o=!1);null!=n&&(this._sheet=this._owner.sheets[n]);null!=i&&(this._rowIndex=i);null!=l&&(this._columnIndex=l);var r=this._sheet?this._sheet.name:"",s=this._expressionCache[r+":"+t+":"+o+":"+e]||this._expressionCache[r+"_"+this._rowIndex+"_"+this._columnIndex+":"+t+":"+o+":"+e];if(s){if(s.token.tokenType===_TokenType.ERROR)throw s.token.value;return s}s=this.parse(e);if(this._token.tokenID!==_TokenID.END||this._token.tokenType!==_TokenType.GROUP)throw new SyntaxError(_ErrorMessages.InvalidExpression(e));this._cacheSize>1e4&&this.clearExpressionCache();this._expressionCache[r+(this._containsCellRef?"_"+this._rowIndex+"_"+this._columnIndex:"")+":"+t+":"+o+":"+e]=s;this._cacheSize++;return s};_CalcEngine.prototype._ensureNonFunctionExpression=function(e,t){for(;e instanceof _FunctionExpression;)e=e.evaluate(this._rowIndex,this._columnIndex,t);return e};_CalcEngine.prototype._numAlpha=function(e){var t=Math.floor((e-1)/26);return(t>0?this._numAlpha(t):"")+String.fromCharCode((e-1)%26+65)};_CalcEngine.PowOf10=Array.apply(null,{length:21}).map((function(e,t){return Math.pow(10,t)}));return _CalcEngine}();export{_CalcEngine};var _Token=function(){function _Token(e,t,o){this._value=e;this._tokenID=t;this._tokenType=o}Object.defineProperty(_Token.prototype,"value",{get:function(){return this._value},enumerable:!0,configurable:!0});Object.defineProperty(_Token.prototype,"tokenID",{get:function(){return this._tokenID},enumerable:!0,configurable:!0});Object.defineProperty(_Token.prototype,"tokenType",{get:function(){return this._tokenType},enumerable:!0,configurable:!0});return _Token}();export{_Token};var _FlexSheetAggregate,_SubtotalFunction,_FunctionDefinition=function(){function _FunctionDefinition(e,t,o){this._paramMax=Number.MAX_VALUE;this._paramMin=Number.MIN_VALUE;this._func=e;isNumber(t)&&!isNaN(t)&&(this._paramMax=t);isNumber(o)&&!isNaN(o)&&(this._paramMin=o)}Object.defineProperty(_FunctionDefinition.prototype,"paramMax",{get:function(){return this._paramMax},enumerable:!0,configurable:!0});Object.defineProperty(_FunctionDefinition.prototype,"paramMin",{get:function(){return this._paramMin},enumerable:!0,configurable:!0});Object.defineProperty(_FunctionDefinition.prototype,"func",{get:function(){return this._func},enumerable:!0,configurable:!0});return _FunctionDefinition}();export{_FunctionDefinition};export 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.ERROR=8]="ERROR";e[e.SQUAREBRACKETS=9]="SQUAREBRACKETS"}(_TokenType||(_TokenType={}));export 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";e[e.PERCENT=20]="PERCENT"}(_TokenID||(_TokenID={}));export var _OpMap=(_a={},_a[_TokenID.GT]=">",_a[_TokenID.LT]="<",_a[_TokenID.GE]=">=",_a[_TokenID.LE]="<=",_a[_TokenID.EQ]="=",_a[_TokenID.NE]="<>",_a[_TokenID.ADD]="+",_a[_TokenID.SUB]="-",_a[_TokenID.MUL]="*",_a[_TokenID.DIV]="/",_a[_TokenID.PERCENT]="%",_a[_TokenID.DIVINT]="\\",_a[_TokenID.POWER]="^",_a[_TokenID.CONCAT]="&",_a);!function(e){e[e.Count=0]="Count";e[e.CountA=1]="CountA";e[e.CountBlank=2]="CountBlank";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={}));!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={}));var rgLetter=/[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEF\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7B9\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]/,_FlexSheetCellFactory=function(e){__extends(_FlexSheetCellFactory,e);function _FlexSheetCellFactory(){return null!==e&&e.apply(this,arguments)||this}_FlexSheetCellFactory.prototype.updateCell=function(t,o,n,i,l){var r,s,a,h=t.grid,u=/^border/;t.cellType===CellType.Cell&&(i.style.cssText="");if(t.cellType===CellType.Cell){var c=o*h.columns.length+n,d=h.selectedSheet;l&&!l.isSingleCell&&(c=l.row*h.columns.length+l.col);if((s=d&&d._styledCells?d._styledCells[c]:null)&&"pre-wrap"==s.whiteSpace&&(a=_isEditingCell(h,o,n))){r=t.rows[o]._getFlag(RowColFlags.MultiLine);t.rows[o]._setFlag(RowColFlags.MultiLine,!0,!0)}}e.prototype.updateCell.call(this,t,o,n,i,l);null!=r&&t.rows[o]._setFlag(RowColFlags.MultiLine,r,!0);if(l&&!l.isSingleCell){o=l.row;n=l.col}switch(t.cellType){case CellType.ColumnHeader:var _=t.getCellData(o,n,!0),f=i.querySelector('[type="checkbox"]'),g=null,p=null;if(f){g=f.checked;p=f.indeterminate}i.textContent?i.innerHTML=i.innerHTML.replace(escapeHtml(i.textContent),_).replace(i.textContent,_):i.innerHTML+=_;if(g||p){var w=i.querySelectorAll('[type="checkbox"]');if(w)for(var m=0;m<w.length;m++){var C=w[m];C.checked=g;C.indeterminate=p}}i.style.textAlign="center";break;case CellType.Cell:var S=h._getBindingColumn(t,o,t.columns[n]);if(l&&!l.isSingleCell){var b=this._getFirstVisibleCell(h,l);o=b.row;n=b.col}if(t.rows[o]instanceof HeaderRow){(t.columns[n].dataMapEditor===DataMapEditor.RadioButtons&&i.firstElementChild instanceof HTMLLabelElement||t.columns[n].dataType===DataType.Boolean&&1===i.childElementCount&&i.firstElementChild instanceof HTMLLabelElement&&i.firstElementChild.firstElementChild instanceof HTMLInputElement&&"checkbox"===i.firstElementChild.firstElementChild.type||t.columns[n].dataType!==DataType.Boolean&&!i.innerHTML)&&(i.innerHTML=escapeHtml(h.getCellValue(o,n)));addClass(i,"wj-header-row")}else{if(a){var v=i.querySelector("input");v&&s&&s.textAlign&&(v.style.textAlign=s.textAlign)}else{var y=t.rows[o]instanceof GroupRow;if(t.columns[n].dataType===DataType.Boolean){var R=i.querySelector('[type="checkbox"]');if(R){R.checked=h.getCellValue(o,n);R.disabled=R.disabled||!h.canEditCell(o,n)}}else if(S.dataMap&&!y){var x=h.getCellValue(o,n,!0),T=i.firstChild;T&&3===T.nodeType&&T.nodeValue!==x&&(T.nodeValue=x)}else if(0===i.childElementCount&&i.textContent===h.getCellData(o,n,!0)){x=h.getCellValue(o,n,!0);var E=(s?s.format:null)||(y?null:S.format);if(""!==x&&isNumber(+x)&&!isNaN(+x)&&/[hsmy\:]/i.test(E)){var F=FlexSheet._fromOADate(+x);isNaN(F.getTime())||(x=Globalize.formatDate(F,E))}if(E||!y){x=isString(x)?x.replace(/^(\')(\s*[\w|=])/,"$2"):x;isString(x)?x&&this._isURL(x)?i.innerHTML='<a href="'+x+'" target="_blank">'+escapeHtml(x)+"</a>":i.innerHTML=escapeHtml(x):i.innerHTML=x}}}if(s){var A,D=i.style;for(var k in s)if("className"===k)s.className&&addClass(i,s.className);else if("format"!==k&&(A=s[k]))if(!hasClass(i,"wj-state-selected")&&!hasClass(i,"wj-state-multi-selected")||"color"!==k&&"backgroundColor"!==k)if("whiteSpace"===k&&"normal"===A)D[k]="";else{if(u.test(k))continue;D[k]=A}else D[k]=""}var I=this._getCellBorders(h,h.selectedSheet,l||new CellRange(o,n));if(I)for(var M in I)i.style[M]=I[M]}if(i.style.backgroundColor||i.style.color){s||(s={});i.style.backgroundColor&&(s.backgroundColor=i.style.backgroundColor);i.style.color&&(s.color=i.style.color)}}if(t.cellType===CellType.Cell){o!==h._lastVisibleFrozenRow||hasClass(i,"wj-frozen-row")||addClass(i,"wj-frozen-row");n!==h._lastVisibleFrozenColumn||hasClass(i,"wj-frozen-col")||addClass(i,"wj-frozen-col")}};_FlexSheetCellFactory.prototype._getFirstVisibleCell=function(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 CellRange(o,n)};_FlexSheetCellFactory.prototype._isURL=function(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)};_FlexSheetCellFactory.prototype._getCellBorders=function(e,t,o){var n=t&&t._styledCells;if(!n)return null;var i=o.topRow,l=o.leftCol,r=o.bottomRow,s=o.rightCol,a=e.columns.length;if(r>i||s>l){r=i;s=l}var h=n[i*a+l],u=n[r*a+s],c=l>0?n[i*a+l-1]:null,d=s+1<a?n[i*a+s+1]:null,_=i>0?n[(i-1)*a+l]:null,f=n[(r+1)*a+l];if(!(h||u||c||d||_||f))return null;var g={},p=h&&h.borderLeftStyle&&"none"!==h.borderLeftStyle&&!(!h.borderLeftColor&&!h.borderLeftWidth),w=c&&c.borderRightStyle&&"none"!==c.borderRightStyle&&!(!c.borderRightColor&&!c.borderRightWidth);if(!p&&w||p&&w&&parseInt(c.borderRightWidth||1)>parseInt(h.borderLeftWidth||1)){if("double"!==c.borderRightStyle){g.borderLeftColor=c.borderRightColor;g.borderLeftStyle=c.borderRightStyle;g.borderLeftWidth=Math.floor(parseInt(c.borderRightWidth||1)/2)+"px"}}else if(p){g.borderLeftColor=h.borderLeftColor;g.borderLeftStyle=h.borderLeftStyle;g.borderLeftWidth="double"!==h.borderLeftStyle?Math.ceil(parseInt(h.borderLeftWidth||1)/2)+"px":g.borderLeftWidth=h.borderLeftWidth}var m=h&&h.borderTopStyle&&"none"!==h.borderTopStyle&&!(!h.borderTopColor&&!h.borderTopWidth),C=_&&_.borderBottomStyle&&"none"!==_.borderBottomStyle&&!(!_.borderBottomColor&&!_.borderBottomWidth);if(!m&&C||m&&C&&parseInt(_.borderBottomWidth||1)>parseInt(h.borderTopWidth||1)){if("double"!==_.borderBottomStyle){g.borderTopColor=_.borderBottomColor;g.borderTopStyle=_.borderBottomStyle;g.borderTopWidth=Math.floor(parseInt(_.borderBottomWidth||1)/2)+"px"}}else if(m){g.borderTopColor=h.borderTopColor;g.borderTopStyle=h.borderTopStyle;g.borderTopWidth="double"!==h.borderTopStyle?Math.ceil(parseInt(h.borderTopWidth||1)/2)+"px":h.borderTopStyle}var S=u&&u.borderRightStyle&&"none"!==u.borderRightStyle&&!(!u.borderRightColor&&!u.borderRightWidth),b=d&&d.borderLeftStyle&&"none"!==d.borderLeftStyle&&!(!d.borderLeftColor&&!d.borderLeftWidth);if(!S&&b||S&&b&&parseInt(d.borderLeftWidth||1)>=parseInt(u.borderRightWidth||1)){if("double"!==d.borderLeftStyle){g.borderRightColor=d.borderLeftColor;g.borderRightStyle=d.borderLeftStyle;g.borderRightWidth=Math.floor(parseInt(d.borderLeftWidth||1)/2)+"px"}}else if(S){g.borderRightColor=u.borderRightColor;g.borderRightStyle=u.borderRightStyle;g.borderRightWidth="double"!==u.borderRightStyle?Math.ceil(parseInt(u.borderRightWidth||1)/2)+"px":u.borderRightWidth}var v=u&&u.borderBottomStyle&&"none"!==u.borderBottomStyle&&!(!u.borderBottomColor&&!u.borderBottomWidth),y=f&&f.borderTopStyle&&"none"!==f.borderTopStyle&&!(!f.borderTopColor&&!f.borderTopWidth);if(!v&&y||v&&y&&parseInt(f.borderTopWidth||1)>=parseInt(u.borderBottomWidth||1)){if("double"!==f.borderTopStyle){g.borderBottomColor=f.borderTopColor;g.borderBottomStyle=f.borderTopStyle;g.borderBottomWidth=Math.floor(parseInt(f.borderTopWidth||1)/2)+"px"}}else if(v){g.borderBottomColor=u.borderBottomColor;g.borderBottomStyle=u.borderBottomStyle;g.borderBottomWidth="double"!==u.borderBottomStyle?Math.ceil(parseInt(u.borderBottomWidth||1)/2)+"px":u.borderBottomWidth}return g};return _FlexSheetCellFactory}(CellFactory);export{_FlexSheetCellFactory};_registerModule("wijmo.grid.sheet",selfModule);