@odoo/o-spreadsheet 16.0.74 → 16.0.75
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/dist/o-spreadsheet.cjs.js +100 -26
- package/dist/o-spreadsheet.esm.js +100 -26
- package/dist/o-spreadsheet.iife.js +100 -26
- package/dist/o-spreadsheet.iife.min.js +176 -176
- package/dist/o_spreadsheet.xml +3 -3
- package/package.json +1 -3
|
@@ -1385,9 +1385,9 @@
|
|
|
1385
1385
|
offset="offset"
|
|
1386
1386
|
direction="'vertical'"
|
|
1387
1387
|
onScroll.bind="onScroll"
|
|
1388
|
-
/>`,Np.defaultProps={position:{top:0}};const Op={ROW:Xo,COL:Yo,CELL:jo};class Mp extends t.Component{constructor(){super(...arguments),this.HEADER_HEIGHT=O,this.HEADER_WIDTH=M,this.keyDownMapping={ENTER:()=>{const e=this.env.model.getters.getActiveCell();!e||e.isEmpty()?this.props.onGridComposerCellFocused():this.props.onComposerContentFocused()},TAB:()=>this.env.model.selection.moveAnchorCell("right",1),"SHIFT+TAB":()=>this.env.model.selection.moveAnchorCell("left",1),F2:()=>{const e=this.env.model.getters.getActiveCell();!e||e.isEmpty()?this.props.onGridComposerCellFocused():this.props.onComposerContentFocused()},DELETE:()=>{this.env.model.dispatch("DELETE_CONTENT",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones()})},BACKSPACE:()=>{this.env.model.dispatch("DELETE_CONTENT",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones()})},"CTRL+A":()=>this.env.model.selection.loopSelection(),"CTRL+S":()=>{var e,t;null===(t=(e=this.props).onSaveRequested)||void 0===t||t.call(e)},"CTRL+Z":()=>this.env.model.dispatch("REQUEST_UNDO"),"CTRL+Y":()=>this.env.model.dispatch("REQUEST_REDO"),"CTRL+B":()=>this.env.model.dispatch("SET_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),style:{bold:!this.env.model.getters.getCurrentStyle().bold}}),"CTRL+I":()=>this.env.model.dispatch("SET_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),style:{italic:!this.env.model.getters.getCurrentStyle().italic}}),"CTRL+U":()=>this.env.model.dispatch("SET_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),style:{underline:!this.env.model.getters.getCurrentStyle().underline}}),"ALT+=":()=>{var e;const t=this.env.model.getters.getActiveSheetId(),i=this.env.model.getters.getSelectedZone(),{anchor:n}=this.env.model.getters.getSelection(),o=this.env.model.getters.getAutomaticSums(t,i,n.cell);if(this.env.model.getters.isSingleCellOrMerge(t,i)||this.env.model.getters.isEmpty(t,i)&&o.length<=1){const i=(null===(e=o[0])||void 0===e?void 0:e.zone)?this.env.model.getters.zoneToXC(t,o[0].zone):"",n=`=SUM(${i})`;this.props.onGridComposerCellFocused(n,{start:5,end:5+i.length})}else this.env.model.dispatch("SUM_SELECTION")},"CTRL+HOME":()=>{const e=this.env.model.getters.getActiveSheetId(),{col:t,row:i}=this.env.model.getters.getNextVisibleCellPosition(e,0,0);this.env.model.selection.selectCell(t,i)},"CTRL+END":()=>{const e=this.env.model.getters.getActiveSheetId(),t=this.env.model.getters.findVisibleHeader(e,"COL",this.env.model.getters.getNumberCols(e)-1,0),i=this.env.model.getters.findVisibleHeader(e,"ROW",this.env.model.getters.getNumberRows(e)-1,0);this.env.model.selection.selectCell(t,i)},"SHIFT+ ":()=>{const e=this.env.model.getters.getActiveSheetId(),t={...this.env.model.getters.getSelectedZone(),left:0,right:this.env.model.getters.getNumberCols(e)-1},i=this.env.model.getters.getPosition();this.env.model.selection.selectZone({cell:i,zone:t})},"CTRL+ ":()=>{const e=this.env.model.getters.getActiveSheetId(),t={...this.env.model.getters.getSelectedZone(),top:0,bottom:this.env.model.getters.getNumberRows(e)-1},i=this.env.model.getters.getPosition();this.env.model.selection.selectZone({cell:i,zone:t})},"CTRL+SHIFT+ ":()=>{this.env.model.selection.selectAll()},"SHIFT+PAGEDOWN":()=>{this.env.model.dispatch("ACTIVATE_NEXT_SHEET")},"SHIFT+PAGEUP":()=>{this.env.model.dispatch("ACTIVATE_PREVIOUS_SHEET")},PAGEDOWN:()=>this.env.model.dispatch("SHIFT_VIEWPORT_DOWN"),PAGEUP:()=>this.env.model.dispatch("SHIFT_VIEWPORT_UP")}}setup(){this.menuState=t.useState({isOpen:!1,position:null,menuItems:[]}),this.gridRef=t.useRef("grid"),this.canvasPosition=Hn(this.gridRef),this.hoveredCell=t.useState({col:void 0,row:void 0}),t.useExternalListener(document.body,"cut",this.copy.bind(this,!0)),t.useExternalListener(document.body,"copy",this.copy.bind(this,!1)),t.useExternalListener(document.body,"paste",this.paste),t.onMounted((()=>this.focusDefaultElement())),this.props.exposeFocus((()=>this.focusDefaultElement())),Ep("canvas",this.env.model,(()=>this.env.model.getters.getSheetViewDimensionWithHeaders())),t.useEffect((()=>this.focusDefaultElement()),(()=>[this.env.model.getters.getActiveSheetId()])),this.onMouseWheel=wp(((e,t)=>{this.moveCanvas(e,t),this.hoveredCell.col=void 0,this.hoveredCell.row=void 0}))}onCellHovered({col:e,row:t}){this.hoveredCell.col=e,this.hoveredCell.row=t}get gridOverlayDimensions(){return"\n top: 26px;\n left: 48px;\n height: calc(100% - 41px);\n width: calc(100% - 63px);\n "}onClosePopover(){this.closeOpenedPopover(),this.focusDefaultElement()}focusDefaultElement(){this.env.model.getters.getSelectedFigureId()||"inactive"!==this.env.model.getters.getEditionMode()||this.env.focusableElement.focus()}get gridEl(){if(!this.gridRef.el)throw new Error("Grid el is not defined.");return this.gridRef.el}getAutofillPosition(){const e=this.env.model.getters.getSelectedZone(),t=this.env.model.getters.getVisibleRect(e);return{left:t.x+t.width-4,top:t.y+t.height-4}}isAutoFillActive(){const e=this.env.model.getters.getSelectedZone(),t=this.env.model.getters.getVisibleRect({left:e.right,right:e.right,top:e.bottom,bottom:e.bottom});return!(0===t.width||0===t.height)}onGridResized({height:e,width:t}){this.env.model.dispatch("RESIZE_SHEETVIEW",{width:t,height:e,gridOffsetX:M,gridOffsetY:O})}moveCanvas(e,t){const{scrollX:i,scrollY:n}=this.env.model.getters.getActiveSheetDOMScrollInfo();this.env.model.dispatch("SET_VIEWPORT_OFFSET",{offsetX:Math.max(i+e,0),offsetY:Math.max(n+t,0)})}getClientPositionKey(e){var t,i,n;return`${e.id}-${null===(t=e.position)||void 0===t?void 0:t.sheetId}-${null===(i=e.position)||void 0===i?void 0:i.col}-${null===(n=e.position)||void 0===n?void 0:n.row}`}isCellHovered(e,t){return this.hoveredCell.col===e&&this.hoveredCell.row===t}onCellClicked(e,t,{addZone:i,expandZone:n}){i&&this.env.model.dispatch("PREPARE_SELECTION_INPUT_EXPANSION"),this.closeOpenedPopover(),"editing"===this.env.model.getters.getEditionMode()&&this.env.model.dispatch("STOP_EDITION"),n?this.env.model.selection.setAnchorCorner(e,t):i?this.env.model.selection.addCellToSelection(e,t):this.env.model.selection.selectCell(e,t);let o=e,s=t;Fr(this.env,((e,t)=>{(e!==o&&-1!=e||t!==s&&-1!=t)&&(o=-1===e?o:e,s=-1===t?s:t,this.env.model.selection.setAnchorCorner(o,s))}),(()=>{this.env.model.dispatch("STOP_SELECTION_INPUT"),this.env.model.getters.isPaintingFormat()&&this.env.model.dispatch("PASTE",{target:this.env.model.getters.getSelectedZones()})}))}onCellDoubleClicked(e,t){const i=this.env.model.getters.getActiveSheetId();({col:e,row:t}=this.env.model.getters.getMainCellPosition(i,e,t));const n=this.env.model.getters.getCell(i,e,t);!n||n.isEmpty()?this.props.onGridComposerCellFocused():this.props.onComposerContentFocused()}closeOpenedPopover(){this.env.model.dispatch("CLOSE_CELL_POPOVER")}processArrows(e){e.preventDefault(),e.stopPropagation(),this.closeOpenedPopover();const t={ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up"}[e.key];e.shiftKey?this.env.model.selection.resizeAnchorZone(t,zn(e)?"end":1):this.env.model.selection.moveAnchorCell(t,zn(e)?"end":1),this.env.model.getters.isPaintingFormat()&&this.env.model.dispatch("PASTE",{target:this.env.model.getters.getSelectedZones()})}onKeydown(e){if(e.key.startsWith("Arrow"))return void this.processArrows(e);let t="";zn(e)&&(t+="CTRL+"),e.altKey&&(t+="ALT+"),e.shiftKey&&(t+="SHIFT+"),t+=e.key.toUpperCase();let i=this.keyDownMapping[t];return i?(e.preventDefault(),e.stopPropagation(),void i()):void 0}onInputContextMenu(e){e.preventDefault();const t=this.env.model.getters.getSelectedZone(),{left:i,top:n}=t;let o="CELL";this.env.model.dispatch("STOP_EDITION"),this.env.model.getters.getActiveCols().has(i)?o="COL":this.env.model.getters.getActiveRows().has(n)&&(o="ROW");const{x:s,y:r,width:a}=this.env.model.getters.getVisibleRect(t);this.toggleContextMenu(o,this.canvasPosition.x+s+a,this.canvasPosition.y+r)}onCellRightClicked(e,t,{x:i,y:n}){const o=this.env.model.getters.getSelectedZones();let s="CELL";Wi(e,t,o[o.length-1])?this.env.model.getters.getActiveCols().has(e)?s="COL":this.env.model.getters.getActiveRows().has(t)&&(s="ROW"):(this.env.model.selection.getBackToDefault(),this.env.model.selection.selectCell(e,t)),this.toggleContextMenu(s,i,n)}toggleContextMenu(e,t,i){this.closeOpenedPopover(),this.menuState.isOpen=!0,this.menuState.position={x:t,y:i},this.menuState.menuItems=Op[e].getAll()}copy(e,t){if(!this.gridEl.contains(document.activeElement))return;if("inactive"!==this.env.model.getters.getEditionMode())return;e?ho(this.env):this.env.model.dispatch("COPY");const i=this.env.model.getters.getClipboardContent();t.clipboardData.setData("text/plain",i),t.preventDefault()}paste(e){if(!this.gridEl.contains(document.activeElement))return;const t=e.clipboardData;if(t.types.indexOf("text/plain")>-1){const e=t.getData("text/plain"),i=this.env.model.getters.getSelectedZones();this.env.model.getters.getClipboardContent()===e?fo(this.env,i):vo(this.env,i,e)}}closeMenu(){this.menuState.isOpen=!1,this.focusDefaultElement()}}Mp.template="o-spreadsheet-Grid",Mp.components={GridComposer:ap,GridOverlay:mp,GridPopover:fp,HeadersOverlay:Cp,Menu:Gn,Autofill:Dr,ClientTag:$r,Highlight:Rp,Popover:Wn,VerticalScrollBar:Np,HorizontalScrollBar:Ap,FilterIconsOverlay:dp};class _p{constructor(e,t,i){this.id=e,this.style=i.style,this.format=i.format,this.lazyEvaluated=t.map((e=>({...e,format:i.format||e.format})))}isFormula(){return!1}isLink(){return!1}isEmpty(){return!1}get evaluated(){return this.lazyEvaluated()}get formattedValue(){return Qt(this.evaluated.value,this.evaluated.format)}get composerContent(){return this.content}get defaultAlign(){switch(this.evaluated.type){case hn.number:case hn.empty:return"right";case hn.boolean:case hn.error:return"center";case hn.text:return"left"}}get isAutoSummable(){var e;switch(this.evaluated.type){case hn.empty:case hn.text:return!0;case hn.number:return!(null===(e=this.evaluated.format)||void 0===e?void 0:e.match(Y));case hn.error:case hn.boolean:return!1}}}class Fp extends _p{constructor(e,t={}){super(e,tt({value:"",type:hn.empty}),t),this.content=""}isEmpty(){return!0}}class Dp extends _p{constructor(e,t,i={}){super(e,tt({value:t,type:hn.number}),i),this.content=Qt(this.evaluated.value)}get composerContent(){var e;return(null===(e=this.format)||void 0===e?void 0:e.includes("%"))?100*this.evaluated.value+"%":super.composerContent}}class kp extends _p{constructor(e,t,i={}){super(e,tt({value:t,type:hn.boolean}),i),this.content=this.evaluated.value?"TRUE":"FALSE"}}class $p extends _p{constructor(e,t,i={}){super(e,tt({value:t,type:hn.text}),i),this.content=this.evaluated.value}}class Lp extends Dp{constructor(e,t,i){super(e,t,i),this.format=i.format}get composerContent(){return Qt(this.evaluated.value,this.format)}}class Pp extends _p{constructor(e,t,i={}){const n=Ge(t);n.label=o(n.label),super(e,tt({value:n.label,type:hn.text}),i),this.link=n,this.content=t}isLink(){return!0}get composerContent(){return this.link.label}}class Up extends Pp{constructor(e,t,i={}){super(e,t,i),this.link.url=this.withHttp(this.link.url),this.link.isExternal=!0,this.content=We(this.link.label,this.link.url),this.urlRepresentation=this.link.url,this.isUrlEditable=!0}action(e){window.open(this.link.url,"_blank")}withHttp(e){return/^https?:\/\//i.test(e)?e:`https://${e}`}}class Vp extends Pp{constructor(e,t,i={},n){super(e,t,i),this.sheetName=n,this.sheetId=Ye(this.link.url),this.isUrlEditable=!1}action(e){e.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e.model.getters.getActiveSheetId(),sheetIdTo:this.sheetId})}get urlRepresentation(){return this.sheetName(this.sheetId)||s("Invalid sheet")}}class zp extends _p{constructor(e,t,i,n,o){super(t,tt({value:"Loading...",type:hn.text}),o),this.buildFormulaString=e,this.compiledFormula=i,this.dependencies=n}get content(){return this.buildFormulaString(this)}isFormula(){return!0}assignEvaluation(e){this.lazyEvaluated=e.map((e=>{if(e instanceof c)return{value:e.errorType,type:hn.error,error:e};const{value:t,format:i}=e;switch(typeof t){case"number":return{value:t||0,format:i,type:hn.number};case"boolean":return{value:t,format:i,type:hn.boolean};case"string":return{value:t,format:i,type:hn.text};case"object":return{value:0,format:i,type:hn.number};default:return{value:"",type:hn.empty}}}))}}class Bp extends _p{constructor(e,t,i,n){super(e,tt({value:i.errorType,type:hn.error,error:i}),n),this.content=t}}function Hp(e){return""===e?"":Ci(e)?wi(e):Ue(e)?"TRUE"===e.toUpperCase():Ve(e)?ve(e).value:e}io.add("Formula",{sequence:10,match:e=>e.startsWith("="),createCell:(e,t,i,n,o)=>{const s=Ug(t),r=s.dependencies.map((e=>o.getRangeFromSheetXC(n,e)));return new zp((e=>o.buildFormulaContent(n,e)),e,s,r,i)}}).add("Empty",{sequence:20,match:e=>""===e,createCell:(e,t,i)=>new Fp(e,i)}).add("NumberWithDateTimeFormat",{sequence:25,match:(e,t)=>!!t&&Ci(e)&&function(e){try{return oi(1,e),!0}catch(e){return!1}}(t),createCell:(e,t,i)=>{const n=i.format;return new Lp(e,wi(t),{...i,format:n})}}).add("Number",{sequence:30,match:e=>Ci(e),createCell:(e,t,i)=>(i.format||(i.format=function(e){const t=e.includes(".")?"0.00":"0",i=e.match(/[\$€]/);if(i){const n=e.match(/[\d]/),o="[$"+i.values().next().value+"]";return n.index<i.index?"#,##"+t+o:o+"#,##"+t}if(e.includes("%"))return t+"%";return}(t)),new Dp(e,wi(t),i))}).add("Boolean",{sequence:40,match:e=>Ue(e),createCell:(e,t,i)=>new kp(e,"TRUE"===t.toUpperCase(),i)}).add("DateTime",{sequence:50,match:e=>Ve(e),createCell:(e,t,i)=>{const n=ve(t),o=i.format||n.format;return new Lp(e,n.value,{...i,format:o})}}).add("MarkdownSheetLink",{sequence:60,match:e=>Ze(e),createCell:(e,t,i,n,o)=>new Vp(e,t,i,(e=>o.tryGetSheetName(e)))}).add("MarkdownLink",{sequence:70,match:e=>He(e),createCell:(e,t,i)=>new Up(e,t,i)}).add("WebLink",{sequence:80,match:e=>{return t=e,Be.test(t);var t},createCell:(e,t,i)=>new Up(e,We(t,t),i)});class Wp{constructor(e){this.xmlString=e}toString(){return this.xmlString}}const Gp=["areaChart","area3DChart","lineChart","line3DChart","stockChart","radarChart","scatterChart","pieChart","pie3DChart","doughnutChart","barChart","bar3DChart","ofPieChart","surfaceChart","surface3DChart","bubbleChart"],qp="000000",Zp={arrows:"3Arrows",smiley:"3Symbols",dots:"3TrafficLights1"},jp={styleSheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",sst:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",Relationships:"http://schemas.openxmlformats.org/package/2006/relationships",Types:"http://schemas.openxmlformats.org/package/2006/content-types",worksheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",workbook:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",drawing:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",table:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",revision:"http://schemas.microsoft.com/office/spreadsheetml/2014/revision",revision3:"http://schemas.microsoft.com/office/spreadsheetml/2016/revision3",markupCompatibility:"http://schemas.openxmlformats.org/markup-compatibility/2006"},Yp="http://schemas.openxmlformats.org/drawingml/2006/main",Xp="http://schemas.openxmlformats.org/drawingml/2006/chart",Kp={workbook:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",sharedStrings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",themes:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",pivot:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",externalLink:"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml"},Qp={document:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",sheet:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",sharedStrings:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",styles:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",drawing:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",chart:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",theme:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",table:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",hyperlink:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"},Jp="http://schemas.openxmlformats.org/officeDocument/2006/relationships",em=.75,tm=.1317,im=8.43,nm=12.75,om=30,sm=100,rm=164,am={FLOOR:[{type:"NUMBER",value:1}],CEILING:[{type:"NUMBER",value:1}],ROUND:[{type:"NUMBER",value:0}],ROUNDUP:[{type:"NUMBER",value:0}],ROUNDDOWN:[{type:"NUMBER",value:0}]},lm=["ACOT","ACOTH","AGGREGATE","ARABIC","BASE","BETA.DIST","BETA.INV","BINOM.DIST","BINOM.DIST.RANGE","BINOM.INV","BITAND","BITLSHIFT","BITOR","BITRSHIFT","BITXOR","BYCOL","BYROW","CEILING.MATH","CEILING.PRECISE","CHISQ.DIST","CHISQ.DIST.RT","CHISQ.INV","CHISQ.INV.RT","CHISQ.TEST","CHOOSECOLS","CHOOSEROWS","COMBINA","CONCAT","CONFIDENCE.NORM","CONFIDENCE.T","COT","COTH","COVARIANCE.P","COVARIANCE.S","CSC","CSCH","DAYS","DECIMAL","DROP","ERF.PRECISE","ERFC.PRECISE","EXPAND","EXPON.DIST","F.DIST","F.DIST.RT","F.INV","F.INV.RT","F.TEST","FIELDVALUE","FILTERXML","FLOOR.MATH","FLOOR.PRECISE","FORECAST.ETS","FORECAST.ETS.CONFINT","FORECAST.ETS.SEASONALITY","FORECAST.ETS.STAT","FORECAST.LINEAR","FORMULATEXT","GAMMA","GAMMA.DIST","GAMMA.INV","GAMMALN.PRECISE","GAUSS","HSTACK","HYPGEOM.DIST","IFNA","IFS","IMCOSH","IMCOT","IMCSC","IMCSCH","IMSEC","IMSECH","IMSINH","IMTAN","ISFORMULA","ISOMITTED","ISOWEEKNUM","LAMBDA","LET","LOGNORM.DIST","LOGNORM.INV","MAKEARRAY","MAP","MAXIFS","MINIFS","MODE.MULT","MODE.SNGL","MUNIT","NEGBINOM.DIST","NORM.DIST","NORM.INV","NORM.S.DIST","NORM.S.INV","NUMBERVALUE","PDURATION","PERCENTILE.EXC","PERCENTILE.INC","PERCENTRANK.EXC","PERCENTRANK.INC","PERMUTATIONA","PHI","POISSON.DIST","PQSOURCE","PYTHON_STR","PYTHON_TYPE","PYTHON_TYPENAME","QUARTILE.EXC","QUARTILE.INC","QUERYSTRING","RANDARRAY","RANK.AVG","RANK.EQ","REDUCE","RRI","SCAN","SEC","SECH","SEQUENCE","SHEET","SHEETS","SKEW.P","SORTBY","STDEV.P","STDEV.S","SWITCH","T.DIST","T.DIST.2T","T.DIST.RT","T.INV","T.INV.2T","T.TEST","TAKE","TEXTAFTER","TEXTBEFORE","TEXTJOIN","TEXTSPLIT","TOCOL","TOROW","UNICHAR","UNICODE","UNIQUE","VAR.P","VAR.S","VSTACK","WEBSERVICE","WEIBULL.DIST","WRAPCOLS","WRAPROWS","XLOOKUP","XOR","Z.TEST"],cm="[Content_Types].xml";var hm;!function(e){e.DiagonalBorderNotSupported="Diagonal Borders",e.BorderStyleNotSupported="Border style",e.FillStyleNotSupported="Fill Style",e.FontNotSupported="Font",e.HorizontalAlignmentNotSupported="Horizontal Alignment",e.VerticalAlignmentNotSupported="Vertical Alignments",e.MultipleRulesCfNotSupported="Multiple rules conditional formats",e.CfTypeNotSupported="Conditional format type",e.CfFormatBorderNotSupported="Borders in conditional formats",e.CfFormatAlignmentNotSupported="Alignment in conditional formats",e.CfFormatNumFmtNotSupported="Num formats in conditional formats",e.CfIconSetEmptyIconNotSupported="IconSets with empty icons",e.BadlyFormattedHyperlink="Badly formatted hyperlink",e.NumFmtIdNotSupported="Number format"}(hm||(hm={}));class dm{constructor(){this._parsingWarnings=new Set,this._conversionWarnings=new Set}addParsingWarning(e){this._parsingWarnings.add(e)}addConversionWarning(e){this._conversionWarnings.add(e)}get warnings(){return[...this._parsingWarnings,...this._conversionWarnings]}generateNotSupportedWarning(e,t,i){let n=`${e} ${t?'"'+t+'" is':"are"} not yet supported. `;i&&(n+=`Only ${i.join(", ")} are currently supported.`),this._conversionWarnings.has(n)||this._conversionWarnings.add(n)}}const um=["thin"],gm=["general","left","center","right"],pm=["Arial"],mm=["solid"],fm=["expression","cellIs","colorScale","iconSet","containsText","notContainsText","beginsWith","endsWith","containsBlanks","notContainsBlanks"],vm={b:"boolean",d:"date",e:"error",inlineStr:"inlineStr",n:"number",s:"sharedString",str:"str"},bm={dashDot:"thin",dashDotDot:"thin",dashed:"thin",dotted:"thin",double:"thin",hair:"thin",medium:"thin",mediumDashDot:"thin",mediumDashDotDot:"thin",mediumDashed:"thin",none:void 0,slantDashDot:"thin",thick:"thin",thin:"thin"},Sm={general:void 0,left:"left",center:"center",right:"right",fill:"left",justify:"left",centerContinuous:"center",distributed:"center"};const Cm={aboveAverage:void 0,expression:void 0,cellIs:void 0,colorScale:void 0,dataBar:void 0,iconSet:void 0,top10:void 0,uniqueValues:void 0,duplicateValues:void 0,containsText:"ContainsText",notContainsText:"NotContains",beginsWith:"BeginsWith",endsWith:"EndsWith",containsBlanks:"IsEmpty",notContainsBlanks:"IsNotEmpty",containsErrors:void 0,notContainsErrors:void 0,timePeriod:void 0},Em={num:"number",percent:"percentage",max:"value",min:"value",percentile:"percentile",formula:"formula"},wm={NoIcons:void 0,"3Arrows":"arrows","3ArrowsGray":"arrows","3Symbols":"smiley","3Symbols2":"smiley","3Signs":"dots","3Flags":"dots","3TrafficLights1":"dots","3TrafficLights2":"dots","4Arrows":"arrows","4ArrowsGray":"arrows","4RedToBlack":"dots","4Rating":"smiley","4TrafficLights":"dots","5Arrows":"arrows","5ArrowsGray":"arrows","5Rating":"smiley","5Quarters":"dots","3Stars":"smiley","3Triangles":"arrows","5Boxes":"dots"},ym={none:"none",b:"bottom",t:"top",l:"left",r:"right",tr:"right"},xm={areaChart:void 0,area3DChart:void 0,lineChart:"line",line3DChart:void 0,stockChart:void 0,radarChart:void 0,scatterChart:void 0,pieChart:"pie",pie3DChart:void 0,doughnutChart:"pie",barChart:"bar",bar3DChart:void 0,ofPieChart:void 0,surfaceChart:void 0,surface3DChart:void 0,bubbleChart:void 0},Rm={1:"AVERAGE",2:"COUNT",3:"COUNTA",4:"MAX",5:"MIN",6:"PRODUCT",7:"STDEV",8:"STDEVP",9:"SUM",10:"VAR",11:"VARP",101:"AVERAGE",102:"COUNT",103:"COUNTA",104:"MAX",105:"MIN",106:"PRODUCT",107:"STDEV",108:"STDEVP",109:"SUM",110:"VAR",111:"VARP"},Im={0:"",1:"0",2:"0.00",3:"#,#00",4:"#,##0.00",9:"0%",10:"0.00%",11:void 0,12:void 0,13:void 0,14:"m/d/yyyy",15:"m/d/yyyy",16:"m/d/yyyy",17:"m/d/yyyy",18:"hh:mm:ss a",19:"hh:mm:ss a",20:"hhhh:mm:ss",21:"hhhh:mm:ss",22:"m/d/yy h:mm",37:void 0,38:void 0,39:void 0,40:void 0,45:"hhhh:mm:ss",46:"hhhh:mm:ss",47:"hhhh:mm:ss",48:void 0,49:void 0},Tm={0:1,"0.00":2,"#,#00":3,"#,##0.00":4,"0%":9,"0.00%":10,"0.00E+00":11,"# ?/?":12,"# ??/??":13,"mm-dd-yy":14,"d-mm-yy":15,"mm-yy":16,"mmm-yy":17,"h:mm AM/PM":18,"h:mm:ss AM/PM":19,"h:mm":20,"h:mm:ss":21,"m/d/yy h:mm":22,"#,##0 ;(#,##0)":37,"#,##0 ;[Red](#,##0)":38,"#,##0.00;(#,##0.00)":39,"#,##0.00;[Red](#,##0.00)":40,"mm:ss":45,"[h]:mm:ss":46,"mmss.0":47,"##0.0E+0":48,"@":49,"hh:mm:ss a":19},Am={0:"000000",1:"FFFFFF",2:"FF0000",3:"00FF00",4:"0000FF",5:"FFFF00",6:"FF00FF",7:"00FFFF",8:"000000",9:"FFFFFF",10:"FF0000",11:"00FF00",12:"0000FF",13:"FFFF00",14:"FF00FF",15:"00FFFF",16:"800000",17:"008000",18:"000080",19:"808000",20:"800080",21:"008080",22:"C0C0C0",23:"808080",24:"9999FF",25:"993366",26:"FFFFCC",27:"CCFFFF",28:"660066",29:"FF8080",30:"0066CC",31:"CCCCFF",32:"000080",33:"FF00FF",34:"FFFF00",35:"00FFFF",36:"800080",37:"800000",38:"008080",39:"0000FF",40:"00CCFF",41:"CCFFFF",42:"CCFFCC",43:"FFFF99",44:"99CCFF",45:"FF99CC",46:"CC99FF",47:"FFCC99",48:"3366FF",49:"33CCCC",50:"99CC00",51:"FFCC00",52:"FF9900",53:"FF6600",54:"666699",55:"969696",56:"003366",57:"339966",58:"003300",59:"333300",60:"993300",61:"993366",62:"333399",63:"333333",64:"000000",65:"FFFFFF"};function Nm(e){if(!e)return;let t;if(e.rgb)t=e.rgb;else if(e.auto)t=qp;else{if(!e.indexed)return;t=Am[e.indexed]}var i;return t=6===(i=t).length?"#"+i+"FF":"#"+i.slice(2)+i.slice(0,2),e.tint&&(t=function(e,t){const i=Et(e),n=yt(i);t<0&&(n.l=n.l*(1+t));t>0&&(n.l=n.l*(1-t)+(100-100*(1-t)));return Ct(wt(n))}(t,e.tint)),t=t.toUpperCase(),9===t.length&&t.endsWith("FF")&&(t=t.slice(0,7)),t}function Om(e,t){const i=e.split("/"),n=t.split("/");let o="",s=0;for(let e=0;e<i.length-1;e++)i[e]===n[e]?s++:o+="../";return o+=n.slice(s).join("/"),o}function Mm(e,t=0){const i={};for(let n=0;n<e.length;n++)e[n]&&(i[n+t]=e[n]);return i}function _m(e){const t=[];for(let i of Object.keys(e).map(Number))t[i]=e[i];return t}function Fm(e){return e.replace(/_x([0-9a-zA-Z]{4})_/g,((e,t)=>String.fromCharCode(parseInt(t,16))))}const Dm=/^(yy|yyyy|m{1,5}|d{1,4}|h{1,2}|s{1,2}|am\/pm|a\/m|\s|-|\/|\.|:)+$/i;function km(e,t,i){var n,o,s;if(0===e)return;let r=Im[e]||(null===(n=t.find((t=>t.id===e)))||void 0===n?void 0:n.format);if(r)try{let e=r.replace(/(.*?);.*/,"$1");e=e.replace(/\[(.*)-[A-Z0-9]{3}\]/g,"[$1]"),e=e.replace(/\[\$\]/g,"");const t=(null===(o=e.match(/"/g))||void 0===o?void 0:o.length)||0;if(t/2+((null===(s=e.match(/\[/g))||void 0===s?void 0:s.length)||0)>1)throw new Error("Multiple escaped blocks in format");if(e=e.replace(/"(.*)"/g,"[$$$1]"),e=e.replace(/_.{1}/g,""),e=e.replace(/\*.{1}/g,""),e=e.replace(/\\ /g," "),e=e.replace(/\\./g,(e=>e[1])),function(e){return null!==e.match(Dm)}(e)&&(e=function(e){return e=e.toLowerCase(),e=e.replace(/mmmmm|mmmm|mmm/g,"mm"),e=e.replace(/dddd|ddd/g,"dd"),e=e.replace(/am\/pm|a\/m/g,"a"),e=e.replace(/\byy\b/g,"yyyy"),e=e.replace(/hhhh/g,"hh"),e=e.replace(/\bh\b/g,"hh"),e}(e)),function(e){try{return Qt(0,e),!0}catch(e){return!1}}(e))return e}catch(e){}i.generateNotSupportedWarning(hm.NumFmtIdNotSupported,r||`nmFmtId ${e}`)}function $m(e,t){const i=e.borders.map((e=>{!function(e,t){e.diagonal&&t.generateNotSupportedWarning(hm.DiagonalBorderNotSupported)}(e,t);const i={top:Lm(e.top,t),bottom:Lm(e.bottom,t),left:Lm(e.left,t),right:Lm(e.right,t)};return Object.keys(i).forEach((e=>void 0===i[e]&&delete i[e])),i}));return Mm(i,1)}function Lm(e,t){if(!e)return;!function(e,t){um.includes(e.style)||t.generateNotSupportedWarning(hm.BorderStyleNotSupported,e.style,um)}(e,t);const i=bm[e.style];return i?[i,Nm(e.color)]:void 0}function Pm(e,t){return Mm(e.styles.map((i=>Um({fontStyle:e.fonts[i.fontId],fillStyle:e.fills[i.fillId],alignment:i.alignment},t))),1)}function Um(e,t){var i,n,o,s,r,a,l,c,h,d,u,g;return function(e,t,i){e&&e.name&&!pm.includes(e.name)&&i.generateNotSupportedWarning(hm.FontNotSupported,e.name,pm);t&&t.patternType&&!mm.includes(t.patternType)&&i.generateNotSupportedWarning(hm.FillStyleNotSupported,t.patternType,mm)}(null==e?void 0:e.fontStyle,null==e?void 0:e.fillStyle,t),function(e,t){e&&!gm.includes(e)&&t.generateNotSupportedWarning(hm.HorizontalAlignmentNotSupported,e,gm)}(null===(i=null==e?void 0:e.alignment)||void 0===i?void 0:i.horizontal,t),function(e,t){e&&t.generateNotSupportedWarning(hm.VerticalAlignmentNotSupported)}(null===(n=null==e?void 0:e.alignment)||void 0===n?void 0:n.vertical,t),{bold:null===(o=e.fontStyle)||void 0===o?void 0:o.bold,italic:null===(s=e.fontStyle)||void 0===s?void 0:s.italic,strikethrough:null===(r=e.fontStyle)||void 0===r?void 0:r.strike,underline:null===(a=e.fontStyle)||void 0===a?void 0:a.underline,align:(null===(l=e.alignment)||void 0===l?void 0:l.horizontal)?Sm[e.alignment.horizontal]:void 0,fillColor:"solid"===(null===(c=e.fillStyle)||void 0===c?void 0:c.patternType)?Nm(null===(h=e.fillStyle)||void 0===h?void 0:h.fgColor):Nm(null===(d=e.fillStyle)||void 0===d?void 0:d.bgColor),textColor:Nm(null===(u=e.fontStyle)||void 0===u?void 0:u.color),fontSize:(null===(g=e.fontStyle)||void 0===g?void 0:g.size)?zm(e.fontStyle.size):void 0}}function Vm(e,t){const i=[];for(let n of e.styles){const o=km(n.numFmtId,e.numFmts,t);o&&(i[n.numFmtId]=o)}return Mm(i,1)}function zm(e){return Object.keys(re).map(Number).reduce(((t,i)=>Math.abs(i-e)<Math.abs(t-e)?i:t))}function Bm(e,t,i){const n=[];let o=1;for(let r of e){if(0===r.cfRules.length)continue;qm(r,t,i);const e=r.cfRules[0];let a;const l=[];if(void 0!==e.dxfId||"colorScale"===e.type||"iconSet"===e.type){switch(e.type){case"aboveAverage":case"containsErrors":case"notContainsErrors":case"dataBar":case"duplicateValues":case"expression":case"top10":case"uniqueValues":case"timePeriod":continue;case"colorScale":const t=Hm(o++,r);t&&n.push(t);continue;case"iconSet":const c=Wm(o++,r,i);c&&n.push(c);continue;case"containsText":case"notContainsText":case"beginsWith":case"endsWith":if(!e.text)continue;a=Cm[e.type],l.push(e.text);break;case"containsBlanks":case"notContainsBlanks":a=Cm[e.type];break;case"cellIs":if(!e.operator||!e.formula||0===e.formula.length)continue;a=(s=e.operator).slice(0,1).toUpperCase()+s.slice(1),l.push(e.formula[0]),2===e.formula.length&&l.push(e.formula[1])}a&&void 0!==e.dxfId&&n.push({id:(o++).toString(),ranges:r.sqref,stopIfTrue:e.stopIfTrue,rule:{type:"CellIsRule",operator:a,values:l,style:Um({fontStyle:t[e.dxfId].font,fillStyle:t[e.dxfId].fill},i)}})}}var s;return n}function Hm(e,t){const i=t.cfRules[0].colorScale;if(!i||i.cfvos.length!==i.colors.length||i.cfvos.length<2||i.cfvos.length>3)return;const n=[];for(let e=0;e<i.cfvos.length;e++)n.push({color:(o=Nm(i.colors[e])||"#FFFFFF",9===o.length&&(o=o.slice(0,7)),parseInt(o.replace("#",""),16)),type:Em[i.cfvos[e].type],value:i.cfvos[e].value});var o;const s=n[0],r=2===n.length?n[1]:n[2],a=3===n.length?n[1]:void 0;return{id:e.toString(),stopIfTrue:t.cfRules[0].stopIfTrue,ranges:t.sqref,rule:{type:"ColorScaleRule",minimum:s,midpoint:a,maximum:r}}}function Wm(e,t,i){const n=t.cfRules[0].iconSet;if(!n)return;let o=n.cfvos,s=n.cfIcons;if(o.length<3||s&&s.length<3)return;o.length>3&&(o=[o[0],o[Math.floor(o.length/2)],o[o.length-1]]),s&&s.length>3&&(s=[s[0],s[Math.floor(s.length/2)],s[s.length-1]]);const r=[];for(let e=1;e<=2;e++){const t=Em[o[e].type];if("value"===t)return;r.push({value:o[e].value||"",operator:o[e].gte?"ge":"gt",type:t})}let a={lower:s?Gm(s[0].iconSet,s[0].iconId):Gm(n.iconSet,0),middle:s?Gm(s[1].iconSet,s[1].iconId):Gm(n.iconSet,1),upper:s?Gm(s[2].iconSet,s[2].iconId):Gm(n.iconSet,2)};n.reverse&&(a={upper:a.lower,middle:a.middle,lower:a.upper});for(let e of Object.keys(a))if(!a[e])switch(i.generateNotSupportedWarning(hm.CfIconSetEmptyIconNotSupported),e){case"upper":a[e]=Cr.dots.good;break;case"middle":a[e]=Cr.dots.neutral;break;case"lower":a[e]=Cr.dots.bad}return{id:e.toString(),stopIfTrue:t.cfRules[0].stopIfTrue,ranges:t.sqref,rule:{type:"IconSetRule",icons:a,upperInflectionPoint:r[1],lowerInflectionPoint:r[0]}}}function Gm(e,t){const i=wm[e];return i?0===t?Cr[i].bad:1===t?Cr[i].neutral:Cr[i].good:""}function qm(e,t,i){if(e.cfRules.length>1&&i.generateNotSupportedWarning(hm.MultipleRulesCfNotSupported),fm.includes(e.cfRules[0].type)||i.generateNotSupportedWarning(hm.CfTypeNotSupported,e.cfRules[0].type),e.cfRules[0].dxfId){const n=t[e.cfRules[0].dxfId];n.border&&i.generateNotSupportedWarning(hm.CfFormatBorderNotSupported),n.alignment&&i.generateNotSupportedWarning(hm.CfFormatAlignmentNotSupported),n.numFmt&&i.generateNotSupportedWarning(hm.CfFormatNumFmtNotSupported)}}function Zm(e){switch(e){case"IsNotEmpty":case"NotContains":return"notContainsBlanks";case"IsEmpty":return"containsBlanks";default:return e.charAt(0).toLowerCase()+e.slice(1)}}function jm(e){return Math.round(em*e*window.devicePixelRatio*100)/100}function Ym(e){return Math.round(tm*e*100)/100}function Xm(e,t){let i={};e.style&&(i=t.styles[e.style]);const n=function(e,t){if(e.format)return t.formats[e.format];if(e.isFormula){const t=Ju(e.content||""),i=Yu.content;if(!t.filter((e=>"FUNCTION"===e.type)).every((e=>i[e.value.toUpperCase()].isExported)))return e.computedFormat}return}(e,t),o={font:{size:(null==i?void 0:i.fontSize)||G,color:{rgb:(null==i?void 0:i.textColor)?i.textColor:"000000"},family:2,name:"Arial"},fill:(null==i?void 0:i.fillColor)?{fgColor:{rgb:i.fillColor}}:{reservedAttribute:"none"},numFmt:n?{format:n,id:0}:void 0,border:e.border||0,alignment:{vertical:"center",horizontal:i.align}};return o.font.strike=!!(null==i?void 0:i.strikethrough)||void 0,o.font.underline=!!(null==i?void 0:i.underline)||void 0,o.font.bold=!!(null==i?void 0:i.bold)||void 0,o.font.italic=!!(null==i?void 0:i.italic)||void 0,o}function Km(e,t){const i=function(e,t){if(!e)return 0;let i=Tm[e.format];i||(i=Jm(e,t)+rm);return i}(t.numFmt,e.numFmts),n={fontId:Jm(t.font,e.fonts),fillId:Jm(t.fill,e.fills),borderId:t.border,numFmtId:i,alignment:{vertical:t.alignment.vertical,horizontal:t.alignment.horizontal}};return Jm(n,e.styles)}function Qm(e,t,i){let n,o=e.find((e=>e.path===t));return o?(n=`rId${(o.rels.length+1).toString()}`,o.rels.push({...i,id:n})):(n="rId1",e.push({path:t,rels:[{...i,id:n}]})),n}function Jm(e,t){let i=t.length;const n="object"==typeof e?ot:(e,t)=>e===t;for(let o=0;o<i;o++)if(n(e,t[o]))return o;return t[t.length]=e,t.length-1}const ef=[];function tf(e){const t=ef.findIndex((t=>t===e));return-1===t?(ef.push(e),ef.length):t+1}function nf(e){return Math.round(914400*e/96)}function of(e,t,i){let n,o,s=e;if(({xc:s,sheetName:n}=$t(e)),n){const e=i.sheets.findIndex((e=>Ai(e.name,n)));if(e<0)throw new Error("Unable to find a sheet with the name "+n);o=e}else o=Number(t);const r=_i(s);return void 0===r.right&&(r.right=i.sheets[o].colNumber),void 0===r.bottom&&(r.bottom=i.sheets[o].rowNumber),(r.right-r.left+1)*(r.bottom-r.top+1)}function sf(e){return Math.round(96*e/914400)}function rf(e,t){var i;let n=0;for(let o=0;o<e;o++){const e=t.cols.find((e=>o>=e.min&&o<=e.max));(null==e?void 0:e.width)?n+=e.width:(null===(i=t.sheetFormat)||void 0===i?void 0:i.defaultColWidth)?n+=t.sheetFormat.defaultColWidth:n+=im}return n/tm}function af(e,t){var i;let n=0;for(let o=0;o<e;o++){const e=t.rows[o];(null==e?void 0:e.height)?n+=e.height:(null===(i=t.sheetFormat)||void 0===i?void 0:i.defaultRowHeight)?n+=t.sheetFormat.defaultRowHeight:n+=nm}return n/em}function lf(e){let t=1;return e.figures.map((i=>function(e,t,i){const n=rf(e.anchors[0].col,i)+sf(e.anchors[0].colOffset),o=rf(e.anchors[1].col,i)+sf(e.anchors[1].colOffset),s=af(e.anchors[0].row,i)+sf(e.anchors[0].rowOffset),r=af(e.anchors[1].row,i)+sf(e.anchors[1].rowOffset),a=o-n,l=r-s,c=cf(e.data);return c?{id:t,x:n,y:s,width:a,height:l,tag:"chart",data:cf(e.data)}:void 0}(i,(t++).toString(),e))).filter(Xe)}function cf(e){var t;if(0===e.dataSets.length)return;const i=null===(t=e.dataSets[0].label)||void 0===t?void 0:t.replace(/\$/g,"");let n=e.dataSets.map((e=>e.range.replace(/\$/g,"")));return"pie"===e.type&&n.reverse(),{dataSets:n,dataSetsHaveTitle:!1,labelRange:i,title:e.title||"",type:e.type,background:Nm({rgb:e.backgroundColor})||"#FFFFFF",verticalAxisPosition:e.verticalAxisPosition,legendPosition:e.legendPosition,stacked:e.stacked||!1,cumulative:e.cumulative||!1,labelsAsText:!1}}const hf=new RegExp(/'?\[([0-9]*)\](.*)'?!(\$?[a-zA-Z]*\$?[0-9]*)/g),df=new RegExp(/SUBTOTAL\(([0-9]*),/g),uf=new RegExp(xt.source,"ig");function gf(e,t){const i=function(e){const t={};for(let i of e.rows)for(let e of i.cells)e.formula&&void 0!==e.formula.sharedIndex&&e.formula.content&&(t[e.formula.sharedIndex]={refCellXc:e.xc,formula:e.formula.content});return t}(e);for(let n of e.rows.map((e=>e.cells)).flat())(null==n?void 0:n.formula)&&(n.formula.content=void 0===n.formula.sharedIndex||n.formula.content?"="+n.formula.content:"="+mf(n.xc,i[n.formula.sharedIndex]),n.formula.content=pf(n.formula.content,t))}function pf(e,t){return e=(e=(e=(e=e.replace("_xlfn.","")).replace(/#REF!/g,"#REF")).replace(df,((e,t)=>{const i=Rm[t];return i?i+"(":e}))).replace(hf,((e,i,n,o)=>{var s;i=Number(i)-1,o=o.replace(/\$/g,"");const r=t.externalBooks[i].sheetNames.findIndex((e=>Ai(e,n)));if(-1===r)return e;const a=null===(s=t.externalBooks[i].datasets.find((e=>e.sheetId===r)))||void 0===s?void 0:s.data;if(!a)return e;const l=a&&a[o];return(Number(l)?l:`"${l}"`)||e}))}function mf(e,t){const i=Ut(t.refCellXc);let n,o=t.formula.slice();do{if(n=uf.exec(o),n){const t=Ut(n[0].replace("$","")),s=Ut(e),r={colFixed:n[0].startsWith("$"),rowFixed:n[0].includes("$",1)},a={col:s.col-i.col,row:s.row-i.row},l={col:r.colFixed?t.col:t.col+a.col,row:r.rowFixed?t.row:t.row+a.row};o=o.slice(0,n.index)+Vt(l.col,l.row,r)+o.slice(n.index+n[0].length)}}while(n);return o}function ff(e,t){return e.sheets.map((i=>{gf(i,e);const n=function(e){const t=[0,0];for(let i of e.rows)t[0]=Math.max(t[0],lt(i.cells.map((e=>Ut(e.xc).col)))),t[1]=Math.max(t[1],i.index);return t[0]=Math.max(t[0],om),t[1]=Math.max(t[1],sm),t}(i),o=i.sheetViews[0];return{id:i.sheetName,areGridLinesVisible:!o||o.showGridLines,name:i.sheetName,colNumber:n[0],rowNumber:n[1],cells:Sf(i,e,n,t),merges:i.merges,cols:vf(i,n[0]),rows:bf(i,n[1]),conditionalFormats:Bm(i.cfs,e.dxfs,t),figures:lf(i),isVisible:i.isVisible,panes:o?{xSplit:o.pane.xSplit,ySplit:o.pane.ySplit}:{xSplit:0,ySplit:0},filterTables:[]}}))}function vf(e,t){var i;const n={};for(let s=1;s<t+1;s++){const t=e.cols.find((e=>e.min<=s&&s<=e.max));let r;r=t&&t.width?t.width:(null===(i=e.sheetFormat)||void 0===i?void 0:i.defaultColWidth)?e.sheetFormat.defaultColWidth:im,n[s-1]={size:(o=r,o?Math.round(o/tm*100)/100:o),isHidden:null==t?void 0:t.hidden}}var o;return n}function bf(e,t){var i;const n={};for(let s=1;s<t+1;s++){const t=e.rows.find((e=>e.index===s));let r;r=t&&t.height?t.height:(null===(i=e.sheetFormat)||void 0===i?void 0:i.defaultRowHeight)?e.sheetFormat.defaultRowHeight:nm,n[s-1]={size:(o=r,o?Math.round(o/em*100)/100:o),isHidden:null==t?void 0:t.hidden}}var o;return n}function Sf(e,t,i,n){const o={},s=t.sharedStrings.map((e=>e.replace(/\n/g,"")));const r=e.hyperlinks.reduce(((e,t)=>(e[t.xc]=t,e)),{});for(let i of e.rows)for(let e of i.cells)o[e.xc]={content:Cf(e,r,s,n),style:e.styleIndex?e.styleIndex+1:void 0,border:e.styleIndex?t.styles[e.styleIndex].borderId+1:void 0,format:e.styleIndex?t.styles[e.styleIndex].numFmtId+1:void 0};for(let n of e.rows.filter((e=>e.styleIndex)))for(let e=1;e<=i[0];e++){const i=Vt(e-1,n.index-1);let s=o[i];s||(s={},o[i]=s),s.style=s.style?s.style:n.styleIndex+1,s.border=s.border?s.border:t.styles[n.styleIndex].borderId+1,s.format=s.format?s.format:t.styles[n.styleIndex].numFmtId+1}for(let n of e.cols.filter((e=>e.styleIndex)))for(let e=n.min;e<=Math.min(n.max,i[0]);e++)for(let s=1;s<=i[1];s++){const i=Vt(e-1,s-1);let r=o[i];r||(r={},o[i]=r),r.style=r.style?r.style:n.styleIndex+1,r.border=r.border?r.border:t.styles[n.styleIndex].borderId+1,r.format=r.format?r.format:t.styles[n.styleIndex].numFmtId+1}return o}function Cf(e,t,i,n){let o;switch(e.type){case"sharedString":o=i[parseInt(e.value,10)];break;case"boolean":o=Number(e.value)?"TRUE":"FALSE";break;case"date":case"error":case"inlineStr":case"number":case"str":o=e.value}return o&&t[e.xc]&&(o=function(e,t,i){const n=e.display||t;e.relTarget||e.location||i.generateNotSupportedWarning(hm.BadlyFormattedHyperlink);const o=e.relTarget?e.relTarget:je($t(e.location).sheetName);return We(n,o)}(t[e.xc],o,n)),e.formula&&(o=e.formula.content),o}const Ef={fillColor:"#000000",textColor:"#ffffff",bold:!0},wf={bold:!0},yf=["thin","#000000FF"];function xf(e,t){for(const i of t.sheets)for(const t of i.tables){const n=e.sheets.find((e=>e.name===i.sheetName));n&&t.autoFilter&&(n.filterTables||(n.filterTables=[]),n.filterTables.push({range:t.ref}))}!function(e,t){var i,n,o,s;const r=_m(e.styles),a=_m(e.borders);for(let l of t.sheets)for(let t of l.tables){const c=e.sheets.find((e=>e.name===l.sheetName));if(!c)continue;const h=Fi(t.ref);for(let e=0;e<t.headerRowCount;e++)Rf(Ef,{...h,bottom:h.top+e},c.cells,r);for(let e=0;e<t.totalsRowCount;e++)Rf(wf,{...h,top:h.bottom-e},c.cells,r);(null===(i=t.style)||void 0===i?void 0:i.showFirstColumn)&&Rf(wf,{...h,right:h.left},c.cells,r),(null===(n=t.style)||void 0===n?void 0:n.showLastColumn)&&Rf(wf,{...h,left:h.right},c.cells,r);for(let e=h.left;e<=h.right;e++)for(let i=h.top;i<=h.bottom;i++){const n=Vt(e,i),r=c.cells[n],l={left:e===h.left||(null===(o=t.style)||void 0===o?void 0:o.showColumnStripes)?yf:void 0,right:e===h.right?yf:void 0,top:i===h.top||(null===(s=t.style)||void 0===s?void 0:s.showRowStripes)||i>h.bottom-t.totalsRowCount?yf:void 0,bottom:i===h.bottom?yf:void 0},d=(null==r?void 0:r.border)?{...a[r.border],...l}:l;let u=a.findIndex((e=>ot(e,d)));-1===u&&(u=a.length,a.push(d)),r?r.border=u:c.cells[n]={border:u}}}e.styles=Mm(r),e.borders=Mm(a)}(e,t),function(e,t){for(let i of e){const n=t.find((e=>Ai(e.sheetName,i.name))).tables;for(let t of n){const n=t.name+"[";for(let o of e)for(let e in o.cells){const s=o.cells[e];if(s&&s.content&&s.content.startsWith("=")){let r;for(;-1!==(r=s.content.indexOf(n));){let a=r+n.length,l=1;for(;l>0&&a<s.content.length;)"["===s.content[a]?l++:"]"===s.content[a]&&l--,a++;let c=s.content.slice(r+n.length,a-1);const h=If(i.id===o.id?"":i.name+"!",c,t,e);s.content=s.content.slice(0,r)+h+s.content.slice(a)}}}}}}(e.sheets,t.sheets)}function Rf(e,t,i,n){for(let o=t.left;o<=t.right;o++)for(let s=t.top;s<=t.bottom;s++){const t=Vt(o,s),r=i[t],a=(null==r?void 0:r.style)?{...n[r.style],...e}:e;let l=n.findIndex((e=>ot(e,a)));-1===l&&(l=n.length,n.push(a)),r?r.style=l:i[t]={style:l}}}function If(e,t,i,n){const o=t.split(",").map((e=>e.trim())),s=Fi(i.ref),r=[],a=[],l=[];for(const e of o)if(Tf(e).startsWith("#")){const t=Tf(e);switch(l.push(t),t){case"#All":a.push(s.top,s.bottom);break;case"#Data":const e=i.headerRowCount?s.top+i.headerRowCount:s.top,t=i.totalsRowCount?s.bottom-i.totalsRowCount:s.bottom;a.push(e,t);break;case"#This Row":a.push(Ut(n).row);break;case"#Headers":if(!i.headerRowCount)return X;a.push(s.top);break;case"#Totals":if(!i.totalsRowCount)return X;a.push(s.bottom)}}else{const t=e.split(":").map((e=>e.trim())).map(Tf);if(r.length)return X;const n=i.cols.findIndex((e=>e.name===t[0]));if(-1===n)return X;if(r.push(n+s.left),t[1]){const e=i.cols.findIndex((e=>e.name===t[1]));if(-1===e)return X;r.push(e+s.left)}}if(!function(e){if(e.length<2)return!0;if(e.length>2)return!1;if(e.includes("#Data")&&e.includes("#Totals"))return!0;if(e.includes("#Headers")&&e.includes("#Data"))return!0;return!1}(l))return X;if(0===a.length){const e=i.headerRowCount?s.top+i.headerRowCount:s.top,t=i.totalsRowCount?s.bottom-i.totalsRowCount:s.bottom;a.push(e,t)}0===r.length&&r.push(s.left,s.right);return e+ki({top:Math.min(...a),left:Math.min(...r),bottom:Math.max(...a),right:Math.max(...r)})}function Tf(e){return e.startsWith("[")&&e.endsWith("]")?e.slice(1,e.length-1):e}function Af(e,t,i){return{content:(new XMLSerializer).serializeToString(e),path:t,contentType:i}}function Nf(e){return String(e).replace(/\&/g,"&").replace(/\</g,"<").replace(/\>/g,">").replace(/\"/g,""").replace(/\'/g,"'").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,"")}function Of(e){return new Wp(e.map((([e,t])=>`${e}="${Nf(t)}"`)).join(" "))}function Mf(e){const t=(new DOMParser).parseFromString(e.toString(),"text/xml"),i=t.querySelector("parsererror");if(i){const t=i.innerHTML,n=parseInt(t.split(":")[0],10),o=e.toString().trim().split("\n"),s=o.slice(Math.max(n-3,0),Math.min(n+2,o.length)).join("\n");throw new Error(`XML string could not be parsed: ${t}\n${s}`)}return t}function _f(e){if(e)return{style:e[0],color:{rgb:e[1]}}}function Ff(e,t){return kf`
|
|
1388
|
+
/>`,Np.defaultProps={position:{top:0}};const Op={ROW:Xo,COL:Yo,CELL:jo};class Mp extends t.Component{constructor(){super(...arguments),this.HEADER_HEIGHT=O,this.HEADER_WIDTH=M,this.keyDownMapping={ENTER:()=>{const e=this.env.model.getters.getActiveCell();!e||e.isEmpty()?this.props.onGridComposerCellFocused():this.props.onComposerContentFocused()},TAB:()=>this.env.model.selection.moveAnchorCell("right",1),"SHIFT+TAB":()=>this.env.model.selection.moveAnchorCell("left",1),F2:()=>{const e=this.env.model.getters.getActiveCell();!e||e.isEmpty()?this.props.onGridComposerCellFocused():this.props.onComposerContentFocused()},DELETE:()=>{this.env.model.dispatch("DELETE_CONTENT",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones()})},BACKSPACE:()=>{this.env.model.dispatch("DELETE_CONTENT",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones()})},"CTRL+A":()=>this.env.model.selection.loopSelection(),"CTRL+S":()=>{var e,t;null===(t=(e=this.props).onSaveRequested)||void 0===t||t.call(e)},"CTRL+Z":()=>this.env.model.dispatch("REQUEST_UNDO"),"CTRL+Y":()=>this.env.model.dispatch("REQUEST_REDO"),"CTRL+B":()=>this.env.model.dispatch("SET_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),style:{bold:!this.env.model.getters.getCurrentStyle().bold}}),"CTRL+I":()=>this.env.model.dispatch("SET_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),style:{italic:!this.env.model.getters.getCurrentStyle().italic}}),"CTRL+U":()=>this.env.model.dispatch("SET_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),style:{underline:!this.env.model.getters.getCurrentStyle().underline}}),"ALT+=":()=>{var e;const t=this.env.model.getters.getActiveSheetId(),i=this.env.model.getters.getSelectedZone(),{anchor:n}=this.env.model.getters.getSelection(),o=this.env.model.getters.getAutomaticSums(t,i,n.cell);if(this.env.model.getters.isSingleCellOrMerge(t,i)||this.env.model.getters.isEmpty(t,i)&&o.length<=1){const i=(null===(e=o[0])||void 0===e?void 0:e.zone)?this.env.model.getters.zoneToXC(t,o[0].zone):"",n=`=SUM(${i})`;this.props.onGridComposerCellFocused(n,{start:5,end:5+i.length})}else this.env.model.dispatch("SUM_SELECTION")},"CTRL+HOME":()=>{const e=this.env.model.getters.getActiveSheetId(),{col:t,row:i}=this.env.model.getters.getNextVisibleCellPosition(e,0,0);this.env.model.selection.selectCell(t,i)},"CTRL+END":()=>{const e=this.env.model.getters.getActiveSheetId(),t=this.env.model.getters.findVisibleHeader(e,"COL",this.env.model.getters.getNumberCols(e)-1,0),i=this.env.model.getters.findVisibleHeader(e,"ROW",this.env.model.getters.getNumberRows(e)-1,0);this.env.model.selection.selectCell(t,i)},"SHIFT+ ":()=>{const e=this.env.model.getters.getActiveSheetId(),t={...this.env.model.getters.getSelectedZone(),left:0,right:this.env.model.getters.getNumberCols(e)-1},i=this.env.model.getters.getPosition();this.env.model.selection.selectZone({cell:i,zone:t})},"CTRL+ ":()=>{const e=this.env.model.getters.getActiveSheetId(),t={...this.env.model.getters.getSelectedZone(),top:0,bottom:this.env.model.getters.getNumberRows(e)-1},i=this.env.model.getters.getPosition();this.env.model.selection.selectZone({cell:i,zone:t})},"CTRL+SHIFT+ ":()=>{this.env.model.selection.selectAll()},"SHIFT+PAGEDOWN":()=>{this.env.model.dispatch("ACTIVATE_NEXT_SHEET")},"SHIFT+PAGEUP":()=>{this.env.model.dispatch("ACTIVATE_PREVIOUS_SHEET")},PAGEDOWN:()=>this.env.model.dispatch("SHIFT_VIEWPORT_DOWN"),PAGEUP:()=>this.env.model.dispatch("SHIFT_VIEWPORT_UP")}}setup(){this.menuState=t.useState({isOpen:!1,position:null,menuItems:[]}),this.gridRef=t.useRef("grid"),this.canvasPosition=Hn(this.gridRef),this.hoveredCell=t.useState({col:void 0,row:void 0}),t.useExternalListener(document.body,"cut",this.copy.bind(this,!0)),t.useExternalListener(document.body,"copy",this.copy.bind(this,!1)),t.useExternalListener(document.body,"paste",this.paste),t.onMounted((()=>this.focusDefaultElement())),this.props.exposeFocus((()=>this.focusDefaultElement())),Ep("canvas",this.env.model,(()=>this.env.model.getters.getSheetViewDimensionWithHeaders())),t.useEffect((()=>this.focusDefaultElement()),(()=>[this.env.model.getters.getActiveSheetId()])),this.onMouseWheel=wp(((e,t)=>{this.moveCanvas(e,t),this.hoveredCell.col=void 0,this.hoveredCell.row=void 0}))}onCellHovered({col:e,row:t}){this.hoveredCell.col=e,this.hoveredCell.row=t}get gridOverlayDimensions(){return"\n top: 26px;\n left: 48px;\n height: calc(100% - 41px);\n width: calc(100% - 63px);\n "}onClosePopover(){this.closeOpenedPopover(),this.focusDefaultElement()}focusDefaultElement(){this.env.model.getters.getSelectedFigureId()||"inactive"!==this.env.model.getters.getEditionMode()||this.env.focusableElement.focus()}get gridEl(){if(!this.gridRef.el)throw new Error("Grid el is not defined.");return this.gridRef.el}getAutofillPosition(){const e=this.env.model.getters.getSelectedZone(),t=this.env.model.getters.getVisibleRect(e);return{left:t.x+t.width-4,top:t.y+t.height-4}}isAutoFillActive(){const e=this.env.model.getters.getSelectedZone(),t=this.env.model.getters.getVisibleRect({left:e.right,right:e.right,top:e.bottom,bottom:e.bottom});return!(0===t.width||0===t.height)}onGridResized({height:e,width:t}){this.env.model.dispatch("RESIZE_SHEETVIEW",{width:t,height:e,gridOffsetX:M,gridOffsetY:O})}moveCanvas(e,t){const{scrollX:i,scrollY:n}=this.env.model.getters.getActiveSheetDOMScrollInfo();this.env.model.dispatch("SET_VIEWPORT_OFFSET",{offsetX:Math.max(i+e,0),offsetY:Math.max(n+t,0)})}getClientPositionKey(e){var t,i,n;return`${e.id}-${null===(t=e.position)||void 0===t?void 0:t.sheetId}-${null===(i=e.position)||void 0===i?void 0:i.col}-${null===(n=e.position)||void 0===n?void 0:n.row}`}isCellHovered(e,t){return this.hoveredCell.col===e&&this.hoveredCell.row===t}onCellClicked(e,t,{addZone:i,expandZone:n}){i&&this.env.model.dispatch("PREPARE_SELECTION_INPUT_EXPANSION"),this.closeOpenedPopover(),"editing"===this.env.model.getters.getEditionMode()&&this.env.model.dispatch("STOP_EDITION"),n?this.env.model.selection.setAnchorCorner(e,t):i?this.env.model.selection.addCellToSelection(e,t):this.env.model.selection.selectCell(e,t);let o=e,s=t;Fr(this.env,((e,t)=>{(e!==o&&-1!=e||t!==s&&-1!=t)&&(o=-1===e?o:e,s=-1===t?s:t,this.env.model.selection.setAnchorCorner(o,s))}),(()=>{this.env.model.dispatch("STOP_SELECTION_INPUT"),this.env.model.getters.isPaintingFormat()&&this.env.model.dispatch("PASTE",{target:this.env.model.getters.getSelectedZones()})}))}onCellDoubleClicked(e,t){const i=this.env.model.getters.getActiveSheetId();({col:e,row:t}=this.env.model.getters.getMainCellPosition(i,e,t));const n=this.env.model.getters.getCell(i,e,t);!n||n.isEmpty()?this.props.onGridComposerCellFocused():this.props.onComposerContentFocused()}closeOpenedPopover(){this.env.model.dispatch("CLOSE_CELL_POPOVER")}processArrows(e){e.preventDefault(),e.stopPropagation(),this.closeOpenedPopover();const t={ArrowDown:"down",ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up"}[e.key];e.shiftKey?this.env.model.selection.resizeAnchorZone(t,zn(e)?"end":1):this.env.model.selection.moveAnchorCell(t,zn(e)?"end":1),this.env.model.getters.isPaintingFormat()&&this.env.model.dispatch("PASTE",{target:this.env.model.getters.getSelectedZones()})}onKeydown(e){if(e.key.startsWith("Arrow"))return void this.processArrows(e);let t="";zn(e)&&(t+="CTRL+"),e.altKey&&(t+="ALT+"),e.shiftKey&&(t+="SHIFT+"),t+=e.key.toUpperCase();let i=this.keyDownMapping[t];return i?(e.preventDefault(),e.stopPropagation(),void i()):void 0}onInputContextMenu(e){e.preventDefault();const t=this.env.model.getters.getSelectedZone(),{left:i,top:n}=t;let o="CELL";this.env.model.dispatch("STOP_EDITION"),this.env.model.getters.getActiveCols().has(i)?o="COL":this.env.model.getters.getActiveRows().has(n)&&(o="ROW");const{x:s,y:r,width:a}=this.env.model.getters.getVisibleRect(t);this.toggleContextMenu(o,this.canvasPosition.x+s+a,this.canvasPosition.y+r)}onCellRightClicked(e,t,{x:i,y:n}){const o=this.env.model.getters.getSelectedZones();let s="CELL";Wi(e,t,o[o.length-1])?this.env.model.getters.getActiveCols().has(e)?s="COL":this.env.model.getters.getActiveRows().has(t)&&(s="ROW"):(this.env.model.selection.getBackToDefault(),this.env.model.selection.selectCell(e,t)),this.toggleContextMenu(s,i,n)}toggleContextMenu(e,t,i){this.closeOpenedPopover(),this.menuState.isOpen=!0,this.menuState.position={x:t,y:i},this.menuState.menuItems=Op[e].getAll()}copy(e,t){if(!this.gridEl.contains(document.activeElement))return;if("inactive"!==this.env.model.getters.getEditionMode())return;e?ho(this.env):this.env.model.dispatch("COPY");const i=this.env.model.getters.getClipboardContent();t.clipboardData.setData("text/plain",i),t.preventDefault()}paste(e){if(!this.gridEl.contains(document.activeElement))return;const t=e.clipboardData;if(t.types.indexOf("text/plain")>-1){const e=t.getData("text/plain"),i=this.env.model.getters.getSelectedZones();this.env.model.getters.getClipboardContent()===e?fo(this.env,i):vo(this.env,i,e)}}closeMenu(){this.menuState.isOpen=!1,this.focusDefaultElement()}}Mp.template="o-spreadsheet-Grid",Mp.components={GridComposer:ap,GridOverlay:mp,GridPopover:fp,HeadersOverlay:Cp,Menu:Gn,Autofill:Dr,ClientTag:$r,Highlight:Rp,Popover:Wn,VerticalScrollBar:Np,HorizontalScrollBar:Ap,FilterIconsOverlay:dp};class _p{constructor(e,t,i){this.id=e,this.style=i.style,this.format=i.format,this.lazyEvaluated=t.map((e=>({...e,format:i.format||e.format})))}isFormula(){return!1}isLink(){return!1}isEmpty(){return!1}get evaluated(){return this.lazyEvaluated()}get formattedValue(){return Qt(this.evaluated.value,this.evaluated.format)}get composerContent(){return this.content}get defaultAlign(){switch(this.evaluated.type){case hn.number:case hn.empty:return"right";case hn.boolean:case hn.error:return"center";case hn.text:return"left"}}get isAutoSummable(){var e;switch(this.evaluated.type){case hn.empty:case hn.text:return!0;case hn.number:return!(null===(e=this.evaluated.format)||void 0===e?void 0:e.match(Y));case hn.error:case hn.boolean:return!1}}}class Fp extends _p{constructor(e,t={}){super(e,tt({value:"",type:hn.empty}),t),this.content=""}isEmpty(){return!0}}class Dp extends _p{constructor(e,t,i={}){super(e,tt({value:t,type:hn.number}),i),this.content=Qt(this.evaluated.value)}get composerContent(){var e;return(null===(e=this.format)||void 0===e?void 0:e.includes("%"))?100*this.evaluated.value+"%":super.composerContent}}class kp extends _p{constructor(e,t,i={}){super(e,tt({value:t,type:hn.boolean}),i),this.content=this.evaluated.value?"TRUE":"FALSE"}}class $p extends _p{constructor(e,t,i={}){super(e,tt({value:t,type:hn.text}),i),this.content=this.evaluated.value}}class Lp extends Dp{constructor(e,t,i){super(e,t,i),this.format=i.format}get composerContent(){return Qt(this.evaluated.value,this.format)}}class Pp extends _p{constructor(e,t,i={}){const n=Ge(t);n.label=o(n.label),super(e,tt({value:n.label,type:hn.text}),i),this.link=n,this.content=t}isLink(){return!0}get composerContent(){return this.link.label}}class Up extends Pp{constructor(e,t,i={}){super(e,t,i),this.link.url=this.withHttp(this.link.url),this.link.isExternal=!0,this.content=We(this.link.label,this.link.url),this.urlRepresentation=this.link.url,this.isUrlEditable=!0}action(e){window.open(this.link.url,"_blank")}withHttp(e){return/^https?:\/\//i.test(e)?e:`https://${e}`}}class Vp extends Pp{constructor(e,t,i={},n){super(e,t,i),this.sheetName=n,this.sheetId=Ye(this.link.url),this.isUrlEditable=!1}action(e){e.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e.model.getters.getActiveSheetId(),sheetIdTo:this.sheetId})}get urlRepresentation(){return this.sheetName(this.sheetId)||s("Invalid sheet")}}class zp extends _p{constructor(e,t,i,n,o){super(t,tt({value:"Loading...",type:hn.text}),o),this.buildFormulaString=e,this.compiledFormula=i,this.dependencies=n}get content(){return this.buildFormulaString(this)}isFormula(){return!0}assignEvaluation(e){this.lazyEvaluated=e.map((e=>{if(e instanceof c)return{value:e.errorType,type:hn.error,error:e};const{value:t,format:i}=e;switch(typeof t){case"number":return{value:t||0,format:i,type:hn.number};case"boolean":return{value:t,format:i,type:hn.boolean};case"string":return{value:t,format:i,type:hn.text};case"object":return{value:0,format:i,type:hn.number};default:return{value:"",type:hn.empty}}}))}}class Bp extends _p{constructor(e,t,i,n){super(e,tt({value:i.errorType,type:hn.error,error:i}),n),this.content=t}}function Hp(e){return""===e?"":Ci(e)?wi(e):Ue(e)?"TRUE"===e.toUpperCase():Ve(e)?ve(e).value:e}io.add("Formula",{sequence:10,match:e=>e.startsWith("="),createCell:(e,t,i,n,o)=>{const s=Ug(t),r=s.dependencies.map((e=>o.getRangeFromSheetXC(n,e)));return new zp((e=>o.buildFormulaContent(n,e)),e,s,r,i)}}).add("Empty",{sequence:20,match:e=>""===e,createCell:(e,t,i)=>new Fp(e,i)}).add("NumberWithDateTimeFormat",{sequence:25,match:(e,t)=>!!t&&Ci(e)&&function(e){try{return oi(1,e),!0}catch(e){return!1}}(t),createCell:(e,t,i)=>{const n=i.format;return new Lp(e,wi(t),{...i,format:n})}}).add("Number",{sequence:30,match:e=>Ci(e),createCell:(e,t,i)=>(i.format||(i.format=function(e){const t=e.includes(".")?"0.00":"0",i=e.match(/[\$€]/);if(i){const n=e.match(/[\d]/),o="[$"+i.values().next().value+"]";return n.index<i.index?"#,##"+t+o:o+"#,##"+t}if(e.includes("%"))return t+"%";return}(t)),new Dp(e,wi(t),i))}).add("Boolean",{sequence:40,match:e=>Ue(e),createCell:(e,t,i)=>new kp(e,"TRUE"===t.toUpperCase(),i)}).add("DateTime",{sequence:50,match:e=>Ve(e),createCell:(e,t,i)=>{const n=ve(t),o=i.format||n.format;return new Lp(e,n.value,{...i,format:o})}}).add("MarkdownSheetLink",{sequence:60,match:e=>Ze(e),createCell:(e,t,i,n,o)=>new Vp(e,t,i,(e=>o.tryGetSheetName(e)))}).add("MarkdownLink",{sequence:70,match:e=>He(e),createCell:(e,t,i)=>new Up(e,t,i)}).add("WebLink",{sequence:80,match:e=>{return t=e,Be.test(t);var t},createCell:(e,t,i)=>new Up(e,We(t,t),i)});class Wp{constructor(e){this.xmlString=e}toString(){return this.xmlString}}const Gp=["areaChart","area3DChart","lineChart","line3DChart","stockChart","radarChart","scatterChart","pieChart","pie3DChart","doughnutChart","barChart","bar3DChart","ofPieChart","surfaceChart","surface3DChart","bubbleChart"],qp="000000",Zp={arrows:"3Arrows",smiley:"3Symbols",dots:"3TrafficLights1"},jp={styleSheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",sst:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",Relationships:"http://schemas.openxmlformats.org/package/2006/relationships",Types:"http://schemas.openxmlformats.org/package/2006/content-types",worksheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",workbook:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",drawing:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",table:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",revision:"http://schemas.microsoft.com/office/spreadsheetml/2014/revision",revision3:"http://schemas.microsoft.com/office/spreadsheetml/2016/revision3",markupCompatibility:"http://schemas.openxmlformats.org/markup-compatibility/2006"},Yp="http://schemas.openxmlformats.org/drawingml/2006/main",Xp="http://schemas.openxmlformats.org/drawingml/2006/chart",Kp={workbook:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",sharedStrings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",themes:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",pivot:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",externalLink:"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml"},Qp={document:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",sheet:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",sharedStrings:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",styles:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",drawing:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",chart:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",theme:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",table:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",hyperlink:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"},Jp="http://schemas.openxmlformats.org/officeDocument/2006/relationships",em=.75,tm=.1317,im=8.43,nm=12.75,om=30,sm=100,rm=164,am={FLOOR:[{type:"NUMBER",value:1}],CEILING:[{type:"NUMBER",value:1}],ROUND:[{type:"NUMBER",value:0}],ROUNDUP:[{type:"NUMBER",value:0}],ROUNDDOWN:[{type:"NUMBER",value:0}]},lm=["ACOT","ACOTH","AGGREGATE","ARABIC","BASE","BETA.DIST","BETA.INV","BINOM.DIST","BINOM.DIST.RANGE","BINOM.INV","BITAND","BITLSHIFT","BITOR","BITRSHIFT","BITXOR","BYCOL","BYROW","CEILING.MATH","CEILING.PRECISE","CHISQ.DIST","CHISQ.DIST.RT","CHISQ.INV","CHISQ.INV.RT","CHISQ.TEST","CHOOSECOLS","CHOOSEROWS","COMBINA","CONCAT","CONFIDENCE.NORM","CONFIDENCE.T","COT","COTH","COVARIANCE.P","COVARIANCE.S","CSC","CSCH","DAYS","DECIMAL","DROP","ERF.PRECISE","ERFC.PRECISE","EXPAND","EXPON.DIST","F.DIST","F.DIST.RT","F.INV","F.INV.RT","F.TEST","FIELDVALUE","FILTERXML","FLOOR.MATH","FLOOR.PRECISE","FORECAST.ETS","FORECAST.ETS.CONFINT","FORECAST.ETS.SEASONALITY","FORECAST.ETS.STAT","FORECAST.LINEAR","FORMULATEXT","GAMMA","GAMMA.DIST","GAMMA.INV","GAMMALN.PRECISE","GAUSS","HSTACK","HYPGEOM.DIST","IFNA","IFS","IMCOSH","IMCOT","IMCSC","IMCSCH","IMSEC","IMSECH","IMSINH","IMTAN","ISFORMULA","ISOMITTED","ISOWEEKNUM","LAMBDA","LET","LOGNORM.DIST","LOGNORM.INV","MAKEARRAY","MAP","MAXIFS","MINIFS","MODE.MULT","MODE.SNGL","MUNIT","NEGBINOM.DIST","NORM.DIST","NORM.INV","NORM.S.DIST","NORM.S.INV","NUMBERVALUE","PDURATION","PERCENTILE.EXC","PERCENTILE.INC","PERCENTRANK.EXC","PERCENTRANK.INC","PERMUTATIONA","PHI","POISSON.DIST","PQSOURCE","PYTHON_STR","PYTHON_TYPE","PYTHON_TYPENAME","QUARTILE.EXC","QUARTILE.INC","QUERYSTRING","RANDARRAY","RANK.AVG","RANK.EQ","REDUCE","RRI","SCAN","SEC","SECH","SEQUENCE","SHEET","SHEETS","SKEW.P","SORTBY","STDEV.P","STDEV.S","SWITCH","T.DIST","T.DIST.2T","T.DIST.RT","T.INV","T.INV.2T","T.TEST","TAKE","TEXTAFTER","TEXTBEFORE","TEXTJOIN","TEXTSPLIT","TOCOL","TOROW","UNICHAR","UNICODE","UNIQUE","VAR.P","VAR.S","VSTACK","WEBSERVICE","WEIBULL.DIST","WRAPCOLS","WRAPROWS","XLOOKUP","XOR","Z.TEST"],cm="[Content_Types].xml";var hm;!function(e){e.DiagonalBorderNotSupported="Diagonal Borders",e.BorderStyleNotSupported="Border style",e.FillStyleNotSupported="Fill Style",e.FontNotSupported="Font",e.HorizontalAlignmentNotSupported="Horizontal Alignment",e.VerticalAlignmentNotSupported="Vertical Alignments",e.MultipleRulesCfNotSupported="Multiple rules conditional formats",e.CfTypeNotSupported="Conditional format type",e.CfFormatBorderNotSupported="Borders in conditional formats",e.CfFormatAlignmentNotSupported="Alignment in conditional formats",e.CfFormatNumFmtNotSupported="Num formats in conditional formats",e.CfIconSetEmptyIconNotSupported="IconSets with empty icons",e.BadlyFormattedHyperlink="Badly formatted hyperlink",e.NumFmtIdNotSupported="Number format"}(hm||(hm={}));class dm{constructor(){this._parsingWarnings=new Set,this._conversionWarnings=new Set}addParsingWarning(e){this._parsingWarnings.add(e)}addConversionWarning(e){this._conversionWarnings.add(e)}get warnings(){return[...this._parsingWarnings,...this._conversionWarnings]}generateNotSupportedWarning(e,t,i){let n=`${e} ${t?'"'+t+'" is':"are"} not yet supported. `;i&&(n+=`Only ${i.join(", ")} are currently supported.`),this._conversionWarnings.has(n)||this._conversionWarnings.add(n)}}const um=["thin"],gm=["general","left","center","right"],pm=["Arial"],mm=["solid"],fm=["expression","cellIs","colorScale","iconSet","containsText","notContainsText","beginsWith","endsWith","containsBlanks","notContainsBlanks"],vm={b:"boolean",d:"date",e:"error",inlineStr:"inlineStr",n:"number",s:"sharedString",str:"str"},bm={dashDot:"thin",dashDotDot:"thin",dashed:"thin",dotted:"thin",double:"thin",hair:"thin",medium:"thin",mediumDashDot:"thin",mediumDashDotDot:"thin",mediumDashed:"thin",none:void 0,slantDashDot:"thin",thick:"thin",thin:"thin"},Sm={general:void 0,left:"left",center:"center",right:"right",fill:"left",justify:"left",centerContinuous:"center",distributed:"center"};const Cm={aboveAverage:void 0,expression:void 0,cellIs:void 0,colorScale:void 0,dataBar:void 0,iconSet:void 0,top10:void 0,uniqueValues:void 0,duplicateValues:void 0,containsText:"ContainsText",notContainsText:"NotContains",beginsWith:"BeginsWith",endsWith:"EndsWith",containsBlanks:"IsEmpty",notContainsBlanks:"IsNotEmpty",containsErrors:void 0,notContainsErrors:void 0,timePeriod:void 0},Em={num:"number",percent:"percentage",max:"value",min:"value",percentile:"percentile",formula:"formula"},wm={NoIcons:void 0,"3Arrows":"arrows","3ArrowsGray":"arrows","3Symbols":"smiley","3Symbols2":"smiley","3Signs":"dots","3Flags":"dots","3TrafficLights1":"dots","3TrafficLights2":"dots","4Arrows":"arrows","4ArrowsGray":"arrows","4RedToBlack":"dots","4Rating":"smiley","4TrafficLights":"dots","5Arrows":"arrows","5ArrowsGray":"arrows","5Rating":"smiley","5Quarters":"dots","3Stars":"smiley","3Triangles":"arrows","5Boxes":"dots"},ym={none:"none",b:"bottom",t:"top",l:"left",r:"right",tr:"right"},xm={areaChart:void 0,area3DChart:void 0,lineChart:"line",line3DChart:void 0,stockChart:void 0,radarChart:void 0,scatterChart:void 0,pieChart:"pie",pie3DChart:void 0,doughnutChart:"pie",barChart:"bar",bar3DChart:void 0,ofPieChart:void 0,surfaceChart:void 0,surface3DChart:void 0,bubbleChart:void 0},Rm={1:"AVERAGE",2:"COUNT",3:"COUNTA",4:"MAX",5:"MIN",6:"PRODUCT",7:"STDEV",8:"STDEVP",9:"SUM",10:"VAR",11:"VARP",101:"AVERAGE",102:"COUNT",103:"COUNTA",104:"MAX",105:"MIN",106:"PRODUCT",107:"STDEV",108:"STDEVP",109:"SUM",110:"VAR",111:"VARP"},Im={0:"",1:"0",2:"0.00",3:"#,#00",4:"#,##0.00",9:"0%",10:"0.00%",11:void 0,12:void 0,13:void 0,14:"m/d/yyyy",15:"m/d/yyyy",16:"m/d/yyyy",17:"m/d/yyyy",18:"hh:mm:ss a",19:"hh:mm:ss a",20:"hhhh:mm:ss",21:"hhhh:mm:ss",22:"m/d/yy h:mm",37:void 0,38:void 0,39:void 0,40:void 0,45:"hhhh:mm:ss",46:"hhhh:mm:ss",47:"hhhh:mm:ss",48:void 0,49:void 0},Tm={0:1,"0.00":2,"#,#00":3,"#,##0.00":4,"0%":9,"0.00%":10,"0.00E+00":11,"# ?/?":12,"# ??/??":13,"mm-dd-yy":14,"d-mm-yy":15,"mm-yy":16,"mmm-yy":17,"h:mm AM/PM":18,"h:mm:ss AM/PM":19,"h:mm":20,"h:mm:ss":21,"m/d/yy h:mm":22,"#,##0 ;(#,##0)":37,"#,##0 ;[Red](#,##0)":38,"#,##0.00;(#,##0.00)":39,"#,##0.00;[Red](#,##0.00)":40,"mm:ss":45,"[h]:mm:ss":46,"mmss.0":47,"##0.0E+0":48,"@":49,"hh:mm:ss a":19},Am={0:"000000",1:"FFFFFF",2:"FF0000",3:"00FF00",4:"0000FF",5:"FFFF00",6:"FF00FF",7:"00FFFF",8:"000000",9:"FFFFFF",10:"FF0000",11:"00FF00",12:"0000FF",13:"FFFF00",14:"FF00FF",15:"00FFFF",16:"800000",17:"008000",18:"000080",19:"808000",20:"800080",21:"008080",22:"C0C0C0",23:"808080",24:"9999FF",25:"993366",26:"FFFFCC",27:"CCFFFF",28:"660066",29:"FF8080",30:"0066CC",31:"CCCCFF",32:"000080",33:"FF00FF",34:"FFFF00",35:"00FFFF",36:"800080",37:"800000",38:"008080",39:"0000FF",40:"00CCFF",41:"CCFFFF",42:"CCFFCC",43:"FFFF99",44:"99CCFF",45:"FF99CC",46:"CC99FF",47:"FFCC99",48:"3366FF",49:"33CCCC",50:"99CC00",51:"FFCC00",52:"FF9900",53:"FF6600",54:"666699",55:"969696",56:"003366",57:"339966",58:"003300",59:"333300",60:"993300",61:"993366",62:"333399",63:"333333",64:"000000",65:"FFFFFF"};function Nm(e){if(!e)return;let t;if(e.rgb)t=e.rgb;else if(e.auto)t=qp;else{if(!e.indexed)return;t=Am[e.indexed]}var i;return t=6===(i=t).length?"#"+i+"FF":"#"+i.slice(2)+i.slice(0,2),e.tint&&(t=function(e,t){const i=Et(e),n=yt(i);t<0&&(n.l=n.l*(1+t));t>0&&(n.l=n.l*(1-t)+(100-100*(1-t)));return Ct(wt(n))}(t,e.tint)),t=t.toUpperCase(),9===t.length&&t.endsWith("FF")&&(t=t.slice(0,7)),t}function Om(e,t){const i=e.split("/"),n=t.split("/");let o="",s=0;for(let e=0;e<i.length-1;e++)i[e]===n[e]?s++:o+="../";return o+=n.slice(s).join("/"),o}function Mm(e,t=0){const i={};for(let n=0;n<e.length;n++)e[n]&&(i[n+t]=e[n]);return i}function _m(e){const t=[];for(let i of Object.keys(e).map(Number))t[i]=e[i];return t}function Fm(e){return e.replace(/_x([0-9a-zA-Z]{4})_/g,((e,t)=>String.fromCharCode(parseInt(t,16))))}const Dm=/^(yy|yyyy|m{1,5}|d{1,4}|h{1,2}|s{1,2}|am\/pm|a\/m|\s|-|\/|\.|:)+$/i;function km(e,t,i){var n,o,s;if(0===e)return;let r=Im[e]||(null===(n=t.find((t=>t.id===e)))||void 0===n?void 0:n.format);if(r)try{let e=r.replace(/(.*?);.*/,"$1");e=e.replace(/\[(.*)-[A-Z0-9]{3}\]/g,"[$1]"),e=e.replace(/\[\$\]/g,"");const t=(null===(o=e.match(/"/g))||void 0===o?void 0:o.length)||0;if(t/2+((null===(s=e.match(/\[/g))||void 0===s?void 0:s.length)||0)>1)throw new Error("Multiple escaped blocks in format");if(e=e.replace(/"(.*)"/g,"[$$$1]"),e=e.replace(/_.{1}/g,""),e=e.replace(/\*.{1}/g,""),e=e.replace(/\\ /g," "),e=e.replace(/\\./g,(e=>e[1])),function(e){return null!==e.match(Dm)}(e)&&(e=function(e){return e=e.toLowerCase(),e=e.replace(/mmmmm|mmmm|mmm/g,"mm"),e=e.replace(/dddd|ddd/g,"dd"),e=e.replace(/am\/pm|a\/m/g,"a"),e=e.replace(/\byy\b/g,"yyyy"),e=e.replace(/hhhh/g,"hh"),e=e.replace(/\bh\b/g,"hh"),e}(e)),function(e){try{return Qt(0,e),!0}catch(e){return!1}}(e))return e}catch(e){}i.generateNotSupportedWarning(hm.NumFmtIdNotSupported,r||`nmFmtId ${e}`)}function $m(e,t){const i=e.borders.map((e=>{!function(e,t){e.diagonal&&t.generateNotSupportedWarning(hm.DiagonalBorderNotSupported)}(e,t);const i={top:Lm(e.top,t),bottom:Lm(e.bottom,t),left:Lm(e.left,t),right:Lm(e.right,t)};return Object.keys(i).forEach((e=>void 0===i[e]&&delete i[e])),i}));return Mm(i,1)}function Lm(e,t){if(!e)return;!function(e,t){um.includes(e.style)||t.generateNotSupportedWarning(hm.BorderStyleNotSupported,e.style,um)}(e,t);const i=bm[e.style];return i?[i,Nm(e.color)]:void 0}function Pm(e,t){return Mm(e.styles.map((i=>Um({fontStyle:e.fonts[i.fontId],fillStyle:e.fills[i.fillId],alignment:i.alignment},t))),1)}function Um(e,t){var i,n,o,s,r,a,l,c,h,d,u,g;return function(e,t,i){e&&e.name&&!pm.includes(e.name)&&i.generateNotSupportedWarning(hm.FontNotSupported,e.name,pm);t&&t.patternType&&!mm.includes(t.patternType)&&i.generateNotSupportedWarning(hm.FillStyleNotSupported,t.patternType,mm)}(null==e?void 0:e.fontStyle,null==e?void 0:e.fillStyle,t),function(e,t){e&&!gm.includes(e)&&t.generateNotSupportedWarning(hm.HorizontalAlignmentNotSupported,e,gm)}(null===(i=null==e?void 0:e.alignment)||void 0===i?void 0:i.horizontal,t),function(e,t){e&&t.generateNotSupportedWarning(hm.VerticalAlignmentNotSupported)}(null===(n=null==e?void 0:e.alignment)||void 0===n?void 0:n.vertical,t),{bold:null===(o=e.fontStyle)||void 0===o?void 0:o.bold,italic:null===(s=e.fontStyle)||void 0===s?void 0:s.italic,strikethrough:null===(r=e.fontStyle)||void 0===r?void 0:r.strike,underline:null===(a=e.fontStyle)||void 0===a?void 0:a.underline,align:(null===(l=e.alignment)||void 0===l?void 0:l.horizontal)?Sm[e.alignment.horizontal]:void 0,fillColor:"solid"===(null===(c=e.fillStyle)||void 0===c?void 0:c.patternType)?Nm(null===(h=e.fillStyle)||void 0===h?void 0:h.fgColor):Nm(null===(d=e.fillStyle)||void 0===d?void 0:d.bgColor),textColor:Nm(null===(u=e.fontStyle)||void 0===u?void 0:u.color),fontSize:(null===(g=e.fontStyle)||void 0===g?void 0:g.size)?zm(e.fontStyle.size):void 0}}function Vm(e,t){const i=[];for(let n of e.styles){const o=km(n.numFmtId,e.numFmts,t);o&&(i[n.numFmtId]=o)}return Mm(i,1)}function zm(e){return Object.keys(re).map(Number).reduce(((t,i)=>Math.abs(i-e)<Math.abs(t-e)?i:t))}function Bm(e,t,i){const n=[];let o=1;for(let r of e){if(0===r.cfRules.length)continue;qm(r,t,i);const e=r.cfRules[0];let a;const l=[];if(void 0!==e.dxfId||"colorScale"===e.type||"iconSet"===e.type){switch(e.type){case"aboveAverage":case"containsErrors":case"notContainsErrors":case"dataBar":case"duplicateValues":case"expression":case"top10":case"uniqueValues":case"timePeriod":continue;case"colorScale":const t=Hm(o++,r);t&&n.push(t);continue;case"iconSet":const c=Wm(o++,r,i);c&&n.push(c);continue;case"containsText":case"notContainsText":case"beginsWith":case"endsWith":if(!e.text)continue;a=Cm[e.type],l.push(e.text);break;case"containsBlanks":case"notContainsBlanks":a=Cm[e.type];break;case"cellIs":if(!e.operator||!e.formula||0===e.formula.length)continue;a=(s=e.operator).slice(0,1).toUpperCase()+s.slice(1),l.push(e.formula[0]),2===e.formula.length&&l.push(e.formula[1])}a&&void 0!==e.dxfId&&n.push({id:(o++).toString(),ranges:r.sqref,stopIfTrue:e.stopIfTrue,rule:{type:"CellIsRule",operator:a,values:l,style:Um({fontStyle:t[e.dxfId].font,fillStyle:t[e.dxfId].fill},i)}})}}var s;return n}function Hm(e,t){const i=t.cfRules[0].colorScale;if(!i||i.cfvos.length!==i.colors.length||i.cfvos.length<2||i.cfvos.length>3)return;const n=[];for(let e=0;e<i.cfvos.length;e++)n.push({color:(o=Nm(i.colors[e])||"#FFFFFF",9===o.length&&(o=o.slice(0,7)),parseInt(o.replace("#",""),16)),type:Em[i.cfvos[e].type],value:i.cfvos[e].value});var o;const s=n[0],r=2===n.length?n[1]:n[2],a=3===n.length?n[1]:void 0;return{id:e.toString(),stopIfTrue:t.cfRules[0].stopIfTrue,ranges:t.sqref,rule:{type:"ColorScaleRule",minimum:s,midpoint:a,maximum:r}}}function Wm(e,t,i){const n=t.cfRules[0].iconSet;if(!n)return;let o=n.cfvos,s=n.cfIcons;if(o.length<3||s&&s.length<3)return;o.length>3&&(o=[o[0],o[Math.floor(o.length/2)],o[o.length-1]]),s&&s.length>3&&(s=[s[0],s[Math.floor(s.length/2)],s[s.length-1]]);const r=[];for(let e=1;e<=2;e++){const t=Em[o[e].type];if("value"===t)return;r.push({value:o[e].value||"",operator:o[e].gte?"ge":"gt",type:t})}let a={lower:s?Gm(s[0].iconSet,s[0].iconId):Gm(n.iconSet,0),middle:s?Gm(s[1].iconSet,s[1].iconId):Gm(n.iconSet,1),upper:s?Gm(s[2].iconSet,s[2].iconId):Gm(n.iconSet,2)};n.reverse&&(a={upper:a.lower,middle:a.middle,lower:a.upper});for(let e of Object.keys(a))if(!a[e])switch(i.generateNotSupportedWarning(hm.CfIconSetEmptyIconNotSupported),e){case"upper":a[e]=Cr.dots.good;break;case"middle":a[e]=Cr.dots.neutral;break;case"lower":a[e]=Cr.dots.bad}return{id:e.toString(),stopIfTrue:t.cfRules[0].stopIfTrue,ranges:t.sqref,rule:{type:"IconSetRule",icons:a,upperInflectionPoint:r[1],lowerInflectionPoint:r[0]}}}function Gm(e,t){const i=wm[e];return i?0===t?Cr[i].bad:1===t?Cr[i].neutral:Cr[i].good:""}function qm(e,t,i){if(e.cfRules.length>1&&i.generateNotSupportedWarning(hm.MultipleRulesCfNotSupported),fm.includes(e.cfRules[0].type)||i.generateNotSupportedWarning(hm.CfTypeNotSupported,e.cfRules[0].type),e.cfRules[0].dxfId){const n=t[e.cfRules[0].dxfId];n.border&&i.generateNotSupportedWarning(hm.CfFormatBorderNotSupported),n.alignment&&i.generateNotSupportedWarning(hm.CfFormatAlignmentNotSupported),n.numFmt&&i.generateNotSupportedWarning(hm.CfFormatNumFmtNotSupported)}}function Zm(e){switch(e){case"IsNotEmpty":case"NotContains":return"notContainsBlanks";case"IsEmpty":return"containsBlanks";default:return e.charAt(0).toLowerCase()+e.slice(1)}}function jm(e){return Math.round(em*e*window.devicePixelRatio*100)/100}function Ym(e){return Math.round(tm*e*100)/100}function Xm(e,t){let i={};e.style&&(i=t.styles[e.style]);const n=function(e,t){if(e.format)return t.formats[e.format];if(e.isFormula){const t=Ju(e.content||""),i=Yu.content;if(!t.filter((e=>"FUNCTION"===e.type)).every((e=>i[e.value.toUpperCase()].isExported)))return e.computedFormat}return}(e,t),o={font:{size:(null==i?void 0:i.fontSize)||G,color:{rgb:(null==i?void 0:i.textColor)?i.textColor:"000000"},family:2,name:"Arial"},fill:(null==i?void 0:i.fillColor)?{fgColor:{rgb:i.fillColor}}:{reservedAttribute:"none"},numFmt:n?{format:n,id:0}:void 0,border:e.border||0,alignment:{vertical:"center",horizontal:i.align}};return o.font.strike=!!(null==i?void 0:i.strikethrough)||void 0,o.font.underline=!!(null==i?void 0:i.underline)||void 0,o.font.bold=!!(null==i?void 0:i.bold)||void 0,o.font.italic=!!(null==i?void 0:i.italic)||void 0,o}function Km(e,t){const i=function(e,t){if(!e)return 0;let i=Tm[e.format];i||(i=Jm(e,t)+rm);return i}(t.numFmt,e.numFmts),n={fontId:Jm(t.font,e.fonts),fillId:Jm(t.fill,e.fills),borderId:t.border,numFmtId:i,alignment:{vertical:t.alignment.vertical,horizontal:t.alignment.horizontal}};return Jm(n,e.styles)}function Qm(e,t,i){let n,o=e.find((e=>e.path===t));return o?(n=`rId${(o.rels.length+1).toString()}`,o.rels.push({...i,id:n})):(n="rId1",e.push({path:t,rels:[{...i,id:n}]})),n}function Jm(e,t){let i=t.length;const n="object"==typeof e?ot:(e,t)=>e===t;for(let o=0;o<i;o++)if(n(e,t[o]))return o;return t[t.length]=e,t.length-1}const ef=[];function tf(e){const t=ef.findIndex((t=>t===e));return-1===t?(ef.push(e),ef.length):t+1}function nf(e){return Math.round(914400*e/96)}function of(e,t,i){let n,o,s=e;if(({xc:s,sheetName:n}=$t(e)),n){const e=i.sheets.findIndex((e=>Ai(e.name,n)));if(e<0)throw new Error("Unable to find a sheet with the name "+n);o=e}else o=Number(t);const r=_i(s);return void 0===r.right&&(r.right=i.sheets[o].colNumber),void 0===r.bottom&&(r.bottom=i.sheets[o].rowNumber),(r.right-r.left+1)*(r.bottom-r.top+1)}function sf(e){return Math.round(96*e/914400)}function rf(e,t){var i;let n=0;for(let o=0;o<e;o++){const e=t.cols.find((e=>o>=e.min&&o<=e.max));(null==e?void 0:e.width)?n+=e.width:(null===(i=t.sheetFormat)||void 0===i?void 0:i.defaultColWidth)?n+=t.sheetFormat.defaultColWidth:n+=im}return n/tm}function af(e,t){var i;let n=0;for(let o=0;o<e;o++){const e=t.rows[o];(null==e?void 0:e.height)?n+=e.height:(null===(i=t.sheetFormat)||void 0===i?void 0:i.defaultRowHeight)?n+=t.sheetFormat.defaultRowHeight:n+=nm}return n/em}function lf(e){let t=1;return e.figures.map((i=>function(e,t,i){const n=rf(e.anchors[0].col,i)+sf(e.anchors[0].colOffset),o=rf(e.anchors[1].col,i)+sf(e.anchors[1].colOffset),s=af(e.anchors[0].row,i)+sf(e.anchors[0].rowOffset),r=af(e.anchors[1].row,i)+sf(e.anchors[1].rowOffset),a=o-n,l=r-s,c=cf(e.data);return c?{id:t,x:n,y:s,width:a,height:l,tag:"chart",data:cf(e.data)}:void 0}(i,(t++).toString(),e))).filter(Xe)}function cf(e){var t;if(0===e.dataSets.length)return;const i=null===(t=e.dataSets[0].label)||void 0===t?void 0:t.replace(/\$/g,"");let n=e.dataSets.map((e=>e.range.replace(/\$/g,"")));return"pie"===e.type&&n.reverse(),{dataSets:n,dataSetsHaveTitle:!1,labelRange:i,title:e.title||"",type:e.type,background:Nm({rgb:e.backgroundColor})||"#FFFFFF",verticalAxisPosition:e.verticalAxisPosition,legendPosition:e.legendPosition,stacked:e.stacked||!1,cumulative:e.cumulative||!1,labelsAsText:!1}}const hf=new RegExp(/'?\[([0-9]*)\](.*)'?!(\$?[a-zA-Z]*\$?[0-9]*)/g),df=new RegExp(/SUBTOTAL\(([0-9]*),/g),uf=new RegExp(xt.source,"ig");function gf(e,t){const i=function(e){const t={};for(let i of e.rows)for(let e of i.cells)e.formula&&void 0!==e.formula.sharedIndex&&e.formula.content&&(t[e.formula.sharedIndex]={refCellXc:e.xc,formula:e.formula.content});return t}(e);for(let n of e.rows.map((e=>e.cells)).flat())(null==n?void 0:n.formula)&&(n.formula.content=void 0===n.formula.sharedIndex||n.formula.content?"="+n.formula.content:"="+mf(n.xc,i[n.formula.sharedIndex]),n.formula.content=pf(n.formula.content,t))}function pf(e,t){return e=(e=(e=(e=e.replace("_xlfn.","")).replace(/#REF!/g,"#REF")).replace(df,((e,t)=>{const i=Rm[t];return i?i+"(":e}))).replace(hf,((e,i,n,o)=>{var s;i=Number(i)-1,o=o.replace(/\$/g,"");const r=t.externalBooks[i].sheetNames.findIndex((e=>Ai(e,n)));if(-1===r)return e;const a=null===(s=t.externalBooks[i].datasets.find((e=>e.sheetId===r)))||void 0===s?void 0:s.data;if(!a)return e;const l=a&&a[o];return(Number(l)?l:`"${l}"`)||e}))}function mf(e,t){const i=Ut(t.refCellXc);let n,o=t.formula.slice();do{if(n=uf.exec(o),n){const t=Ut(n[0].replace("$","")),s=Ut(e),r={colFixed:n[0].startsWith("$"),rowFixed:n[0].includes("$",1)},a={col:s.col-i.col,row:s.row-i.row},l={col:r.colFixed?t.col:t.col+a.col,row:r.rowFixed?t.row:t.row+a.row};o=o.slice(0,n.index)+Vt(l.col,l.row,r)+o.slice(n.index+n[0].length)}}while(n);return o}function ff(e,t){return e.sheets.map((i=>{gf(i,e);const n=function(e){const t=[0,0];for(let i of e.rows)t[0]=Math.max(t[0],lt(i.cells.map((e=>Ut(e.xc).col)))),t[1]=Math.max(t[1],i.index);return t[0]=Math.max(t[0],om),t[1]=Math.max(t[1],sm),t}(i),o=i.sheetViews[0];return{id:i.sheetName,areGridLinesVisible:!o||o.showGridLines,name:i.sheetName,colNumber:n[0],rowNumber:n[1],cells:Sf(i,e,n,t),merges:i.merges,cols:vf(i,n[0]),rows:bf(i,n[1]),conditionalFormats:Bm(i.cfs,e.dxfs,t),figures:lf(i),isVisible:i.isVisible,panes:o?{xSplit:o.pane.xSplit,ySplit:o.pane.ySplit}:{xSplit:0,ySplit:0},filterTables:[]}}))}function vf(e,t){var i;const n={};for(let s=1;s<t+1;s++){const t=e.cols.find((e=>e.min<=s&&s<=e.max));let r;r=t&&t.width?t.width:(null===(i=e.sheetFormat)||void 0===i?void 0:i.defaultColWidth)?e.sheetFormat.defaultColWidth:im,n[s-1]={size:(o=r,o?Math.round(o/tm*100)/100:o),isHidden:null==t?void 0:t.hidden}}var o;return n}function bf(e,t){var i;const n={};for(let s=1;s<t+1;s++){const t=e.rows.find((e=>e.index===s));let r;r=t&&t.height?t.height:(null===(i=e.sheetFormat)||void 0===i?void 0:i.defaultRowHeight)?e.sheetFormat.defaultRowHeight:nm,n[s-1]={size:(o=r,o?Math.round(o/em*100)/100:o),isHidden:null==t?void 0:t.hidden}}var o;return n}function Sf(e,t,i,n){const o={},s=t.sharedStrings.map((e=>e.replace(/\n/g,"")));const r=e.hyperlinks.reduce(((e,t)=>(e[t.xc]=t,e)),{});for(let i of e.rows)for(let e of i.cells)o[e.xc]={content:Cf(e,r,s,n),style:e.styleIndex?e.styleIndex+1:void 0,border:e.styleIndex?t.styles[e.styleIndex].borderId+1:void 0,format:e.styleIndex?t.styles[e.styleIndex].numFmtId+1:void 0};for(let n of e.rows.filter((e=>e.styleIndex)))for(let e=1;e<=i[0];e++){const i=Vt(e-1,n.index-1);let s=o[i];s||(s={},o[i]=s),s.style=s.style?s.style:n.styleIndex+1,s.border=s.border?s.border:t.styles[n.styleIndex].borderId+1,s.format=s.format?s.format:t.styles[n.styleIndex].numFmtId+1}for(let n of e.cols.filter((e=>e.styleIndex)))for(let e=n.min;e<=Math.min(n.max,i[0]);e++)for(let s=1;s<=i[1];s++){const i=Vt(e-1,s-1);let r=o[i];r||(r={},o[i]=r),r.style=r.style?r.style:n.styleIndex+1,r.border=r.border?r.border:t.styles[n.styleIndex].borderId+1,r.format=r.format?r.format:t.styles[n.styleIndex].numFmtId+1}return o}function Cf(e,t,i,n){let o;switch(e.type){case"sharedString":o=i[parseInt(e.value,10)];break;case"boolean":o=Number(e.value)?"TRUE":"FALSE";break;case"date":case"error":case"inlineStr":case"number":case"str":o=e.value}return o&&t[e.xc]&&(o=function(e,t,i){const n=e.display||t;e.relTarget||e.location||i.generateNotSupportedWarning(hm.BadlyFormattedHyperlink);const o=e.relTarget?e.relTarget:je($t(e.location).sheetName);return We(n,o)}(t[e.xc],o,n)),e.formula&&(o=e.formula.content),o}const Ef={fillColor:"#000000",textColor:"#ffffff",bold:!0},wf={bold:!0},yf=["thin","#000000FF"];function xf(e,t){for(const i of t.sheets)for(const t of i.tables){const n=e.sheets.find((e=>e.name===i.sheetName));n&&t.autoFilter&&(n.filterTables||(n.filterTables=[]),n.filterTables.push({range:t.ref}))}!function(e,t){var i,n,o,s;const r=_m(e.styles),a=_m(e.borders);for(let l of t.sheets)for(let t of l.tables){const c=e.sheets.find((e=>e.name===l.sheetName));if(!c)continue;const h=Fi(t.ref);for(let e=0;e<t.headerRowCount;e++)Rf(Ef,{...h,bottom:h.top+e},c.cells,r);for(let e=0;e<t.totalsRowCount;e++)Rf(wf,{...h,top:h.bottom-e},c.cells,r);(null===(i=t.style)||void 0===i?void 0:i.showFirstColumn)&&Rf(wf,{...h,right:h.left},c.cells,r),(null===(n=t.style)||void 0===n?void 0:n.showLastColumn)&&Rf(wf,{...h,left:h.right},c.cells,r);for(let e=h.left;e<=h.right;e++)for(let i=h.top;i<=h.bottom;i++){const n=Vt(e,i),r=c.cells[n],l={left:e===h.left||(null===(o=t.style)||void 0===o?void 0:o.showColumnStripes)?yf:void 0,right:e===h.right?yf:void 0,top:i===h.top||(null===(s=t.style)||void 0===s?void 0:s.showRowStripes)||i>h.bottom-t.totalsRowCount?yf:void 0,bottom:i===h.bottom?yf:void 0},d=(null==r?void 0:r.border)?{...a[r.border],...l}:l;let u=a.findIndex((e=>ot(e,d)));-1===u&&(u=a.length,a.push(d)),r?r.border=u:c.cells[n]={border:u}}}e.styles=Mm(r),e.borders=Mm(a)}(e,t),function(e,t){let i=null;for(let n of e){const o=t.find((e=>Ai(e.sheetName,n.name))).tables;if(o&&0!==o.length){i||(i=If(e));for(let t of o)for(let o in i){const s=e.find((e=>e.id===o));for(let e in i[o]){for(let r=i[o][e].length-3;r>=0;r-=2){const a=i[o][e][r];if(!a.endsWith(t.name))continue;const l=i[o][e][r+1],c=Tf(n.id===s.id?"":n.name+"!",l,t,e);i[o][e][r+2]=a.slice(0,a.indexOf(t.name))+c+i[o][e][r+2],i[o][e].splice(r,2)}}}}}if(!i)return;for(let t in i){const n=e.find((e=>e.id===t));for(let e in i[t]){const o=i[t][e];if(1===o.length){n.cells[e].content=o[0];continue}let s="";for(let e=0;e<o.length;e+=2)s+=o[e]+"["+o[e+1]+"]";s+=o[o.length-1],n.cells[e].content=s}}}(e.sheets,t.sheets)}function Rf(e,t,i,n){for(let o=t.left;o<=t.right;o++)for(let s=t.top;s<=t.bottom;s++){const t=Vt(o,s),r=i[t],a=(null==r?void 0:r.style)?{...n[r.style],...e}:e;let l=n.findIndex((e=>ot(e,a)));-1===l&&(l=n.length,n.push(a)),r?r.style=l:i[t]={style:l}}}function If(e){var t;const i={};for(let n of e)for(let e in n.cells){const o=null===(t=n.cells[e])||void 0===t?void 0:t.content;if(!o||!o.startsWith("="))continue;const s=o.indexOf("[");if(-1===s)continue;const r=[];let a=o.slice(0,s),l="",c=1,h=0,d=s;for(let e=s+1;e<o.length;e++)"["!==o[e]?"]"===o[e]&&(c--,0===c&&(l=o.slice(d+1,e),r.push(a),r.push(l),h=e+1)):(0===c&&(a=o.slice(h,e),d=e),c++);r.length&&(i[n.id]||(i[n.id]={}),r.push(o.slice(h)),i[n.id][e]=[...r])}return i}function Tf(e,t,i,n){const o=t.split(",").map((e=>e.trim())),s=Fi(i.ref),r=[],a=[],l=[];for(const e of o)if(Af(e).startsWith("#")){const t=Af(e);switch(l.push(t),t){case"#All":a.push(s.top,s.bottom);break;case"#Data":const e=i.headerRowCount?s.top+i.headerRowCount:s.top,t=i.totalsRowCount?s.bottom-i.totalsRowCount:s.bottom;a.push(e,t);break;case"#This Row":a.push(Ut(n).row);break;case"#Headers":if(!i.headerRowCount)return X;a.push(s.top);break;case"#Totals":if(!i.totalsRowCount)return X;a.push(s.bottom)}}else{const t=e.split(":").map((e=>e.trim())).map(Af);if(r.length)return X;const n=i.cols.findIndex((e=>e.name===t[0]));if(-1===n)return X;if(r.push(n+s.left),t[1]){const e=i.cols.findIndex((e=>e.name===t[1]));if(-1===e)return X;r.push(e+s.left)}}if(!function(e){if(e.length<2)return!0;if(e.length>2)return!1;if(e.includes("#Data")&&e.includes("#Totals"))return!0;if(e.includes("#Headers")&&e.includes("#Data"))return!0;return!1}(l))return X;if(0===a.length){const e=i.headerRowCount?s.top+i.headerRowCount:s.top,t=i.totalsRowCount?s.bottom-i.totalsRowCount:s.bottom;a.push(e,t)}0===r.length&&r.push(s.left,s.right);return e+ki({top:Math.min(...a),left:Math.min(...r),bottom:Math.max(...a),right:Math.max(...r)})}function Af(e){return e.startsWith("[")&&e.endsWith("]")?e.slice(1,e.length-1):e}function Nf(e,t,i){return{content:(new XMLSerializer).serializeToString(e),path:t,contentType:i}}function Of(e){return String(e).replace(/\&/g,"&").replace(/\</g,"<").replace(/\>/g,">").replace(/\"/g,""").replace(/\'/g,"'").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,"")}function Mf(e){return new Wp(e.map((([e,t])=>`${e}="${Of(t)}"`)).join(" "))}function _f(e){const t=(new DOMParser).parseFromString(e.toString(),"text/xml"),i=t.querySelector("parsererror");if(i){const t=i.innerHTML,n=parseInt(t.split(":")[0],10),o=e.toString().trim().split("\n"),s=o.slice(Math.max(n-3,0),Math.min(n+2,o.length)).join("\n");throw new Error(`XML string could not be parsed: ${t}\n${s}`)}return t}function Ff(e){if(e)return{style:e[0],color:{rgb:e[1]}}}function Df(e,t){return $f`
|
|
1389
1389
|
<Override ContentType="${t}" PartName="${e}" />
|
|
1390
|
-
`}function Df(e){return new Wp(e.join("\n"))}function kf(e,...t){let i=[e[0]];for(let n=0;n<t.length;n++){const o=t[n]instanceof Wp?t[n]:Nf(t[n]);i.push(o+e[n+1])}return new Wp(et(i))}function $f(e){return e.replace(/[a-z0-9]+:(?=[a-z0-9]+)/gi,"")}function Lf(e){return e.replace(/([a-z0-9]+):(?=[a-z0-9]+)/gi,"$1\\:")}class Pf{constructor(e){this.value=e}asString(){return Fm(String(this.value))}asBool(){return Boolean(Number(this.value))}asNum(){return Number(this.value)}}class Uf{constructor(e,t,i){this.currentFile=void 0,this.rootFile=e,this.currentFile=e.file.fileName,this.xlsxFileStructure=t,this.warningManager=i,this.areNamespaceIgnored=null!==(new DOMParser).parseFromString("<t:test xmlns:t='a'/>","text/xml").querySelector("test"),this.relationships={},e.rels&&this.extractRelationships(e.rels).map((e=>{this.relationships[e.id]=e}))}extractRelationships(e){return this.mapOnElements({parent:e.xml,query:"Relationship"},(e=>({id:this.extractAttr(e,"Id",{required:!0}).asString(),target:this.extractAttr(e,"Target",{required:!0}).asString(),type:this.extractAttr(e,"Type",{required:!0}).asString()})))}getListOfFiles(){return Object.values(this.xlsxFileStructure).flat().filter(Xe)}mapOnElements(e,t){var i;const n=[],o=this.currentFile;let s;if(e.children){const t=null===(i=this.querySelector(e.parent,e.query))||void 0===i?void 0:i.children;s=t||[]}else s=this.querySelectorAll(e.parent,e.query);if(s)for(let e of s)try{n.push(t(e))}catch(t){this.catchErrorOnElement(t,e)}return this.currentFile=o,n}catchErrorOnElement(e,t){const i=t?`Error when parsing an element <${t.tagName}> of file ${this.currentFile}, skip this element. \n${e.stack}`:`Error when parsing file ${this.currentFile}.`;this.warningManager.addParsingWarning([i,e.message].join("\n"))}extractAttr(e,t,i){const n=e.attributes[t];n||this.handleMissingValue(e,`attribute "${t}"`,i);const o=(null==n?void 0:n.value)?n.value:null==i?void 0:i.default;return void 0===o?void 0:new Pf(o)}extractTextContent(e,t){var i;if(void 0!==(null==t?void 0:t.default)&&"string"!=typeof t.default)throw new Error("extractTextContent default value should be a string");const n="preserve"===(null===(i=null==e?void 0:e.attributes["xml:space"])||void 0===i?void 0:i.value);let o=null==e?void 0:e.textContent;return e&&null!==o||this.handleMissingValue(e,"text content",t),o&&(o=n?o:o.trim()),o?Fm(o):null==t?void 0:t.default}extractChildAttr(e,t,i,n){var o;let s;s="number"==typeof t?e.children[t]:this.querySelector(e,t),s||this.handleMissingValue(e,"number"==typeof t?`child at index ${t}`:`child <${t}>`,n);const r=s?null===(o=this.extractAttr(s,i,n))||void 0===o?void 0:o.asString():null==n?void 0:n.default;return void 0!==r?new Pf(r):void 0}extractChildTextContent(e,t,i){if(void 0!==(null==i?void 0:i.default)&&"string"!=typeof i.default)throw new Error("extractTextContent default value should be a string");let n=this.querySelector(e,t);return n||this.handleMissingValue(e,`child <${t}>`,i),n?this.extractTextContent(n,i):null==i?void 0:i.default}handleMissingValue(e,t,i){if(null==i?void 0:i.required){if(void 0===(null==i?void 0:i.default))throw new Error(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, and no default value was set`);this.warningManager.addParsingWarning(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, replacing it by the default value ${i.default}`)}}extractColor(e,t,i){var n,o,s,r,a;if(!e)return i?{rgb:i}:void 0;const l=null===(n=this.extractAttr(e,"theme"))||void 0===n?void 0:n.asString();let c;if(void 0!==l){if(!t||!t.clrScheme)throw new Error("Color referencing a theme but no theme was provided");c=this.getThemeColor(l,t.clrScheme)}else c=null===(o=this.extractAttr(e,"rgb"))||void 0===o?void 0:o.asString();return{rgb:c,auto:null===(s=this.extractAttr(e,"auto"))||void 0===s?void 0:s.asBool(),indexed:null===(r=this.extractAttr(e,"indexed"))||void 0===r?void 0:r.asNum(),tint:null===(a=this.extractAttr(e,"tint"))||void 0===a?void 0:a.asNum()}}getTargetXmlFile(e){if(!e)throw new Error("Undefined target file");let t=e.target;t=t.replace("../",""),t=t.replace("./","");const i=this.getListOfFiles().find((e=>e.file.fileName.endsWith(t)));if(!i||!i.file)throw new Error("Cannot find target file");return i}querySelector(e,t){return t=this.areNamespaceIgnored?$f(t):Lf(t),e.querySelector(t)}querySelectorAll(e,t){return t=this.areNamespaceIgnored?$f(t):Lf(t),e.querySelectorAll(t)}getThemeColor(e,t){switch(e){case"0":return"FFFFFF";case"1":return"000000";case"2":return t[3].value;case"3":return t[2].value;default:return t[e].value}}}class Vf extends Uf{getTheme(){return{clrScheme:this.mapOnElements({query:"a:clrScheme",parent:this.rootFile.file.xml,children:!0},(e=>({name:e.tagName,value:this.extractChildAttr(e,0,"val",{required:!0,default:qp}).asString(),lastClr:this.extractChildAttr(e,0,"lastClr",{default:qp}).asString()})))}}getSharedStrings(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"si"},(e=>"t"===e.children[0].tagName?this.extractTextContent(e)||"":this.mapOnElements({parent:e,query:"t"},(e=>this.extractTextContent(e)||"")).join("")))}}class zf extends Uf{constructor(e,t,i,n){super(e,t,i),this.theme=n}extractConditionalFormattings(){const e=this.mapOnElements({parent:this.rootFile.file.xml,query:"worksheet > conditionalFormatting"},(e=>{var t;return{sqref:this.extractAttr(e,"sqref",{required:!0}).asString().split(" "),pivot:null===(t=this.extractAttr(e,"pivot"))||void 0===t?void 0:t.asBool(),cfRules:this.extractCFRules(e,this.theme)}}));return e.push(...this.mapOnElements({parent:this.rootFile.file.xml,query:"extLst x14:conditionalFormatting"},(e=>{var t;return{sqref:this.extractChildTextContent(e,"xm:sqref",{required:!0}).split(" "),pivot:null===(t=this.extractAttr(e,"xm:pivot"))||void 0===t?void 0:t.asBool(),cfRules:this.extractCFRules(e,this.theme)}}))),e}extractCFRules(e,t){return this.mapOnElements({parent:e,query:"cfRule, x14:cfRule"},(e=>{var i,n,o,s,r,a,l,c,h,d,u;const g=this.extractAttr(e,"type",{required:!0}).asString();if("dataBar"===g)throw new Error("Databars conditional formats are not supported.");return{type:g,priority:this.extractAttr(e,"priority",{required:!0}).asNum(),colorScale:this.extractCfColorScale(e,t),formula:this.extractCfFormula(e),iconSet:this.extractCfIconSet(e),dxfId:null===(i=this.extractAttr(e,"dxfId"))||void 0===i?void 0:i.asNum(),stopIfTrue:null===(n=this.extractAttr(e,"stopIfTrue"))||void 0===n?void 0:n.asBool(),aboveAverage:null===(o=this.extractAttr(e,"aboveAverage"))||void 0===o?void 0:o.asBool(),percent:null===(s=this.extractAttr(e,"percent"))||void 0===s?void 0:s.asBool(),bottom:null===(r=this.extractAttr(e,"bottom"))||void 0===r?void 0:r.asBool(),operator:null===(a=this.extractAttr(e,"operator"))||void 0===a?void 0:a.asString(),text:null===(l=this.extractAttr(e,"text"))||void 0===l?void 0:l.asString(),timePeriod:null===(c=this.extractAttr(e,"timePeriod"))||void 0===c?void 0:c.asString(),rank:null===(h=this.extractAttr(e,"rank"))||void 0===h?void 0:h.asNum(),stdDev:null===(d=this.extractAttr(e,"stdDev"))||void 0===d?void 0:d.asNum(),equalAverage:null===(u=this.extractAttr(e,"equalAverage"))||void 0===u?void 0:u.asBool()}}))}extractCfFormula(e){return this.mapOnElements({parent:e,query:"formula"},(e=>this.extractTextContent(e,{required:!0})))}extractCfColorScale(e,t){const i=this.querySelector(e,"colorScale");if(i)return{colors:this.mapOnElements({parent:i,query:"color"},(e=>this.extractColor(e,t,"ffffff"))),cfvos:this.extractCFVos(i)}}extractCfIconSet(e){var t,i;const n=this.querySelector(e,"iconSet, x14:iconSet");if(n)return{iconSet:this.extractAttr(n,"iconSet",{default:"3TrafficLights1"}).asString(),showValue:this.extractAttr(n,"showValue",{default:!0}).asBool(),percent:this.extractAttr(n,"percent",{default:!0}).asBool(),reverse:null===(t=this.extractAttr(n,"reverse"))||void 0===t?void 0:t.asBool(),custom:null===(i=this.extractAttr(n,"custom"))||void 0===i?void 0:i.asBool(),cfvos:this.extractCFVos(n),cfIcons:this.extractCfIcons(n)}}extractCfIcons(e){const t=this.mapOnElements({parent:e,query:"cfIcon, x14:cfIcon"},(e=>({iconSet:this.extractAttr(e,"iconSet",{required:!0}).asString(),iconId:this.extractAttr(e,"iconId",{required:!0}).asNum()})));return 0===t.length?void 0:t}extractCFVos(e){return this.mapOnElements({parent:e,query:"cfvo, x14:cfvo"},(e=>{var t,i;return{type:this.extractAttr(e,"type",{required:!0}).asString(),gte:null===(t=this.extractAttr(e,"gte",{default:!0}))||void 0===t?void 0:t.asBool(),value:e.attributes.val?null===(i=this.extractAttr(e,"val"))||void 0===i?void 0:i.asString():this.extractChildTextContent(e,"f, xm:f")}}))}}class Bf extends Uf{extractChart(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"c:chartSpace"},(e=>{const t=this.getChartType(e);if(!xm[t])throw new Error(`Unsupported chart type ${t}`);const i=this.mapOnElements({parent:e,query:"c:title a:t"},(e=>e.textContent||"")).join(""),n=this.extractChildAttr(e,"c:grouping","val",{default:"clustered"}).asString();return{title:i,type:xm[t],dataSets:this.extractChartDatasets(this.querySelector(e,`c:${t}`)),backgroundColor:this.extractChildAttr(e,"c:chartSpace > c:spPr a:srgbClr","val",{default:"ffffff"}).asString(),verticalAxisPosition:"r"===this.extractChildAttr(e,"c:valAx > c:axPos","val",{default:"l"}).asString()?"right":"left",legendPosition:ym[this.extractChildAttr(e,"c:legendPos","val",{default:"none"}).asString()],stacked:"stacked"===n,fontColor:"000000"}}))[0]}extractChartDatasets(e){return this.mapOnElements({parent:e,query:"c:ser"},(e=>({label:this.extractChildTextContent(e,"c:cat c:f"),range:this.extractChildTextContent(e,"c:val c:f",{required:!0})})))}getChartType(e){const t=this.querySelector(e,"c:plotArea");if(!t)throw new Error("Missing plot area in the chart definition.");for(let e of t.children){const t=$f(e.tagName);if(Gp.some((e=>e===t)))return t}throw new Error("Unknown chart type")}}class Hf extends Uf{extractFigures(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"xdr:wsDr",children:!0},(e=>{if("twoCellAnchor"!==$f(e.tagName))throw new Error("Only twoCellAnchor are supported for xlsx drawings.");const t=this.querySelector(e,"c:chart");if(!t)throw new Error("Only chart figures are currently supported.");return{anchors:[this.extractFigureAnchor("xdr:from",e),this.extractFigureAnchor("xdr:to",e)],data:this.extractChart(t)}}))}extractFigureAnchor(e,t){const i=this.querySelector(t,e);if(!i)throw new Error(`Missing anchor element ${e}`);return{col:Number(this.extractChildTextContent(i,"xdr:col",{required:!0})),colOffset:Number(this.extractChildTextContent(i,"xdr:colOff",{required:!0})),row:Number(this.extractChildTextContent(i,"xdr:row",{required:!0})),rowOffset:Number(this.extractChildTextContent(i,"xdr:rowOff",{required:!0}))}}extractChart(e){const t=this.extractAttr(e,"r:id",{required:!0}).asString(),i=this.getTargetXmlFile(this.relationships[t]),n=new Bf(i,this.xlsxFileStructure,this.warningManager).extractChart();if(!n)throw new Error("Unable to extract chart definition");return n}}class Wf extends Uf{getPivotTable(){return this.mapOnElements({query:":root",parent:this.rootFile.file.xml},(e=>({displayName:this.extractAttr(e,"name",{required:!0}).asString(),id:this.extractAttr(e,"name",{required:!0}).asString(),ref:this.extractChildAttr(e,"location","ref",{required:!0}).asString(),headerRowCount:this.extractChildAttr(e,"location","firstDataRow",{default:0}).asNum(),totalsRowCount:1,cols:[],style:{showFirstColumn:!0,showRowStripes:!0}})))[0]}}class Gf extends Uf{getTable(){return this.mapOnElements({query:"table",parent:this.rootFile.file.xml},(e=>{var t;return{displayName:this.extractAttr(e,"displayName",{required:!0}).asString(),name:null===(t=this.extractAttr(e,"name"))||void 0===t?void 0:t.asString(),id:this.extractAttr(e,"id",{required:!0}).asString(),ref:this.extractAttr(e,"ref",{required:!0}).asString(),headerRowCount:this.extractAttr(e,"headerRowCount",{default:1}).asNum(),totalsRowCount:this.extractAttr(e,"totalsRowCount",{default:0}).asNum(),cols:this.extractTableCols(e),style:this.extractTableStyleInfo(e),autoFilter:this.extractTableAutoFilter(e)}}))[0]}extractTableCols(e){return this.mapOnElements({query:"tableColumn",parent:e},(e=>({id:this.extractAttr(e,"id",{required:!0}).asString(),name:this.extractAttr(e,"name",{required:!0}).asString(),colFormula:this.extractChildTextContent(e,"calculatedColumnFormula")})))}extractTableStyleInfo(e){return this.mapOnElements({query:"tableStyleInfo",parent:e},(e=>{var t,i,n,o,s;return{name:null===(t=this.extractAttr(e,"name"))||void 0===t?void 0:t.asString(),showFirstColumn:null===(i=this.extractAttr(e,"showFirstColumn"))||void 0===i?void 0:i.asBool(),showLastColumn:null===(n=this.extractAttr(e,"showLastColumn"))||void 0===n?void 0:n.asBool(),showRowStripes:null===(o=this.extractAttr(e,"showRowStripes"))||void 0===o?void 0:o.asBool(),showColumnStripes:null===(s=this.extractAttr(e,"showColumnStripes"))||void 0===s?void 0:s.asBool()}}))[0]}extractTableAutoFilter(e){return this.mapOnElements({query:"autoFilter",parent:e},(e=>({columns:this.extractFilterColumns(e),zone:this.extractAttr(e,"ref",{required:!0}).asString()})))[0]}extractFilterColumns(e){return this.mapOnElements({query:"tableColumn",parent:e},(t=>({colId:this.extractAttr(e,"colId",{required:!0}).asNum(),hiddenButton:this.extractAttr(e,"hiddenButton",{default:!1}).asBool(),filters:this.extractSimpleFilter(t)})))}extractSimpleFilter(e){return this.mapOnElements({query:"filter",parent:e},(e=>({val:this.extractAttr(e,"val",{required:!0}).asString()})))}}class qf extends Uf{constructor(e,t,i,n){super(e,t,i),this.theme=n}getSheet(){return this.mapOnElements({query:"worksheet",parent:this.rootFile.file.xml},(e=>{const t=this.getSheetWorkbookInfo();return{sheetName:this.extractSheetName(),sheetViews:this.extractSheetViews(e),sheetFormat:this.extractSheetFormat(e),cols:this.extractCols(e),rows:this.extractRows(e),sharedFormulas:this.extractSharedFormulas(e),merges:this.extractMerges(e),cfs:this.extractConditionalFormats(),figures:this.extractFigures(e),hyperlinks:this.extractHyperLinks(e),tables:[...this.extractTables(e),...this.extractPivotTables()],isVisible:"visible"===t.state}}))[0]}extractSheetViews(e){return this.mapOnElements({parent:e,query:"sheetView"},(e=>{const t=this.querySelector(e,"pane");return{tabSelected:this.extractAttr(e,"tabSelected",{default:!1}).asBool(),showFormulas:this.extractAttr(e,"showFormulas",{default:!1}).asBool(),showGridLines:this.extractAttr(e,"showGridLines",{default:!0}).asBool(),showRowColHeaders:this.extractAttr(e,"showRowColHeaders",{default:!0}).asBool(),pane:{xSplit:t?this.extractAttr(t,"xSplit",{default:0}).asNum():0,ySplit:t?this.extractAttr(t,"ySplit",{default:0}).asNum():0}}}))}extractSheetName(){const e=Om(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find((t=>t.target===e)).id;for(let e of this.querySelectorAll(this.xlsxFileStructure.workbook.file.xml,"sheet"))if(e.attributes["r:id"].value===t)return e.attributes.name.value;throw new Error("Missing sheet name")}getSheetWorkbookInfo(){const e=Om(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find((t=>t.target===e)).id,i=this.mapOnElements({parent:this.xlsxFileStructure.workbook.file.xml,query:"sheet"},(e=>({relationshipId:this.extractAttr(e,"r:id",{required:!0}).asString(),sheetId:this.extractAttr(e,"sheetId",{required:!0}).asString(),sheetName:this.extractAttr(e,"name",{required:!0}).asString(),state:this.extractAttr(e,"state",{default:"visible"}).asString()}))).find((e=>e.relationshipId===t));if(!i)throw new Error("Cannot find corresponding workbook sheet");return i}extractConditionalFormats(){return new zf(this.rootFile,this.xlsxFileStructure,this.warningManager,this.theme).extractConditionalFormattings()}extractFigures(e){return this.mapOnElements({parent:e,query:"drawing"},(e=>{var t;const i=null===(t=this.extractAttr(e,"r:id",{required:!0}))||void 0===t?void 0:t.asString(),n=this.getTargetXmlFile(this.relationships[i]);return new Hf(n,this.xlsxFileStructure,this.warningManager).extractFigures()}))[0]||[]}extractTables(e){return this.mapOnElements({query:"tablePart",parent:e},(e=>{var t;const i=null===(t=this.extractAttr(e,"r:id",{required:!0}))||void 0===t?void 0:t.asString(),n=this.getTargetXmlFile(this.relationships[i]);return new Gf(n,this.xlsxFileStructure,this.warningManager).getTable()}))}extractPivotTables(){try{return Object.values(this.relationships).filter((e=>e.type.endsWith("pivotTable"))).map((e=>{const t=this.getTargetXmlFile(e);return new Wf(t,this.xlsxFileStructure,this.warningManager).getPivotTable()}))}catch(e){return this.catchErrorOnElement(e),[]}}extractMerges(e){return this.mapOnElements({parent:e,query:"mergeCell"},(e=>this.extractAttr(e,"ref",{required:!0}).asString()))}extractSheetFormat(e){const t=this.querySelector(e,"sheetFormatPr");if(t)return{defaultColWidth:this.extractAttr(t,"defaultColWidth",{default:im.toString()}).asNum(),defaultRowHeight:this.extractAttr(t,"defaultRowHeight",{default:nm.toString()}).asNum()}}extractCols(e){return this.mapOnElements({parent:e,query:"cols col"},(e=>{var t,i,n,o,s,r,a;return{width:null===(t=this.extractAttr(e,"width"))||void 0===t?void 0:t.asNum(),customWidth:null===(i=this.extractAttr(e,"customWidth"))||void 0===i?void 0:i.asBool(),bestFit:null===(n=this.extractAttr(e,"bestFit"))||void 0===n?void 0:n.asBool(),hidden:null===(o=this.extractAttr(e,"hidden"))||void 0===o?void 0:o.asBool(),min:null===(s=this.extractAttr(e,"min",{required:!0}))||void 0===s?void 0:s.asNum(),max:null===(r=this.extractAttr(e,"max",{required:!0}))||void 0===r?void 0:r.asNum(),styleIndex:null===(a=this.extractAttr(e,"style"))||void 0===a?void 0:a.asNum()}}))}extractRows(e){return this.mapOnElements({parent:e,query:"sheetData row"},(e=>{var t,i,n,o,s;return{index:null===(t=this.extractAttr(e,"r",{required:!0}))||void 0===t?void 0:t.asNum(),cells:this.extractCells(e),height:null===(i=this.extractAttr(e,"ht"))||void 0===i?void 0:i.asNum(),customHeight:null===(n=this.extractAttr(e,"customHeight"))||void 0===n?void 0:n.asBool(),hidden:null===(o=this.extractAttr(e,"hidden"))||void 0===o?void 0:o.asBool(),styleIndex:null===(s=this.extractAttr(e,"s"))||void 0===s?void 0:s.asNum()}}))}extractCells(e){return this.mapOnElements({parent:e,query:"c"},(e=>{var t,i,n;return{xc:null===(t=this.extractAttr(e,"r",{required:!0}))||void 0===t?void 0:t.asString(),styleIndex:null===(i=this.extractAttr(e,"s"))||void 0===i?void 0:i.asNum(),type:vm[null===(n=this.extractAttr(e,"t",{default:"n"}))||void 0===n?void 0:n.asString()],value:this.extractChildTextContent(e,"v"),formula:this.extractCellFormula(e)}}))}extractCellFormula(e){var t,i;const n=this.querySelector(e,"f");if(n)return{content:this.extractTextContent(n),sharedIndex:null===(t=this.extractAttr(n,"si"))||void 0===t?void 0:t.asNum(),ref:null===(i=this.extractAttr(n,"ref"))||void 0===i?void 0:i.asString()}}extractHyperLinks(e){return this.mapOnElements({parent:e,query:"hyperlink"},(e=>{var t,i,n,o;const s=null===(t=this.extractAttr(e,"r:id"))||void 0===t?void 0:t.asString();return{xc:null===(i=this.extractAttr(e,"ref",{required:!0}))||void 0===i?void 0:i.asString(),location:null===(n=this.extractAttr(e,"location"))||void 0===n?void 0:n.asString(),display:null===(o=this.extractAttr(e,"display"))||void 0===o?void 0:o.asString(),relTarget:s?this.relationships[s].target:void 0}}))}extractSharedFormulas(e){const t=this.querySelectorAll(e,"f[si][ref]"),i={};for(let e of t){const t=this.extractAttr(e,"si",{required:!0}).asNum(),n=this.extractTextContent(e,{required:!0});i[t]=n}const n=[];for(let e=0;e<Object.keys(i).length;e++)i[e]?n.push(i[e]):(this.warningManager.addParsingWarning(`Missing shared formula ${e}, replacing it by empty formula`),n.push(""));return n}}class Zf extends Uf{constructor(e,t,i){super(e.styles,e,t),this.theme=i}getNumFormats(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"numFmt"},(e=>this.extractNumFormats(e)))}extractNumFormats(e){return{id:this.extractAttr(e,"numFmtId",{required:!0}).asNum(),format:this.extractAttr(e,"formatCode",{required:!0,default:""}).asString()}}getFonts(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"font"},(e=>this.extractFont(e)))}extractFont(e){var t,i,n,o;const s=this.extractChildAttr(e,"name","val",{default:"Arial"}).asString(),r=this.extractChildAttr(e,"sz","val",{default:G.toString()}).asNum(),a=this.extractColor(this.querySelector(e,"color"),this.theme),l=this.querySelector(e,"i")||void 0,c=l&&"0"!==(null===(t=l.attributes.val)||void 0===t?void 0:t.value),h=this.querySelector(e,"b")||void 0,d=h&&"0"!==(null===(i=h.attributes.val)||void 0===i?void 0:i.value),u=this.querySelector(e,"strike")||void 0,g=u&&"0"!==(null===(n=u.attributes.val)||void 0===n?void 0:n.value),p=this.querySelector(e,"u")||void 0;return{name:s,size:r,color:a,italic:c,bold:d,underline:p&&"none"!==(null===(o=p.attributes.val)||void 0===o?void 0:o.value),strike:g}}getFills(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"fill"},(e=>this.extractFill(e)))}extractFill(e){var t;const i=e.children[0];return"patternFill"===i.tagName?{patternType:null===(t=i.attributes.patternType)||void 0===t?void 0:t.value,bgColor:this.extractColor(this.querySelector(i,"bgColor"),this.theme),fgColor:this.extractColor(this.querySelector(i,"fgColor"),this.theme)}:{patternType:"solid",fgColor:this.extractColor(this.querySelectorAll(i,"color")[1],this.theme)}}getBorders(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"border"},(e=>this.extractBorder(e)))}extractBorder(e){var t,i;const n={left:this.extractSingleBorder(e,"left",this.theme),right:this.extractSingleBorder(e,"right",this.theme),top:this.extractSingleBorder(e,"top",this.theme),bottom:this.extractSingleBorder(e,"bottom",this.theme),diagonal:this.extractSingleBorder(e,"diagonal",this.theme)};return n.diagonal&&(n.diagonalUp=null===(t=this.extractAttr(e,"diagonalUp"))||void 0===t?void 0:t.asBool(),n.diagonalDown=null===(i=this.extractAttr(e,"diagonalDown"))||void 0===i?void 0:i.asBool()),n}extractSingleBorder(e,t,i){const n=this.querySelector(e,t);if(n&&n.attributes.style)return{style:this.extractAttr(n,"style",{required:!0,default:"thin"}).asString(),color:this.extractColor(n.children[0],i,"000000")}}extractAlignment(e){var t,i,n,o,s,r,a;return{horizontal:this.extractAttr(e,"horizontal",{default:"general"}).asString(),vertical:this.extractAttr(e,"vertical",{default:"center"}).asString(),textRotation:null===(t=this.extractAttr(e,"textRotation"))||void 0===t?void 0:t.asNum(),wrapText:null===(i=this.extractAttr(e,"wrapText"))||void 0===i?void 0:i.asBool(),indent:null===(n=this.extractAttr(e,"indent"))||void 0===n?void 0:n.asNum(),relativeIndent:null===(o=this.extractAttr(e,"relativeIndent"))||void 0===o?void 0:o.asNum(),justifyLastLine:null===(s=this.extractAttr(e,"justifyLastLine"))||void 0===s?void 0:s.asBool(),shrinkToFit:null===(r=this.extractAttr(e,"shrinkToFit"))||void 0===r?void 0:r.asBool(),readingOrder:null===(a=this.extractAttr(e,"readingOrder"))||void 0===a?void 0:a.asNum()}}getDxfs(){return this.mapOnElements({query:"dxf",parent:this.rootFile.file.xml},(e=>{const t=this.querySelector(e,"font"),i=this.querySelector(e,"fill"),n=this.querySelector(e,"border"),o=this.querySelector(e,"numFmt"),s=this.querySelector(e,"alignment");return{font:t?this.extractFont(t):void 0,fill:i?this.extractFill(i):void 0,numFmt:o?this.extractNumFormats(o):void 0,alignment:s?this.extractAlignment(s):void 0,border:n?this.extractBorder(n):void 0}}))}getStyles(){return this.mapOnElements({query:"cellXfs xf",parent:this.rootFile.file.xml},(e=>{const t=this.querySelector(e,"alignment");return{fontId:this.extractAttr(e,"fontId",{required:!0,default:0}).asNum(),fillId:this.extractAttr(e,"fillId",{required:!0,default:0}).asNum(),borderId:this.extractAttr(e,"borderId",{required:!0,default:0}).asNum(),numFmtId:this.extractAttr(e,"numFmtId",{required:!0,default:0}).asNum(),alignment:t?this.extractAlignment(t):void 0}}))}}class jf extends Uf{getExternalBook(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"externalBook"},(e=>({rId:this.extractAttr(e,"r:id",{required:!0}).asString(),sheetNames:this.mapOnElements({parent:e,query:"sheetName"},(e=>this.extractAttr(e,"val",{required:!0}).asString())),datasets:this.extractExternalSheetData(e)})))[0]}extractExternalSheetData(e){return this.mapOnElements({parent:e,query:"sheetData"},(e=>{const t=this.mapOnElements({parent:e,query:"cell"},(e=>({xc:this.extractAttr(e,"r",{required:!0}).asString(),value:this.extractChildTextContent(e,"v",{required:!0})}))),i={};for(let e of t)i[e.xc]=e.value;return{sheetId:this.extractAttr(e,"sheetId",{required:!0}).asNum(),data:i}}))}}function Yf(e,t){const i=function(e,t){const i=t[cm],n=i.querySelectorAll(`Override[ContentType="${e}"]`),o=[];for(let e of n){const t=null==e?void 0:e.attributes.PartName.value;o.push(t.substring(1))}return o}(e,t);return function(e,t){const i=[];for(let n of e){const e=Xf(n,t);i.push({file:{fileName:n,xml:t[n]},rels:e?{fileName:e,xml:t[e]}:void 0})}return i}(i,t)}function Xf(e,t){if(e===cm)return"_rels/.rels";let i="";const n=e.split("/");for(let e=0;e<n.length-1;e++)i+=n[e]+"/";return i+="_rels/",i+=n[n.length-1]+".rels",t[i]||(i=void 0),i}class Kf{constructor(e){this.warningManager=new dm,this.xmls={};for(let t of Object.keys(e))(t.endsWith(".xml")||t.endsWith(".rels"))&&(this.xmls[t]=Mf(new Wp(e[t])))}convertXlsx(){const e=this.getXlsxData();return this.convertImportedData(e)}getXlsxData(){const e=this.buildXlsxFileStructure(),t=e.theme?new Vf(e.theme,e,this.warningManager).getTheme():void 0,i=e.sharedStrings?new Vf(e.sharedStrings,e,this.warningManager).getSharedStrings():[],n=e.sheets.sort(((e,t)=>e.file.fileName.localeCompare(t.file.fileName,void 0,{numeric:!0}))).map((i=>new qf(i,e,this.warningManager,t).getSheet())),o=e.externalLinks.map((t=>new jf(t,e,this.warningManager).getExternalBook())),s=new Zf(e,this.warningManager,t);return{fonts:s.getFonts(),fills:s.getFills(),borders:s.getBorders(),dxfs:s.getDxfs(),numFmts:s.getNumFormats(),styles:s.getStyles(),sheets:n,sharedStrings:i,externalBooks:o}}buildXlsxFileStructure(){const e={sheets:Yf(Kp.sheet,this.xmls),workbook:Yf(Kp.workbook,this.xmls)[0],styles:Yf(Kp.styles,this.xmls)[0],sharedStrings:Yf(Kp.sharedStrings,this.xmls)[0],theme:Yf(Kp.themes,this.xmls)[0],charts:Yf(Kp.chart,this.xmls),figures:Yf(Kp.drawing,this.xmls),tables:Yf(Kp.table,this.xmls),pivots:Yf(Kp.pivot,this.xmls),externalLinks:Yf(Kp.externalLink,this.xmls)};if(!e.workbook.rels)throw Error(s("Cannot find workbook relations file"));return e}convertImportedData(e){const t={version:12,sheets:ff(e,this.warningManager),styles:Pm(e,this.warningManager),formats:Vm(e,this.warningManager),borders:$m(e,this.warningManager),entities:{},revisionId:K};return xf(t,e),Object.keys(e.styles).map((t=>{e.styles[t]=rt(e.styles[t])})),t}}function Qf(e){const t=bg(e);let i=[];return{text:"".concat(...t.map((e=>{if("REFERENCE"===e.type&&xt.test(e.value)){const t=e.value.trim();return i.includes(t)||i.push(t),`${ie}${i.indexOf(t)}${ie}`}return e.value}))),dependencies:i}}const Jf=12.5,ev="Sheet1";function tv(e,t){if(!e)return rv();if(e["[Content_Types].xml"]){const i=new Kf(e);if(e=i.convertXlsx(),t)for(let e of i.warningManager.warnings.sort())console.warn(e)}return"version"in(e=Ae(e))&&e.version<Jf&&(e=function(e){for(let t=iv.findIndex((t=>t.from===e.version));t<iv.length;t++)e=iv[t].applyMigration(e);return e}(e)),e=function(e){return e=function(e){if(e.uniqueFigureIds)return e;const t=new Set,i=new Mi;for(const n of e.sheets||[])for(const e of n.figures||[])t.has(e.id)&&(e.id+=i.smallUuid()),t.add(e.id);return e.uniqueFigureIds=!0,e}(e),e=function(e){e=Object.assign(rv(),e,{version:Jf}),e.sheets=e.sheets?e.sheets.map(((e,t)=>Object.assign(sv(`Sheet${t+1}`,`Sheet${t+1}`),e))):[],0===e.sheets.length&&e.sheets.push(sv(ev,"Sheet1"));return e}(e),e}(e),e}const iv=[{description:"add the `activeSheet` field on data",from:1,to:2,applyMigration:e=>(e.sheets&&e.sheets[0]&&(e.activeSheet=e.sheets[0].name),e)},{description:"add an id field in each sheet",from:2,to:3,applyMigration(e){if(e.sheets&&e.sheets.length)for(let t of e.sheets)t.id=t.id||t.name;return e}},{description:"activeSheet is now an id, not the name of a sheet",from:3,to:4,applyMigration(e){if(e.sheets&&e.activeSheet){const t=e.sheets.find((t=>t.name===e.activeSheet));e.activeSheet=t.id}return e}},{description:"add figures object in each sheets",from:4,to:5,applyMigration(e){for(let t of e.sheets||[])t.figures=t.figures||[];return e}},{description:"normalize the content of the cell if it is a formula to avoid parsing all the formula that vary only by the cells they use",from:5,to:6,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const i=t.cells[e];i.content&&i.content.startsWith("=")&&(i.formula=Qf(i.content))}return e}},{description:"transform chart data structure",from:6,to:7,applyMigration(e){for(let t of e.sheets||[])for(let e in t.figures||[]){const{dataSets:i,...n}=t.figures[e].data,o=[];for(let e of i)if(e.labelCell){const t=Fi(e.dataRange),i=e.labelCell+":"+Vt(t.right,t.bottom);o.push(i)}else o.push(e.dataRange);n.dataSetsHaveTitle=Boolean(i[0].labelCell),n.dataSets=o,t.figures[e].data=n}return e}},{description:"remove single quotes in sheet names",from:7,to:8,applyMigration(e){var t;const i=[],n=new RegExp(te,"g");for(let o of e.sheets||[]){if(!o.name)continue;const e=o.name,s=e.replace(n,"_");let r=1,a=s;for(;i.includes(a);)a=`${s}${r}`,r++;o.name=a,i.push(a);const l=t=>{if(void 0===t)return t;let i=t.replace(e,a),n=t;for(;n!==i;)n=i,i=n.replace(e,a);return n};for(let e in o.cells){const t=o.cells[e];t.formula&&(t.formula.dependencies=t.formula.dependencies.map(l))}for(let e of o.figures||[])if("chart"===e.type){const t=e.data.dataSets.map(l),i=l(e.data.labelRange);e.data={...e.data,dataSets:t,labelRange:i}}for(let e of o.conditionalFormats||[]){e.ranges=e.ranges.map(l);for(const i of["minimum","maximum","midpoint","upperInflectionPoint","lowerInflectionPoint"])"formula"===(null===(t=e.rule[i])||void 0===t?void 0:t.type)&&(e.rule[i].value=l(e.rule[i].value))}}return e}},{description:"transform chart data structure with design attributes",from:8,to:9,applyMigration(e){for(const t of e.sheets||[])for(const e of t.figures||[])e.data.background=w,e.data.verticalAxisPosition="left",e.data.legendPosition="top",e.data.stacked=!1;return e}},{description:"de-normalize formula to reduce exported json size (~30%)",from:9,to:10,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const i=t.cells[e];if(i.formula){let{text:e,dependencies:t}=i.formula;for(let[i,n]of Object.entries(t)){const t=`\\${ie}${i}\\${ie}`;e=e.replace(new RegExp(t,"g"),n)}i.content=e,delete i.formula}}return e}},{description:"normalize the formats of the cells",from:10,to:11,applyMigration(e){const t={};for(let i of e.sheets||[])for(let e in i.cells||[]){const n=i.cells[e];n.format&&(n.format=Je(n.format,t))}return e.formats=t,e}},{description:"Add isVisible to sheets",from:11,to:12,applyMigration(e){for(let t of e.sheets||[])t.isVisible=!0;return e}},{description:"Fix datafilter duplication",from:12,to:12.5,applyMigration(e){for(let t of e.sheets||[]){let e=[];for(let i of t.filterTables||[]){const t=Fi(i.range),n=e.findIndex((e=>Hi(e,t)));-1!==n?e[n]=t:e.push(t)}t.filterTables=e.map((e=>({range:ki(e)})))}return e}}];function nv(e,t){return t=function(e,t){if(0!==Object.keys(e).length)return t;const i=[],n=[],o=e=>{if("CREATE_SHEET"===e.type)i.push(e.sheetId);else if("sheetId"in e&&!i.includes(e.sheetId))return{...e,sheetId:ev};return e};for(const e of t)"REMOTE_REVISION"===e.type?n.push({...e,commands:e.commands.map(o)}):n.push(e);return n}(e,t),t=ov(t,"SORT_CELLS"),t=function(e,t){var i;const n=[],o={};for(const t of e.sheets||[])null===(i=t.figures)||void 0===i||i.forEach((e=>{"chart"===e.tag&&(o[e.id]=e.data)}));for(const e of t)if("REMOTE_REVISION"===e.type){const t=[];for(const i of e.commands){let e=i;switch(i.type){case"CREATE_CHART":o[i.id]=i.definition;break;case"UPDATE_CHART":if(!o[i.id]){console.log(`Fix chart definition: chart with id ${i.id} not found.`);continue}const t={...o[i.id],...i.definition};e={...i,definition:t},o[i.id]=t}t.push(e)}n.push({...e,commands:t})}else n.push(e);return n}(e,t=ov(t,"SET_DECIMAL")),t=function(e,t){var i;const n={};for(const t of e.sheets||[])n[t.id]=t.name;const o=[];for(const e of t)if("REMOTE_REVISION"===e.type){const t=[];for(const o of e.commands){switch(o.type){case"DUPLICATE_SHEET":o.sheetNameTo=null!==(i=o.sheetNameTo)&&void 0!==i?i:Oi(n[o.sheetId],Object.values(n));break;case"CREATE_SHEET":case"RENAME_SHEET":n[o.sheetId]=o.name||Ni(Object.values(n))}t.push(o)}o.push({...e,commands:t})}else o.push(e);return t}(e,t),t}function ov(e,t){const i=[];for(const n of e)"REMOTE_REVISION"===n.type?i.push({...n,commands:n.commands.filter((e=>e.type!==t))}):i.push(n);return i}function sv(e,t){return{id:e,name:t,colNumber:26,rowNumber:100,cells:{},cols:{},rows:{},merges:[],conditionalFormats:[],figures:[],filterTables:[],isVisible:!0}}function rv(e="Sheet1"){return{version:Jf,sheets:[sv(ev,e)],entities:{},styles:{},formats:{},borders:{},revisionId:K,uniqueFigureIds:!0}}function av(e,t){return{...sv(e,t),charts:[]}}class lv extends Wg{constructor(e,t,i,n,o,s){super(t,n,o),this.dispatch=n,this.range=i,i.addRangeProvider(this.adaptRanges.bind(this)),this.getters=e,this.uuidGenerator=s}import(e){}export(e){}adaptRanges(e,t){}}class cv extends lv{constructor(){super(...arguments),this.borders={}}allowDispatch(e){return"SET_BORDER"===e.type?this.checkBordersUnchanged(e):0}handle(e){switch(e.type){case"ADD_MERGE":for(const t of e.target)this.addBordersToMerge(e.sheetId,t);break;case"DUPLICATE_SHEET":const t=this.borders[e.sheetId];if(t){const i=t.slice().map((e=>null==e?void 0:e.slice().map((e=>({...e})))));this.history.update("borders",e.sheetIdTo,i)}break;case"DELETE_SHEET":const i={...this.borders};delete i[e.sheetId],this.history.update("borders",i);break;case"SET_BORDER":this.setBorder(e.sheetId,e.col,e.row,e.border);break;case"SET_FORMATTING":if(e.border){const t=e.target.map((t=>this.getters.expandZone(e.sheetId,t)));this.setBorders(e.sheetId,t,e.border)}break;case"CLEAR_FORMATTING":this.clearBorders(e.sheetId,e.target);break;case"REMOVE_COLUMNS_ROWS":const n=[...e.elements].sort(((e,t)=>t-e));for(const t of Le(n))if("COL"===e.dimension){if(t[0]>=this.getters.getNumberCols(e.sheetId))for(let i=0;i<this.getters.getNumberRows(e.sheetId);i++)this.history.update("borders",e.sheetId,t[0]+1,i,"vertical",void 0);if(0===t[t.length-1])for(let t=0;t<this.getters.getNumberRows(e.sheetId);t++)this.history.update("borders",e.sheetId,0,t,"vertical",void 0);const i=this.getters.getColsZone(e.sheetId,t[t.length-1]+1,t[0]);this.clearInsideBorders(e.sheetId,[i]),this.shiftBordersHorizontally(e.sheetId,t[0]+1,-t.length)}else{if(t[0]>=this.getters.getNumberRows(e.sheetId))for(let i=0;i<this.getters.getNumberCols(e.sheetId);i++)this.history.update("borders",e.sheetId,i,t[0]+1,"horizontal",void 0);if(0===t[t.length-1])for(let t=0;t<this.getters.getNumberCols(e.sheetId);t++)this.history.update("borders",e.sheetId,t,0,"horizontal",void 0);const i=this.getters.getRowsZone(e.sheetId,t[t.length-1]+1,t[0]);this.clearInsideBorders(e.sheetId,[i]),this.shiftBordersVertically(e.sheetId,t[0]+1,-t.length)}break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumns(e):this.handleAddRows(e)}}handleAddColumns(e){let t,i;"before"===e.position?(this.shiftBordersHorizontally(e.sheetId,e.base,e.quantity,{moveFirstLeftBorder:!0}),t=e.base-1,i=e.base+e.quantity):(this.shiftBordersHorizontally(e.sheetId,e.base+1,e.quantity,{moveFirstLeftBorder:!1}),t=e.base,i=e.base+e.quantity+1),this.ensureColumnBorderContinuity(e.sheetId,t,i)}handleAddRows(e){let t,i;"before"===e.position?(this.shiftBordersVertically(e.sheetId,e.base,e.quantity,{moveFirstTopBorder:!0}),t=e.base-1,i=e.base+e.quantity):(this.shiftBordersVertically(e.sheetId,e.base+1,e.quantity,{moveFirstTopBorder:!1}),t=e.base,i=e.base+e.quantity+1),this.ensureRowBorderContinuity(e.sheetId,t,i)}getCellBorder(e,t,i){var n,o,s,r,a,l,c,h,d,u,g,p;const m={top:null===(s=null===(o=null===(n=this.borders[e])||void 0===n?void 0:n[t])||void 0===o?void 0:o[i])||void 0===s?void 0:s.horizontal,bottom:null===(l=null===(a=null===(r=this.borders[e])||void 0===r?void 0:r[t])||void 0===a?void 0:a[i+1])||void 0===l?void 0:l.horizontal,left:null===(d=null===(h=null===(c=this.borders[e])||void 0===c?void 0:c[t])||void 0===h?void 0:h[i])||void 0===d?void 0:d.vertical,right:null===(p=null===(g=null===(u=this.borders[e])||void 0===u?void 0:u[t+1])||void 0===g?void 0:g[i])||void 0===p?void 0:p.vertical};return m.bottom||m.left||m.right||m.top?m:null}ensureColumnBorderContinuity(e,t,i){const n=$e(t+1,i);for(let o=0;o<this.getters.getNumberRows(e);o++){const s=this.getCellBorder(e,t,o),r=this.getCellBorder(e,i,o);if(s&&r){const t=this.getCommonSides(s,r);for(let i of n)this.addBorder(e,i,o,t)}}}ensureRowBorderContinuity(e,t,i){const n=$e(t+1,i);for(let o=0;o<this.getters.getNumberCols(e);o++){const s=this.getCellBorder(e,o,t),r=this.getCellBorder(e,o,i);if(s&&r){const t=this.getCommonSides(s,r);for(let i of n)this.addBorder(e,o,i,t)}}}getCommonSides(e,t){const i={};for(let n of["top","bottom","left","right"])e[n]&&e[n]===t[n]&&(i[n]=e[n]);return i}getColumnsWithBorders(e){const t=this.borders[e];return t?Object.keys(t).map((e=>parseInt(e,10))):[]}getRowsWithBorders(e){var t;const i=null===(t=this.borders[e])||void 0===t?void 0:t.filter(Xe);if(!i)return[];const n=new Set;for(const e of i)for(const t in e)n.add(parseInt(t,10));return Array.from(n)}getRowsRange(e){return this.borders[e]?$e(0,this.getters.getNumberRows(e)+1):[]}shiftBordersHorizontally(e,t,i,{moveFirstLeftBorder:n}={}){this.borders[e]&&(i<0&&this.moveBordersOfColumn(e,t,i,"vertical",{destructive:!1}),this.getColumnsWithBorders(e).filter((e=>e>=t)).sort(((e,t)=>i<0?e-t:t-e)).forEach((o=>{(o===t&&n||o!==t)&&this.moveBordersOfColumn(e,o,i,"vertical"),this.moveBordersOfColumn(e,o,i,"horizontal")})))}shiftBordersVertically(e,t,i,{moveFirstTopBorder:n}={}){this.borders[e]&&(i<0&&this.moveBordersOfRow(e,t,i,"horizontal",{destructive:!1}),this.getRowsWithBorders(e).filter((e=>e>=t)).sort(((e,t)=>i<0?e-t:t-e)).forEach((o=>{(o===t&&n||o!==t)&&this.moveBordersOfRow(e,o,i,"horizontal"),this.moveBordersOfRow(e,o,i,"vertical")})))}moveBordersOfRow(e,t,i,n,{destructive:o}={destructive:!0}){const s=this.borders[e];s&&this.getColumnsWithBorders(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=s[r])||void 0===a?void 0:a[t+i])||void 0===l?void 0:l[n],u=null===(h=null===(c=s[r])||void 0===c?void 0:c[t])||void 0===h?void 0:h[n];this.history.update("borders",e,r,t+i,n,o?u:u||d),this.history.update("borders",e,r,t,n,void 0)}))}moveBordersOfColumn(e,t,i,n,{destructive:o}={destructive:!0}){const s=this.borders[e];s&&this.getRowsRange(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=s[t+i])||void 0===a?void 0:a[r])||void 0===l?void 0:l[n],u=null===(h=null===(c=s[t])||void 0===c?void 0:c[r])||void 0===h?void 0:h[n];this.history.update("borders",e,t+i,r,n,o?u:u||d),this.history.update("borders",e,t,r,n,void 0)}))}setBorder(e,t,i,n,o=!0){var s,r,a,l,c,h,d,u,g,p,m,f,v,b,S,C;!o&&(null===(l=null===(a=null===(r=null===(s=this.borders)||void 0===s?void 0:s[e])||void 0===r?void 0:r[t])||void 0===a?void 0:a[i])||void 0===l?void 0:l.vertical)||this.history.update("borders",e,t,i,"vertical",null==n?void 0:n.left),!o&&(null===(u=null===(d=null===(h=null===(c=this.borders)||void 0===c?void 0:c[e])||void 0===h?void 0:h[t])||void 0===d?void 0:d[i])||void 0===u?void 0:u.horizontal)||this.history.update("borders",e,t,i,"horizontal",null==n?void 0:n.top),!o&&(null===(f=null===(m=null===(p=null===(g=this.borders)||void 0===g?void 0:g[e])||void 0===p?void 0:p[t+1])||void 0===m?void 0:m[i])||void 0===f?void 0:f.vertical)||this.history.update("borders",e,t+1,i,"vertical",null==n?void 0:n.right),!o&&(null===(C=null===(S=null===(b=null===(v=this.borders)||void 0===v?void 0:v[e])||void 0===b?void 0:b[t])||void 0===S?void 0:S[i+1])||void 0===C?void 0:C.horizontal)||this.history.update("borders",e,t,i+1,"horizontal",null==n?void 0:n.bottom)}clearBorders(e,t){for(let i of t){for(let t=i.top;t<=i.bottom;t++){this.history.update("borders",e,i.right+1,t,"vertical",void 0);for(let n=i.left;n<=i.right;n++)this.history.update("borders",e,n,t,void 0)}for(let t=i.left;t<=i.right;t++)this.history.update("borders",e,t,i.bottom+1,"horizontal",void 0)}}clearInsideBorders(e,t){for(let i of t)for(let t=i.top;t<=i.bottom;t++)for(let n=i.left;n<=i.right;n++)this.history.update("borders",e,n,t,void 0)}addBorder(e,t,i,n){this.setBorder(e,t,i,{...this.getCellBorder(e,t,i),...n})}setBorders(e,t,i){if("clear"===i)return this.clearBorders(e,t);for(let n of t){if("h"===i||"hv"===i||"all"===i)for(let t=n.top+1;t<=n.bottom;t++)for(let i=n.left;i<=n.right;i++)this.addBorder(e,i,t,{top:Z});if("v"===i||"hv"===i||"all"===i)for(let t=n.top;t<=n.bottom;t++)for(let i=n.left+1;i<=n.right;i++)this.addBorder(e,i,t,{left:Z});if("left"===i||"all"===i||"external"===i)for(let t=n.top;t<=n.bottom;t++)this.addBorder(e,n.left,t,{left:Z});if("right"===i||"all"===i||"external"===i)for(let t=n.top;t<=n.bottom;t++)this.addBorder(e,n.right+1,t,{left:Z});if("top"===i||"all"===i||"external"===i)for(let t=n.left;t<=n.right;t++)this.addBorder(e,t,n.top,{top:Z});if("bottom"===i||"all"===i||"external"===i)for(let t=n.left;t<=n.right;t++)this.addBorder(e,t,n.bottom+1,{top:Z})}}addBordersToMerge(e,t){const{left:i,right:n,top:o,bottom:s}=t,r=this.getCellBorder(e,i,o),a=this.getCellBorder(e,n,s);this.clearBorders(e,[t]),(null==r?void 0:r.top)&&this.setBorders(e,[{...t,bottom:o}],"top"),(null==r?void 0:r.left)&&this.setBorders(e,[{...t,right:i}],"left"),((null==a?void 0:a.bottom)||(null==r?void 0:r.bottom))&&this.setBorders(e,[{...t,top:s}],"bottom"),((null==a?void 0:a.right)||(null==r?void 0:r.right))&&this.setBorders(e,[{...t,left:n}],"right")}checkBordersUnchanged(e){var t,i,n,o;const s=this.getCellBorder(e.sheetId,e.col,e.row),r=!((null===(t=e.border)||void 0===t?void 0:t.bottom)||(null===(i=e.border)||void 0===i?void 0:i.left)||(null===(n=e.border)||void 0===n?void 0:n.right)||(null===(o=e.border)||void 0===o?void 0:o.top));return!s&&r||ot(s,e.border)?89:0}import(e){if(e.borders)for(let t of e.sheets)for(let[i,n]of Object.entries(t.cells))if(null==n?void 0:n.border){const o=e.borders[n.border],{col:s,row:r}=Ut(i);this.setBorder(t.id,s,r,o,!1)}for(let t of e.sheets)if(t.merges)for(let e of t.merges)this.addBordersToMerge(t.id,Fi(e))}export(e){let t=0;const i={};function n(e){for(let[t,n]of Object.entries(i))if(ot(n,e))return parseInt(t,10);return i[++t]=e,t}for(let t of e.sheets)for(let e=0;e<t.colNumber;e++)for(let i=0;i<t.rowNumber;i++){const o=this.getCellBorder(t.id,e,i);if(o){const s=Vt(e,i),r=t.cells[s],a=n(o);r?r.border=a:t.cells[s]={border:a}}}e.borders=i}exportForExcel(e){this.export(e)}}cv.getters=["getCellBorder"];const hv={textColor:R};class dv extends lv{constructor(){super(...arguments),this.nextId=1,this.cells={},this.createCell=function(e){const t=io.getAll().sort(((e,t)=>e.sequence-t.sequence));return function(i,n,o,s){const r=t.find((e=>e.match(n,o.format)));if(!r)return new $p(i,n,o);try{return r.createCell(i,n,o,s,e)}catch(e){return new Bp(i,n,e instanceof c?e:new h(e.message||ne),o)}}}(this.getters)}adaptRanges(e,t){for(const i of Object.keys(this.cells))for(const n of Object.values(this.cells[i]||{}))if(n.isFormula())for(const o of n.dependencies)if(!t||o.sheetId===t){const t=e(o);"NONE"!==t.changeType&&this.history.update("cells",i,n.id,"dependencies",n.dependencies.indexOf(o),t.range)}}allowDispatch(e){var t;switch(e.type){case"UPDATE_CELL":return this.checkValidations(e,this.checkCellOutOfSheet,this.checkUselessUpdateCell);case"CLEAR_CELL":return this.checkValidations(e,this.checkCellOutOfSheet,this.checkUselessClearCell);case"UPDATE_CELL_POSITION":return!e.cellId||(null===(t=this.cells[e.sheetId])||void 0===t?void 0:t[e.cellId])?0:28;default:return 0}}handle(e){switch(e.type){case"SET_FORMATTING":"style"in e&&this.setStyle(e.sheetId,e.target,e.style),"format"in e&&void 0!==e.format&&this.setFormatter(e.sheetId,e.target,e.format);break;case"CLEAR_FORMATTING":this.clearFormatting(e.sheetId,e.target);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumnsRows(e,this.copyColumnStyle.bind(this)):this.handleAddColumnsRows(e,this.copyRowStyle.bind(this));break;case"UPDATE_CELL":this.updateCell(e.sheetId,e.col,e.row,e);break;case"CLEAR_CELL":this.dispatch("UPDATE_CELL",{sheetId:e.sheetId,col:e.col,row:e.row,content:"",style:null,format:""});break;case"DELETE_SHEET":this.history.update("cells",e.sheetId,void 0)}}setFormatter(e,t,i){for(let n of t)for(let t=n.top;t<=n.bottom;t++)for(let o=n.left;o<=n.right;o++)this.dispatch("UPDATE_CELL",{sheetId:e,col:o,row:t,format:i})}clearFormatting(e,t){for(let i of t)for(let t=i.left;t<=i.right;t++)for(let n=i.top;n<=i.bottom;n++)this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:n,style:null,format:""})}handleAddColumnsRows(e,t){let i,n;"before"===e.position?(i=$e(e.base,e.base+e.quantity),n=e.base+e.quantity):(i=$e(e.base+1,e.base+e.quantity+1),n=e.base),t(e.sheetId,n,i)}import(e){for(let t of e.sheets)for(let i in t.cells){const n=t.cells[i],{col:o,row:s}=Ut(i);if((null==n?void 0:n.content)||(null==n?void 0:n.format)||(null==n?void 0:n.style)){const i=this.importCell(t.id,n,e.styles,e.formats);this.history.update("cells",t.id,i.id,i),this.dispatch("UPDATE_CELL_POSITION",{cellId:i.id,col:o,row:s,sheetId:t.id})}}}export(e){const t={},i={};for(let n of e.sheets){const e={},o=Object.keys(this.cells[n.id]||{}).map((e=>this.getters.getCellPosition(e))).sort(((e,t)=>e.col===t.col?e.row-t.row:e.col-t.col));for(const{col:s,row:r}of o){const o=this.getters.getCell(n.id,s,r);e[Vt(s,r)]={style:o.style?Je(o.style,t):void 0,format:o.format?Je(o.format,i):void 0,content:o.content||void 0}}n.cells=e}e.styles=t,e.formats=i}importCell(e,t,i,n){const o=t.style&&i[t.style]||void 0,s=t.format&&n[t.format]||void 0,r=this.getNextUid(),a={format:s,style:o};return this.createCell(r,(null==t?void 0:t.content)||"",a,e)}exportForExcel(e){this.export(e);for(let t of e.sheets)for(const e in t.cells){const{col:i,row:n}=Ut(e),o=this.getters.getCell(t.id,i,n),s=t.cells[e];s.value=o.evaluated.value,s.isFormula=o.isFormula(),o.isFormula()&&(s.content=this.buildFormulaContent(t.id,o,o.dependencies,!0)),o.format!==o.evaluated.format&&(s.computedFormat=o.evaluated.format)}}getCells(e){return this.cells[e]||{}}getCellById(e){const t=this.getters.getCellPosition(e);return this.cells[t.sheetId][e]}buildFormulaContent(e,t,i,n=!1){const o=i||t.dependencies;let s=0;return et(t.compiledFormula.tokens.map((t=>{if("REFERENCE"===t.type){const t=o[s++];return this.getters.getRangeString(t,e,n)}return t.value})))}getFormulaCellContent(e,t){return this.buildFormulaContent(e,t)}getCellStyle(e){if(!e)return{};return{...e.isLink()?hv:{},...e.style}}zoneToXC(e,t,i=[{colFixed:!1,rowFixed:!1}]){const n=Vt((t=this.getters.expandZone(e,t)).left,t.top,i[0]),o=Vt(t.right,t.bottom,i.length>1?i[1]:i[0]),s=this.getters.getMainCellPosition(e,t.left,t.top),r=this.getters.getMainCellPosition(e,t.right,t.bottom),a=s.col===r.col&&s.row===r.row;return n==o||a?n:n+":"+o}setStyle(e,t,i){for(let n of t)for(let t=n.left;t<=n.right;t++)for(let o=n.top;o<=n.bottom;o++){const n=this.getters.getCell(e,t,o);this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:o,style:i?{...null==n?void 0:n.style,...i}:void 0})}}copyColumnStyle(e,t,i){for(let n=0;n<this.getters.getNumberRows(e);n++){const o=this.getFormat(e,t,n);if(o.style||o.format)for(let t of i)this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:n,...o})}}copyRowStyle(e,t,i){for(let n=0;n<this.getters.getNumberCols(e);n++){const o=this.getFormat(e,n,t);if(o.style||o.format)for(let t of i)this.dispatch("UPDATE_CELL",{sheetId:e,col:n,row:t,...o})}}getFormat(e,t,i){const n={},{col:o,row:s}=this.getters.getMainCellPosition(e,t,i),r=this.getters.getCell(e,o,s);return r&&(r.style&&(n.style=r.style),r.format&&(n.format=r.format)),n}getNextUid(){const e=this.nextId.toString();return this.history.update("nextId",this.nextId+1),e}updateCell(e,t,i,n){const o=this.getters.getCell(e,t,i),s="content"in n||"formula"in n,r=(s?n.content:null==o?void 0:o.content)||"";let a;a=void 0!==n.style?n.style||void 0:o?o.style:void 0;let l=("format"in n?n.format:o&&o.format)||undefined;if((s&&!r&&!n.formula||!s&&(!o||o.isEmpty()))&&!a&&!l)return void(o&&(this.history.update("cells",e,o.id,void 0),this.dispatch("UPDATE_CELL_POSITION",{cellId:void 0,col:t,row:i,sheetId:e})));const c=(null==o?void 0:o.id)||this.getNextUid(),h=s,d={format:l,style:a},u=this.createCell(c,r,d,e);o&&!h&&u.isFormula()&&u.assignEvaluation(tt(o.evaluated)),this.history.update("cells",e,u.id,u),this.dispatch("UPDATE_CELL_POSITION",{cellId:u.id,col:t,row:i,sheetId:e})}checkCellOutOfSheet(e){const{sheetId:t,col:i,row:n}=e;if(!this.getters.tryGetSheet(t))return 27;return Wi(i,n,this.getters.getSheetZone(t))?0:18}checkUselessClearCell(e){const t=this.getters.getCell(e.sheetId,e.col,e.row);return t&&(t.content||t.style||t.format)?0:89}checkUselessUpdateCell(e){const t=this.getters.getCell(e.sheetId,e.col,e.row),i="style"in e,n="format"in e;return("content"in e||"formula"in e)&&(null==t?void 0:t.content)!==e.content||i&&!ot(null==t?void 0:t.style,e.style)||n&&(null==t?void 0:t.format)!==e.format?0:89}}dv.getters=["zoneToXC","getCells","getFormulaCellContent","getCellStyle","buildFormulaContent","getCellById"];class uv extends lv{constructor(){super(...arguments),this.charts={},this.createChart=function(e){const t=rn.getAll();return function(i,n,o){const s=t.find((e=>e.match(n.type)));if(!s)throw new Error(`No builder for this chart: ${n.type}`);return s.createChart(n,o,e)}}(this.getters),this.validateChartDefinition=e=>function(e,t){const i=rn.getAll().find((e=>e.match(t.type)));if(!i)throw new Error("Unknown chart type.");return i.validateChartDefinition(e,t)}(this,e.definition)}adaptRanges(e){for(const[t,i]of Object.entries(this.charts))this.history.update("charts",t,null==i?void 0:i.updateRanges(e))}allowDispatch(e){switch(e.type){case"CREATE_CHART":return this.checkValidations(e,this.chainValidations(this.validateChartDefinition,this.checkChartDuplicate));case"UPDATE_CHART":return this.checkValidations(e,this.chainValidations(this.validateChartDefinition,this.checkChartExists));default:return 0}}handle(e){var t;switch(e.type){case"CREATE_CHART":this.addFigure(e.id,e.sheetId,e.position,e.size),this.addChart(e.id,e.definition);break;case"UPDATE_CHART":this.addChart(e.id,e.definition);break;case"DUPLICATE_SHEET":{const i=this.getters.getFigures(e.sheetId);for(const n of i)if("chart"===n.tag){const i=n.id.split("??").pop(),o=`${e.sheetIdTo}??${i}`,s=null===(t=this.charts[n.id])||void 0===t?void 0:t.copyForSheetId(e.sheetIdTo);s&&this.dispatch("CREATE_CHART",{id:o,position:{x:n.x,y:n.y},size:{width:n.width,height:n.height},definition:s.getDefinition(),sheetId:e.sheetIdTo})}break}case"DELETE_FIGURE":this.history.update("charts",e.id,void 0);break;case"DELETE_SHEET":for(let t of this.getChartIds(e.sheetId))this.history.update("charts",t,void 0)}}getContextCreationChart(e){var t;return null===(t=this.charts[e])||void 0===t?void 0:t.getContextCreation()}getChart(e){return this.charts[e]}getChartType(e){var t;const i=null===(t=this.charts[e])||void 0===t?void 0:t.type;if(!i)throw new Error("Chart not defined.");return i}isChartDefined(e){return e in this.charts&&void 0!==this.charts}getChartIds(e){return Object.entries(this.charts).filter((([,t])=>(null==t?void 0:t.sheetId)===e)).map((([e])=>e))}getChartDefinition(e){var t;const i=null===(t=this.charts[e])||void 0===t?void 0:t.getDefinition();if(!i)throw new Error(`There is no chart with the given figureId: ${e}`);return i}import(e){for(let t of e.sheets)if(t.figures)for(let e of t.figures)"chart"===e.tag&&(this.charts[e.id]=this.createChart(e.id,e.data,t.id))}export(e){var t;if(e.sheets)for(let i of e.sheets){const e=this.getters.getFigures(i.id),n=[];for(let i of e){const e=i;if(e&&"chart"===e.tag){const i=null===(t=this.charts[e.id])||void 0===t?void 0:t.getDefinition();i&&(e.data=i,n.push(e))}else n.push(e)}i.figures=n}}exportForExcel(e){var t;for(let i of e.sheets){const e=this.getters.getFigures(i.id),n=[];for(let i of e)if(i&&"chart"===i.tag){const e=null===(t=this.charts[i.id])||void 0===t?void 0:t.getDefinitionForExcel();e&&n.push({...i,data:e})}i.charts=n}}addFigure(e,t,i={x:0,y:0},n={width:536,height:335}){if(this.getters.getFigure(t,e))return;const o={id:e,x:i.x,y:i.y,width:n.width,height:n.height,tag:"chart"};this.dispatch("CREATE_FIGURE",{sheetId:t,figure:o})}addChart(e,t){const i=this.getters.getFigureSheetId(e);i&&this.history.update("charts",e,this.createChart(e,t,i))}checkChartDuplicate(e){return this.getters.getFigureSheetId(e.id)?85:0}checkChartExists(e){return this.isChartDefined(e.id)?0:86}}function gv(e){return""===e?NaN:Number(e)}uv.getters=["isChartDefined","getChartDefinition","getChartType","getChartIds","getChart","getContextCreationChart"];class pv extends lv{constructor(){super(...arguments),this.cfRules={}}loopThroughRangesOfSheet(e,t){for(const i of this.cfRules[e])for(const n of i.ranges){const o=t(n);switch(o.changeType){case"REMOVE":let t=i.ranges.slice();t.splice(i.ranges.indexOf(n),1),t.length>=1?this.history.update("cfRules",e,this.cfRules[e].indexOf(i),"ranges",t):this.removeConditionalFormatting(i.id,e);break;case"RESIZE":case"MOVE":case"CHANGE":this.history.update("cfRules",e,this.cfRules[e].indexOf(i),"ranges",i.ranges.indexOf(n),o.range)}}}adaptRanges(e,t){if(t)this.loopThroughRangesOfSheet(t,e);else for(const t of Object.keys(this.cfRules))this.loopThroughRangesOfSheet(t,e)}allowDispatch(e){switch(e.type){case"ADD_CONDITIONAL_FORMAT":return this.checkValidations(e,this.checkCFRule,this.checkEmptyRange);case"MOVE_CONDITIONAL_FORMAT":return this.checkValidReordering(e.cfId,e.direction,e.sheetId)}return 0}handle(e){switch(e.type){case"CREATE_SHEET":this.cfRules[e.sheetId]=[];break;case"DUPLICATE_SHEET":this.history.update("cfRules",e.sheetIdTo,[]);for(const t of this.getConditionalFormats(e.sheetId))this.addConditionalFormatting(t,e.sheetIdTo);break;case"DELETE_SHEET":const t=Object.assign({},this.cfRules);delete t[e.sheetId],this.history.update("cfRules",t);break;case"ADD_CONDITIONAL_FORMAT":const i={...e.cf,ranges:e.ranges.map((t=>this.getters.getRangeString(this.getters.getRangeFromRangeData(t),e.sheetId)))};this.addConditionalFormatting(i,e.sheetId);break;case"REMOVE_CONDITIONAL_FORMAT":this.removeConditionalFormatting(e.id,e.sheetId);break;case"MOVE_CONDITIONAL_FORMAT":this.reorderConditionalFormatting(e.cfId,e.direction,e.sheetId)}}import(e){for(let t of e.sheets)this.cfRules[t.id]=t.conditionalFormats.map((e=>this.mapToConditionalFormatInternal(t.id,e)))}export(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map((e=>this.mapToConditionalFormat(t.id,e))))}exportForExcel(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map((e=>this.mapToConditionalFormat(t.id,e,{useFixedReference:!0}))))}getConditionalFormats(e){var t;return(null===(t=this.cfRules[e])||void 0===t?void 0:t.map((t=>this.mapToConditionalFormat(e,t))))||[]}getRulesSelection(e,t){const i=new Set;return t.forEach((t=>{this.getRulesByZone(e,t).forEach((e=>{i.add(e)}))})),Array.from(i)}getRulesByZone(e,t){const i=new Set;for(let n=t.top;n<=t.bottom;n++)for(let o=t.left;o<=t.right;o++){this.getRulesByCell(e,o,n).forEach((e=>{i.add(e.id)}))}return i}getRulesByCell(e,t,i){const n=[];for(let o of this.cfRules[e])for(let e of o.ranges)Wi(t,i,e.zone)&&n.push(o);return new Set(n.map((t=>this.mapToConditionalFormat(e,t))))}mapToConditionalFormat(e,t,i={useFixedReference:!1}){return{...t,ranges:t.ranges.map((t=>this.getters.getRangeString(t,e,i.useFixedReference)))}}mapToConditionalFormatInternal(e,t){const i={...t,ranges:t.ranges.map((t=>this.getters.getRangeFromSheetXC(e,t)))};return i}addConditionalFormatting(e,t){const i=this.cfRules[t].slice(),n=i.findIndex((t=>t.id===e.id)),o=this.mapToConditionalFormatInternal(t,e);n>-1?i.splice(n,1,o):i.push(o),this.history.update("cfRules",t,i)}checkValidReordering(e,t,i){if(!this.cfRules[i])return 27;const n=this.cfRules[i].findIndex((t=>t.id===e));if(-1===n)return 72;const o="up"===t?n-1:n+1;return o<0||o>=this.cfRules[i].length?72:0}checkEmptyRange(e){return e.ranges.length?0:24}checkCFRule(e){const t=e.cf.rule;switch(t.type){case"CellIsRule":return this.checkValidations(t,this.checkOperatorArgsNumber(2,["Between","NotBetween"]),this.checkOperatorArgsNumber(1,["BeginsWith","ContainsText","EndsWith","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","NotContains"]),this.checkOperatorArgsNumber(0,["IsEmpty","IsNotEmpty"]));case"ColorScaleRule":return this.checkValidations(t,this.chainValidations(this.checkThresholds(this.checkFormulaCompilation)),this.chainValidations(this.checkThresholds(this.checkNaN),this.batchValidations(this.checkMinBiggerThanMax,this.checkMinBiggerThanMid,this.checkMidBiggerThanMax)));case"IconSetRule":return this.checkValidations(t,this.chainValidations(this.checkInflectionPoints(this.checkNaN),this.checkLowerBiggerThanUpper),this.chainValidations(this.checkInflectionPoints(this.checkFormulaCompilation)))}return 0}checkOperatorArgsNumber(e,t){if(e>2)throw new Error("Checking more than 2 arguments is currently not supported. Add the appropriate CommandResult if you want to.");return i=>{if(t.includes(i.operator)){const t=[],n=e=>void 0===e||""===e;return e>=1&&n(i.values[0])&&t.push(52),e>=2&&n(i.values[1])&&t.push(53),t.length?t:0}return 0}}checkNaN(e,t){if(["number","percentage","percentile"].includes(e.type)&&(""===e.value||isNaN(e.value)))switch(t){case"min":return 54;case"max":return 56;case"mid":return 55;case"upperInflectionPoint":return 57;case"lowerInflectionPoint":return 58}return 0}checkFormulaCompilation(e,t){if("formula"!==e.type)return 0;try{Ug(e.value||"")}catch(e){switch(t){case"min":return 59;case"max":return 61;case"mid":return 60;case"upperInflectionPoint":return 62;case"lowerInflectionPoint":return 63}}return 0}checkThresholds(e){return this.batchValidations((t=>e(t.minimum,"min")),(t=>e(t.maximum,"max")),(t=>t.midpoint?e(t.midpoint,"mid"):0))}checkInflectionPoints(e){return this.batchValidations((t=>e(t.lowerInflectionPoint,"lowerInflectionPoint")),(t=>e(t.upperInflectionPoint,"upperInflectionPoint")))}checkLowerBiggerThanUpper(e){const t=e.lowerInflectionPoint.value,i=e.upperInflectionPoint.value;return["number","percentage","percentile"].includes(e.lowerInflectionPoint.type)&&e.lowerInflectionPoint.type===e.upperInflectionPoint.type&&Number(t)>Number(i)?49:0}checkMinBiggerThanMax(e){const t=e.minimum.value,i=e.maximum.value;return["number","percentage","percentile"].includes(e.minimum.type)&&e.minimum.type===e.maximum.type&&gv(t)>=gv(i)?48:0}checkMidBiggerThanMax(e){var t;const i=null===(t=e.midpoint)||void 0===t?void 0:t.value,n=e.maximum.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.midpoint.type===e.maximum.type&&gv(i)>=gv(n)?50:0}checkMinBiggerThanMid(e){var t;const i=e.minimum.value,n=null===(t=e.midpoint)||void 0===t?void 0:t.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.minimum.type===e.midpoint.type&&gv(i)>=gv(n)?51:0}removeConditionalFormatting(e,t){const i=this.cfRules[t].findIndex((t=>t.id===e));if(-1!==i){const e=this.cfRules[t].slice();e.splice(i,1),this.history.update("cfRules",t,e)}}reorderConditionalFormatting(e,t,i){const n=this.cfRules[i].findIndex((t=>t.id===e)),o="up"===t?n-1:n+1;if(!(o<0||o>=this.cfRules[i].length)&&-1!==n&&-1!==o){const e=[...this.cfRules[i]],t=e[n];e[n]=e[o],e[o]=t,this.history.update("cfRules",i,e)}}}pv.getters=["getConditionalFormats","getRulesSelection","getRulesByCell"];class mv extends lv{constructor(){super(...arguments),this.figures={}}allowDispatch(e){switch(e.type){case"CREATE_FIGURE":return this.checkFigureDuplicate(e.figure.id);case"UPDATE_FIGURE":case"DELETE_FIGURE":return this.checkFigureExists(e.sheetId,e.id);default:return 0}}beforeHandle(e){if("DELETE_SHEET"===e.type)this.getters.getFigures(e.sheetId).forEach((t=>{this.dispatch("DELETE_FIGURE",{id:t.id,sheetId:e.sheetId})}))}handle(e){switch(e.type){case"CREATE_SHEET":this.figures[e.sheetId]={};break;case"DELETE_SHEET":this.deleteSheet(e.sheetId);break;case"CREATE_FIGURE":this.addFigure(e.figure,e.sheetId);break;case"UPDATE_FIGURE":const{type:t,sheetId:i,...n}=e,o=n;this.updateFigure(i,o);break;case"DELETE_FIGURE":this.removeFigure(e.id,e.sheetId)}}updateFigure(e,t){if("id"in t)for(const[i,n]of Object.entries(t))switch(i){case"x":case"y":void 0!==n&&this.history.update("figures",e,t.id,i,Math.max(n,0));break;case"width":case"height":void 0!==n&&this.history.update("figures",e,t.id,i,n)}}addFigure(e,t){this.history.update("figures",t,e.id,e)}deleteSheet(e){this.history.update("figures",e,void 0)}removeFigure(e,t){this.history.update("figures",t,e,void 0)}checkFigureExists(e,t){var i;return void 0===(null===(i=this.figures[e])||void 0===i?void 0:i[t])?71:0}checkFigureDuplicate(e){return Object.values(this.figures).find((t=>null==t?void 0:t[e]))?83:0}getFigures(e){return Object.values(this.figures[e]||{}).filter(Xe)}getFigure(e,t){var i;return null===(i=this.figures[e])||void 0===i?void 0:i[t]}getFigureSheetId(e){return Object.keys(this.figures).find((t=>{var i;return void 0!==(null===(i=this.figures[t])||void 0===i?void 0:i[e])}))}import(e){for(let t of e.sheets){const e={};t.figures.forEach((t=>{e[t.id]=t})),this.figures[t.id]=e}}export(e){for(const t of e.sheets)for(const e of this.getFigures(t.id)){const i=void 0;t.figures.push({...e,data:i})}}exportForExcel(e){this.export(e)}}mv.getters=["getFigures","getFigure","getFigureSheetId"];class fv{constructor(e){this.filters=[],this.zone=e;const t=new Mi;this.id=t.smallUuid();for(const i of $e(e.left,e.right+1)){const e={...this.zone,left:i,right:i};this.filters.push(new vv(t.smallUuid(),e))}}get contentZone(){if(this.zone.bottom!==this.zone.top)return{...this.zone,top:this.zone.top+1}}getFilterId(e){var t;return null===(t=this.filters.find((t=>t.col===e)))||void 0===t?void 0:t.id}clone(){return new fv(this.zone)}}class vv{constructor(e,t){if(t.left!==t.right)throw new Error("Can only define a filter on a single column");this.id=e,this.zoneWithHeaders=t}get col(){return this.zoneWithHeaders.left}get filteredZone(){const e=this.zoneWithHeaders;if(e.bottom!==e.top)return{...e,top:e.top+1}}}class bv extends lv{constructor(){super(...arguments),this.tables={}}allowDispatch(e){switch(e.type){case"CREATE_FILTER_TABLE":if(!on(...e.target))return 82;const t=Vi(...e.target),i=()=>this.getFilterTables(e.sheetId).some((e=>Hi(e.zone,t)))?79:0,n=()=>{const i=this.getters.getMergesInZone(e.sheetId,t);for(let e of i)if(Hi(t,e))return 81;return 0};return this.checkValidations(e,i,n);case"ADD_MERGE":for(let t of e.target)for(let i of this.getFilterTables(e.sheetId))if(Hi(i.zone,t))return 81}return 0}handle(e){switch(e.type){case"CREATE_SHEET":this.history.update("tables",e.sheetId,{});break;case"DELETE_SHEET":const t={...this.tables};delete t[e.sheetId],this.history.update("tables",t);break;case"DUPLICATE_SHEET":const i={};for(const t of Object.values(this.tables[e.sheetId]||{}))if(t){const e=Ae(t);i[e.id]=e}this.history.update("tables",e.sheetIdTo,i);break;case"ADD_COLUMNS_ROWS":this.onAddColumnsRows(e);break;case"REMOVE_COLUMNS_ROWS":this.onDeleteColumnsRows(e);break;case"CREATE_FILTER_TABLE":{const t=Vi(...e.target),i=this.createFilterTable(t);this.history.update("tables",e.sheetId,i.id,i);break}case"REMOVE_FILTER_TABLE":{const t={};for(const i of this.getFilterTables(e.sheetId))e.target.every((e=>!zi(e,i.zone)))&&(t[i.id]=i);this.history.update("tables",e.sheetId,t);break}case"UPDATE_CELL":{const t=e.sheetId;for(let i of this.getFilterTables(t))this.canUpdateCellCmdExtendTable(e,i)&&this.extendTableDown(t,i);break}}}getFilters(e){return this.getFilterTables(e).map((e=>e.filters)).flat()}getFilterTables(e){return this.tables[e]?Object.values(this.tables[e]).filter(Xe):[]}getFilter(e,t,i){var n;return null===(n=this.getFilterTable(e,t,i))||void 0===n?void 0:n.filters.find((e=>e.col===t))}getFilterId(e,t,i){var n;return null===(n=this.getFilter(e,t,i))||void 0===n?void 0:n.id}getFilterTable(e,t,i){return this.getFilterTables(e).find((e=>Wi(t,i,e.zone)))}getFilterTablesInZone(e,t){return this.getFilterTables(e).filter((e=>Gi(e.zone,t)))}doesZonesContainFilter(e,t){for(const i of t)for(const t of this.getFilterTables(e))if(zi(i,t.zone))return!0;return!1}onAddColumnsRows(e){for(const t of this.getFilterTables(e.sheetId)){const i=$i(t.zone,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity),n=[];for(const i of t.filters){const t=$i(i.zoneWithHeaders,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);n.push(new vv(i.id,t))}if(n.length<ji(i).width){for(let e=i.left;e<=i.right;e++)n.find((t=>t.col===e))||n.push(new vv(this.uuidGenerator.smallUuid(),{...i,left:e,right:e}));n.sort(((e,t)=>e.col-t.col))}this.history.update("tables",e.sheetId,t.id,"zone",i),this.history.update("tables",e.sheetId,t.id,"filters",n)}}onDeleteColumnsRows(e){for(const t of this.getFilterTables(e.sheetId)){if("ROW"===e.dimension&&e.elements.includes(t.zone.top)){const i={...this.tables[e.sheetId]};delete i[t.id],this.history.update("tables",e.sheetId,i);continue}const i=Ui(t.zone,"COL"===e.dimension?"left":"top",e.elements);if(i){if(ki(i)!==ki(t.zone)){const n=[];for(const i of t.filters){const t=Ui(i.zoneWithHeaders,"COL"===e.dimension?"left":"top",e.elements);t&&n.push(new vv(i.id,t))}this.history.update("tables",e.sheetId,t.id,"zone",i),this.history.update("tables",e.sheetId,t.id,"filters",n)}}else{const i={...this.tables[e.sheetId]};delete i[t.id],this.history.update("tables",e.sheetId,i)}}}createFilterTable(e){return new fv(e)}extendTableDown(e,t){const i={...t.zone,bottom:t.zone.bottom+1};this.history.update("tables",e,t.id,"zone",i);for(let i=0;i<t.filters.length;i++){const n=t.filters[i],o={...n.zoneWithHeaders,bottom:n.zoneWithHeaders.bottom+1};this.history.update("tables",e,t.id,"filters",i,"zoneWithHeaders",o)}}canUpdateCellCmdExtendTable({content:e,sheetId:t,col:i,row:n},o){var s;if(!e)return;const r=o.zone;if(!(r.bottom+1===n&&i>=r.left&&i<=r.right))return!1;for(const e of $e(r.left,r.right+1)){if(null===(s=this.getters.getCell(t,e,n))||void 0===s?void 0:s.content)return!1;if(this.getters.getFilter(t,e,n))return!1;if(this.getters.isInMerge(t,e,n))return!1}return!0}import(e){for(const t of e.sheets)for(const e of t.filterTables||[]){const i=this.createFilterTable(Fi(e.range));this.history.update("tables",t.id,i.id,i)}}export(e){for(const t of e.sheets)for(const e of this.getFilterTables(t.id))t.filterTables.push({range:ki(e.zone)})}exportForExcel(e){for(const t of e.sheets)for(const e of this.getFilterTables(t.id))1!==ji(e.zone).height&&t.filterTables.push({range:ki(e.zone),filters:[]})}}bv.getters=["doesZonesContainFilter","getFilter","getFilters","getFilterTable","getFilterTables","getFilterTablesInZone","getFilterId"];class Sv extends lv{constructor(){super(...arguments),this.sizes={}}handle(e){var t,i;switch(e.type){case"CREATE_SHEET":{const t=this.computeSheetSizes(e.sheetId),i={COL:t.COL.map((e=>({manualSize:void 0,computedSize:tt(e)}))),ROW:t.ROW.map((e=>({manualSize:void 0,computedSize:tt(e)})))};this.history.update("sizes",e.sheetId,i);break}case"DUPLICATE_SHEET":for(const t of this.sizes[e.sheetId].ROW)t.computedSize();for(const t of this.sizes[e.sheetId].COL)t.computedSize();this.history.update("sizes",e.sheetIdTo,Ae(this.sizes[e.sheetId]));break;case"DELETE_SHEET":const n={...this.sizes};delete n[e.sheetId],this.history.update("sizes",n);break;case"REMOVE_COLUMNS_ROWS":{let t=[...this.sizes[e.sheetId][e.dimension]];for(let i of[...e.elements].sort(((e,t)=>t-e)))t.splice(i,1);const i=ct(e.elements);t=t.map(((t,n)=>"ROW"===e.dimension&&n>=i?{manualSize:t.manualSize,computedSize:tt((()=>this.getRowTallestCellSize(e.sheetId,n)))}:t)),this.history.update("sizes",e.sheetId,e.dimension,t);break}case"ADD_COLUMNS_ROWS":{let t=[...this.sizes[e.sheetId][e.dimension]];const i=nt(e.position,e.base),n=t[e.base],o=$e(0,e.quantity).map((()=>({manualSize:n.manualSize,computedSize:tt(n.computedSize())})));t.splice(i,0,...o),t=t.map(((t,i)=>"ROW"===e.dimension&&i>e.base+e.quantity?{manualSize:t.manualSize,computedSize:tt((()=>this.getRowTallestCellSize(e.sheetId,i)))}:t)),this.history.update("sizes",e.sheetId,e.dimension,t);break}case"RESIZE_COLUMNS_ROWS":for(let t of e.elements)if("ROW"===e.dimension){const i=this.getRowTallestCellSize(e.sheetId,t);this.history.update("sizes",e.sheetId,e.dimension,t,{manualSize:e.size||void 0,computedSize:tt(i)})}else this.history.update("sizes",e.sheetId,e.dimension,t,{manualSize:e.size||void 0,computedSize:tt(e.size||_)});break;case"UPDATE_CELL":const o=null===(i=null===(t=this.sizes[e.sheetId])||void 0===t?void 0:t.ROW)||void 0===i?void 0:i[e.row];if(o&&!o.manualSize){const{sheetId:t,row:i}=e;this.history.update("sizes",t,"ROW",i,"computedSize",tt((()=>this.getRowTallestCellSize(t,i))))}break;case"ADD_MERGE":case"REMOVE_MERGE":for(let t of e.target)for(let i of $e(t.top,t.bottom+1)){const t=this.getRowTallestCellSize(e.sheetId,i);t!==this.getRowSize(e.sheetId,i)&&this.history.update("sizes",e.sheetId,"ROW",i,"computedSize",tt(t))}}}getColSize(e,t){return this.getHeaderSize(e,"COL",t)}getRowSize(e,t){return this.getHeaderSize(e,"ROW",t)}getHeaderSize(e,t,i){var n,o,s,r;return Math.round((null===(o=null===(n=this.sizes[e])||void 0===n?void 0:n[t][i])||void 0===o?void 0:o.manualSize)||(null===(r=null===(s=this.sizes[e])||void 0===s?void 0:s[t][i])||void 0===r?void 0:r.computedSize())||this.getDefaultHeaderSize(t))}computeSheetSizes(e){var t,i;const n={COL:[],ROW:[]};for(let t of $e(0,this.getters.getNumberCols(e)))n.COL.push(this.getHeaderSize(e,"COL",t));for(let o of $e(0,this.getters.getNumberRows(e))){let s=null===(i=null===(t=this.sizes[e])||void 0===t?void 0:t.ROW)||void 0===i?void 0:i[o].manualSize;if(!s){s=this.getRowTallestCellSize(e,o)}n.ROW.push(s)}return n}getDefaultHeaderSize(e){return"COL"===e?_:F}getCellHeight(e,t,i){const n=this.getters.getMerge(e,t,i);if(n&&n.bottom!==n.top)return F;const o=this.getters.getCell(e,t,i);return(null==(s=null==o?void 0:o.style)?void 0:s.fontSize)?(r||1)*(ke(s)+P)-P+2*U:F;var s,r}getRowTallestCellSize(e,t){const i=this.getters.getRowCells(e,t);let n=0;for(let t=0;t<i.length;t++){const o=this.getters.getCellById(i[t]);if(!o)continue;const{col:s,row:r}=this.getters.getCellPosition(o.id),a=this.getCellHeight(e,s,r);a>n&&a>F&&(n=a)}return n<=F?F:n}import(e){for(let t of e.sheets){const e={COL:[],ROW:[]};for(let[i,n]of Object.entries(t.rows))n.size&&(e.ROW[i]=n.size);for(let[i,n]of Object.entries(t.cols))n.size&&(e.COL[i]=n.size);const i=this.computeSheetSizes(t.id);this.sizes[t.id]={COL:i.COL.map(((t,i)=>({manualSize:e.COL[i],computedSize:tt(t)}))),ROW:i.ROW.map(((t,i)=>({manualSize:e.ROW[i],computedSize:tt(t)})))}}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){var i,n;for(let o of e.sheets){void 0===o.rows&&(o.rows={});for(let e of $e(0,this.getters.getNumberRows(o.id)))(t||(null===(i=this.sizes[o.id].ROW[e])||void 0===i?void 0:i.manualSize))&&(o.rows[e]={...o.rows[e],size:this.getRowSize(o.id,e)});void 0===o.cols&&(o.cols={});for(let e of $e(0,this.getters.getNumberCols(o.id)))(t||(null===(n=this.sizes[o.id].COL[e])||void 0===n?void 0:n.manualSize))&&(o.cols[e]={...o.cols[e],size:this.getColSize(o.id,e)})}}}Sv.getters=["getRowSize","getColSize"];class Cv extends lv{constructor(){super(...arguments),this.hiddenHeaders={}}allowDispatch(e){switch(e.type){case"HIDE_COLUMNS_ROWS":{if(!this.getters.tryGetSheet(e.sheetId))return 27;const t="COL"===e.dimension?this.getHiddenColsGroups(e.sheetId):this.getHiddenRowsGroups(e.sheetId),i="COL"===e.dimension?this.getters.getNumberCols(e.sheetId):this.getters.getNumberRows(e.sheetId);return new Set((t||[]).flat().concat(e.elements)).size>=i?67:ct(e.elements)<0||lt(e.elements)>i?87:0}case"REMOVE_COLUMNS_ROWS":return this.getters.tryGetSheet(e.sheetId)?this.checkElementsIncludeAllVisibleHeaders(e.sheetId,e.dimension,e.elements)?8:0:27}return 0}handle(e){switch(e.type){case"CREATE_SHEET":const t={COL:Array(this.getters.getNumberCols(e.sheetId)).fill(!1),ROW:Array(this.getters.getNumberRows(e.sheetId)).fill(!1)};this.history.update("hiddenHeaders",e.sheetId,t);break;case"DUPLICATE_SHEET":this.history.update("hiddenHeaders",e.sheetIdTo,Ae(this.hiddenHeaders[e.sheetId]));break;case"DELETE_SHEET":this.history.update("hiddenHeaders",e.sheetId,void 0);break;case"REMOVE_COLUMNS_ROWS":{const t=[...this.hiddenHeaders[e.sheetId][e.dimension]];for(let i of[...e.elements].sort(((e,t)=>t-e)))t.splice(i,1);this.history.update("hiddenHeaders",e.sheetId,e.dimension,t);break}case"ADD_COLUMNS_ROWS":{const t=[...this.hiddenHeaders[e.sheetId][e.dimension]],i=nt(e.position,e.base);t.splice(i,0,...Array(e.quantity).fill(!1)),this.history.update("hiddenHeaders",e.sheetId,e.dimension,t);break}case"HIDE_COLUMNS_ROWS":for(let t of e.elements)this.history.update("hiddenHeaders",e.sheetId,e.dimension,t,!0);break;case"UNHIDE_COLUMNS_ROWS":for(let t of e.elements)this.history.update("hiddenHeaders",e.sheetId,e.dimension,t,!1)}}checkElementsIncludeAllVisibleHeaders(e,t,i){return st(i,this.getAllVisibleHeaders(e,t))}isRowHiddenByUser(e,t){return this.hiddenHeaders[e].ROW[t]}isColHiddenByUser(e,t){return this.hiddenHeaders[e].COL[t]}getHiddenColsGroups(e){const t=[[]],i=this.hiddenHeaders[e].COL;for(let e=0;e<i.length;e++){i[e]?t[t.length-1].push(e):0!==t[t.length-1].length&&t.push([])}return 0===t[t.length-1].length&&t.pop(),t}getHiddenRowsGroups(e){const t=[[]],i=this.hiddenHeaders[e].ROW;for(let e=0;e<i.length;e++){i[e]?t[t.length-1].push(e):0!==t[t.length-1].length&&t.push([])}return 0===t[t.length-1].length&&t.pop(),t}getAllVisibleHeaders(e,t){return $e(0,this.hiddenHeaders[e][t].length).filter((i=>!this.hiddenHeaders[e][t][i]))}import(e){var t,i;for(let n of e.sheets){this.hiddenHeaders[n.id]={COL:[],ROW:[]};for(let e=0;e<n.rowNumber;e++)this.hiddenHeaders[n.id].ROW[e]=Boolean(null===(t=n.rows[e])||void 0===t?void 0:t.isHidden);for(let e=0;e<n.colNumber;e++)this.hiddenHeaders[n.id].COL[e]=Boolean(null===(i=n.cols[e])||void 0===i?void 0:i.isHidden)}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){for(let i of e.sheets){void 0===i.rows&&(i.rows={});for(let e=0;e<this.getters.getNumberRows(i.id);e++)(t||this.hiddenHeaders[i.id].ROW[e])&&(void 0===i.rows[e]&&(i.rows[e]={}),i.rows[e].isHidden=this.hiddenHeaders[i.id].ROW[e]);void 0===i.cols&&(i.cols={});for(let e=0;e<this.getters.getNumberCols(i.id);e++)(t||this.hiddenHeaders[i.id].COL[e])&&(void 0===i.cols[e]&&(i.cols[e]={}),i.cols[e].isHidden=this.hiddenHeaders[i.id].COL[e])}}}Cv.getters=["checkElementsIncludeAllVisibleHeaders","getHiddenColsGroups","getHiddenRowsGroups","isRowHiddenByUser","isColHiddenByUser"];class Ev extends lv{constructor(){super(...arguments),this.nextId=1,this.merges={},this.mergeCellMap={}}allowDispatch(e){const t="force"in e&&!!e.force;switch(e.type){case"ADD_MERGE":return t?this.checkValidations(e,this.checkFrozenPanes):this.checkValidations(e,this.checkDestructiveMerge,this.checkOverlap,this.checkFrozenPanes);case"UPDATE_CELL":return this.checkMergedContentUpdate(e);case"REMOVE_MERGE":return this.checkMergeExists(e);default:return 0}}handle(e){switch(e.type){case"CREATE_SHEET":case"DELETE_SHEET":this.history.update("merges",e.sheetId,{}),this.history.update("mergeCellMap",e.sheetId,{});break;case"DUPLICATE_SHEET":const t=this.merges[e.sheetId];if(!t)break;for(const i of Object.values(t).filter(Xe))this.addMerge(e.sheetIdTo,i.zone);break;case"ADD_MERGE":for(const t of e.target)this.addMerge(e.sheetId,t);break;case"REMOVE_MERGE":for(const t of e.target)this.removeMerge(e.sheetId,t)}}adaptRanges(e,t){const i=t?[t]:Object.keys(this.merges);for(const t of i)this.applyRangeChangeOnSheet(t,e)}getMerges(e){return Object.keys(this.merges[e]||{}).map((t=>this.getMergeById(e,parseInt(t,10)))).filter(Xe)}getMerge(e,t,i){var n;const o=this.mergeCellMap[e],s=o?t in o&&(null===(n=o[t])||void 0===n?void 0:n[i]):void 0;return s?this.getMergeById(e,s):void 0}getMergesInZone(e,t){var i;const n=this.mergeCellMap[e];if(!n)return[];const o=new Set;for(const{col:e,row:s}of Xi(t)){const t=null===(i=n[e])||void 0===i?void 0:i[s];t&&o.add(t)}return Array.from(o).map((t=>this.getMergeById(e,t))).filter(Xe)}doesIntersectMerge(e,t){const{left:i,right:n,top:o,bottom:s}=t;for(let t=o;t<=s;t++)for(let o=i;o<=n;o++)if(this.getMerge(e,o,t))return!0;return!1}doesColumnsHaveCommonMerges(e,t,i){const n=this.getters.getSheet(e);for(let o=0;o<this.getters.getNumberRows(e);o++)if(this.isInSameMerge(n.id,t,o,i,o))return!0;return!1}doesRowsHaveCommonMerges(e,t,i){const n=this.getters.getSheet(e);for(let o=0;o<=this.getters.getNumberCols(e);o++)if(this.isInSameMerge(n.id,o,t,o,i))return!0;return!1}expandZone(e,t){let{left:i,right:n,top:o,bottom:s}=t,r={left:i,right:n,top:o,bottom:s};for(let t in this.merges[e]){const i=this.getMergeById(e,parseInt(t));i&&Hi(i,r)&&(r=Vi(i,r))}return Bi(r,t)?r:this.expandZone(e,r)}isInSameMerge(e,t,i,n,o){const s=this.getMerge(e,t,i),r=this.getMerge(e,n,o);return!(!s||!r)&&Bi(s,r)}isInMerge(e,t,i){var n;const o=this.mergeCellMap[e];return!!o&&(t in o&&Boolean(null===(n=o[t])||void 0===n?void 0:n[i]))}getMainCellPosition(e,t,i){if(!this.isInMerge(e,t,i))return{col:t,row:i};const n=this.getMerge(e,t,i).topLeft;return{col:n.col,row:n.row}}getBottomLeftCell(e,t,i){if(!this.isInMerge(e,t,i))return{col:t,row:i};const{bottom:n,left:o}=this.getMerge(e,t,i);return{col:o,row:n}}isMergeHidden(e,t){const i=this.getters.getHiddenColsGroups(e),n=this.getters.getHiddenRowsGroups(e);for(let e of i)if(t.left>=e[0]&&t.right<=e[e.length-1])return!0;for(let e of n)if(t.top>=e[0]&&t.bottom<=e[e.length-1])return!0;return!1}isSingleCellOrMerge(e,t){const i=this.getMerge(e,t.left,t.top);if(i)return Bi(t,i);const{width:n,height:o}=ji(t);return 1===n&&1===o}isMergeDestructive(e,t){let{left:i,right:n,top:o,bottom:s}=t;n=Me(n,0,this.getters.getNumberCols(e)-1),s=Me(s,0,this.getters.getNumberRows(e)-1);for(let t=o;t<=s;t++)for(let s=i;s<=n;s++)if(s!==i||t!==o){const i=this.getters.getCell(e,s,t);if(i&&!i.isEmpty())return!0}return!1}getMergeById(e,t){var i;const n=null===(i=this.merges[e])||void 0===i?void 0:i[t];return void 0!==n?yv(t,n):void 0}checkDestructiveMerge({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return 0;return t.some((t=>this.isMergeDestructive(e,t)))?3:0}checkOverlap({target:e}){for(const t of e)for(const i of e)if(t!==i&&Hi(t,i))return 66;return 0}checkFrozenPanes({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return 0;const{xSplit:i,ySplit:n}=this.getters.getPaneDivisions(e);for(const e of t)if(e.left<i&&e.right>=i||e.top<n&&e.bottom>=n)return 76;return 0}checkMergedContentUpdate(e){const{col:t,row:i,sheetId:n,content:o}=e;if(void 0===o)return 0;const{col:s,row:r}=this.getMainCellPosition(n,t,i);return s===t&&r===i?0:4}checkMergeExists(e){const{sheetId:t,target:i}=e;for(const e of i){const{left:i,top:n}=e,o=this.getMerge(t,i,n);if(void 0===o||!Bi(e,o))return 5}return 0}addMerge(e,t){let{left:i,right:n,top:o,bottom:s}=t;n=Me(n,0,this.getters.getNumberCols(e)-1),s=Me(s,0,this.getters.getNumberRows(e)-1);if(Vt(i,o)===Vt(n,s))return;const r=this.getters.getCell(e,i,o);let a=this.nextId++;this.history.update("merges",e,a,this.getters.getRangeFromSheetXC(e,ki({left:i,top:o,right:n,bottom:s})));let l=new Set;for(let t=o;t<=s;t++)for(let s=i;s<=n;s++){s===i&&t===o||this.dispatch("UPDATE_CELL",{sheetId:e,col:s,row:t,style:r?r.style:null,content:""});const n=this.getMerge(e,s,t);n&&l.add(n.id),this.history.update("mergeCellMap",e,s,t,a)}for(let t of l){const{top:i,bottom:n,left:o,right:s}=this.getMergeById(e,t);for(let t=i;t<=n;t++)for(let i=o;i<=s;i++){const n=this.getMerge(e,i,t);n&&n.id===a||(this.history.update("mergeCellMap",e,i,t,void 0),this.dispatch("CLEAR_CELL",{sheetId:e,col:i,row:t}))}this.history.update("merges",e,t,void 0)}}removeMerge(e,t){const{left:i,top:n,bottom:o,right:s}=t,r=this.getMerge(e,i,n);if(void 0!==r&&Bi(t,r)){this.history.update("merges",e,r.id,void 0);for(let t=n;t<=o;t++)for(let n=i;n<=s;n++)this.history.update("mergeCellMap",e,n,t,void 0)}}applyRangeChangeOnSheet(e,t){const i=Object.entries(this.merges[e]||{});for(const[n,o]of i)if(o){const i=o.zone,s=t(o);switch(s.changeType){case"NONE":break;case"REMOVE":this.removeMerge(e,i);break;default:const{width:t,height:o}=ji(s.range.zone);1===t&&1===o?this.removeMerge(e,i):this.history.update("merges",e,parseInt(n,10),s.range)}}this.history.update("mergeCellMap",e,{});for(const t of this.getMerges(e))for(const{col:i,row:n}of Xi(t))this.history.update("mergeCellMap",e,i,n,t.id)}import(e){const t=e.sheets||[];for(let e of t)this.history.update("merges",e.id,{}),this.history.update("mergeCellMap",e.id,{}),e.merges&&this.importMerges(e.id,e.merges)}importMerges(e,t){for(let i of t)this.addMerge(e,Fi(i))}export(e){for(let t of e.sheets){const e=this.merges[t.id];e&&t.merges.push(...wv(e))}}exportForExcel(e){this.export(e)}}function wv(e){return Object.entries(e).map((([e,t])=>t?yv(parseInt(e,10),t):void 0)).filter(Xe).map((e=>Vt(e.left,e.top)+":"+Vt(e.right,e.bottom)))}function yv(e,t){return{...t.zone,topLeft:{col:t.zone.left,row:t.zone.top},id:e}}Ev.getters=["isInMerge","isInSameMerge","isMergeHidden","getMainCellPosition","getBottomLeftCell","expandZone","doesIntersectMerge","doesColumnsHaveCommonMerges","doesRowsHaveCommonMerges","getMerges","getMerge","getMergesInZone","isSingleCellOrMerge"];class xv extends lv{constructor(){super(...arguments),this.sheetIdsMapName={},this.orderedSheetIds=[],this.sheets={},this.cellPosition={}}allowDispatch(e){const t=this.chainValidations(this.checkSheetExists,this.checkZones)(e);if(0!==t)return t;switch(e.type){case"HIDE_SHEET":return 1===this.getVisibleSheetIds().length?9:0;case"CREATE_SHEET":return this.checkValidations(e,this.checkSheetName,this.checkSheetPosition);case"DUPLICATE_SHEET":return this.sheets[e.sheetIdTo]?12:this.orderedSheetIds.map(this.getSheetName.bind(this)).includes(e.sheetNameTo)?11:0;case"MOVE_SHEET":const t=this.orderedSheetIds.indexOf(e.sheetId);if("left"===e.direction){return this.orderedSheetIds.slice(0,t).map((e=>!this.isSheetVisible(e))).every((e=>e))?14:0}return this.orderedSheetIds.slice(t+1).map((e=>!this.isSheetVisible(e))).every((e=>e))?14:0;case"RENAME_SHEET":return this.isRenameAllowed(e);case"DELETE_SHEET":return this.getVisibleSheetIds().length>1?0:9;case"ADD_COLUMNS_ROWS":const i="COL"===e.dimension?this.getNumberCols(e.sheetId):this.getNumberRows(e.sheetId);return e.base<0||e.base>=i?87:e.quantity<=0?88:0;case"REMOVE_COLUMNS_ROWS":{const t="COL"===e.dimension?this.getNumberCols(e.sheetId):this.getNumberRows(e.sheetId);return ct(e.elements)<0||lt(e.elements)>t?87:this.checkElementsIncludeAllNonFrozenHeaders(e.sheetId,e.dimension,e.elements)?8:0}case"FREEZE_ROWS":return this.checkValidations(e,this.checkRowFreezeQuantity,this.checkRowFreezeOverlapMerge);case"FREEZE_COLUMNS":return this.checkValidations(e,this.checkColFreezeQuantity,this.checkColFreezeOverlapMerge);default:return 0}}handle(e){switch(e.type){case"SET_GRID_LINES_VISIBILITY":this.setGridLinesVisibility(e.sheetId,e.areGridLinesVisible);break;case"DELETE_CONTENT":this.clearZones(e.sheetId,e.target);break;case"CREATE_SHEET":const t=this.createSheet(e.sheetId,e.name||this.getNextSheetName(),e.cols||26,e.rows||100,e.position);this.history.update("sheetIdsMapName",t.name,t.id);break;case"MOVE_SHEET":this.moveSheet(e.sheetId,e.direction);break;case"RENAME_SHEET":this.renameSheet(this.sheets[e.sheetId],e.name);break;case"HIDE_SHEET":this.hideSheet(e.sheetId);break;case"SHOW_SHEET":this.showSheet(e.sheetId);break;case"DUPLICATE_SHEET":this.duplicateSheet(e.sheetId,e.sheetIdTo,e.sheetNameTo);break;case"DELETE_SHEET":this.deleteSheet(this.sheets[e.sheetId]);break;case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.removeColumns(this.sheets[e.sheetId],[...e.elements]):this.removeRows(this.sheets[e.sheetId],[...e.elements]);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.addColumns(this.sheets[e.sheetId],e.base,e.position,e.quantity):this.addRows(this.sheets[e.sheetId],e.base,e.position,e.quantity);break;case"UPDATE_CELL_POSITION":this.updateCellPosition(e);break;case"FREEZE_COLUMNS":this.setPaneDivisions(e.sheetId,e.quantity,"COL");break;case"FREEZE_ROWS":this.setPaneDivisions(e.sheetId,e.quantity,"ROW");break;case"UNFREEZE_ROWS":this.setPaneDivisions(e.sheetId,0,"ROW");break;case"UNFREEZE_COLUMNS":this.setPaneDivisions(e.sheetId,0,"COL");break;case"UNFREEZE_COLUMNS_ROWS":this.setPaneDivisions(e.sheetId,0,"COL"),this.setPaneDivisions(e.sheetId,0,"ROW")}}import(e){var t,i;for(let t of e.sheets)this.sheetIdsMapName[t.name]=t.id;for(let n of e.sheets){const e=n.name||o("Sheet")+(Object.keys(this.sheets).length+1),{colNumber:s,rowNumber:r}=this.getImportedSheetSize(n),a={id:n.id,name:e,numberOfCols:s,rows:Ti(r),areGridLinesVisible:void 0===n.areGridLinesVisible||n.areGridLinesVisible,isVisible:n.isVisible,panes:{xSplit:(null===(t=n.panes)||void 0===t?void 0:t.xSplit)||0,ySplit:(null===(i=n.panes)||void 0===i?void 0:i.ySplit)||0}};this.orderedSheetIds.push(a.id),this.sheets[a.id]=a}}exportSheets(e){e.sheets=this.orderedSheetIds.filter(Xe).map((e=>{const t=this.sheets[e],i={id:t.id,name:t.name,colNumber:t.numberOfCols,rowNumber:this.getters.getNumberRows(t.id),rows:{},cols:{},merges:[],cells:{},conditionalFormats:[],figures:[],filterTables:[],areGridLinesVisible:void 0===t.areGridLinesVisible||t.areGridLinesVisible,isVisible:t.isVisible};return(t.panes.xSplit||t.panes.ySplit)&&(i.panes=t.panes),i}))}export(e){this.exportSheets(e)}exportForExcel(e){this.exportSheets(e)}getGridLinesVisibility(e){return this.getSheet(e).areGridLinesVisible}tryGetSheet(e){return this.sheets[e]}getSheet(e){const t=this.sheets[e];if(!t)throw new Error(`Sheet ${e} not found.`);return t}isSheetVisible(e){return this.getSheet(e).isVisible}getSheetName(e){return this.getSheet(e).name}getCellsInZone(e,t){return Xi(t).map((({col:t,row:i})=>this.getCell(e,t,i)))}tryGetSheetName(e){var t;return null===(t=this.tryGetSheet(e))||void 0===t?void 0:t.name}getSheetIdByName(e){if(e){const t=Ne(e);for(const e in this.sheetIdsMapName)if(Ai(e,t))return this.sheetIdsMapName[e]}}getSheetIds(){return this.orderedSheetIds}getVisibleSheetIds(){return this.orderedSheetIds.filter(this.isSheetVisible.bind(this))}getEvaluationSheets(){return this.sheets}doesHeaderExist(e,t,i){return"COL"===t?i>=0&&i<this.getNumberCols(e):i>=0&&i<this.getNumberRows(e)}getRow(e,t){const i=this.getSheet(e).rows[t];if(!i)throw new Error(`Row ${i} not found.`);return i}getCell(e,t,i){var n;const o=this.tryGetSheet(e),s=null===(n=null==o?void 0:o.rows[i])||void 0===n?void 0:n.cells[t];if(void 0!==s)return this.getters.getCellById(s)}getColCells(e,t){return this.getSheet(e).rows.map((e=>e.cells[t])).filter(Xe).map((e=>this.getters.getCellById(e))).filter(Xe)}getColsZone(e,t,i){return{top:0,bottom:this.getNumberRows(e)-1,left:t,right:i}}getRowCells(e,t){var i;return Object.values(null===(i=this.getSheet(e).rows[t])||void 0===i?void 0:i.cells).filter(Xe)}getRowsZone(e,t,i){return{top:t,bottom:i,left:0,right:this.getSheet(e).numberOfCols-1}}getCellPosition(e){const t=this.cellPosition[e];if(!t)throw new Error(`asking for a cell position that doesn't exist, cell id: ${e}`);return t}getNumberCols(e){return this.getSheet(e).numberOfCols}getNumberRows(e){return this.getSheet(e).rows.length}getNumberHeaders(e,t){return"COL"===t?this.getNumberCols(e):this.getNumberRows(e)}getNextSheetName(e="Sheet"){return Ni(this.orderedSheetIds.map(this.getSheetName.bind(this)),e)}getSheetSize(e){return{height:this.getNumberRows(e),width:this.getNumberCols(e)}}getSheetZone(e){return{top:0,left:0,bottom:this.getNumberRows(e)-1,right:this.getNumberCols(e)-1}}getPaneDivisions(e){return this.getSheet(e).panes}setPaneDivisions(e,t,i){const n={...this.getPaneDivisions(e)};"COL"===i?n.xSplit=t:"ROW"===i&&(n.ySplit=t),this.history.update("sheets",e,"panes",n)}checkElementsIncludeAllNonFrozenHeaders(e,t,i){const n=this.getters.getPaneDivisions(e),o="ROW"===t?n.ySplit:n.xSplit,s=this.getters.getNumberHeaders(e,t);if(!o)return!1;return st(i,$e(o,s))}isEmpty(e,t){return this.getCellsInZone(e,t).flat().every((e=>!e||e.isEmpty()))}updateCellPosition(e){const{sheetId:t,cellId:i,col:n,row:o}=e;i?this.setNewPosition(i,t,n,o):this.clearPosition(t,n,o)}setNewPosition(e,t,i,n){const o=this.cellPosition[e];o&&this.clearPosition(t,o.col,o.row),this.history.update("cellPosition",e,{row:n,col:i,sheetId:t}),this.history.update("sheets",t,"rows",n,"cells",i,e)}clearPosition(e,t,i){var n;const o=null===(n=this.sheets[e])||void 0===n?void 0:n.rows[i].cells[t];o&&(this.history.update("cellPosition",o,void 0),this.history.update("sheets",e,"rows",i,"cells",t,void 0))}setGridLinesVisibility(e,t){this.history.update("sheets",e,"areGridLinesVisible",t)}clearZones(e,t){for(let i of t)for(let t=i.left;t<=i.right;t++)for(let n=i.top;n<=i.bottom;n++){this.sheets[e].rows[n].cells[t]&&this.dispatch("UPDATE_CELL",{sheetId:e,content:"",col:t,row:n})}}createSheet(e,t,i,n,o){const s={id:e,name:t,numberOfCols:i,rows:Ti(n),areGridLinesVisible:!0,isVisible:!0,panes:{xSplit:0,ySplit:0}},r=this.orderedSheetIds.slice();r.splice(o,0,s.id);const a=this.sheets;return this.history.update("orderedSheetIds",r),this.history.update("sheets",Object.assign({},a,{[s.id]:s})),s}moveSheet(e,t){const i=this.orderedSheetIds.slice(),n=i.findIndex((t=>t===e)),o=i.splice(n,1);let s="left"===t?this.findIndexOfPreviousVisibleSheet(n-1,i):this.findIndexOfNextVisibleSheet(n+1,i);void 0===s&&(s=i.length),i.splice(s,0,o[0]),this.history.update("orderedSheetIds",i)}findIndexOfPreviousVisibleSheet(e,t){for(;e>=0&&!this.isSheetVisible(t[e]);)e--;if(-1===e)throw new Error("There is no previous visible sheet");return e}findIndexOfNextVisibleSheet(e,t){for(;e<t.length&&!this.isSheetVisible(t[e]);)e++;if(e!==t.length-1||this.isSheetVisible(t[e-1]))return e}checkSheetName(e){const{orderedSheetIds:t,sheets:i}=this,n=e.name&&e.name.trim().toLowerCase();return t.find((e=>{var t;return Ai(null===(t=i[e])||void 0===t?void 0:t.name,n)}))?11:te.test(n)?13:0}checkSheetPosition(e){const{orderedSheetIds:t}=this;return e.position>t.length||e.position<0?15:0}checkRowFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberRows(e.sheetId)?0:75}checkColFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberCols(e.sheetId)?0:75}checkRowFreezeOverlapMerge(e){const t=this.getters.getMerges(e.sheetId);for(let i of t)if(i.top<e.quantity&&e.quantity<=i.bottom)return 66;return 0}checkColFreezeOverlapMerge(e){const t=this.getters.getMerges(e.sheetId);for(let i of t)if(i.left<e.quantity&&e.quantity<=i.right)return 66;return 0}isRenameAllowed(e){return e.name&&e.name.trim().toLowerCase()?this.checkSheetName(e):10}renameSheet(e,t){const i=e.name;this.history.update("sheets",e.id,"name",t.trim());const n=Object.assign({},this.sheetIdsMapName);n[t]=e.id,delete n[i],this.history.update("sheetIdsMapName",n)}hideSheet(e){this.history.update("sheets",e,"isVisible",!1)}showSheet(e){this.history.update("sheets",e,"isVisible",!0)}duplicateSheet(e,t,i){const n=Ae(this.getSheet(e));n.id=t,n.name=i;for(let e=0;e<=n.numberOfCols;e++)for(let t=0;t<=n.rows.length;t++)n.rows[t]&&(n.rows[t].cells[e]=void 0);const o=this.orderedSheetIds.slice(),s=o.indexOf(e);o.splice(s+1,0,n.id),this.history.update("orderedSheetIds",o),this.history.update("sheets",Object.assign({},this.sheets,{[n.id]:n}));for(const t of Object.values(this.getters.getCells(e))){const{col:e,row:i}=this.getCellPosition(t.id);this.dispatch("UPDATE_CELL",{sheetId:n.id,col:e,row:i,content:t.content,format:t.format,style:t.style})}const r=Object.assign({},this.sheetIdsMapName);r[n.name]=n.id,this.history.update("sheetIdsMapName",r)}getDuplicateSheetName(e){return Oi(e,this.orderedSheetIds.map(this.getSheetName.bind(this)))}deleteSheet(e){const t=e.name,i=Object.assign({},this.sheets);delete i[e.id],this.history.update("sheets",i);const n=this.orderedSheetIds.slice(),o=n.indexOf(e.id);n.splice(o,1),this.history.update("orderedSheetIds",n);const s=Object.assign({},this.sheetIdsMapName);delete s[t],this.history.update("sheetIdsMapName",s)}removeColumns(e,t){t.sort(((e,t)=>t-e));for(let i of t)this.moveCellOnColumnsDeletion(e,i);const i=this.sheets[e.id].numberOfCols;this.history.update("sheets",e.id,"numberOfCols",i-t.length);const n=t.filter((t=>t<e.panes.xSplit)).length;n&&this.setPaneDivisions(e.id,e.panes.xSplit-n,"COL")}removeRows(e,t){t.sort(((e,t)=>t-e));for(let i of Le(t)){const t=i[i.length-1],n=i[0];this.moveCellOnRowsDeletion(e,t,n),this.updateRowsStructureOnDeletion(e,t,n)}const i=t.filter((t=>t<e.panes.ySplit)).length;i&&this.setPaneDivisions(e.id,e.panes.ySplit-i,"ROW")}addColumns(e,t,i,n){const o="before"===i?t:t+1;this.moveCellsOnAddition(e,o,n,"columns");const s=this.sheets[e.id].numberOfCols;this.history.update("sheets",e.id,"numberOfCols",s+n),o<e.panes.xSplit&&this.setPaneDivisions(e.id,e.panes.xSplit+n,"COL")}addRows(e,t,i,n){const o="before"===i?t:t+1;this.addEmptyRows(e,n),this.moveCellsOnAddition(e,o,n,"rows"),o<e.panes.ySplit&&this.setPaneDivisions(e.id,e.panes.ySplit+n,"ROW")}moveCellOnColumnsDeletion(e,t){for(let i=0;i<e.rows.length;i++){const n=e.rows[i];for(let o in n.cells){const s=Number(o),r=n.cells[o];r&&(s===t&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:s,row:i}),s>t&&this.setNewPosition(r,e.id,s-1,i))}}}moveCellsOnAddition(e,t,i,n){const o=[];for(let s=0;s<e.rows.length;s++){const r=e.rows[s];if("rows"!==n||s>=t)for(let a in r.cells){const l=Number(a),c=r.cells[a];c&&("rows"===n||l>=t)&&o.push({sheetId:e.id,cellId:c,col:l+("columns"===n?i:0),row:s+("rows"===n?i:0),type:"UPDATE_CELL_POSITION"})}}for(let e of o.reverse())this.updateCellPosition(e)}moveCellOnRowsDeletion(e,t,i){const n=i-t+1;for(let o=0;o<e.rows.length;o++){const s=e.rows[o];if(o>=t&&o<=i)for(let t in s.cells){const i=Number(t);s.cells[t]&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:i,row:o})}if(o>i)for(let t in s.cells){const i=Number(t),r=s.cells[t];r&&this.setNewPosition(r,e.id,i,o-n)}}}updateRowsStructureOnDeletion(e,t,i){const n=[],o=e.rows.map((e=>e.cells)).reverse();for(let s in e.rows){const e=Number(s);e>=t&&e<=i||n.push({cells:o.pop()})}this.history.update("sheets",e.id,"rows",n)}addEmptyRows(e,t){const i=e.rows.slice();for(let e=0;e<t;e++)i.push({cells:{}});this.history.update("sheets",e.id,"rows",i)}getImportedSheetSize(e){const t=Object.keys(e.cells).map(Ut);let i=e.rowNumber,n=e.colNumber;for(let{col:e,row:o}of t)i=Math.max(i,o+1),n=Math.max(n,e+1);return{rowNumber:i,colNumber:n}}checkSheetExists(e){return"CREATE_SHEET"!==e.type&&"sheetId"in e&&void 0===this.sheets[e.sheetId]?27:"CREATE_SHEET"===e.type&&void 0!==this.sheets[e.sheetId]?12:0}checkZones(e){const t=[];if("zone"in e&&t.push(e.zone),"target"in e&&Array.isArray(e.target)&&t.push(...e.target),"ranges"in e&&Array.isArray(e.ranges)){if(e.ranges.some((e=>!this.getters.tryGetSheet(e._sheetId))))return 27;t.push(...e.ranges.map((e=>this.getters.getRangeFromRangeData(e).zone)))}if(!t.every(Di))return 25;if(t.length&&"sheetId"in e){const i=this.getSheetZone(e.sheetId);return t.every((e=>Gi(e,i)))?0:18}return 0}}xv.getters=["getSheetName","tryGetSheetName","getSheet","tryGetSheet","getSheetIdByName","getSheetIds","getVisibleSheetIds","isSheetVisible","getEvaluationSheets","doesHeaderExist","getCell","getCellsInZone","getCellPosition","getColCells","getColsZone","getRowCells","getRowsZone","getNumberCols","getNumberRows","getNumberHeaders","getGridLinesVisibility","getNextSheetName","isEmpty","getSheetSize","getSheetZone","getPaneDivisions","checkElementsIncludeAllNonFrozenHeaders","getDuplicateSheetName"];class Rv{constructor(e,t,i){this.index=0,this.cells=e,this.getters=t,this.direction=i}next(){const e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:i,tooltip:n}=cn.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:i,tooltip:n,origin:{col:e.data.col,row:e.data.row}}}}class Iv extends Gg{constructor(){super(...arguments),this.lastCellSelected={}}allowDispatch(e){switch(e.type){case"AUTOFILL_SELECT":const t=this.getters.getActiveSheetId();return this.lastCellSelected.col=-1===e.col?this.lastCellSelected.col:Me(e.col,0,this.getters.getNumberCols(t)),this.lastCellSelected.row=-1===e.row?this.lastCellSelected.row:Me(e.row,0,this.getters.getNumberRows(t)),void 0!==this.lastCellSelected.col&&void 0!==this.lastCellSelected.row?0:46;case"AUTOFILL_AUTO":const i=this.getters.getSelectedZone();return i.top===i.bottom?0:1}return 0}handle(e){switch(e.type){case"AUTOFILL":this.autofill(!0);break;case"AUTOFILL_SELECT":this.select(e.col,e.row);break;case"AUTOFILL_AUTO":this.autofillAuto();break;case"AUTOFILL_CELL":this.autoFillMerge(e.originCol,e.originRow,e.col,e.row);const t=this.getters.getActiveSheetId();this.dispatch("UPDATE_CELL",{sheetId:t,col:e.col,row:e.row,style:e.style||null,content:e.content||"",format:e.format||""}),this.dispatch("SET_BORDER",{sheetId:t,col:e.col,row:e.row,border:e.border})}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||!this.steps||void 0===this.direction)return void(this.tooltip=void 0);const t=this.getters.getSelectedZone(),i=this.autofillZone;switch(this.direction){case"down":for(let n=t.left;n<=t.right;n++){const o=[];for(let e=t.top;e<=t.bottom;e++)o.push(Vt(n,e));const s=this.createGenerator(o);for(let t=i.top;t<=i.bottom;t++)this.computeNewCell(s,n,t,e)}break;case"up":for(let n=t.left;n<=t.right;n++){const o=[];for(let e=t.bottom;e>=t.top;e--)o.push(Vt(n,e));const s=this.createGenerator(o);for(let t=i.bottom;t>=i.top;t--)this.computeNewCell(s,n,t,e)}break;case"left":for(let n=t.top;n<=t.bottom;n++){const o=[];for(let e=t.right;e>=t.left;e--)o.push(Vt(e,n));const s=this.createGenerator(o);for(let t=i.right;t>=i.left;t--)this.computeNewCell(s,t,n,e)}break;case"right":for(let n=t.top;n<=t.bottom;n++){const o=[];for(let e=t.left;e<=t.right;e++)o.push(Vt(e,n));const s=this.createGenerator(o);for(let t=i.left;t<=i.right;t++)this.computeNewCell(s,t,n,e)}}e&&(this.autofillZone=void 0,this.selection.resizeAnchorZone(this.direction,this.steps),this.lastCellSelected={},this.direction=void 0,this.steps=0,this.tooltip=void 0)}select(e,t){const i=this.getters.getSelectedZone();if(Wi(e,t,i))this.autofillZone=void 0;else{switch(this.direction=this.getDirection(e,t),this.direction){case"up":this.saveZone(t,i.top-1,i.left,i.right),this.steps=i.top-t;break;case"down":this.saveZone(i.bottom+1,t,i.left,i.right),this.steps=t-i.bottom;break;case"left":this.saveZone(i.top,i.bottom,e,i.left-1),this.steps=i.left-e;break;case"right":this.saveZone(i.top,i.bottom,i.right+1,e),this.steps=e-i.right}this.autofill(!1)}}autofillAuto(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();let i=e.left,n=e.bottom;if(i>0){let e=this.getters.getCell(t,i-1,n);for(;e&&!e.isEmpty();)n+=1,e=this.getters.getCell(t,i-1,n)}if(n===e.bottom&&(i=e.right,i<=this.getters.getNumberCols(t))){let e=this.getters.getCell(t,i+1,n);for(;e&&!e.isEmpty();)n+=1,e=this.getters.getCell(t,i+1,n)}n!==e.bottom&&(this.select(e.left,n-1),this.autofill(!0))}computeNewCell(e,t,i,n){const{cellData:o,tooltip:s,origin:r}=e.next(),{content:a,style:l,border:c,format:h}=o;this.tooltip=s,n&&this.dispatch("AUTOFILL_CELL",{originCol:r.col,originRow:r.row,col:t,row:i,content:a,style:l,border:c,format:h})}getRule(e,t){const i=En.getAll().sort(((e,t)=>e.sequence-t.sequence)).find((i=>i.condition(e,t)));return i&&this.direction&&i.generateRule(e,t,this.direction)}createGenerator(e){const t=[],i=[],n=this.getters.getActiveSheetId();for(let t of e){const{col:e,row:o}=Ut(t),s=this.getters.getCell(n,e,o);i.push({col:e,row:o,cell:s,sheetId:n})}const o=i.map((e=>e.cell));for(let e of i){let i={type:"COPY_MODIFIER"};if(e&&e.cell){i=this.getRule(e.cell,o)||i}const{sheetId:n,col:s,row:r}=e,a=this.getters.getCellBorder(n,s,r)||void 0;t.push({data:{...e,border:a},rule:i})}return new Rv(t,this.getters,this.direction)}saveZone(e,t,i,n){this.autofillZone={top:e,bottom:t,left:i,right:n}}getDirection(e,t){const i=this.getters.getSelectedZone(),n={up:{number:i.top-t,value:"up"},down:{number:t-i.bottom,value:"down"},left:{number:i.left-e,value:"left"},right:{number:e-i.right,value:"right"}};if(1===Object.values(n).map((e=>e.number>0?1:0)).reduce(((e,t)=>e+t)))return Object.values(n).find((e=>e.number>0?1:0)).value;const o=n.up.number>0?"up":"down",s=n.left.number>0?"left":"right";return Math.abs(n[o].number)>=Math.abs(n[s].number)?n[o].value:n[s].value}autoFillMerge(e,t,i,n){const o=this.getters.getActiveSheet();if(this.getters.isInMerge(o.id,i,n)&&!this.getters.isInMerge(o.id,e,t)){const e=this.getters.getMerge(o.id,i,n);e&&this.dispatch("REMOVE_MERGE",{sheetId:o.id,target:[e]})}const s=this.getters.getMerge(o.id,e,t);(null==s?void 0:s.topLeft.col)===e&&(null==s?void 0:s.topLeft.row)===t&&this.dispatch("ADD_MERGE",{sheetId:o.id,target:[{top:n,bottom:n+s.bottom-s.top,left:i,right:i+s.right-s.left}]})}drawGrid(e){if(!this.autofillZone)return;const{ctx:t,thinLineWidth:i}=e,{x:n,y:o,width:s,height:r}=this.getters.getVisibleRect(this.autofillZone);s>0&&r>0&&(t.strokeStyle="black",t.lineWidth=i,t.setLineDash([3]),t.strokeRect(n,o,s,r),t.setLineDash([]))}}Iv.layers=[6],Iv.getters=["getAutofillTooltip"];class Tv extends Gg{handle(e){if("SUM_SELECTION"===e.type){const e=this.getters.getActiveSheetId(),{zones:t,anchor:i}=this.getters.getSelection();for(const n of t){const t=this.getAutomaticSums(e,n,i.cell);this.dispatchCellUpdates(e,t)}}}getAutomaticSums(e,t,i){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,i):this.sumData(e,t)}sumData(e,t){const i=this.dimensionsToSum(e,t),n=this.sumDimensions(e,t,i).filter((({zone:t})=>!this.getters.isEmpty(e,t)));return i.has("ROW")&&i.has("COL")&&n.push(this.sumTotal(t)),n}sumAdjacentData(e,t,i){const{col:n,row:o}=Wi(i.col,i.row,t)?i:{col:t.left,row:t.top},s=this.findAdjacentData(e,n,o);return s?this.getters.isSingleCellOrMerge(e,t)||Yi(Vi(s,t))?[{position:{col:n,row:o},zone:s}]:this.sumDimensions(e,Vi(s,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,i){const n=this.getters.getSheet(e),o=this.getters.getMainCellPosition(e,t,i),s=this.findSuitableZoneToSum(n,o.col,o.row);if(s)return this.getters.expandZone(e,s)}findSuitableZoneToSum(e,t,i){const n=this.getters.getCell(e.id,t,i-1),o=this.getters.getCell(e.id,t-1,i);if(this.isNumber(o)&&!this.isNumber(n))return this.findHorizontalZone(e,t,i);const s=this.findVerticalZone(e,t,i);if(this.isZoneValid(s))return s;const r=this.findHorizontalZone(e,t,i);return this.isZoneValid(r)?r:void 0}findVerticalZone(e,t,i){const n={top:0,bottom:i-1,left:t,right:t},o=this.reduceZoneStart(e,n,n.bottom);return{...n,top:o}}findHorizontalZone(e,t,i){const n={top:i,bottom:i,left:0,right:t-1},o=this.reduceZoneStart(e,n,n.right);return{...n,left:o}}reduceZoneStart(e,t,i){const n=this.getters.getCellsInZone(e.id,t),o=$e(i,-1,-1),s=lt(o.filter((e=>{var t;return n[e]&&!(null===(t=n[e])||void 0===t?void 0:t.isAutoSummable)}))),r=Le(o.filter((e=>this.isNumber(n[e]))))[0]||[];return lt(r)<s?1/0:ct(r)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){var t;return(null==e?void 0:e.evaluated.type)===hn.number&&!(null===(t=e.evaluated.format)||void 0===t?void 0:t.match(Y))}isZoneValid(e){return e.bottom>=e.top&&e.right>=e.left}lastColIsEmpty(e,t){return this.getters.isEmpty(e,{...t,left:t.right})}lastRowIsEmpty(e,t){return this.getters.isEmpty(e,{...t,top:t.bottom})}dimensionsToSum(e,t){const i=new Set;return Yi(t)?(i.add(1===ji(t).width?"COL":"ROW"),i):(this.lastColIsEmpty(e,t)&&i.add("ROW"),this.lastRowIsEmpty(e,t)&&i.add("COL"),0===i.size&&i.add("COL"),i)}sumDimensions(e,t,i){return[...i.has("COL")?this.sumColumns(t,e):[],...i.has("ROW")?this.sumRows(t,e):[]]}sumTotal(e){const{bottom:t,right:i}=e;return{position:{col:i,row:t},zone:{...e,top:t,right:i-1}}}sumColumns(e,t){const i=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,i.bottom-1)},Xi(i).map((t=>({position:t,zone:{...e,right:t.col,left:t.col}})))}sumRows(e,t){const i=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,i.right-1)},Xi(i).map((t=>({position:t,zone:{...e,top:t.row,bottom:t.row}})))}dispatchCellUpdates(e,t){for(const i of t){const{col:t,row:n}=i.position;this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:n,content:`=SUM(${this.getters.zoneToXC(e,i.zone)})`})}}nextEmptyRow(e,t){let i=t.bottom+1;const{left:n,right:o}=t;for(;!this.getters.isEmpty(e,{bottom:i,top:i,left:n,right:o});)i++;return{...t,top:i,bottom:i}}nextEmptyCol(e,t){let i=t.right+1;const{top:n,bottom:o}=t;for(;!this.getters.isEmpty(e,{left:i,right:i,top:n,bottom:o});)i++;return{...t,left:i,right:i}}transpose(e){return new Set([...e.values()].map((e=>"COL"===e?"ROW":"COL")))}}Tv.getters=["getAutomaticSums"];class Av extends Gg{allowDispatch(e){if("OPEN_CELL_POPOVER"===e.type){try{to.get(e.popoverType)}catch(e){return 73}return 0}return 0}handle(e){switch(e.type){case"ACTIVATE_SHEET":case"CLOSE_CELL_POPOVER":this.persistentPopover=void 0;break;case"OPEN_CELL_POPOVER":this.persistentPopover={col:e.col,row:e.row,type:e.popoverType}}}getCellPopover({col:e,row:t}){var i,n;const o=this.getters.getActiveSheetId();if(this.persistentPopover&&this.getters.isVisibleInViewport(o,this.persistentPopover.col,this.persistentPopover.row)){const e=this.getters.getMainCellPosition(o,this.persistentPopover.col,this.persistentPopover.row),t=null===(n=(i=to.get(this.persistentPopover.type)).onOpen)||void 0===n?void 0:n.call(i,e,this.getters);return(null==t?void 0:t.isOpen)?{...t,...this.computePopoverProps(this.persistentPopover,t.cellCorner)}:{isOpen:!1}}if(void 0===e||void 0===t||!this.getters.isVisibleInViewport(o,e,t))return{isOpen:!1};const s=this.getters.getMainCellPosition(o,e,t),r=to.getAll().map((e=>{var t;return null===(t=e.onHover)||void 0===t?void 0:t.call(e,s,this.getters)})).find((e=>null==e?void 0:e.isOpen));return(null==r?void 0:r.isOpen)?{...r,...this.computePopoverProps(s,r.cellCorner)}:{isOpen:!1}}getPersistentPopoverTypeAtPosition({col:e,row:t}){if(this.persistentPopover&&this.persistentPopover.col===e&&this.persistentPopover.row===t)return this.persistentPopover.type}computePopoverProps({col:e,row:t},i){const{width:n,height:o}=this.getters.getVisibleRect(en({col:e,row:t}));return{coordinates:this.computePopoverPosition({col:e,row:t},i),cellWidth:-n,cellHeight:-o}}computePopoverPosition({col:e,row:t},i){const n=this.getters.getActiveSheetId(),o=this.getters.getMerge(n,e,t);o&&(e="TopRight"===i?o.right:o.left,t="TopRight"===i?o.top:o.bottom);const{x:s,y:r,width:a,height:l}=this.getters.getVisibleRect(en({col:e,row:t}));switch(i){case"BottomLeft":return{x:s,y:r+l};case"TopRight":return{x:s+a,y:r}}}}Av.getters=["getCellPopover","getPersistentPopoverTypeAtPosition"],Av.modes=["normal"];class Nv{constructor(e,t,i,n){this.getters=t,this.dispatch=i,this.selection=n,this.operation=e,this.sheetId=t.getActiveSheetId()}isCutAllowed(e){return 0}isPasteAllowed(e,t){return 0}addMissingDimensions(e,t,i,n){const o=this.getters.getActiveSheetId(),s=t+n-this.getters.getNumberRows(o);s>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"ROW",base:this.getters.getNumberRows(o)-1,sheetId:o,quantity:s,position:"after"});const r=e+i-this.getters.getNumberCols(o);r>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"COL",base:this.getters.getNumberCols(o)-1,sheetId:o,quantity:r,position:"after"})}isColRowDirtyingClipboard(e,t){return!1}drawClipboard(e){}}class Ov extends Nv{constructor(e,t,i,n,o){if(super(t,i,n,o),!e.length)return this.cells=[[]],this.zones=[],void(this.copiedTables=[]);const s=new Set(e.map((e=>e.left))),r=new Set(e.map((e=>e.right))),a=new Set(e.map((e=>e.top))),l=new Set(e.map((e=>e.bottom))),c=1===a.size&&1===l.size||1===s.size&&1===r.size?function(e){return e.reduce(((e,t)=>{const i=e.length;for(let n=0;n<i;n++)if(Hi(e[n],t))return e[n]=Vi(e[n],t),e;return e[i]=t,e}),[])}(e):[e[e.length-1]],h=c.map((e=>Xi(e))).flat(),d=[...new Set(h.map((e=>e.col)))].sort(((e,t)=>e-t)),u=[...new Set(h.map((e=>e.row)))].sort(((e,t)=>e-t)),g=[],p=i.getActiveSheetId();for(let e of u){let t=[];for(let n of d)t.push({cell:i.getCell(p,n,e),border:i.getCellBorder(p,n,e)||void 0,position:{col:n,row:e,sheetId:p}});g.push(t)}const m=[];for(const t of e)for(const e of this.getters.getFilterTablesInZone(p,t)){const t=[];for(const i of $e(e.zone.left,e.zone.right+1))t.push(this.getters.getFilterValues(p,i,e.zone.top));m.push({filtersValues:t,zone:e.zone})}this.cells=g,this.zones=c,this.copiedTables=m}isCutAllowed(e){return 1!==e.length?19:0}isPasteAllowed(e,t){const i=this.getters.getActiveSheetId();if("CUT"===this.operation&&void 0!==(null==t?void 0:t.pasteOption))return 21;if(e.length>1&&(this.cells.length>1||this.cells[0].length>1))return 20;const n=this.cells.length,o=this.cells[0].length;for(let t of this.getPasteZones(e))if(this.getters.doesIntersectMerge(i,t)&&(e.length>1||!this.getters.isSingleCellOrMerge(i,e[0])||n*o!=1))return 2;const{xSplit:s,ySplit:r}=this.getters.getPaneDivisions(i);for(const t of this.getPasteZones(e))if(t.left<s&&t.right>=s||t.top<r&&t.bottom>=r)return 76;return 0}paste(e,t){"COPY"===this.operation?this.pasteFromCopy(e,t):this.pasteFromCut(e,t);const i=this.cells.length,n=this.cells[0].length,o="CUT"===this.operation;(null==t?void 0:t.selectTarget)&&this.selectPastedZone(n,i,o,e)}pasteFromCopy(e,t){if(1===e.length){const i=this.cells.length,n=this.cells[0].length,o=this.pastedZones(e,n,i);for(const e of o)this.pasteZone(e.left,e.top,t)}else for(const i of e)for(let e=i.left;e<=i.right;e++)for(let n=i.top;n<=i.bottom;n++)this.pasteZone(e,n,t);void 0===(null==t?void 0:t.pasteOption)&&this.pasteCopiedTables(e)}pasteFromCut(e,t){this.clearClippedZones();const i=e[0];this.pasteZone(i.left,i.top,t),this.dispatch("MOVE_RANGES",{target:this.zones,sheetId:this.sheetId,targetSheetId:this.getters.getActiveSheetId(),col:i.left,row:i.top});for(const e of this.copiedTables)this.dispatch("REMOVE_FILTER_TABLE",{sheetId:this.sheetId,target:[e.zone]});this.pasteCopiedTables(e)}pastedZones(e,t,i){const n=e[0],o=Math.max(1,Math.floor((n.right+1-n.left)/t)),s=Math.max(1,Math.floor((n.bottom+1-n.top)/i)),r=[];for(let e=0;e<o;e++)for(let o=0;o<s;o++){const s=n.top+o*i,a=n.left+e*t;r.push({left:a,top:s,bottom:s+i-1,right:a+t-1})}return r}getPasteZones(e){const t=this.cells;if(!t.length||!t[0].length)return e;const i=[],n=t.length,o=t[0].length,s=e[e.length-1],r=s.left,a=s.top,l=Math.max(1,Math.floor((s.right+1-r)/o)),c=Math.max(1,Math.floor((s.bottom+1-a)/n));for(let e=1;e<=l;e++)for(let t=1;t<=c;t++)i.push({left:r,top:a,right:r-1+e*o,bottom:a-1+t*n});return i}selectPastedZone(e,t,i,n){const o=n[0],s=o.left,r=o.top;if(t>1||e>1||i){const o=this.pastedZones(n,e,t),a=i?o[0]:Vi(...o);this.selection.selectZone({cell:{col:s,row:r},zone:a})}}clearClippedZones(){for(const e of this.cells)for(const t of e)t.cell&&this.dispatch("CLEAR_CELL",t.position);this.dispatch("CLEAR_FORMATTING",{sheetId:this.sheetId,target:this.zones})}pasteZone(e,t,i){const n=this.cells.length,o=this.cells[0].length,s="onlyValue"!==(null==i?void 0:i.pasteOption)&&(null==i?void 0:i.shouldPasteCF),r=this.getters.getActiveSheetId();this.addMissingDimensions(o,n,e,t);for(let a=0;a<n;a++){const n=this.cells[a];for(let l=0;l<o;l++){const o=n[l],c={col:e+l,row:t+a,sheetId:r};this.pasteMergeIfExist(o.position,c,this.operation),this.pasteCell(o,c,this.operation,i),s&&this.dispatch("PASTE_CONDITIONAL_FORMAT",{origin:o.position,target:c,operation:this.operation})}}}pasteCell(e,t,i,n){const{sheetId:o,col:s,row:r}=t,a=this.getters.getCell(o,s,r);if("onlyValue"!==(null==n?void 0:n.pasteOption)){const t=this.getters.getCellBorder(o,s,r),i=e.border,n={top:(null==t?void 0:t.top)||(null==i?void 0:i.top),bottom:(null==t?void 0:t.bottom)||(null==i?void 0:i.bottom),left:(null==t?void 0:t.left)||(null==i?void 0:i.left),right:(null==t?void 0:t.right)||(null==i?void 0:i.right)};this.dispatch("SET_BORDER",{sheetId:o,col:s,row:r,border:n})}if(e.cell){if("onlyFormat"===(null==n?void 0:n.pasteOption))return void this.dispatch("UPDATE_CELL",{...t,style:e.cell.style,format:e.cell.evaluated.format||e.cell.format});if("onlyValue"===(null==n?void 0:n.pasteOption)){const i=Qt(e.cell.evaluated.value);return void this.dispatch("UPDATE_CELL",{...t,content:i})}let a=e.cell.content;if(e.cell.isFormula()&&"COPY"===i){const t=s-e.position.col,n=r-e.position.row;a=this.getUpdatedContent(o,e.cell,t,n,i)}this.dispatch("UPDATE_CELL",{...t,content:a,style:e.cell.style||null,format:e.cell.format})}else a&&("onlyValue"===(null==n?void 0:n.pasteOption)?this.dispatch("UPDATE_CELL",{...t,content:""}):"onlyFormat"===(null==n?void 0:n.pasteOption)?this.dispatch("UPDATE_CELL",{...t,style:null,format:""}):this.dispatch("CLEAR_CELL",t))}getUpdatedContent(e,t,i,n,o){const s=this.getters.createAdaptedRanges(t.dependencies,i,n,e);return this.getters.buildFormulaContent(e,t,s)}pasteMergeIfExist(e,t,i){let{sheetId:n,col:o,row:s}=e;const{col:r,row:a}=this.getters.getMainCellPosition(n,o,s);if(r===o&&a===s){const e=this.getters.getMerge(n,o,s);if(!e)return;"CUT"===i&&this.dispatch("REMOVE_MERGE",{sheetId:n,target:[e]}),({sheetId:n,col:o,row:s}=t),this.dispatch("ADD_MERGE",{sheetId:n,force:!0,target:[{left:o,top:s,right:o+e.right-e.left,bottom:s+e.bottom-e.top}]})}}pasteCopiedTables(e){const t=this.getters.getActiveSheetId(),i=e[0],n=this.zones[0],o=[i.left-n.left,i.top-n.top];for(const e of this.copiedTables){const i=Ki(e.zone,"both","MOVE",o);this.dispatch("CREATE_FILTER_TABLE",{sheetId:t,target:[i]});for(const n of $e(0,e.filtersValues.length))this.dispatch("UPDATE_FILTER",{sheetId:t,col:i.left+n,row:i.top,values:e.filtersValues[n]})}}getClipboardContent(){return this.cells.map((e=>e.map((e=>e.cell?this.getters.getCellText(e.cell,this.getters.shouldShowFormulas()):"")).join("\t"))).join("\n")||"\t"}isColRowDirtyingClipboard(e,t){if(!this.zones)return!1;for(let i of this.zones){if("COL"===t&&e<=i.right)return!0;if("ROW"===t&&e<=i.bottom)return!0}return!1}drawClipboard(e){const{ctx:t,thinLineWidth:i}=e;if(this.sheetId===this.getters.getActiveSheetId()&&this.zones&&this.zones.length){t.setLineDash([8,5]),t.strokeStyle=E,t.lineWidth=3.3*i;for(const e of this.zones){const{x:i,y:n,width:o,height:s}=this.getters.getVisibleRect(e);o>0&&s>0&&t.strokeRect(i,n,o,s)}}}}class Mv{constructor(e,t,i){this.getters=t,this.dispatch=i,this.sheetId=t.getActiveSheetId();const n=t.getSelectedFigureId();if(!n)throw new Error("No figure selected");const o=t.getFigure(this.sheetId,n);if(!o)throw new Error(`No figure for the given id: ${n}`);this.copiedFigure={...o};const s=t.getChart(n);if(!s)throw new Error(`No chart for the given id: ${n}`);this.copiedChart=s.copyInSheetId(this.sheetId),this.operation=e}isCutAllowed(e){return 0}isPasteAllowed(e,t){return 0===e.length?74:void 0!==(null==t?void 0:t.pasteOption)?22:0}paste(e){const t=this.getters.getActiveSheetId(),i={x:this.getters.getColDimensions(t,e[0].left).start,y:this.getters.getRowDimensions(t,e[0].top).start},n=this.copiedChart.copyInSheetId(t),o=(new Mi).smallUuid();this.dispatch("CREATE_CHART",{id:o,sheetId:t,position:i,size:{height:this.copiedFigure.height,width:this.copiedFigure.width},definition:n.getDefinition()}),"CUT"===this.operation&&this.dispatch("DELETE_FIGURE",{sheetId:this.copiedChart.sheetId,id:this.copiedFigure.id}),this.dispatch("SELECT_FIGURE",{id:o})}getClipboardContent(){return"\t"}isColRowDirtyingClipboard(e,t){return!1}drawClipboard(e){}}class _v extends Nv{constructor(e,t,i,n){super("COPY",t,i,n),this.values=e.replace(/\r/g,"").split("\n").map((e=>e.split("\t")))}isPasteAllowed(e,t){const i=this.getters.getActiveSheetId(),n=this.getPasteZone(e);return this.getters.doesIntersectMerge(i,n)?2:0}paste(e){const t=this.values,i=this.getPasteZone(e),{left:n,top:o}=i,{width:s,height:r}=ji(i),a=this.getters.getActiveSheetId();this.addMissingDimensions(s,r,n,o);for(let e=0;e<t.length;e++)for(let i=0;i<t[e].length;i++)this.dispatch("UPDATE_CELL",{row:o+e,col:n+i,content:t[e][i],sheetId:a});const l={left:n,top:o,right:n+s-1,bottom:o+r-1};this.selection.selectZone({cell:{col:n,row:o},zone:l})}getClipboardContent(){return this.values.map((e=>e.join("\t"))).join("\n")}getPasteZone(e){const t=this.values.length,i=Math.max(...this.values.map((e=>e.length))),{left:n,top:o}=e[0];return{top:o,left:n,bottom:o+t-1,right:n+i-1}}}class Fv extends Gg{constructor(){super(...arguments),this.status="invisible",this._isPaintingFormat=!1}allowDispatch(e){switch(e.type){case"CUT":const t=this.getters.getSelectedZones();return this.getClipboardState(t,e.type).isCutAllowed(t);case"PASTE":if(!this.state)return 23;const i=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);return this.state.isPasteAllowed(e.target,{pasteOption:i});case"PASTE_FROM_OS_CLIPBOARD":return new _v(e.text,this.getters,this.dispatch,this.selection).isPasteAllowed(e.target);case"INSERT_CELL":{const{cut:t,paste:i}=this.getInsertCellsTargets(e.zone,e.shiftDimension);return this.getClipboardStateForCopyCells(t,"CUT").isPasteAllowed(i)}case"DELETE_CELL":{const{cut:t,paste:i}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);return this.getClipboardStateForCopyCells(t,"CUT").isPasteAllowed(i)}}return 0}handle(e){var t,i,n,o;switch(e.type){case"COPY":case"CUT":const s=this.getters.getSelectedZones();this.state=this.getClipboardState(s,e.type),this.status="visible";break;case"PASTE":if(!this.state)break;const r=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);this._isPaintingFormat=!1,this.state.paste(e.target,{pasteOption:r,shouldPasteCF:!0,selectTarget:!0}),"CUT"===this.state.operation&&(this.state=void 0),this.status="invisible";break;case"DELETE_CELL":{const{cut:t,paste:i}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);if(!Di(t[0])){for(const{col:t,row:i}of Xi(e.zone))this.dispatch("CLEAR_CELL",{col:t,row:i,sheetId:this.getters.getActiveSheetId()});break}this.getClipboardStateForCopyCells(t,"CUT").paste(i);break}case"INSERT_CELL":{const{cut:t,paste:i}=this.getInsertCellsTargets(e.zone,e.shiftDimension);this.getClipboardStateForCopyCells(t,"CUT").paste(i);break}case"ADD_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(t=this.state)||void 0===t?void 0:t.operation)||e.sheetId!==(null===(i=this.state)||void 0===i?void 0:i.sheetId))return;this.state.isColRowDirtyingClipboard("before"===e.position?e.base:e.base+1,e.dimension)&&(this.state=void 0);break;case"REMOVE_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(n=this.state)||void 0===n?void 0:n.operation)||e.sheetId!==(null===(o=this.state)||void 0===o?void 0:o.sheetId))return;for(let t of e.elements){if(this.state.isColRowDirtyingClipboard(t,e.dimension)){this.state=void 0;break}}this.status="invisible";break;case"PASTE_FROM_OS_CLIPBOARD":new _v(e.text,this.getters,this.dispatch,this.selection).paste(e.target),this.status="invisible";break;case"ACTIVATE_PAINT_FORMAT":{const e=this.getters.getSelectedZones();this.state=this.getClipboardStateForCopyCells(e,"COPY"),this._isPaintingFormat=!0,this.status="visible";break}default:mn(e)&&(this.status="invisible")}}getClipboardContent(){var e;return(null===(e=this.state)||void 0===e?void 0:e.getClipboardContent())||"\t"}isCutOperation(){return!!this.state&&"CUT"===this.state.operation}isPaintingFormat(){return this._isPaintingFormat}getDeleteCellsTargets(e,t){const i=this.getters.getActiveSheetId();let n;return n="COL"===t?{...e,left:e.right+1,right:this.getters.getNumberCols(i)-1}:{...e,top:e.bottom+1,bottom:this.getters.getNumberRows(i)-1},{cut:[n],paste:[e]}}getInsertCellsTargets(e,t){const i=this.getters.getActiveSheetId();let n,o;return"COL"===t?(n={...e,right:this.getters.getNumberCols(i)-1},o={...e,left:e.right+1,right:e.right+1}):(n={...e,bottom:this.getters.getNumberRows(i)-1},o={...e,top:e.bottom+1,bottom:this.getters.getNumberRows(i)-1}),{cut:[n],paste:[o]}}getClipboardStateForCopyCells(e,t){return new Ov(e,t,this.getters,this.dispatch,this.selection)}getClipboardState(e,t){return this.getters.getSelectedFigureId()?new Mv(t,this.getters,this.dispatch):new Ov(e,t,this.getters,this.dispatch,this.selection)}drawGrid(e){"visible"===this.status&&this.state&&this.state.drawClipboard(e)}}Fv.layers=[2],Fv.getters=["getClipboardContent","isCutOperation","isPaintingFormat"];class Dv extends Gg{constructor(){super(...arguments),this.customColors=new Set,this.shouldUpdateColors=!1}handle(e){switch(e.type){case"UPDATE_CELL":case"UPDATE_CHART":case"CREATE_CHART":case"ADD_CONDITIONAL_FORMAT":this.shouldUpdateColors=!0}}finalize(){if(this.shouldUpdateColors){this.shouldUpdateColors=!1;for(const e of this.getCustomColors())this.tryToAddColor(e)}}getCustomColors(){let e=[];for(const t of this.getters.getSheetIds()){const i=Object.values(this.getters.getCells(t));e=e.concat(this.getColorsFromCells(i),this.getFormattingColors(t),this.getChartColors(t))}return function(e){const t=[{leadColor:bt(255,0,0),colors:[]},{leadColor:bt(255,128,0),colors:[]},{leadColor:bt(128,128,0),colors:[]},{leadColor:bt(128,255,0),colors:[]},{leadColor:bt(0,255,0),colors:[]},{leadColor:bt(0,255,128),colors:[]},{leadColor:bt(0,255,255),colors:[]},{leadColor:bt(0,127,255),colors:[]},{leadColor:bt(0,0,255),colors:[]},{leadColor:bt(127,0,255),colors:[]},{leadColor:bt(128,0,128),colors:[]},{leadColor:bt(255,0,128),colors:[]}];for(const i of e.map(Et)){let e=500,n=0;t.forEach(((t,o)=>{const s=(r=i,a=t.leadColor,Math.sqrt(Math.pow(r.r-a.r,2)+Math.pow(r.g-a.g,2)+Math.pow(r.b-a.b,2)));var r,a;e>s&&(e=s,n=o)})),t[n].colors.push(i)}return t.map((e=>e.colors.sort(((e,t)=>yt(e).s-yt(t).s)))).flat().map(Ct)}([...new Set([...new Set([...e,...this.customColors])].filter(ft).map(mt))]).filter((e=>!N.includes(e)))}getColorsFromCells(e){var t,i;const n=new Set;for(const o of e)(null===(t=o.style)||void 0===t?void 0:t.textColor)&&n.add(o.style.textColor),(null===(i=o.style)||void 0===i?void 0:i.fillColor)&&n.add(o.style.fillColor);return[...n]}getFormattingColors(e){const t=this.getters.getConditionalFormats(e),i=[];for(const e of t){const t=e.rule;"CellIsRule"===t.type?(i.push(t.style.textColor),i.push(t.style.fillColor)):"ColorScaleRule"===t.type&&(i.push(gt(t.minimum.color)),i.push(t.midpoint?gt(t.midpoint.color):void 0),i.push(gt(t.maximum.color)))}return i.filter(Xe)}getChartColors(e){const t=this.getters.getChartIds(e).map((e=>this.getters.getChart(e)));let i=new Set;for(let e of t){if(void 0===e)continue;const t=e.getDefinition().background;switch(void 0!==t&&i.add(t),e.type){case"gauge":const t=e.sectionRule.colors;i.add(t.lowerColor),i.add(t.middleColor),i.add(t.upperColor);break;case"scorecard":const n=e;i.add(n.baselineColorDown),i.add(n.baselineColorUp)}}return[...i]}tryToAddColor(e){const t=mt(e);e&&!N.includes(t)&&this.customColors.add(t)}}Dv.getters=["getCustomColors"];const kv=Yu.mapping;class $v extends Gg{constructor(e,t,i,n,o){super(e,t,i,n,o),this.isUpToDate=!1,this.evalContext=n.evalContext}handle(e){switch(dn.has(e.type)&&(this.isUpToDate=!1),e.type){case"UPDATE_CELL":("content"in e||"format"in e)&&(this.isUpToDate=!1);break;case"EVALUATE_CELLS":this.evaluate()}}finalize(){this.isUpToDate||this.evaluate()}evaluateFormula(e,t=this.getters.getActiveSheetId()){try{const i=Ug(e),n=this.getCompilationParameters((()=>{})),o=[];for(let e of i.dependencies)o.push(this.getters.getRangeFromSheetXC(t,e));return i.execute(o,...n).value}catch(e){return e instanceof c?e.errorType:a.GenericError}}getRangeFormattedValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[]:this.getters.getCellsInZone(t.id,e.zone).map((e=>(null==e?void 0:e.formattedValue)||""))}getRangeValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[]:this.getters.getCellsInZone(t.id,e.zone).map((e=>null==e?void 0:e.evaluated.value))}*getAllCells(){for(const e of this.getters.getSheetIds()){const t=this.getters.getCells(e);for(const e in t)yield t[e]}}evaluate(){const e=this.getCompilationParameters(i),t={};for(const e of this.getAllCells())i(e);function i(i){if(!i.isFormula())return;const n=i.id,o=tt((()=>{if(e[2].__originCellXC=()=>{const t=e[2].getters.getCellPosition(n);return Vt(t.col,t.row)},n in t)return null===t[n]?new d:i.evaluated;t[n]=null;try{const o=i.compiledFormula.execute(i.dependencies,...e);if(t[n]=!0,Array.isArray(o.value))throw new Error(s("This formula depends on invalid values"));return{value:o.value,format:i.format||o.format}}catch(i){return t[n]=!0,function(t){t instanceof Error||(t=new Error(t));const i=(null==t?void 0:t.errorType)||a.GenericError,n=e[2].__lastFnCalled||"";return new c(i,t.message.replace("[[FUNCTION_NAME]]",n),void 0!==t.logLevel?t.logLevel:l.error)}(i)}}));i.assignEvaluation(o)}this.isUpToDate=!0}getCompilationParameters(e){const t=Object.assign(Object.create(kv),this.evalContext,{getters:this.getters}),i=this.getters;function n(e){if(e.evaluated.type===hn.error)throw new c(e.evaluated.value,e.evaluated.error.message,e.evaluated.error.logLevel);return e.evaluated}const o={};function r(e){if(!Di(e.zone))throw new u;if(e.invalidSheetName)throw new Error(s("Invalid sheet name: %s",e.invalidSheetName))}return[function(e,t,o,a){if(r(e),t)return{value:ki(e.zone)};if(e.zone.bottom!==e.zone.top||e.zone.left!==e.zone.right)throw new Error(a?s("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",o.toString(),a.toString()):s("Function %s expects its parameters to be single values or single cell references, not ranges.",o.toString()));return function(e){let t;if(!i.tryGetSheet(e.sheetId))throw new Error(s("Invalid sheet name"));return t=i.getCell(e.sheetId,e.zone.left,e.zone.top),!t||t.isEmpty()?{value:null,format:null==t?void 0:t.format}:n(t)}(e)},function(e){r(e);const s=e.sheetId,a=i.getSheetZone(s),l=zi(e.zone,a);if(!l)return[[]];const{top:c,left:h,bottom:d,right:u}=l,g=`${s}-${c}-${h}-${d}-${u}`;if(g in o)return o[g];const p=new Array(u-h+1);for(let i=h;i<=u;i++){const o=new Array(d-c+1);for(let s=c;s<=d;s++){const r=t.getters.getCell(e.sheetId,i,s);o[s-c]=r?n(r):void 0}p[i-h]=o}return o[g]=p,p},t]}}$v.getters=["evaluateFormula","getRangeFormattedValues","getRangeValues"];class Lv extends Gg{constructor(){super(...arguments),this.charts={},this.createRuntimeChart=function(e){const t=rn.getAll();return function(i){const n=t.find((e=>e.match(i.type)));if(!n)throw new Error("No runtime builder for this chart.");return n.getChartRuntime(i,e)}}(this.getters)}handle(e){if(dn.has(e.type)||un.has(e.type)||"EVALUATE_CELLS"===e.type||"UPDATE_CELL"===e.type)for(const e in this.charts)this.charts[e]=void 0;switch(e.type){case"UPDATE_CHART":case"CREATE_CHART":case"DELETE_FIGURE":this.charts[e.id]=void 0;break;case"DELETE_SHEET":for(let e in this.charts)this.getters.isChartDefined(e)||(this.charts[e]=void 0)}}getChartRuntime(e){if(!this.charts[e]){const t=this.getters.getChart(e);if(!t)throw new Error(`No chart for the given id: ${e}`);this.charts[e]=this.createRuntimeChart(t)}return this.charts[e]}getStyleOfSingleCellChart(e,t){if(e)return{background:e,fontColor:Rs(e)};if(!t)return{background:w,fontColor:Rs(w)};const i=t.zone.left,n=t.zone.top,o=t.sheetId,s=this.getters.getCellComputedStyle(o,i,n),r=s.fillColor||w;return{background:r,fontColor:s.textColor||Rs(r)}}}Lv.getters=["getChartRuntime","getStyleOfSingleCellChart"];class Pv extends Gg{constructor(){super(...arguments),this.isStale=!0,this.computedStyles={},this.computedIcons={},this.uuidGenerator=new Mi,this.rulePredicate={CellIsRule:(e,t)=>{if(e&&e.evaluated.type===hn.error)return!1;const i=t.values.map(Hp);switch(t.operator){case"IsEmpty":return!Xe(e)||""===e.evaluated.value.toString().trim();case"IsNotEmpty":return Xe(e)&&""!==e.evaluated.value.toString().trim();case"BeginsWith":return!(!e&&""===i[0])&&(Xe(e)&&(null==e?void 0:e.evaluated.value.toString().startsWith(i[0].toString())));case"EndsWith":return!(!e&&""===i[0])&&(Xe(e)&&e.evaluated.value.toString().endsWith(i[0].toString()));case"Between":return Xe(e)&&e.evaluated.value>=i[0]&&e.evaluated.value<=i[1];case"NotBetween":return!(Xe(e)&&e.evaluated.value>=i[0]&&e.evaluated.value<=i[1]);case"ContainsText":return Xe(e)&&e.evaluated.value.toString().indexOf(i[0].toString())>-1;case"NotContains":return!Xe(e)||!e.evaluated.value||-1==e.evaluated.value.toString().indexOf(i[0].toString());case"GreaterThan":return Xe(e)&&e.evaluated.value>i[0];case"GreaterThanOrEqual":return Xe(e)&&e.evaluated.value>=i[0];case"LessThan":return Xe(e)&&e.evaluated.value<i[0];case"LessThanOrEqual":return Xe(e)&&e.evaluated.value<=i[0];case"NotEqual":return!(!Xe(e)&&""===i[0])&&(Xe(e)&&e.evaluated.value!==i[0]);case"Equal":return!e&&""===i[0]||Xe(e)&&e.evaluated.value===i[0];default:console.warn(s("Not implemented operator %s for kind of conditional formatting: %s",t.operator,t.type))}return!1}}}handle(e){switch((un.has(e.type)||"UPDATE_CELL"===e.type&&"content"in e)&&(this.isStale=!0),e.type){case"ACTIVATE_SHEET":const t=e.sheetIdTo;this.computedStyles[t]=this.computedStyles[t]||{},this.computedIcons[t]=this.computedIcons[t]||{},this.isStale=!0;break;case"AUTOFILL_CELL":const i=this.getters.getActiveSheetId(),n=this.getters.getRulesByCell(i,e.originCol,e.originRow);for(const t of n)this.adaptRules(i,t,[Vt(e.col,e.row)],[]);break;case"PASTE_CONDITIONAL_FORMAT":this.pasteCf(e.origin,e.target,e.operation)}}finalize(){this.isStale&&(this.computeStyles(),this.isStale=!1)}getCellComputedStyle(e,t,i){var n;const o=this.getters.getCell(e,t,i),s=this.computedStyles[e],r=s&&(null===(n=s[t])||void 0===n?void 0:n[i]),a={...null==o?void 0:o.style,...r};return this.getters.isFilterHeader(e,t,i)&&(a.bold=!0),a}getConditionalIcon(e,t){var i;const n=this.getters.getActiveSheetId(),o=this.computedIcons[n];return o&&(null===(i=o[e])||void 0===i?void 0:i[t])}computeStyles(){var e;const t=this.getters.getActiveSheetId();this.computedStyles[t]={},this.computedIcons[t]={};const i=this.computedStyles[t];for(let n of this.getters.getConditionalFormats(t).reverse())switch(n.rule.type){case"ColorScaleRule":for(let e of n.ranges)this.applyColorScale(e,n.rule);break;case"IconSetRule":for(let e of n.ranges)this.applyIcon(e,n.rule);break;default:for(let o of n.ranges){const s=this.getters.getRangeFromSheetXC(t,o).zone;for(let o=s.top;o<=s.bottom;o++)for(let r=s.left;r<=s.right;r++){const s=this.rulePredicate[n.rule.type];let a=this.getters.getCell(t,r,o);s&&s(a,n.rule)&&(i[r]||(i[r]=[]),i[r][o]=Object.assign((null===(e=i[r])||void 0===e?void 0:e[o])||{},n.rule.style))}}}}parsePoint(e,t,i){const n=this.getters.getActiveSheetId(),o=this.getters.getRangeValues(this.getters.getRangeFromSheetXC(n,e)).filter(this.isCellValueNumber);switch(t.type){case"value":return"max"===i?lt(o):ct(o);case"number":return Number(t.value);case"percentage":const e=ct(o);return e+(lt(o)-e)*Number(t.value)/100;case"percentile":return yi(o,Number(t.value)/100,!0);case"formula":const n=t.value&&this.getters.evaluateFormula(t.value);return"number"==typeof n?n:null;default:return null}}applyIcon(e,t){const i=this.parsePoint(e,t.lowerInflectionPoint),n=this.parsePoint(e,t.upperInflectionPoint);if(null===i||null===n||i>n)return;const o=this.getters.getActiveSheetId(),s=this.getters.getRangeFromSheetXC(o,e).zone,r=this.computedIcons[o],a=[t.icons.upper,t.icons.middle,t.icons.lower];for(let e=s.top;e<=s.bottom;e++)for(let l=s.left;l<=s.right;l++){const s=this.getters.getCell(o,l,e);if((null==s?void 0:s.evaluated.type)!==hn.number)continue;const c=this.computeIcon(s.evaluated.value,n,t.upperInflectionPoint.operator,i,t.lowerInflectionPoint.operator,a);r[l]||(r[l]=[]),r[l][e]=c}}computeIcon(e,t,i,n,o,s){return"ge"===i&&e>=t||"gt"===i&&e>t?s[0]:"ge"===o&&e>=n||"gt"===o&&e>n?s[1]:s[2]}applyColorScale(e,t){var i;const n=this.parsePoint(e,t.minimum,"min"),o=t.midpoint?this.parsePoint(e,t.midpoint):null,s=this.parsePoint(e,t.maximum,"max");if(null===n||null===s||n>=s||o&&(n>=o||o>=s))return;const r=this.getters.getActiveSheetId(),a=this.getters.getRangeFromSheetXC(r,e).zone,l=this.computedStyles[r],c=[];t.midpoint&&o?(c.push({minValue:n,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(n,o,t.minimum.color,t.midpoint.color)}),c.push({minValue:o,minColor:t.midpoint.color,colorDiffUnit:this.computeColorDiffUnits(o,s,t.midpoint.color,t.maximum.color)})):c.push({minValue:n,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(n,s,t.minimum.color,t.maximum.color)});for(let e=a.top;e<=a.bottom;e++)for(let t=a.left;t<=a.right;t++){const a=this.getters.getCell(r,t,e);if((null==a?void 0:a.evaluated.type)===hn.number){const r=Me(a.evaluated.value,n,s);let h;h=2===c.length&&o?r<=o?this.colorCell(r,c[0].minValue,c[0].minColor,c[0].colorDiffUnit):this.colorCell(r,c[1].minValue,c[1].minColor,c[1].colorDiffUnit):this.colorCell(r,c[0].minValue,c[0].minColor,c[0].colorDiffUnit),l[t]||(l[t]=[]),l[t][e]=(null===(i=l[t])||void 0===i?void 0:i[e])||{},l[t][e].fillColor=gt(h)}}}computeColorDiffUnits(e,t,i,n){const o=t-e;return[((i>>16)%256-(n>>16)%256)/o,((i>>8)%256-(n>>8)%256)/o,(i%256-n%256)/o]}colorCell(e,t,i,n){const[o,s,r]=n;return Math.round((i>>16)%256-o*(e-t))<<16|Math.round((i>>8)%256-s*(e-t))<<8|Math.round(i%256-r*(e-t))}adaptRules(e,t,i,n){if(0===i.length&&0===n.length)return;const o=this.getters.getConditionalFormats(e),s=o.findIndex((e=>e.id===t.id));let r=[];s>-1&&(r=o[s].ranges),r=r.concat(i);const a=qi(r,n);0!==a.length?this.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{id:t.id,rule:t.rule,stopIfTrue:t.stopIfTrue},ranges:a.map((t=>this.getters.getRangeDataFromXc(e,t))),sheetId:e}):this.dispatch("REMOVE_CONDITIONAL_FORMAT",{id:t.id,sheetId:e})}pasteCf(e,t,i){const n=Vt(t.col,t.row);for(let o of this.getters.getConditionalFormats(e.sheetId))for(let s of o.ranges)if(Wi(e.col,e.row,this.getters.getRangeFromSheetXC(e.sheetId,s).zone)){const s=o,r=[];if("CUT"===i&&r.push(Vt(e.col,e.row)),e.sheetId===t.sheetId)this.adaptRules(e.sheetId,s,[n],r);else{this.adaptRules(e.sheetId,s,[],r);const i=this.getCFToCopyTo(t.sheetId,s);this.adaptRules(t.sheetId,i,[n],[])}}}isCellValueNumber(e){return"number"==typeof e}getCFToCopyTo(e,t){const i=this.getters.getConditionalFormats(e).find((e=>e.stopIfTrue===t.stopIfTrue&&ot(e.rule,t.rule)));return i||{...t,id:this.uuidGenerator.smallUuid(),ranges:[]}}}Pv.getters=["getConditionalIcon","getCellComputedStyle"];class Uv extends Gg{constructor(){super(...arguments),this.filterValues={},this.hiddenRows=new Set,this.isEvaluationDirty=!1}allowDispatch(e){if("UPDATE_FILTER"===e.type)if(!this.getters.getFilterId(e.sheetId,e.col,e.row))return 80;return 0}handle(e){switch(e.type){case"UNDO":case"REDO":case"UPDATE_CELL":case"EVALUATE_CELLS":case"ACTIVATE_SHEET":case"REMOVE_FILTER_TABLE":this.isEvaluationDirty=!0;break;case"START":for(const e of this.getters.getSheetIds()){this.filterValues[e]={};for(const t of this.getters.getFilters(e))this.filterValues[e][t.id]=[]}break;case"CREATE_SHEET":this.filterValues[e.sheetId]={};break;case"HIDE_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"REMOVE_COLUMNS_ROWS":this.updateHiddenRows();break;case"UPDATE_FILTER":this.updateFilter(e),this.updateHiddenRows();break;case"DUPLICATE_SHEET":const t={};for(const i of this.getters.getFilters(e.sheetIdTo)){const n=i.zoneWithHeaders;t[i.id]=this.getFilterValues(e.sheetId,n.left,n.top)}this.filterValues[e.sheetIdTo]=t}}finalize(){this.isEvaluationDirty&&(this.updateHiddenRows(),this.isEvaluationDirty=!1)}isRowFiltered(e,t){return e===this.getters.getActiveSheetId()&&this.hiddenRows.has(t)}getCellBorderWithFilterBorder(e,t,i){let n;for(let o of this.getters.getFilterTables(e)){const s=o.zone;if(Wi(t,i,s)){const o=this.intersectZoneWithViewport(e,s);n={top:i===o.top?j:void 0,bottom:i===o.bottom?j:void 0,left:t===o.left?j:void 0,right:t===o.right?j:void 0}}}const o=this.getters.getCellBorder(e,t,i),s={...n,...rt(o||{})};return Qe(s)?null:s}getFilterHeaders(e){const t=[];for(let i of this.getters.getFilterTables(e)){const n=i.zone;if(!n)continue;const o=n.top;for(let i=n.left;i<=n.right;i++)this.getters.isColHidden(e,i)||this.getters.isRowHidden(e,o)||t.push({col:i,row:o})}return t}getFilterValues(e,t,i){const n=this.getters.getFilterId(e,t,i);return n&&this.filterValues[e]&&this.filterValues[e][n]||[]}isFilterHeader(e,t,i){return this.getFilterHeaders(e).some((e=>e.col===t&&e.row===i))}isFilterActive(e,t,i){var n,o;const s=this.getters.getFilterId(e,t,i);return Boolean(s&&(null===(o=null===(n=this.filterValues[e])||void 0===n?void 0:n[s])||void 0===o?void 0:o.length))}intersectZoneWithViewport(e,t){return{left:this.getters.findVisibleHeader(e,"COL",t.left,t.right),right:this.getters.findVisibleHeader(e,"COL",t.right,t.left),top:this.getters.findVisibleHeader(e,"ROW",t.top,t.bottom),bottom:this.getters.findVisibleHeader(e,"ROW",t.bottom,t.top)}}updateFilter({col:e,row:t,values:i,sheetId:n}){const o=this.getters.getFilterId(n,e,t);o&&(this.filterValues[n]||(this.filterValues[n]={}),this.filterValues[n][o]=i)}updateHiddenRows(){var e,t;const i=this.getters.getActiveSheetId(),n=this.getters.getFilters(i).sort(((e,t)=>e.zoneWithHeaders.top-t.zoneWithHeaders.top)),o=new Set;for(let s of n){if(this.getters.isRowHiddenByUser(i,s.zoneWithHeaders.top))continue;if(o.has(s.zoneWithHeaders.top))continue;const n=null===(t=null===(e=this.filterValues[i])||void 0===e?void 0:e[s.id])||void 0===t?void 0:t.map(at);if(!n||!s.filteredZone)continue;const r=new Set(n);for(let e=s.filteredZone.top;e<=s.filteredZone.bottom;e++){const t=this.getCellValueAsString(i,s.col,e);r.has(t)&&o.add(e)}}this.hiddenRows=o}getCellValueAsString(e,t,i){var n;const o=null===(n=this.getters.getCell(e,t,i))||void 0===n?void 0:n.formattedValue;return(null==o?void 0:o.toLowerCase())||""}exportForExcel(e){var t;for(const i of e.sheets)for(const e of i.filterTables){const n=Fi(e.range),o=[],s=[];for(const e of $e(0,ji(n).width)){const r=this.getFilterValues(i.id,n.left+e,n.top),a=this.getters.getFilter(i.id,n.left+e,n.top);if(!a)continue;const l=a.filteredZone?Xi(a.filteredZone).map((e=>{var t;return null===(t=this.getters.getCell(i.id,e.col,e.row))||void 0===t?void 0:t.formattedValue})):[];if(r.length){const t=l.filter(Ke).filter((e=>!r.includes(e)));o.push({colId:e,displayedValues:[...new Set(t)],displayBlanks:!r.includes("")&&l.some((e=>!e))})}const c={col:a.col,row:a.zoneWithHeaders.top},h=null===(t=this.getters.getCell(i.id,c.col,c.row))||void 0===t?void 0:t.formattedValue,d=this.getUniqueColNameForExcel(e,h,s);s.push(d),i.cells[Vt(c.col,c.row)]={...i.cells[Vt(c.col,c.row)],content:d,value:d,isFormula:!1}}e.filters=o}}getUniqueColNameForExcel(e,t,i){t||(t=`Column${e}`);let n=t,o=2;for(;i.includes(n);)n=t+String(o),o++;return n}}Uv.getters=["getCellBorderWithFilterBorder","getFilterHeaders","getFilterValues","isFilterHeader","isRowFiltered","isFilterActive"];var Vv;!function(e){e[e.previous=-1]="previous",e[e.current=0]="current",e[e.next=1]="next"}(Vv||(Vv={}));class zv extends Gg{constructor(){super(...arguments),this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1},this.toSearch="",this.isSearchDirty=!1}handle(e){switch(e.type){case"UPDATE_SEARCH":this.updateSearch(e.toSearch,e.searchOptions);break;case"CLEAR_SEARCH":this.clearSearch();break;case"SELECT_SEARCH_PREVIOUS_MATCH":this.selectNextCell(Vv.previous);break;case"SELECT_SEARCH_NEXT_MATCH":this.selectNextCell(Vv.next);break;case"REPLACE_SEARCH":this.replace(e.replaceWith);break;case"REPLACE_ALL_SEARCH":this.replaceAll(e.replaceWith);break;case"EVALUATE_CELLS":case"UPDATE_CELL":case"REMOVE_FILTER_TABLE":case"UPDATE_FILTER":this.isSearchDirty=!0;break;case"UNDO":case"REDO":case"REMOVE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"ACTIVATE_SHEET":this.refreshSearch()}}finalize(){this.isSearchDirty&&(this.refreshSearch(),this.isSearchDirty=!1)}getSearchMatches(){return this.searchMatches}getCurrentSelectedMatchIndex(){return this.selectedMatchIndex}updateSearch(e,t){this.searchOptions=t,e!==this.toSearch&&(this.selectedMatchIndex=null),this.toSearch=e,this.updateRegex(),this.refreshSearch()}refreshSearch(){const e=this.findMatches();this.searchMatches=e,this.selectNextCell(Vv.current)}updateRegex(){let e=Te(this.toSearch);const t=this.searchOptions.matchCase?"":"i";this.searchOptions.exactMatch&&(e=`^${e}$`),this.currentSearchRegex=RegExp(e,t)}findMatches(){const e=this.getters.getActiveSheetId(),t=this.getters.getCells(e),i=[];if(this.toSearch)for(const n of Object.values(t)){const{col:t,row:o}=this.getters.getCellPosition(n.id),s=this.getters.isColHidden(e,t),r=this.getters.isRowHidden(e,o);if(!s&&!r&&(n&&this.currentSearchRegex&&this.currentSearchRegex.test(this.searchOptions.searchFormulas?n.content:String(n.evaluated.value)))){const e=this.getters.getCellPosition(n.id),t={col:e.col,row:e.row,selected:!1};i.push(t)}}return i.sort(this.sortByRowThenColumn)}sortByRowThenColumn(e,t){return e.row===t.row?e.col-t.col:e.row>t.row?1:-1}selectNextCell(e){const t=this.searchMatches;if(!t.length)return void(this.selectedMatchIndex=null);let i;i=null===this.selectedMatchIndex?0:this.selectedMatchIndex+e,i=(i%t.length+t.length)%t.length,null!==this.selectedMatchIndex&&this.selectedMatchIndex===i||(this.selectedMatchIndex=i,this.selection.selectCell(t[i].col,t[i].row));for(let e=0;e<this.searchMatches.length;e++)this.searchMatches[e].selected=e===this.selectedMatchIndex}clearSearch(){this.toSearch="",this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1}}replace(e){if(null===this.selectedMatchIndex||!this.currentSearchRegex)return;const t=this.searchMatches[this.selectedMatchIndex],i=this.getters.getActiveSheetId(),n=this.getters.getCell(i,t.col,t.row),o=this.toReplace(n,i);if(n&&o){const i=new RegExp(this.currentSearchRegex.source,this.currentSearchRegex.flags+"g"),n=o.toString().replace(i,e);this.dispatch("UPDATE_CELL",{sheetId:this.getters.getActiveSheetId(),col:t.col,row:t.row,content:n}),this.searchMatches.splice(this.selectedMatchIndex,1),this.selectNextCell(Vv.current)}else this.selectNextCell(Vv.next)}replaceAll(e){const t=this.searchMatches.length;for(let i=0;i<t;i++)this.replace(e)}toReplace(e,t){if(e){if(this.searchOptions.searchFormulas&&e.isFormula())return e.content;if(this.searchOptions.searchFormulas||!e.isFormula())return e.evaluated.value.toString()}return null}drawGrid(e){const{ctx:t}=e,i=this.getters.getActiveSheetId();for(const e of this.searchMatches){const n=this.getters.getMerge(i,e.col,e.row),o=n?n.left:e.col,s=n?n.right:e.col,r=n?n.top:e.row,a=n?n.bottom:e.row,{x:l,y:c,width:h,height:d}=this.getters.getVisibleRect({top:r,left:o,right:s,bottom:a});h>0&&d>0&&(t.fillStyle="#8B008B33",t.fillRect(l,c,h,d),e.selected&&(t.strokeStyle="#8B008B",t.strokeRect(l,c,h,d)))}}}zv.layers=[3],zv.getters=["getSearchMatches","getCurrentSelectedMatchIndex"];class Bv extends Gg{handle(e){if("SET_DECIMAL"===e.type)this.setDecimal(e.sheetId,e.target,e.step)}setDecimal(e,t,i){const n=this.searchNumberFormat(e,t);if(void 0!==n){const o=function(e,t){const i=Kt(e).map((e=>"NUMBER"===e.type?{...e,format:ci(e.format,t)}:e)),n=gi(i);return Xt[n]=i,n}(n,i);this.dispatch("SET_FORMATTING",{sheetId:e,target:t,format:o})}}searchNumberFormat(e,t){var i;for(let n of t)for(let t=n.top;t<=n.bottom;t++)for(let o=n.left;o<=n.right;o++){const n=this.getters.getCell(e,o,t);if((null==n?void 0:n.evaluated.type)===hn.number&&!(null===(i=n.evaluated.format)||void 0===i?void 0:i.match(Y)))return n.evaluated.format||ai(n.evaluated.value)}}}Bv.modes=["normal"];class Hv extends Gg{isRowHidden(e,t){return this.getters.isRowHiddenByUser(e,t)||this.getters.isRowFiltered(e,t)}isColHidden(e,t){return this.getters.isColHiddenByUser(e,t)}isHeaderHidden(e,t,i){return"COL"===t?this.isColHidden(e,i):this.isRowHidden(e,i)}getNextVisibleCellPosition(e,t,i){return{col:this.findVisibleHeader(e,"COL",t,this.getters.getNumberCols(e)-1),row:this.findVisibleHeader(e,"ROW",i,this.getters.getNumberRows(e)-1)}}findVisibleHeader(e,t,i,n){if(i<=n)for(let o=i;o<=n;o++)if(this.getters.doesHeaderExist(e,t,o)&&!this.isHeaderHidden(e,t,o))return o;if(i>n)for(let o=i;o>=n;o--)if(this.getters.doesHeaderExist(e,t,o)&&!this.isHeaderHidden(e,t,o))return o}findLastVisibleColRowIndex(e,t,i){let n;for(n=i.last;n>=i.first;n--)if(!this.isHeaderHidden(e,t,n))return n;return n}findFirstVisibleColRowIndex(e,t){const i=this.getters.getNumberHeaders(e,t);for(let n=0;n<i;n++){if("COL"===t&&!this.isColHidden(e,n))return n;if("ROW"===t&&!this.isRowHidden(e,n))return n}}exportForExcel(e){for(const t of e.sheets)for(const[e,i]of Object.entries(t.rows)){const n=this.isRowHidden(t.id,Number(e));i.isHidden=n}}}Hv.getters=["getNextVisibleCellPosition","findVisibleHeader","findLastVisibleColRowIndex","findFirstVisibleColRowIndex","isRowHidden","isColHidden","isHeaderHidden"];class Wv extends Gg{getHighlights(){return this.prepareHighlights(this.getters.getComposerHighlights().concat(this.getters.getSelectionInputHighlights()))}prepareHighlights(e){return e.filter((e=>e.zone.top>=0&&e.zone.left>=0&&e.zone.bottom<this.getters.getNumberRows(e.sheetId)&&e.zone.right<this.getters.getNumberCols(e.sheetId))).map((e=>{const{height:t,width:i}=ji(e.zone),n=t*i==1?this.getters.expandZone(e.sheetId,e.zone):e.zone;return{...e,zone:n}}))}drawGrid(e){const{ctx:t,thinLineWidth:i}=e,n=this.getters.getActiveSheetId(),o=3*i;t.lineWidth=o;const s=this.getHighlights();for(let e of s.filter(((e,t)=>s.findIndex((t=>Bi(t.zone,e.zone)&&t.sheetId===n))===t))){const{x:i,y:n,width:s,height:r}=this.getters.getVisibleRect(e.zone);s>0&&r>0&&(t.strokeStyle=e.color,t.strokeRect(i+o/2,n+o/2,s-o,r-o),t.globalCompositeOperation="source-over",t.fillStyle=e.color+"20",t.fillRect(i+o,n+o,s-2*o,r-2*o))}}}Wv.layers=[1],Wv.getters=["getHighlights"];class Gv extends Gg{constructor(){super(...arguments),this.boxes=[]}getColDimensionsInViewport(e,t){const i=Math.min(...this.getters.getSheetViewVisibleCols()),n=this.getters.getColRowOffsetInViewport("COL",i,t),o=this.getters.getColSize(e,t);return{start:n,size:o,end:n+(this.getters.isColHidden(e,t)?0:o)}}getRowDimensionsInViewport(e,t){const i=Math.min(...this.getters.getSheetViewVisibleRows()),n=this.getters.getColRowOffsetInViewport("ROW",i,t),o=this.getters.getRowSize(e,t);return{start:n,size:o,end:n+(this.getters.isRowHidden(e,t)?0:o)}}getHeaderOffset(e,t,i){let n=this.getters.getColRowOffsetInViewport(e,t,i);return this.getters.isDashboard()||(n+="ROW"===e?O:M),n}drawGrid(e,t){switch(t){case 0:this.drawBackground(e);for(const t of this.getters.getAllActiveViewportsZones()){const{ctx:i}=e;i.save(),i.beginPath();const n=this.getters.getVisibleRect(t);i.rect(n.x,n.y,n.width,n.height),i.clip(),this.boxes=this.getGridBoxes(t),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e),this.drawIcon(e),i.restore()}this.drawFrozenPanes(e);break;case 7:this.getters.isDashboard()||(this.drawHeaders(e),this.drawFrozenPanesHeaders(e))}}drawBackground(e){const{ctx:t,thinLineWidth:i}=e,{width:n,height:o}=this.getters.getSheetViewDimensionWithHeaders(),s=this.getters.getActiveSheetId();t.fillStyle="#ffffff",t.fillRect(0,0,n+m,o+m);const r=this.getters.getSheetViewVisibleCols(),a=r[0],l=r[r.length-1],c=this.getters.getSheetViewVisibleRows(),h=c[0],d=c[c.length-1];if(this.getters.getGridLinesVisibility(s)&&!this.getters.isDashboard()){t.lineWidth=2*i,t.strokeStyle="#E2E3E3",t.beginPath();for(const e of r){const i={top:h,bottom:d,left:e,right:e},{x:n,width:s,height:r}=this.getters.getVisibleRect(i);t.moveTo(n+s,0),t.lineTo(n+s,Math.min(o,r+(this.getters.isDashboard()?0:O)))}for(const e of c){const i={left:a,right:l,top:e,bottom:e},{y:o,width:s,height:r}=this.getters.getVisibleRect(i);t.moveTo(0,o+r),t.lineTo(Math.min(n,s+(this.getters.isDashboard()?0:M)),o+r)}t.stroke()}}drawCellBackground(e){const{ctx:t,thinLineWidth:i}=e,n=!this.getters.isDashboard()&&this.getters.getGridLinesVisibility(this.getters.getActiveSheetId());t.lineWidth=n?.3*i:i;const o=n?.1*i:0;t.strokeStyle="#111";for(let e of this.boxes){let s=e.style;(s.fillColor&&"#ffffff"!==s.fillColor||e.isMerge)&&(t.fillStyle=s.fillColor||"#ffffff",n?(t.fillRect(e.x,e.y,e.width,e.height),t.strokeRect(e.x+o,e.y+o,e.width-2*o,e.height-2*o)):t.fillRect(e.x-i,e.y-i,e.width+2*i,e.height+2*i)),e.error&&(t.fillStyle="red",t.beginPath(),t.moveTo(e.x+e.width-5,e.y),t.lineTo(e.x+e.width,e.y),t.lineTo(e.x+e.width,e.y+5),t.fill())}}drawBorders(e){const{ctx:t,thinLineWidth:i}=e;for(let e of this.boxes){const t=e.border;if(t){const{x:i,y:o,width:s,height:r}=e;t.left&&n(t.left,i,o,i,o+r),t.top&&n(t.top,i,o,i+s,o),t.right&&n(t.right,i+s,o,i+s,o+r),t.bottom&&n(t.bottom,i,o+r,i+s,o+r)}}function n([e,n],o,s,r,a){t.strokeStyle=n,t.lineWidth=("thin"===e?2:3)*i,t.beginPath(),t.moveTo(o,s),t.lineTo(r,a),t.stroke()}}drawTexts(e){const{ctx:t,thinLineWidth:i}=e;let n;t.textBaseline="top";for(let e of this.boxes)if(e.content){const o=e.style||{},s=e.content.align||"left",r=De(o);let a;r!==n&&(n=r,t.font=r),t.fillStyle=o.textColor||"#000";let l=e.y+e.height/2+1;if(a="left"===s?e.x+(e.image?e.image.size+2*L:P):"right"===s?e.x+e.width-P-(e.isFilterHeader?20:0):e.x+e.width/2,t.textAlign=s,e.clipRect){t.save(),t.beginPath();const{x:i,y:n,width:o,height:s}=e.clipRect;t.rect(i,n,o,s),t.clip()}const c=e.content.multiLineText.length,h=ke(o);let d=l-(c*(h+P)-P)/2;for(let n of e.content.multiLineText){if(t.fillText(n,Math.round(a),Math.round(d)),o.strikethrough||o.underline){const e=_e(t,n,o);let r=a;"right"===s?r-=e:"center"===s&&(r-=e/2),o.strikethrough&&t.fillRect(r,d+h/2,e,2.6*i),o.underline&&t.fillRect(r,d+h+1,e,1.3*i)}d+=P+h}e.clipRect&&t.restore()}}drawIcon(e){const{ctx:t}=e;for(const e of this.boxes)if(e.image){const i=e.image.image,n=e.image.size,o=(e.height-n)/2;if(e.image.clipIcon){t.save(),t.beginPath();const{x:i,y:n,width:o,height:s}=e.image.clipIcon;t.rect(i,n,o,s),t.clip()}t.drawImage(i,e.x+L,e.y+o,n,n),e.image.clipIcon&&t.restore()}}drawHeaders(e){const{ctx:t,thinLineWidth:i}=e,n=this.getters.getSheetViewVisibleCols(),o=n[0],s=this.getters.getSheetViewVisibleRows(),r=s[0],{width:a,height:l}=this.getters.getSheetViewDimensionWithHeaders(),c=this.getters.getSelectedZones(),h=function(e){const t=new Set;for(let i of e)for(let e of $e(i.left,i.right+1))t.add(e);return t}(c),d=function(e){const t=new Set;for(let i of e)for(let e of $e(i.top,i.bottom+1))t.add(e);return t}(c),u=this.getters.getActiveSheetId(),g=this.getters.getNumberCols(u),p=this.getters.getNumberRows(u),m=this.getters.getActiveCols(),f=this.getters.getActiveRows();t.font=`400 11px ${q}`,t.textAlign="center",t.textBaseline="middle",t.lineWidth=i,t.strokeStyle="#333";for(const e of n){const i={left:e,right:e,top:0,bottom:p-1},{x:n,width:o}=this.getters.getVisibleRect(i),s=this.getters.doesZonesContainFilter(u,[i]),r=m.has(e),a=h.has(e);t.fillStyle=r?s?I:S:a?s?A:b:s?T:v,t.fillRect(n,0,o,O)}for(const e of s){const i={top:e,bottom:e,left:0,right:g-1},{y:n,height:o}=this.getters.getVisibleRect(i),s=this.getters.doesZonesContainFilter(u,[i]),r=f.has(e),a=d.has(e);t.fillStyle=r?s?I:S:a?s?A:b:s?T:v,t.fillRect(0,n,M,o)}t.beginPath(),t.moveTo(M,0),t.lineTo(M,l),t.moveTo(0,O),t.lineTo(a,O),t.strokeStyle="#C0C0C0",t.stroke(),t.beginPath();for(const e of n){const i=this.getters.getColSize(u,e),n=Lt(e);t.fillStyle=m.has(e)?"#fff":C;let s=this.getHeaderOffset("COL",o,e);t.fillText(n,s+i/2,13),t.moveTo(s+i,0),t.lineTo(s+i,O)}for(const e of s){const i=this.getters.getRowSize(u,e);t.fillStyle=f.has(e)?"#fff":C;let n=this.getHeaderOffset("ROW",r,e);t.fillText(String(e+1),24,n+i/2),t.moveTo(0,n+i),t.lineTo(M,n+i)}t.stroke()}drawFrozenPanesHeaders(e){const{ctx:t,thinLineWidth:i}=e,{x:n,y:o}=this.getters.getMainViewportCoordinates(),s=this.getters.isDashboard()?0:M,r=this.getters.isDashboard()?0:O;t.lineWidth=6*i,t.strokeStyle="#BCBCBC",t.beginPath(),n&&(t.moveTo(s+n,0),t.lineTo(s+n,r)),o&&(t.moveTo(0,r+o),t.lineTo(s,r+o)),t.stroke()}drawFrozenPanes(e){const{ctx:t,thinLineWidth:i}=e,{x:n,y:o}=this.getters.getMainViewportCoordinates(),s=this.getters.getSheetViewVisibleCols(),r=s[0],a=s[s.length-1],l=this.getters.getSheetViewVisibleRows(),c={left:r,right:a,top:l[0],bottom:l[l.length-1]},h=this.getters.getVisibleRect(c),d=this.getters.isDashboard()?0:M,u=this.getters.isDashboard()?0:O;t.lineWidth=6*i,t.strokeStyle="#DADFE8",t.beginPath(),n&&(t.moveTo(d+n,u),t.lineTo(d+n,h.height+u)),o&&(t.moveTo(d,u+o),t.lineTo(h.width+d,u+o)),t.stroke()}hasContent(e,t){const i=this.getters.getActiveSheetId(),n=this.getters.getCell(i,e,t);return n&&!n.isEmpty()||this.getters.isInMerge(i,e,t)}findNextEmptyCol(e,t,i){let n=e;for(;n<t&&!this.hasContent(n+1,i);)n++;return n}findPreviousEmptyCol(e,t,i){let n=e;for(;n>t&&!this.hasContent(n-1,i);)n--;return n}computeCellAlignment(e,t){if(e.isFormula()&&this.getters.shouldShowFormulas())return"left";const{align:i}=this.getters.getCellStyle(e);return t&&e.evaluated.type===hn.number?"center"!==i?"left":i:i||e.defaultAlign}createZoneBox(e,t,i){const{left:n,right:o}=i,s=t.left,r=t.top,a=this.getters.getCell(e,s,r),c=this.getters.shouldShowFormulas(),{x:h,y:d,width:u,height:g}=this.getters.getRect(t),p={x:h,y:d,width:u,height:g,border:this.getters.getCellBorderWithFilterBorder(e,s,r)||void 0,style:this.getters.getCellComputedStyle(e,s,r)};if(!a)return p;const m=this.getters.getConditionalIcon(s,r),f=ke(p.style),v=m?2*L+f:0;m&&(p.image={type:"icon",size:f,clipIcon:{x:p.x,y:p.y,width:Math.min(v,u),height:g},image:Sr[m].img}),p.isFilterHeader=this.getters.isFilterHeader(e,s,r);const b=p.isFilterHeader?19:0,S=this.getters.getCellText(a,c),C=this.getters.getTextWidth(a),E=this.getters.getCellStyle(a).wrapping||"overflow",w="wrap"===E?this.getters.getCellMultiLineText(a,u-2*P):[S],y=v+C+b,x=this.computeCellAlignment(a,y>u);p.content={multiLineText:w,width:"overflow"===E?C:u,align:x},a.evaluated.type===hn.error&&a.evaluated.error.logLevel>l.silent&&(p.error=a.evaluated.error.message);const R=y>u||f>g;if(m||p.isFilterHeader)p.clipRect={x:p.x+v,y:p.y,width:Math.max(0,u-v-b),height:g};else if(R&&"overflow"===E){let i,a;switch(this.getters.isInMerge(e,s,r)?(i=this.getters.getMerge(e,s,r).right,a=s):(i=this.findNextEmptyCol(s,o,r),a=this.findPreviousEmptyCol(s,n,r)),x){case"left":{const e=en({col:i,row:r}),{x:n,y:o,width:s,height:a}=this.getters.getVisibleRect(Vi(t,e));(s<C||f>a)&&(p.clipRect={x:n,y:o,width:s,height:a});break}case"right":{const e=en({col:a,row:r}),{x:i,y:n,width:o,height:s}=this.getters.getVisibleRect(Vi(t,e));(o<C||f>s)&&(p.clipRect={x:i,y:n,width:o,height:s});break}case"center":{const e={...t,right:i,left:a},{x:n,y:o,width:r,height:l}=this.getters.getVisibleRect(e);(r<C||a===s||i===s||f>l)&&(p.clipRect={x:n,y:o,width:r,height:l});break}}}else"clip"!==E&&"wrap"!==E||(p.clipRect={x:p.x,y:p.y,width:u,height:g});return p}getGridBoxes(e){const t=[],i=this.getters.getSheetViewVisibleCols().filter((t=>t>=e.left&&t<=e.right)),n=i[0],o=i[i.length-1],s=this.getters.getSheetViewVisibleRows().filter((t=>t>=e.top&&t<=e.bottom)),r={left:n,right:o,top:s[0],bottom:s[s.length-1]},a=this.getters.getActiveSheetId();for(const e of s)for(const n of i)this.getters.isInMerge(a,n,e)||t.push(this.createZoneBox(a,en({col:n,row:e}),r));for(const e of this.getters.getMerges(a))if(!this.getters.isMergeHidden(a,e)&&Hi(e,r)){const i=this.createZoneBox(a,e,r),n=this.getters.getCellBorder(a,e.right,e.bottom);i.border={...i.border,bottom:n?n.bottom:void 0,right:n?n.right:void 0},i.isMerge=!0,t.push(i)}return t}}Gv.layers=[0,7],Gv.getters=["getColDimensionsInViewport","getRowDimensionsInViewport"];const qv=[{name:s("Sum"),types:[hn.number],compute:e=>pl.compute([e])},{name:s("Avg"),types:[hn.number],compute:e=>Rl.compute([e])},{name:s("Min"),types:[hn.number],compute:e=>Bl.compute([e])},{name:s("Max"),types:[hn.number],compute:e=>Pl.compute([e])},{name:s("Count"),types:[hn.number,hn.text,hn.boolean,hn.error],compute:e=>Fl.compute([e])},{name:s("Count Numbers"),types:[hn.number,hn.text,hn.boolean,hn.error],compute:e=>_l.compute([e])}];class Zv extends Gg{constructor(e,t,i,n,o){super(e,t,i,n,o),this.gridSelection={anchor:{cell:{col:0,row:0},zone:{top:0,left:0,bottom:0,right:0}},zones:[{top:0,left:0,bottom:0,right:0}]},this.selectedFigureId=null,this.sheetsData={},this.activeSheet=null,this.moveClient=n.moveClient}allowDispatch(e){switch(e.type){case"ACTIVATE_SHEET":try{this.getters.getSheet(e.sheetIdTo);break}catch(e){return 27}case"MOVE_COLUMNS_ROWS":return this.isMoveElementAllowed(e)}return 0}handleEvent(e){const t=e.anchor;let i=[];switch(e.mode){case"overrideSelection":i=[t.zone];break;case"updateAnchor":i=[...this.gridSelection.zones];const n=i.findIndex((t=>Bi(t,e.previousAnchor.zone)));n>=0&&(i[n]=t.zone);break;case"newAnchor":i=[...this.gridSelection.zones,t.zone]}this.setSelectionMixin(e.anchor,i),this.selection.resetDefaultAnchor(this,Ae(this.gridSelection.anchor));const{col:n,row:o}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.getters.getActiveSheetId(),col:n,row:o}),this.selectedFigureId=null}handle(e){switch(e.type){case"START_EDITION":case"ACTIVATE_SHEET":this.selectedFigureId=null;break;case"DELETE_FIGURE":this.selectedFigureId===e.id&&(this.selectedFigureId=null);break;case"DELETE_SHEET":this.selectedFigureId&&this.getters.getFigure(e.sheetId,this.selectedFigureId)&&(this.selectedFigureId=null)}switch(e.type){case"START":const t=this.getters.getVisibleSheetIds()[0];this.dispatch("ACTIVATE_SHEET",{sheetIdTo:t,sheetIdFrom:t});const{col:i,row:n}=this.getters.getNextVisibleCellPosition(t,0,0);this.selectCell(i,n),this.selection.registerAsDefault(this,this.gridSelection.anchor,{handleEvent:this.handleEvent.bind(this)}),this.moveClient({sheetId:t,col:0,row:0});break;case"ACTIVATE_SHEET":{if(this.getters.isSheetVisible(e.sheetIdTo)||this.dispatch("SHOW_SHEET",{sheetId:e.sheetIdTo}),this.setActiveSheet(e.sheetIdTo),this.sheetsData[e.sheetIdFrom]={gridSelection:Ae(this.gridSelection)},e.sheetIdTo in this.sheetsData)Object.assign(this,this.sheetsData[e.sheetIdTo]),this.selection.resetDefaultAnchor(this,Ae(this.gridSelection.anchor));else{const{col:t,row:i}=this.getters.getNextVisibleCellPosition(e.sheetIdTo,0,0);this.selectCell(t,i)}const{col:t,row:i}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.activeSheet.id,col:t,row:i});break}case"REMOVE_COLUMNS_ROWS":{const t=this.getters.getActiveSheetId();if(e.sheetId===t){"COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e);const{col:i,row:n}=this.gridSelection.anchor.cell;this.moveClient({sheetId:t,col:i,row:n})}break}case"ADD_COLUMNS_ROWS":{const t=this.getters.getActiveSheetId();if(e.sheetId===t){this.onAddElements(e);const{col:i,row:n}=this.gridSelection.anchor.cell;this.moveClient({sheetId:t,col:i,row:n})}break}case"MOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onMoveElements(e);break;case"SELECT_FIGURE":this.selectedFigureId=e.id;break;case"ACTIVATE_NEXT_SHEET":this.activateNextSheet("right");break;case"ACTIVATE_PREVIOUS_SHEET":this.activateNextSheet("left");break;case"HIDE_SHEET":e.sheetId===this.getActiveSheetId()&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e.sheetId,sheetIdTo:this.getters.getVisibleSheetIds()[0]});break;case"UNDO":case"REDO":case"DELETE_SHEET":const o=Object.keys(this.sheetsData).filter((e=>!this.getters.tryGetSheet(e)));for(const e of o)delete this.sheetsData[e];for(const e in this.sheetsData){const t=this.clipSelection(e,this.sheetsData[e].gridSelection);this.sheetsData[e]={gridSelection:Ae(t)}}this.fallbackToVisibleSheet();const s=this.getters.getActiveSheetId();this.gridSelection.zones=this.gridSelection.zones.map((e=>this.getters.expandZone(s,e))),this.gridSelection.anchor.zone=this.getters.expandZone(s,this.gridSelection.anchor.zone),this.setSelectionMixin(this.gridSelection.anchor,this.gridSelection.zones),this.selectedFigureId=null}}finalize(){this.fallbackToVisibleSheet(),this.selection.resetDefaultAnchor(this,Ae(this.gridSelection.anchor))}isGridSelectionActive(){return this.selection.isListening(this)}getActiveSheet(){return this.activeSheet}getActiveSheetId(){return this.activeSheet.id}getActiveCell(){const e=this.getters.getActiveSheetId(),{col:t,row:i}=this.gridSelection.anchor.cell,{col:n,row:o}=this.getters.getMainCellPosition(e,t,i);return this.getters.getCell(e,n,o)}getActiveCols(){const e=new Set;for(let t of this.gridSelection.zones)if(0===t.top&&t.bottom===this.getters.getNumberRows(this.getters.getActiveSheetId())-1)for(let i=t.left;i<=t.right;i++)e.add(i);return e}getActiveRows(){const e=new Set,t=this.getters.getActiveSheetId();for(let i of this.gridSelection.zones)if(0===i.left&&i.right===this.getters.getNumberCols(t)-1)for(let t=i.top;t<=i.bottom;t++)e.add(t);return e}getCurrentStyle(){const e=this.getters.getActiveCell();return e?this.getters.getCellStyle(e):{}}getSelectedZones(){return Ae(this.gridSelection.zones)}getSelectedZone(){return Ae(this.gridSelection.anchor.zone)}getSelection(){return Ae(this.gridSelection)}getSelectedFigureId(){return this.selectedFigureId}getPosition(){return{col:this.gridSelection.anchor.cell.col,row:this.gridSelection.anchor.cell.row}}getSheetPosition(e){if(e===this.getters.getActiveSheetId())return this.getPosition();{const t=this.sheetsData[e];return t?{col:t.gridSelection.anchor.cell.col,row:t.gridSelection.anchor.cell.row}:this.getters.getNextVisibleCellPosition(e,0,0)}}getStatisticFnResults(){const e=this.getters.getActiveSheetId(),t=new Set(this.gridSelection.zones.map((t=>this.getters.getCellsInZone(e,t))).flat().filter((t=>{if(!t)return!1;const{col:i,row:n}=this.getters.getCellPosition(null==t?void 0:t.id);return!this.getters.isRowHidden(e,n)&&!this.getters.isColHidden(e,i)})));let i=new Set,n=[];for(let e of t)i.add(e.evaluated.type),n.push(e.evaluated.value);let o={};for(let e of qv){let t;e.types.some((e=>i.has(e)))&&(t=e.compute(n)),o[e.name]=t}return o}getAggregate(){let e=0,t=0;const i=this.getters.getActiveSheetId(),n=this.gridSelection.zones.map(Xi).flat();for(const{col:o,row:s}of n){const n=this.getters.getCell(i,o,s);(null==n?void 0:n.evaluated.type)===hn.number&&(t++,e+=n.evaluated.value)}return t<2?null:Qt(e)}isSelected(e){return!!this.getters.getSelectedZones().find((t=>Bi(t,e)))}getElementsFromSelection(e){if("COL"===e&&0===this.getters.getActiveCols().size)return[];if("ROW"===e&&0===this.getters.getActiveRows().size)return[];const t=this.getters.getSelectedZones();let i=[];const n="COL"===e?"left":"top",o="COL"===e?"right":"bottom";for(const e of t){const t=Array.from({length:e[o]-e[n]+1},((t,i)=>e[n]+i));i=i.concat(t)}return[...new Set(i)].sort()}setSelectionMixin(e,t){const{anchor:i,zones:n}=this.clipSelection(this.getters.getActiveSheetId(),{anchor:e,zones:t});this.gridSelection.anchor=i,this.gridSelection.zones=function(e){return e.reverse().filter(((e,t,i)=>t===i.findIndex((t=>t.top===e.top&&t.bottom===e.bottom&&t.left===e.left&&t.right===e.right)))).reverse()}(n)}selectCell(e,t){const i=this.getters.getActiveSheetId(),n=this.getters.expandZone(i,{left:e,right:e,top:t,bottom:t});this.setSelectionMixin({zone:n,cell:{col:e,row:t}},[n])}setActiveSheet(e){const t=this.getters.getSheet(e);this.activeSheet=t}activateNextSheet(e){const t=this.getters.getSheetIds(),i=(t.findIndex((e=>e===this.activeSheet.id))+("left"===e?t.length-1:1))%t.length;this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getActiveSheetId(),sheetIdTo:t[i]})}onColumnsRemoved(e){const{cell:t,zone:i}=this.gridSelection.anchor,n=Pi(i,"left",[...e.elements]);let o={left:t.col,right:t.col,top:t.row,bottom:t.row};o=Pi(o,"left",[...e.elements]);const s={cell:{col:o.left,row:o.top},zone:n};this.setSelectionMixin(s,[n])}onRowsRemoved(e){const{cell:t,zone:i}=this.gridSelection.anchor,n=Pi(i,"top",[...e.elements]);let o={left:t.col,right:t.col,top:t.row,bottom:t.row};o=Pi(o,"top",[...e.elements]);const s={cell:{col:o.left,row:o.top},zone:n};this.setSelectionMixin(s,[n])}onAddElements(e){const t=Li(this.gridSelection.anchor.zone,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity),i={cell:{col:t.left,row:t.top},zone:t};this.setSelectionMixin(i,[t])}onMoveElements(e){const t=e.elements.length;this.dispatch("ADD_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,base:e.base,quantity:t,position:e.position});const i="COL"===e.dimension,n=e.elements[0],o=e.elements[t-1],s=e.base<n,r=s&&i?t:0,a=s&&!i?t:0,l=[{left:i?n+r:0,right:i?o+r:this.getters.getNumberCols(e.sheetId)-1,top:i?0:n+a,bottom:i?this.getters.getNumberRows(e.sheetId)-1:o+a}],c=new Ov(l,"CUT",this.getters,this.dispatch,this.selection),h=s?e.base:e.base+1,d=[{left:i?h:0,right:i?h+t-1:this.getters.getNumberCols(e.sheetId)-1,top:i?0:h,bottom:i?this.getters.getNumberRows(e.sheetId)-1:h+t-1}];c.paste(d,{selectTarget:!0});const u=s?e.elements.map((e=>e+t)):e.elements;let g=s?e.base:e.base+1;for(const t of u){const i="COL"===e.dimension?this.getters.getColSize(e.sheetId,t):this.getters.getRowSize(e.sheetId,t);this.dispatch("RESIZE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,size:i,elements:[g]}),g+=1}this.dispatch("REMOVE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,elements:u})}isMoveElementAllowed(e){const t="COL"===e.dimension,i=e.elements[0],n=e.elements[e.elements.length-1],o=e.sheetId,s=t?this.getters.doesColumnsHaveCommonMerges:this.getters.doesRowsHaveCommonMerges;if(s(o,i-1,i)||s(o,n,n+1)||s(o,e.base-1,e.base))return 2;const r=[e.base,...e.elements],a=t?this.getters.getNumberCols(o):this.getters.getNumberRows(o);return r.some((e=>e<0||e>=a))?87:0}fallbackToVisibleSheet(){if(!this.getters.tryGetSheet(this.getters.getActiveSheetId())){const e=this.getters.getVisibleSheetIds();if(this.activeSheet=this.getters.getSheet(e[0]),this.activeSheet.id in this.sheetsData){const{anchor:e}=this.clipSelection(this.activeSheet.id,this.sheetsData[this.activeSheet.id].gridSelection);this.selectCell(e.cell.col,e.cell.row)}else this.selectCell(0,0);const{col:t,row:i}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.getters.getActiveSheetId(),col:t,row:i})}}clipSelection(e,t){const i=this.getters.getNumberCols(e)-1,n=this.getters.getNumberRows(e)-1;return{zones:t.zones.map((e=>({left:Me(e.left,0,i),right:Me(e.right,0,i),top:Me(e.top,0,n),bottom:Me(e.bottom,0,n)}))),anchor:{cell:{col:Me(t.anchor.cell.col,0,i),row:Me(t.anchor.cell.row,0,n)},zone:{left:Me(t.anchor.zone.left,0,i),right:Me(t.anchor.zone.right,0,i),top:Me(t.anchor.zone.top,0,n),bottom:Me(t.anchor.zone.bottom,0,n)}}}}drawGrid(e){if(this.getters.isDashboard())return;const{ctx:t,thinLineWidth:i}=e,n=this.getSelectedZones();t.fillStyle="#f3f7fe";const o=1===n.length&&n[0].left===n[0].right&&n[0].top===n[0].bottom;t.fillStyle=o?"#f3f7fe":"#e9f0ff",t.strokeStyle=E,t.lineWidth=1.5*i,t.globalCompositeOperation="multiply";for(const e of n){const{x:i,y:n,width:o,height:s}=this.getters.getVisibleRect(e);t.fillRect(i,n,o,s),t.strokeRect(i,n,o,s)}t.globalCompositeOperation="source-over";const s=this.getters.getActiveSheetId(),{col:r,row:a}=this.getPosition();let l;t.strokeStyle=E,t.lineWidth=3*i,l=this.getters.isInMerge(s,r,a)?this.getters.getMerge(s,r,a):{top:a,bottom:a,left:r,right:r};const{x:c,y:h,width:d,height:u}=this.getters.getVisibleRect(l);d>0&&u>0&&t.strokeRect(c,h,d,u)}}Zv.layers=[5],Zv.getters=["getActiveSheet","getActiveSheetId","getActiveCell","getActiveCols","getActiveRows","getCurrentStyle","getSelectedZones","getSelectedZone","getStatisticFnResults","getAggregate","getSelectedFigureId","getSelection","getPosition","getSheetPosition","isSelected","getElementsFromSelection","isGridSelectionActive"];const jv=new Mi;class Yv extends Gg{constructor(e,t,i,n,o,s,r){if(r&&s.length>1)throw new Error("Input with a single range cannot be instantiated with several range references.");super(e,t,i,n,o),this.inputHasSingleRange=r,this.ranges=[],this.focusedRangeIndex=null,this.willAddNewRange=!1,this.insertNewRange(0,s),this.activeSheet=this.getters.getActiveSheetId(),0===this.ranges.length&&(this.insertNewRange(this.ranges.length,[""]),this.focusLast())}handleEvent(e){const t=ki(e.anchor.zone),i=this.activeSheet,n=this.getters.getActiveSheetId(),o=this.getters.getSheetName(n);this.add([n===i?t:`${Oe(o)}!${t}`])}handle(e){switch(e.type){case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"FOCUS_RANGE":this.focus(this.getIndex(e.rangeId));break;case"CHANGE_RANGE":{const t=this.getIndex(e.rangeId);if(null!==t&&this.focusedRangeIndex!==t&&this.focus(t),null!==t){const i=e.value.split(",").map((e=>e.trim()));this.setRange(t,i)}break}case"ADD_EMPTY_RANGE":this.insertNewRange(this.ranges.length,[""]),this.focusLast();break;case"REMOVE_RANGE":const t=this.getIndex(e.rangeId);null!==t&&this.removeRange(t);break;case"STOP_SELECTION_INPUT":this.willAddNewRange=!1;break;case"PREPARE_SELECTION_INPUT_EXPANSION":{const e=this.focusedRangeIndex;null===e||this.inputHasSingleRange||(this.willAddNewRange=""!==this.ranges[e].xc.trim());break}case"ACTIVATE_SHEET":if(e.sheetIdFrom!==e.sheetIdTo){const{col:t,row:i}=this.getters.getNextVisibleCellPosition(e.sheetIdTo,0,0),n=this.getters.expandZone(e.sheetIdTo,en({col:t,row:i}));this.selection.resetAnchor(this,{cell:{col:t,row:i},zone:n})}}}getSelectionInputValue(){return this.cleanInputs(this.ranges.map((e=>e.xc?e.xc:"")))}getSelectionInputHighlights(){return this.ranges.map((e=>this.inputToHighlights(e))).flat()}focus(e){this.focusedRangeIndex=e}focusLast(){this.focus(this.ranges.length-1)}unfocus(){this.focusedRangeIndex=null}add(e){null!==this.focusedRangeIndex&&0!==e.length&&(this.willAddNewRange?(this.insertNewRange(this.ranges.length,e),this.focusLast(),this.willAddNewRange=!1):this.setRange(this.focusedRangeIndex,e))}setContent(e,t){this.ranges[e]={...this.ranges[e],id:jv.smallUuid(),xc:t}}insertNewRange(e,t){this.ranges.splice(e,0,...t.map(((e,t)=>({xc:e,id:(this.ranges.length+t+1).toString(),color:(pt=++pt%ut.length,ut[pt])}))))}setRange(e,t){const[,...i]=t;this.setContent(e,t[0]),this.insertNewRange(e+1,i),i.length&&this.focus(e+i.length)}removeRange(e){this.ranges.splice(e,1),null!==this.focusedRangeIndex&&this.focusLast()}inputToHighlights({xc:e,color:t}){const i=this.cleanInputs([e]).filter((e=>this.getters.isRangeValid(e))).filter((e=>this.shouldBeHighlighted(this.activeSheet,e)));return i.map((e=>{const{sheetName:i}=$t(e);return{zone:this.getters.getRangeFromSheetXC(this.activeSheet,e).zone,sheetId:i&&this.getters.getSheetIdByName(i)||this.activeSheet,color:t}}))}cleanInputs(e){return e.map((e=>e.split(","))).flat().map((e=>e.trim())).filter((e=>""!==e))}shouldBeHighlighted(e,t){const{sheetName:i}=$t(t),n=this.getters.getSheetIdByName(i),o=this.getters.getActiveSheet().id;return this.getters.isRangeValid(t)&&(n===o||void 0===n&&o===e)}getIndex(e){const t=this.ranges.findIndex((t=>t.id===e));return t>=0?t:null}}Yv.layers=[1],Yv.getters=[];class Xv extends Gg{get currentInput(){return this.focusedInputId?this.inputs[this.focusedInputId]:null}constructor(e,t,i,n,o){super(e,t,i,n,o),this.state=t,this.config=n,this.inputs={},this.focusedInputId=null}allowDispatch(e){var t,i;switch(e.type){case"FOCUS_RANGE":case"CHANGE_RANGE":case"ADD_EMPTY_RANGE":case"REMOVE_RANGE":if(!this.inputs[e.id])return 31}switch(e.type){case"FOCUS_RANGE":const n=null===(t=this.currentInput)||void 0===t?void 0:t.getIndex(e.rangeId);if(this.focusedInputId===e.id&&(null===(i=this.currentInput)||void 0===i?void 0:i.focusedRangeIndex)===n)return 29;break;case"ADD_EMPTY_RANGE":const o=this.inputs[e.id];if(o.inputHasSingleRange&&1===o.ranges.length)return 30;break;case"CHANGE_RANGE":if(this.inputs[e.id].inputHasSingleRange&&e.value.split(",").length>1)return 30;break}return 0}handle(e){var t;switch(e.type){case"ENABLE_NEW_SELECTION_INPUT":this.initInput(e.id,e.initialRanges||[],e.hasSingleRange);break;case"DISABLE_SELECTION_INPUT":this.focusedInputId===e.id&&this.unfocus(),delete this.inputs[e.id];break;case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"ADD_EMPTY_RANGE":case"REMOVE_RANGE":case"FOCUS_RANGE":case"CHANGE_RANGE":if(e.id!==this.focusedInputId){const t=this.inputs[e.id];this.selection.capture(t,{cell:{col:0,row:0},zone:en({col:0,row:0})},{handleEvent:t.handleEvent.bind(t)}),this.focusedInputId=e.id}}null===(t=this.currentInput)||void 0===t||t.handle(e)}getSelectionInput(e){return this.inputs[e]?this.inputs[e].ranges.map(((t,i)=>Object.assign({},t,{color:this.focusedInputId===e&&null!==this.inputs[e].focusedRangeIndex&&this.isRangeValid(t.xc)?t.color:null,isFocused:this.focusedInputId===e&&this.inputs[e].focusedRangeIndex===i}))):[]}isRangeValid(e){if(!e)return!1;const{xc:t,sheetName:i}=$t(e);return null!==t.match(Ot)&&(!i||void 0!==this.getters.getSheetIdByName(i))}getSelectionInputValue(e){return this.inputs[e].getSelectionInputValue()}getSelectionInputHighlights(){return this.focusedInputId?this.inputs[this.focusedInputId].getSelectionInputHighlights():[]}initInput(e,t,i=!1){if(this.inputs[e]=new Yv(this.getters,this.state,this.dispatch,this.config,this.selection,t,i),0===t.length){const t=this.inputs[e],i={zone:en({col:0,row:0}),cell:{col:0,row:0}};this.selection.capture(t,i,{handleEvent:t.handleEvent.bind(t)}),this.focusedInputId=e}}unfocus(){this.selection.release(this.currentInput),this.focusedInputId=null}}Xv.layers=[1],Xv.getters=["getSelectionInput","getSelectionInputValue","isRangeValid","getSelectionInputHighlights"];class Kv{constructor(){this.subscriptions={}}on(e,t,i){if(!i)throw new Error("Missing callback");this.subscriptions[e]||(this.subscriptions[e]=[]),this.subscriptions[e].push({owner:t,callback:i})}trigger(e,t){const i=this.subscriptions[e]||[];for(let e=0,n=i.length;e<n;e++){const n=i[e];n.callback.call(n.owner,t)}}off(e,t){const i=this.subscriptions[e];i&&(this.subscriptions[e]=i.filter((e=>e.owner!==t)))}clear(){this.subscriptions={}}}function Qv(e,t){return{...e,definition:Us(e.definition,t)}}function Jv(e,t){if(e.sheetId!==t.sheetId)return e;if(("FREEZE_COLUMNS"===e.type?"COL":"ROW")!==t.dimension)return e;let i=e.quantity;if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));for(let t of e)i>t&&i--}if("ADD_COLUMNS_ROWS"===t.type){i=i>("before"===t.position?t.base-1:t.base)?i+t.quantity:i}return i>0?{...e,quantity:i}:void 0}as.addTransformation("ADD_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],Qv),as.addTransformation("REMOVE_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],Qv),as.addTransformation("DELETE_SHEET",["MOVE_RANGES"],(function(e,t){const i=t.sheetId;if(e.targetSheetId===i||e.sheetId===i)return;return e})),as.addTransformation("DELETE_FIGURE",["UPDATE_FIGURE","UPDATE_CHART"],(function(e,t){if(e.id===t.id)return;return e})),as.addTransformation("CREATE_SHEET",["CREATE_SHEET"],(function(e,t){var i;e.sheetId===t.sheetId&&(e={...e,sheetId:`${e.sheetId}~`});if(e.name===t.name)return{...e,name:(null===(i=e.name)||void 0===i?void 0:i.match(/\d+/))?e.name.replace(/\d+/,(e=>(parseInt(e)+1).toString())):`${e.name}~`,position:e.position+1};return e})),as.addTransformation("ADD_MERGE",["ADD_MERGE","REMOVE_MERGE","CREATE_FILTER_TABLE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;const i=[];for(const n of e.target)t.target.every((e=>!Hi(n,e)))&&i.push(n);if(i.length)return{...e,target:i};return})),as.addTransformation("ADD_COLUMNS_ROWS",["FREEZE_COLUMNS","FREEZE_ROWS"],Jv),as.addTransformation("REMOVE_COLUMNS_ROWS",["FREEZE_COLUMNS","FREEZE_ROWS"],Jv),as.addTransformation("CREATE_FILTER_TABLE",["CREATE_FILTER_TABLE","ADD_MERGE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;for(const i of e.target)for(const e of t.target)if(Hi(e,i))return;return e}));const eb=[{match:function(e){return"sheetId"in e},fn:nb},{match:function(e){return"target"in e&&"sheetId"in e},fn:function(e,t){const i=nb(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;const n=[];for(const i of e.target){const e=ps(i,t);e&&n.push(e)}if(!n.length)return"IGNORE_COMMAND";return{...e,target:n}}},{match:function(e){return"col"in e&&"row"in e&&"sheetId"in e},fn:function(e,t){const i=nb(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type)return function(e,t){const i="COL"===t.dimension?"col":"row";let n=e[i];if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));if(e.includes(n))return"IGNORE_COMMAND";for(let t of e)n>=t&&n--}"ADD_COLUMNS_ROWS"===t.type&&(n>t.base||n===t.base&&"before"===t.position)&&(n+=t.quantity);return{...e,[i]:n}}(e,t);if("ADD_MERGE"===t.type)return function(e,t){for(const i of t.target){if(!(e.col===i.left&&e.row===i.top)&&Wi(e.col,e.row,i))return"IGNORE_COMMAND"}return e}(e,t);return"SKIP_TRANSFORMATION"}},{match:function(e){return"dimension"in e&&"sheetId"in e},fn:function(e,t){const i=nb(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type){if(t.dimension!==e.dimension)return e;const i="ADD_COLUMNS_ROWS"===e.type,n=i?"base":"elements";let o=i?[e[n]]:e[n];if("REMOVE_COLUMNS_ROWS"===t.type&&(o=o.map((e=>{if(t.elements.includes(e))return;const i=t.elements.sort(((e,t)=>t-e));for(let t of i)e>t&&e--;return e})).filter(Xe)),"ADD_COLUMNS_ROWS"===t.type){const e="before"===t.position?t.base-1:t.base;o=o.map((i=>i>e?i+t.quantity:i))}if(o.length){let t=o;return i&&(t=o[0]),{...e,[n]:t}}return"IGNORE_COMMAND"}return"SKIP_TRANSFORMATION"}},{match:function(e){return"ranges"in e},fn:function(e,t){const i=[],n="DELETE_SHEET"===t.type&&t.sheetId;for(const o of e.ranges)if(o._sheetId!==t.sheetId)i.push({...o,_zone:o._zone});else{const e=ps(o._zone,t);e&&n!==o._sheetId&&i.push({...o,_zone:e})}if(!i.length)return"IGNORE_COMMAND";return{...e,ranges:i}}}];function tb(e,t){const i=as.getTransformation(e.type,t.type);return i?i(e,t):function(e,t){for(const{match:i,fn:n}of eb)if(i(e)){const i=n(e,t);if("SKIP_TRANSFORMATION"===i)continue;if("IGNORE_COMMAND"===i)return;e=i}return e}(e,t)}function ib(e,t){let i=[...e];const n=new Set(as.getKeys());for(const e of t)n.has(e.type)&&(i=i.reduce(((t,i)=>{const n=tb(i,e);return n&&t.push(n),t}),[]));return i}function nb(e,t){const i="DELETE_SHEET"===t.type&&t.sheetId;return e.sheetId===i?"IGNORE_COMMAND":"CREATE_SHEET"===e.type||"CREATE_SHEET"===t.type||e.sheetId!==t.sheetId?e:"SKIP_TRANSFORMATION"}class ob{constructor(e,t,i,n){this._commands=[],this._changes=[],this.id=e,this.clientId=t,this._commands=[...i],this._changes=n?[...n]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}}class sb extends Error{}class rb extends Kv{constructor(e,t,i=K){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=i,this.clients={},this.clientId="local",this.pendingMessages=[],this.waitingAck=!1,this.waitingUndoRedoAck=!1,this.isReplayingInitialRevisions=!1,this.processedRevisions=new Set,this.uuidGenerator=new Mi,this.debouncedMove=function(e,t,i){let n;return function(){const o=this,s=arguments,r=i&&!n;clearTimeout(n),n=setTimeout((function(){n=null,i||e.apply(o,s)}),t),r&&e.apply(o,s)}}(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t){if(!e.length||!t.length||!this.canApplyOptimisticUpdate())return;const i=new ob(this.uuidGenerator.uuidv4(),this.clientId,e,t);this.revisions.append(i.id,i),this.trigger("new-local-state-update",{id:i.id}),this.sendUpdateMessage({type:"REMOTE_REVISION",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:i.id,clientId:i.clientId,commands:i.commands})}undo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_UNDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),undoneRevisionId:e})}redo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_REDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),redoneRevisionId:e})}move(e){this.debouncedMove(e)}join(e){e?(this.clients[e.id]=e,this.clientId=e.id):(this.clients.local={id:"local",name:"local"},this.clientId="local"),this.transportService.onNewMessage(this.clientId,this.onMessageReceived.bind(this))}loadInitialMessages(e){this.isReplayingInitialRevisions=!0;for(const t of e)this.onMessageReceived(t);this.isReplayingInitialRevisions=!1}leave(){delete this.clients[this.clientId],this.transportService.leave(this.clientId),this.transportService.sendMessage({type:"CLIENT_LEFT",clientId:this.clientId,version:1})}snapshot(e){const t=this.uuidGenerator.uuidv4();this.transportService.sendMessage({type:"SNAPSHOT",nextRevisionId:t,serverRevisionId:this.serverRevisionId,data:{...e,revisionId:t},version:1})}getClient(){const e=this.clients[this.clientId];if(!e)throw new sb("The client left the session");return e}getConnectedClients(){return new Set(Object.values(this.clients).filter(Xe))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return 0===this.pendingMessages.length}_move(e){var t;if(!this.clients[this.clientId])return;const i=null===(t=this.clients[this.clientId])||void 0===t?void 0:t.position;if((null==i?void 0:i.col)===e.col&&i.row===e.row&&i.sheetId===e.sheetId)return;const n=i?"CLIENT_MOVED":"CLIENT_JOINED",o=this.getClient();this.clients[this.clientId]={...o,position:e},this.transportService.sendMessage({type:n,version:1,client:{...o,position:e}})}onMessageReceived(e){if(!this.isAlreadyProcessed(e))if(this.isWrongServerRevisionId(e))this.trigger("unexpected-revision-id");else{switch(e.type){case"CLIENT_MOVED":this.onClientMoved(e);break;case"CLIENT_JOINED":this.onClientJoined(e);break;case"CLIENT_LEFT":this.onClientLeft(e);break;case"REVISION_REDONE":this.revisions.redo(e.redoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-redone",{revisionId:e.redoneRevisionId,commands:this.revisions.get(e.redoneRevisionId).commands});break;case"REVISION_UNDONE":this.revisions.undo(e.undoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-undone",{revisionId:e.undoneRevisionId,commands:this.revisions.get(e.undoneRevisionId).commands});break;case"REMOTE_REVISION":const{clientId:t,commands:i}=e,n=new ob(e.nextRevisionId,t,i);if(n.clientId!==this.clientId){this.revisions.insert(n.id,n,e.serverRevisionId);const t=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.commands)).flat();this.trigger("remote-revision-received",{commands:ib(i,t)})}break;case"SNAPSHOT_CREATED":{const t=new ob(e.nextRevisionId,"server",[]);this.revisions.insert(t.id,t,e.serverRevisionId),this.dropPendingHistoryMessages(),this.trigger("snapshot");break}}this.acknowledge(e),this.trigger("collaborative-event-received")}}onClientMoved(e){e.client.id!==this.clientId&&(this.clients[e.client.id]=e.client)}onClientJoined(e){if(e.client.id!==this.clientId){this.clients[e.client.id]=e.client;const t=this.clients[this.clientId];if(t){const{position:e}=t;e&&this.transportService.sendMessage({type:"CLIENT_MOVED",version:1,client:{...t,position:e}})}}}onClientLeft(e){e.clientId!==this.clientId&&delete this.clients[e.clientId]}sendUpdateMessage(e){this.pendingMessages.push(e),this.waitingAck||this.sendPendingMessage()}sendPendingMessage(){let e=this.pendingMessages[0];if(e){if("REMOTE_REVISION"===e.type){let t=this.revisions.get(e.nextRevisionId);0===t.commands.length&&(this.revisions.rebase(t.id),t=this.revisions.get(e.nextRevisionId)),e={...e,clientId:t.clientId,commands:t.commands}}if(this.isReplayingInitialRevisions)throw new Error(`Trying to send a new revision while replaying initial revision. This can lead to endless dispatches every time the spreadsheet is open.\n ${JSON.stringify(e)}`);this.waitingAck=!0,this.transportService.sendMessage({...e,serverRevisionId:this.serverRevisionId})}}acknowledge(e){switch("REVISION_UNDONE"!==e.type&&"REVISION_REDONE"!==e.type||(this.waitingUndoRedoAck=!1),e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"SNAPSHOT_CREATED":this.waitingAck=!1,this.pendingMessages=this.pendingMessages.filter((t=>t.nextRevisionId!==e.nextRevisionId)),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.sendPendingMessage();break;case"REVISION_UNDONE":{this.waitingAck=!1,this.pendingMessages=this.pendingMessages.filter((t=>t.nextRevisionId!==e.nextRevisionId));const t=this.pendingMessages.findIndex((e=>"REMOTE_REVISION"===e.type));-1!==t&&this.revisions.rebase(this.pendingMessages[t].nextRevisionId),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.sendPendingMessage();break}}}isAlreadyProcessed(e){if("CLIENT_MOVED"===e.type&&e.client.id===this.clientId)return!0;switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":return this.processedRevisions.has(e.nextRevisionId);default:return!1}}isWrongServerRevisionId(e){switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":return e.serverRevisionId!==this.serverRevisionId;default:return!1}}dropPendingHistoryMessages(){this.waitingUndoRedoAck=!1,this.pendingMessages=this.pendingMessages.filter((({type:e})=>"REVISION_REDONE"!==e&&"REVISION_UNDONE"!==e))}}const ab=["#ff851b","#0074d9","#7fdbff","#b10dc9","#39cccc","#f012be","#3d9970","#111111","#ff4136","#aaaaaa","#85144b","#001f3f"];class lb extends Gg{constructor(){super(...arguments),this.availableColors=new Set(ab),this.colors={}}isPositionValid(e){return e.row<this.getters.getNumberRows(e.sheetId)&&e.col<this.getters.getNumberCols(e.sheetId)}chooseNewColor(){0===this.availableColors.size&&(this.availableColors=new Set(ab));const e=(t=[...this.availableColors.values()])[Math.floor(Math.random()*t.length)];var t;return this.availableColors.delete(e),e}getClientsToDisplay(){try{this.getters.getClient()}catch(e){if(e instanceof sb)return[];throw e}const e=this.getters.getActiveSheetId(),t=[];for(const i of this.getters.getConnectedClients())if(i.id!==this.getters.getClient().id&&i.position&&i.position.sheetId===e&&this.isPositionValid(i.position)){const e=i.position;this.colors[i.id]||(this.colors[i.id]=this.chooseNewColor());const n=this.colors[i.id];t.push({...i,position:e,color:n})}return t}drawGrid(e){if(this.getters.isDashboard())return;const{ctx:t,thinLineWidth:i}=e,n=this.getters.getActiveSheetId();for(const e of this.getClientsToDisplay()){const{row:o,col:s}=e.position,r=this.getters.expandZone(n,{top:o,bottom:o,left:s,right:s}),{x:a,y:l,width:c,height:h}=this.getters.getVisibleRect(r);if(c<=0||h<=0)continue;const d=e.color,u=`${d}10`;t.fillStyle=u,t.lineWidth=4*i,t.strokeStyle=d,t.globalCompositeOperation="multiply",t.fillRect(a,l,c,h),t.globalCompositeOperation="source-over",t.strokeRect(a,l,c,h),t.font=`bold ${G+1}px ${q}`}}}lb.getters=["getClientsToDisplay"],lb.layers=[5];class cb{constructor(e,t,i,n,o,s){if(this.getters=e,this.sheetId=t,this.boundaries=i,n.width<0||n.height<0)throw new Error("Viewport size cannot be negative");this.viewportWidth=n.height&&n.width,this.viewportHeight=n.width&&n.height,this.top=i.top,this.bottom=i.bottom,this.left=i.left,this.right=i.right,this.offsetX=s.x,this.offsetY=s.y,this.offsetScrollbarX=s.x,this.offsetScrollbarY=s.y,this.canScrollVertically=o.canScrollVertically,this.canScrollHorizontally=o.canScrollHorizontally,this.offsetCorrectionX=this.getters.getColDimensions(this.sheetId,this.boundaries.left).start,this.offsetCorrectionY=this.getters.getRowDimensions(this.sheetId,this.boundaries.top).start,this.adjustViewportOffsetX(),this.adjustViewportOffsetY()}getMaxSize(){const e=this.getters.findLastVisibleColRowIndex(this.sheetId,"COL",{first:this.boundaries.left,last:this.boundaries.right}),t=this.getters.findLastVisibleColRowIndex(this.sheetId,"ROW",{first:this.boundaries.top,last:this.boundaries.bottom}),{end:i,size:n}=this.getters.getColDimensions(this.sheetId,e),{end:o,size:s}=this.getters.getRowDimensions(this.sheetId,t),r=this.searchHeaderIndex("COL",i-this.viewportWidth,0),a=this.getters.getColSize(this.sheetId,r),l=this.searchHeaderIndex("ROW",o-this.viewportHeight,0),c=this.getters.getRowSize(this.sheetId,l);let h=i-this.offsetCorrectionX;this.canScrollHorizontally&&(h+=Math.max(_,Math.min(a,this.viewportWidth-n)),h=Math.max(h,this.viewportWidth));let d=o-this.offsetCorrectionY;return this.canScrollVertically&&(d+=Math.max(F+5,Math.min(c,this.viewportHeight-s)),d=Math.max(d,this.viewportHeight)),{width:h,height:d}}getColIndex(e,t=!1){return e<this.offsetCorrectionX||e>this.offsetCorrectionX+this.viewportWidth?-1:this.searchHeaderIndex("COL",e-this.offsetCorrectionX,this.left,t)}getRowIndex(e,t=!1){return e<this.offsetCorrectionY||e>this.offsetCorrectionY+this.viewportHeight?-1:this.searchHeaderIndex("ROW",e-this.offsetCorrectionY,this.top,t)}adjustPosition(e){const t=this.sheetId;e||(e=this.getters.getSheetPosition(t));const i=this.getters.getMainCellPosition(t,e.col,e.row),{col:n,row:o}=this.getters.getNextVisibleCellPosition(t,i.col,i.row);Wi(n,this.boundaries.top,this.boundaries)&&this.adjustPositionX(n),Wi(this.boundaries.left,o,this.boundaries)&&this.adjustPositionY(o)}adjustPositionX(e){const t=this.sheetId,{end:i}=this.getters.getColDimensions(t,e),n=this.getters.getNumberCols(t);if(this.offsetX+this.offsetCorrectionX+this.viewportWidth<i){let i=e;for(;this.getters.isColHidden(t,i)&&e<n;)i++;const o=this.getters.getColDimensions(t,i).end,s=this.searchHeaderIndex("COL",o-this.viewportWidth-this.offsetCorrectionX,this.boundaries.left,!0);this.offsetX=this.getters.getColDimensions(t,s).end-this.offsetCorrectionX,this.offsetScrollbarX=this.offsetX,this.adjustViewportZoneX()}else if(this.left>e){let i=e;for(;this.getters.isColHidden(t,i)&&e>0;)i--;this.offsetX=this.getters.getColDimensions(t,i).start-this.offsetCorrectionX,this.offsetScrollbarX=this.offsetX,this.adjustViewportZoneX()}}adjustPositionY(e){const t=this.sheetId,{end:i}=this.getters.getRowDimensions(t,e),n=this.getters.getNumberRows(t);if(this.offsetY+this.viewportHeight+this.offsetCorrectionY<i){let i=e;for(;this.getters.isRowHidden(t,i)&&e<n;)i++;const o=this.getters.getRowDimensions(t,i).end,s=this.searchHeaderIndex("ROW",o-this.viewportHeight-this.offsetCorrectionY,this.boundaries.top,!0);this.offsetY=this.getters.getRowDimensions(t,s).end-this.offsetCorrectionY,this.offsetScrollbarY=this.offsetY,this.adjustViewportZoneY()}else if(this.top>e){let i=e;for(;this.getters.isRowHidden(t,i)&&e>0;)i--;this.offsetY=this.getters.getRowDimensions(t,i).start-this.offsetCorrectionY,this.offsetScrollbarY=this.offsetY,this.adjustViewportZoneY()}}setViewportOffset(e,t){this.setViewportOffsetX(e),this.setViewportOffsetY(t)}adjustViewportZone(){this.adjustViewportZoneX(),this.adjustViewportZoneY()}getVisibleRect(e){const t=zi(e,this.zone);if(t){return{x:this.getters.getColRowOffset("COL",this.zone.left,t.left)+this.offsetCorrectionX,y:this.getters.getColRowOffset("ROW",this.zone.top,t.top)+this.offsetCorrectionY,width:Math.min(this.getters.getColRowOffset("COL",t.left,t.right+1),this.viewportWidth),height:Math.min(this.getters.getColRowOffset("ROW",t.top,t.bottom+1),this.viewportHeight)}}}getFullRect(e){if(zi(e,this.zone)){return{x:this.getters.getColRowOffset("COL",this.zone.left,e.left)+this.offsetCorrectionX,y:this.getters.getColRowOffset("ROW",this.zone.top,e.top)+this.offsetCorrectionY,width:this.getters.getColRowOffset("COL",e.left,e.right+1),height:this.getters.getColRowOffset("ROW",e.top,e.bottom+1)}}}isVisible(e,t){return t<=this.bottom&&t>=this.top&&e>=this.left&&e<=this.right&&!this.getters.isColHidden(this.sheetId,e)&&!this.getters.isRowHidden(this.sheetId,t)}searchHeaderIndex(e,t,i=0,n=!1){if(this.viewportWidth<=0||this.viewportHeight<=0)return-1;let o=0;const s=this.sheetId,r=this.getters.getNumberHeaders(s,e);for(let a=i;a<=r-1;a++){const i=n||"COL"!==e?a<this.top&&a>this.bottom:a<this.left&&a>this.right;if(!this.getters.isHeaderHidden(s,e,a)&&!i&&(o+="COL"===e?this.getters.getColSize(s,a):this.getters.getRowSize(s,a),o>t))return a}return-1}get zone(){return{left:this.left,right:this.right,top:this.top,bottom:this.bottom}}setViewportOffsetX(e){this.canScrollHorizontally&&(this.offsetScrollbarX=e,this.adjustViewportZoneX())}setViewportOffsetY(e){this.canScrollVertically&&(this.offsetScrollbarY=e,this.adjustViewportZoneY())}adjustViewportOffsetX(){if(this.canScrollHorizontally){const{width:e}=this.getMaxSize();this.viewportWidth+this.offsetScrollbarX>e&&(this.offsetScrollbarX=Math.max(0,e-this.viewportWidth))}this.left=this.getColIndex(this.offsetScrollbarX,!0),this.right=this.getColIndex(this.offsetScrollbarX+this.viewportWidth,!0),-1===this.right&&(this.right=this.boundaries.right),this.adjustViewportZoneX()}adjustViewportOffsetY(){if(this.canScrollVertically){const{height:e}=this.getMaxSize();this.viewportHeight+this.offsetScrollbarY>e&&(this.offsetScrollbarY=Math.max(0,e-this.viewportHeight))}this.top=this.getRowIndex(this.offsetScrollbarY,!0),this.bottom=this.getRowIndex(this.offsetScrollbarY+this.viewportWidth,!0),-1===this.bottom&&(this.bottom=this.boundaries.bottom),this.adjustViewportZoneY()}adjustViewportZoneX(){const e=this.sheetId;this.left=this.searchHeaderIndex("COL",this.offsetScrollbarX,this.boundaries.left),this.right=Math.min(this.boundaries.right,this.searchHeaderIndex("COL",this.viewportWidth,this.left)),this.viewportWidth&&(-1===this.left&&(this.left=this.boundaries.left),-1===this.right&&(this.right=this.boundaries.right),this.offsetX=this.getters.getColDimensions(e,this.left).start-this.getters.getColDimensions(e,this.boundaries.left).start)}adjustViewportZoneY(){const e=this.sheetId;this.top=this.searchHeaderIndex("ROW",this.offsetScrollbarY,this.boundaries.top),this.bottom=Math.min(this.boundaries.bottom,this.searchHeaderIndex("ROW",this.viewportHeight,this.top)),this.viewportHeight&&(-1===this.top&&(this.top=this.boundaries.top),-1===this.bottom&&(this.bottom=this.boundaries.bottom),this.offsetY=this.getters.getRowDimensions(e,this.top).start-this.getters.getRowDimensions(e,this.boundaries.top).start)}}class hb extends Gg{constructor(){super(...arguments),this.viewports={},this.sheetViewWidth=1e3,this.sheetViewHeight=1e3,this.gridOffsetX=0,this.gridOffsetY=0,this.sheetsWithDirtyViewports=new Set}allowDispatch(e){switch(e.type){case"SET_VIEWPORT_OFFSET":return this.checkScrollingDirection(e);case"RESIZE_SHEETVIEW":return this.chainValidations(this.checkValuesAreDifferent,this.checkPositiveDimension)(e);default:return 0}}handleEvent(e){switch(e.type){case"HeadersSelected":case"AlterZoneCorner":break;case"ZonesSelected":const t=this.getters.getActiveSheetId();let{col:i,row:n}=Qi(e.previousAnchor.zone,e.anchor.zone);if("updateAnchor"===e.mode){const o=e.previousAnchor.zone,s=e.anchor.zone,{top:r,bottom:a,left:l,right:c}=this.getMainInternalViewport(t);o.left===s.left&&o.right===s.right&&(i=l>i||i>c?l:i),o.top===s.top&&o.bottom===s.bottom&&(n=r>n||n>a?r:n)}i=Math.min(i,this.getters.getNumberCols(t)-1),n=Math.min(n,this.getters.getNumberRows(t)-1),this.refreshViewport(t,{col:i,row:n})}}handle(e){var t;switch(e.type){case"START":this.selection.observe(this,{handleEvent:this.handleEvent.bind(this)}),this.resetViewports(this.getters.getActiveSheetId());break;case"UNDO":case"REDO":this.resetSheetViews();break;case"RESIZE_SHEETVIEW":this.resizeSheetView(e.height,e.width,e.gridOffsetX,e.gridOffsetY);break;case"SET_VIEWPORT_OFFSET":this.setSheetViewOffset(e.offsetX,e.offsetY);break;case"SHIFT_VIEWPORT_DOWN":const i=this.getters.getActiveSheetId(),{top:n,viewportHeight:o,offsetCorrectionY:s}=this.getMainInternalViewport(i),r=this.getters.getRowDimensions(i,n);this.shiftVertically(r.start+o-s);break;case"SHIFT_VIEWPORT_UP":{const e=this.getters.getActiveSheetId(),{top:t,viewportHeight:i,offsetCorrectionY:n}=this.getMainInternalViewport(e),o=this.getters.getRowDimensions(e,t);this.shiftVertically(o.end-n-i);break}case"REMOVE_COLUMNS_ROWS":case"RESIZE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"UPDATE_FILTER":this.resetViewports(e.sheetId);break;case"UPDATE_CELL":("content"in e||"format"in e||void 0!==(null===(t=e.style)||void 0===t?void 0:t.fontSize))&&this.sheetsWithDirtyViewports.add(e.sheetId);break;case"DELETE_SHEET":this.cleanViewports(),this.sheetsWithDirtyViewports.delete(e.sheetId);break;case"ACTIVATE_SHEET":this.setViewports(),this.refreshViewport(e.sheetIdTo);break;case"UNFREEZE_ROWS":case"UNFREEZE_COLUMNS":case"FREEZE_COLUMNS":case"FREEZE_ROWS":case"UNFREEZE_COLUMNS_ROWS":this.resetViewports(this.getters.getActiveSheetId());break;case"START_EDITION":const{col:a,row:l}=this.getters.getPosition();this.refreshViewport(this.getters.getActiveSheetId(),{col:a,row:l})}}finalize(){for(const e of this.sheetsWithDirtyViewports)this.resetViewports(e);this.sheetsWithDirtyViewports=new Set,this.setViewports()}setViewports(){var e;const t=this.getters.getSheetIds();for(const i of t)(null===(e=this.viewports[i])||void 0===e?void 0:e.bottomRight)||this.resetViewports(i)}getColIndex(e){const t=this.getters.getActiveSheetId();return Math.max(...this.getSubViewports(t).map((t=>t.getColIndex(e))))}getRowIndex(e){const t=this.getters.getActiveSheetId();return Math.max(...this.getSubViewports(t).map((t=>t.getRowIndex(e))))}getSheetViewDimensionWithHeaders(){return{width:this.sheetViewWidth+this.gridOffsetX,height:this.sheetViewHeight+this.gridOffsetY}}getSheetViewDimension(){return{width:this.sheetViewWidth,height:this.sheetViewHeight}}getActiveMainViewport(){const e=this.getters.getActiveSheetId();return this.getMainViewport(e)}getActiveSheetScrollInfo(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e);return{scrollX:t.offsetX,scrollY:t.offsetY}}getActiveSheetDOMScrollInfo(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e);return{scrollX:t.offsetScrollbarX,scrollY:t.offsetScrollbarY}}getSheetViewVisibleCols(){const e=this.getters.getActiveSheetId(),t=this.getSubViewports(e);return[...new Set(t.map((e=>$e(e.left,e.right+1))).flat())].filter((t=>t>=0&&!this.getters.isHeaderHidden(e,"COL",t)))}getSheetViewVisibleRows(){const e=this.getters.getActiveSheetId(),t=this.getSubViewports(e);return[...new Set(t.map((e=>$e(e.top,e.bottom+1))).flat())].filter((t=>t>=0&&!this.getters.isHeaderHidden(e,"ROW",t)))}getMainViewportRect(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e),{xSplit:i,ySplit:n}=this.getters.getPaneDivisions(e);let{width:o,height:s}=t.getMaxSize();return{x:this.getters.getColDimensions(e,i).start,y:this.getters.getRowDimensions(e,n).start,width:o,height:s}}getMaximumSheetOffset(){const e=this.getters.getActiveSheetId(),{width:t,height:i}=this.getMainViewportRect(),n=this.getMainInternalViewport(e);return{maxOffsetX:Math.max(0,t-n.viewportWidth+1),maxOffsetY:Math.max(0,i-n.viewportHeight+1)}}getColRowOffsetInViewport(e,t,i){if(i<t)return-this.getColRowOffsetInViewport(e,i,t);const n=this.getters.getActiveSheetId(),o="COL"===e?this.getters.getSheetViewVisibleCols():this.getters.getSheetViewVisibleRows(),s=o.findIndex((e=>t>=e));let r=o.findIndex((e=>i<=e));r=-1===r?o.length:r;const a=o.slice(s,r);let l=0;for(const t of a)l+="COL"===e?this.getters.getColSize(n,t):this.getters.getRowSize(n,t);return l}isVisibleInViewport(e,t,i){return this.getSubViewports(e).some((e=>e.isVisible(t,i)))}getEdgeScrollCol(e,t,i){let n=!1,o=0,s=0;const{xSplit:r}=this.getters.getPaneDivisions(this.getters.getActiveSheetId()),{width:a}=this.getSheetViewDimension(),{x:l}=this.getMainViewportCoordinates(),c=this.getActiveSheetScrollInfo().scrollX;return e>a?(n=!0,s=Wt(e-a),o=1):e<l&&i>=l&&c>0?(n=!0,s=Wt(l-e),o=-1):r&&t<l&&e>l&&(n=!0,s=Wt(e),o="reset"),{canEdgeScroll:n,direction:o,delay:s}}getEdgeScrollRow(e,t,i){let n=!1,o=0,s=0;const{ySplit:r}=this.getters.getPaneDivisions(this.getters.getActiveSheetId()),{height:a}=this.getSheetViewDimension(),{y:l}=this.getMainViewportCoordinates(),c=this.getActiveSheetScrollInfo().scrollY;return e>a?(n=!0,s=Wt(e-a),o=1):e<l&&i>=l&&c>0?(n=!0,s=Wt(l-e),o=-1):r&&t<l&&e>l&&(n=!0,s=Wt(e),o="reset"),{canEdgeScroll:n,direction:o,delay:s}}getVisibleRect(e){const t=this.getters.getActiveSheetId();return this.mapViewportsToRect(t,(t=>t.getVisibleRect(e)))}getRect(e){const t=this.getters.getActiveSheetId();return this.mapViewportsToRect(t,(t=>t.getFullRect(e)))}getMainViewportCoordinates(){const e=this.getters.getActiveSheetId(),{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e);return{x:this.getters.getColDimensions(e,t).start,y:this.getters.getRowDimensions(e,i).start}}getAllActiveViewportsZones(){const e=this.getters.getActiveSheetId();return this.getSubViewports(e)}ensureMainViewportExist(e){this.viewports[e]||this.resetViewports(e)}getSubViewports(e){return this.ensureMainViewportExist(e),Object.values(this.viewports[e]).filter(Xe)}checkPositiveDimension(e){return e.width<0||e.height<0?69:0}checkValuesAreDifferent(e){const{height:t,width:i}=this.getSheetViewDimension();return e.gridOffsetX===this.gridOffsetX&&e.gridOffsetY===this.gridOffsetY&&e.width===i&&e.height===t?77:0}checkScrollingDirection({offsetX:e,offsetY:t}){const i=this.getMainInternalViewport(this.getters.getActiveSheetId());return!i.canScrollHorizontally&&e>0||!i.canScrollVertically&&t>0?70:0}getMainViewport(e){const t=this.getMainInternalViewport(e);return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}getMainInternalViewport(e){return this.ensureMainViewportExist(e),this.viewports[e].bottomRight}cleanViewports(){const e={};for(const t of this.getters.getSheetIds())e[t]=this.viewports[t];this.viewports=e}resetSheetViews(){this.cleanViewports();for(let e of Object.keys(this.viewports)){const t=this.getters.getSheetPosition(e);this.resetViewports(e);const i=this.getSubViewports(e);Object.values(i).forEach((e=>{e.adjustPosition(t)}))}}resizeSheetView(e,t,i=0,n=0){this.sheetViewHeight=e,this.sheetViewWidth=t,this.gridOffsetX=i,this.gridOffsetY=n,this.recomputeViewports()}recomputeViewports(){for(const e of this.getters.getSheetIds())this.resetViewports(e)}setSheetViewOffset(e,t){const i=this.getters.getActiveSheetId(),{maxOffsetX:n,maxOffsetY:o}=this.getMaximumSheetOffset();this.getSubViewports(i).forEach((i=>i.setViewportOffset(Me(e,0,n),Me(t,0,o))))}getViewportOffset(e){var t,i;return{x:(null===(t=this.viewports[e])||void 0===t?void 0:t.bottomRight.offsetScrollbarX)||0,y:(null===(i=this.viewports[e])||void 0===i?void 0:i.bottomRight.offsetScrollbarY)||0}}resetViewports(e){if(!this.getters.tryGetSheet(e))return;const{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e),n=this.getters.getNumberCols(e),o=this.getters.getNumberRows(e),s=Math.min(this.getters.getColRowOffset("COL",0,t,e),this.sheetViewWidth),r=Math.min(this.getters.getColRowOffset("ROW",0,i,e),this.sheetViewHeight),a=Math.max(this.sheetViewWidth-s,0),l=Math.max(this.sheetViewHeight-r,0),{xRatio:c,yRatio:h}=this.getFrozenSheetViewRatio(e),d=c<1,u=h<1,g=this.getViewportOffset(e),p={topLeft:i&&t&&new cb(this.getters,e,{left:0,right:t-1,top:0,bottom:i-1},{width:s,height:r},{canScrollHorizontally:!1,canScrollVertically:!1},{x:0,y:0})||void 0,topRight:i&&new cb(this.getters,e,{left:t,right:n-1,top:0,bottom:i-1},{width:a,height:r},{canScrollHorizontally:d,canScrollVertically:!1},{x:d?g.x:0,y:0})||void 0,bottomLeft:t&&new cb(this.getters,e,{left:0,right:t-1,top:i,bottom:o-1},{width:s,height:l},{canScrollHorizontally:!1,canScrollVertically:u},{x:0,y:u?g.y:0})||void 0,bottomRight:new cb(this.getters,e,{left:t,right:n-1,top:i,bottom:o-1},{width:a,height:l},{canScrollHorizontally:d,canScrollVertically:u},{x:d?g.x:0,y:u?g.y:0})};this.viewports[e]=p}refreshViewport(e,t){this.getSubViewports(e).forEach((e=>{e.adjustViewportZone(),e.adjustPosition(t)}))}shiftVertically(e){const t=this.getters.getActiveSheetId(),{top:i}=this.getMainInternalViewport(t),{scrollX:n}=this.getActiveSheetScrollInfo();this.setSheetViewOffset(n,e);const{anchor:o}=this.getters.getSelection();if(o.cell.row>=this.getters.getPaneDivisions(t).ySplit){const e=this.getMainInternalViewport(t).top-i;this.selection.selectCell(o.cell.col,o.cell.row+e)}}getVisibleFigures(){const e=this.getters.getActiveSheetId(),t=[],i=this.getters.getFigures(e),{scrollX:n,scrollY:o}=this.getActiveSheetScrollInfo(),{x:s,y:r}=this.getters.getMainViewportCoordinates(),{width:a,height:l}=this.getters.getSheetViewDimensionWithHeaders();for(const e of i)e.x>=s&&(e.x+e.width<=s+n||e.x>=a+n+s)||e.y>=r&&(e.y+e.height<=r+o||e.y>=l+o+r)||t.push(e);return t}getFrozenSheetViewRatio(e){const{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e),n=this.getters.getColDimensions(e,t).start,o=this.getters.getRowDimensions(e,i).start;return{xRatio:n/(this.sheetViewWidth+this.gridOffsetX),yRatio:o/(this.sheetViewHeight+this.gridOffsetY)}}mapViewportsToRect(e,t){let i=1/0,n=1/0,o=0,s=0,r=!1;for(const a of this.getSubViewports(e)){const e=t(a);e&&(r=!0,i=Math.min(i,e.x),n=Math.min(n,e.y),o=Math.max(o,e.x+e.width),s=Math.max(s,e.y+e.height))}return r?{x:i+this.gridOffsetX,y:n+this.gridOffsetY,width:o-i,height:s-n}:{x:0,y:0,width:0,height:0}}}hb.getters=["getColIndex","getRowIndex","getActiveMainViewport","getSheetViewDimension","getSheetViewDimensionWithHeaders","getMainViewportRect","isVisibleInViewport","getEdgeScrollCol","getEdgeScrollRow","getVisibleFigures","getVisibleRect","getColRowOffsetInViewport","getMainViewportCoordinates","getActiveSheetScrollInfo","getActiveSheetDOMScrollInfo","getSheetViewVisibleCols","getSheetViewVisibleRows","getFrozenSheetViewRatio","getAllActiveViewportsZones","getRect"];class db extends Gg{allowDispatch(e){if("SORT_CELLS"===e.type){if(!Wi(e.col,e.row,e.zone))throw new Error(s("The anchor must be part of the provided zone"));return this.checkValidations(e,this.checkMerge,this.checkMergeSizes)}return 0}handle(e){if("SORT_CELLS"===e.type)this.sortZone(e.sheetId,e,e.zone,e.sortDirection,e.sortOptions||{})}checkMerge({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;for(let i=t.top;i<=t.bottom;i++)for(let n=t.left;n<=t.right;n++)if(!this.getters.isInMerge(e,n,i))return 64;return 0}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;const i=this.getters.getMerges(e).filter((e=>Hi(e,t))),n=ji(i[0]);let[o,s]=[n.width,n.height];return i.every((e=>{let[t,i]=[e.right-e.left+1,e.bottom-e.top+1];return t===o&&i===s}))?0:64}expand(e,t){const{left:i,right:n,top:o,bottom:s}=this.getters.expandZone(e,t);return{left:Math.max(0,i),right:Math.min(this.getters.getNumberCols(e)-1,n),top:Math.max(0,o),bottom:Math.min(this.getters.getNumberRows(e)-1,s)}}checkExpandedValues(e,t){const i=this.expand(e,t);let n;if(this.getters.doesIntersectMerge(e,i)){const{left:t,right:o,top:s,bottom:r}=i;for(let i=t;i<=o;i++)for(let t=s;t<=r;t++){const{col:o,row:s}=this.getters.getMainCellPosition(e,i,t);if(n=this.getters.getCell(e,o,s),null==n?void 0:n.formattedValue)return!0}}else for(let t of this.getters.getCellsInZone(e,i))if(null==t?void 0:t.formattedValue)return!0;return!1}getContiguousZone(e,t){let i,{top:n,bottom:o,left:s,right:r}=t,a=!1;for(;!a;)a=!0,n>0&&(i=this.checkExpandedValues(e,{left:s-1,right:r+1,top:n-1,bottom:n-1}),i&&(a=!1,n--)),s>0&&(i=this.checkExpandedValues(e,{left:s-1,right:s-1,top:n-1,bottom:o+1}),i&&(a=!1,s--)),r<this.getters.getNumberCols(e)-1&&(i=this.checkExpandedValues(e,{left:r+1,right:r+1,top:n-1,bottom:o+1}),i&&(a=!1,r++)),o<this.getters.getNumberRows(e)-1&&(i=this.checkExpandedValues(e,{left:s-1,right:r+1,top:o+1,bottom:o+1}),i&&(a=!1,o++));return{left:s,right:r,top:n,bottom:o}}hasHeader(e){if(1===e[0].length)return!1;let t=e.map((e=>e.map((e=>(null==e?void 0:e.evaluated.type)||hn.empty))));return t[0][0]===hn.empty&&(t=t.slice(1)),!t.some((e=>e[0]===hn.empty))&&!!t.some((e=>e[1]!==hn.empty&&e[0]!==e[1]))}sortZone(e,t,i,n,o){const[s,r]=this.mainCellsSteps(e,i);let a=this.getters.getMainCellPosition(e,t.col,t.row).col,l=Object.assign({},i),c=this.mainCells(e,i);!o.sortHeaders&&this.hasHeader(c)&&(l.top+=r),c=this.mainCells(e,l);const h=function(e,t,i){const n=e.map(lo);let o=n.filter((e=>e.type===hn.empty)),s=n.filter((e=>e.type!==hn.empty));i&&(s.push(...o.map((e=>({...e,type:hn.number,value:0})))),o=[]);const r="descending"===t?-1:1;return s.sort(((e,t)=>{let i=ao.indexOf(e.type)-ao.indexOf(t.type);return 0===i&&(i=e.type===hn.text||e.type===hn.error?e.value.localeCompare(t.value):e.value-t.value),r*i})).concat(o)}(c[a-l.left],n,Boolean(o.emptyCellAsZero)),d=h.map((e=>e.index)),[u,g]=[c.length,c[0].length],p=[];for(let t=0;t<u;t++)for(let i=0;i<g;i++){let n=c[t][d[i]],o=l.left+t*s,a=l.top+i*r,h={sheetId:e,col:o,row:a,content:""};if(n){let t=n.content;if(n.isFormula()){const i=a-this.getters.getCellPosition(n.id).row,o=this.getters.createAdaptedRanges(n.dependencies,0,i,e);t=this.getters.buildFormulaContent(e,n,o)}h.style=n.style,h.content=t,h.format=n.format}p.push(h)}p.forEach((e=>this.dispatch("UPDATE_CELL",e)))}mainCellsSteps(e,t){const i=this.getters.getMerge(e,t.left,t.top);return[i?i.right-i.left+1:1,i?i.bottom-i.top+1:1]}mainCells(e,t){const[i,n]=this.mainCellsSteps(e,t),o=[],s=$e(t.left,t.right+1,i),r=$e(t.top,t.bottom+1,n);for(const t of s){const i=[];o.push(i);for(const n of r)i.push(this.getters.getCell(e,t,n))}return o}}db.getters=["getContiguousZone"];class ub extends Gg{constructor(){super(...arguments),this.showFormulas=!1}handle(e){if("SET_FORMULA_VISIBILITY"===e.type)this.showFormulas=e.show}shouldShowFormulas(){return this.showFormulas}}ub.getters=["shouldShowFormulas"];class gb extends Gg{constructor(){super(...arguments),this.ctx=document.createElement("canvas").getContext("2d")}allowDispatch(e){switch(e.type){case"AUTORESIZE_ROWS":case"AUTORESIZE_COLUMNS":try{this.getters.getSheet(e.sheetId);break}catch(e){return 27}}return 0}handle(e){switch(e.type){case"AUTORESIZE_COLUMNS":for(let t of e.cols){const i=this.getColMaxWidth(e.sheetId,t);0!==i&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"COL",size:i,sheetId:e.sheetId})}break;case"AUTORESIZE_ROWS":this.dispatch("RESIZE_COLUMNS_ROWS",{elements:e.rows,dimension:"ROW",size:null,sheetId:e.sheetId})}}getCellWidth(e,{col:t,row:i}){const n=this.getters.getCell(e,t,i);let o=0;n&&(o+=this.getTextWidth(n));this.getters.getConditionalIcon(t,i)&&(o+=ke(this.getters.getCellStyle(n))+2*L);if(this.getters.isFilterHeader(e,t,i)&&(o+=20),o>0&&(o+=2*V,"wrap"===this.getters.getCellStyle(n).wrapping)){const e=en({col:t,row:i}),n=this.getters.getColSize(this.getters.getActiveSheetId(),e.left);return Math.min(n,o)}return o}getTextWidth(e){const t=this.getters.getCellText(e,this.getters.shouldShowFormulas()),{sheetId:i,col:n,row:o}=this.getters.getCellPosition(e.id);return _e(this.ctx,t,this.getters.getCellComputedStyle(i,n,o))}getCellText(e,t=!1){return t&&(e.isFormula()||e.evaluated.type===hn.error)?e.content:e.formattedValue}getCellMultiLineText(e,t){const i=this.getters.getCellStyle(e),n=this.getters.getCellText(e).split(" "),o=[];let s="",r=t;for(let e of n){const n=this.splitWordToSpecificWidth(this.ctx,e,t,i),a=n.pop(),l=_e(this.ctx,a,i);if(n.length)""!==s&&(o.push(s),s="",r=t),n.forEach((e=>{o.push(e)})),s=a,r=t-l;else{const e=""===s?a:" "+a,n=_e(this.ctx,e,i);n<=r?(s+=e,r-=n):(o.push(s),s=a,r=t-l)}}return""!==s&&o.push(s),o}getColDimensions(e,t){const i=this.getColRowOffset("COL",0,t,e),n=this.getters.getColSize(e,t);return{start:i,size:n,end:i+(this.getters.isColHidden(e,t)?0:n)}}getRowDimensions(e,t){const i=this.getColRowOffset("ROW",0,t,e),n=this.getters.getRowSize(e,t);return{start:i,size:n,end:i+(this.getters.isRowHidden(e,t)?0:n)}}getColRowOffset(e,t,i,n=this.getters.getActiveSheetId()){if(i<t)return-this.getColRowOffset(e,i,t);let o=0;for(let s=t;s<i;s++)this.getters.isHeaderHidden(n,e,s)||(o+="COL"===e?this.getters.getColSize(n,s):this.getters.getRowSize(n,s));return o}getColMaxWidth(e,t){const i=Xi(this.getters.getColsZone(e,t,t)).map((t=>this.getCellWidth(e,t)));return Math.max(0,lt(i))}splitWordToSpecificWidth(e,t,i,n){if(_e(e,t,n)<=i)return[t];const o=[];let s="";for(let r of t){_e(e,s+r,n)>i?(o.push(s),s=r):s+=r}return o.push(s),o}}gb.getters=["getCellWidth","getTextWidth","getCellText","getCellMultiLineText","getColDimensions","getRowDimensions","getColRowOffset"];const pb=(new sn).add("sheet",xv).add("header visibility",Cv).add("filters",bv).add("cell",dv).add("merge",Ev).add("headerSize",Sv).add("borders",cv).add("conditional formatting",pv).add("figures",mv).add("chart",uv),mb=(new sn).add("selection",Zv).add("ui_sheet",gb).add("header_visibility_ui",Hv).add("ui_options",ub).add("evaluation",$v).add("evaluation_filter",Uv).add("evaluation_cf",Pv).add("evaluation_chart",Lv).add("clipboard",Fv).add("edition",Zg).add("selectionInputManager",Xv).add("highlight",Wv).add("viewport",hb).add("grid renderer",Gv).add("autofill",Iv).add("find_and_replace",zv).add("sort",db).add("automatic_sum",Tv).add("format",Bv).add("cell_popovers",Av).add("selection_multiuser",lb).add("custom_colors",Dv),fb=new sn;fb.add("link",{condition:e=>e.isLink(),action:(e,t)=>{e.action(t)},sequence:5});class vb{constructor(){this.focusableElement=void 0}setFocusableElement(e){this.focusableElement=e}focus(){var e;null===(e=this.focusableElement)||void 0===e||e.focus()}}xn`
|
|
1390
|
+
`}function kf(e){return new Wp(e.join("\n"))}function $f(e,...t){let i=[e[0]];for(let n=0;n<t.length;n++){const o=t[n]instanceof Wp?t[n]:Of(t[n]);i.push(o+e[n+1])}return new Wp(et(i))}function Lf(e){return e.replace(/[a-z0-9]+:(?=[a-z0-9]+)/gi,"")}function Pf(e){return e.replace(/([a-z0-9]+):(?=[a-z0-9]+)/gi,"$1\\:")}class Uf{constructor(e){this.value=e}asString(){return Fm(String(this.value))}asBool(){return Boolean(Number(this.value))}asNum(){return Number(this.value)}}class Vf{constructor(e,t,i){this.currentFile=void 0,this.rootFile=e,this.currentFile=e.file.fileName,this.xlsxFileStructure=t,this.warningManager=i,this.areNamespaceIgnored=null!==(new DOMParser).parseFromString("<t:test xmlns:t='a'/>","text/xml").querySelector("test"),this.relationships={},e.rels&&this.extractRelationships(e.rels).map((e=>{this.relationships[e.id]=e}))}extractRelationships(e){return this.mapOnElements({parent:e.xml,query:"Relationship"},(e=>({id:this.extractAttr(e,"Id",{required:!0}).asString(),target:this.extractAttr(e,"Target",{required:!0}).asString(),type:this.extractAttr(e,"Type",{required:!0}).asString()})))}getListOfFiles(){return Object.values(this.xlsxFileStructure).flat().filter(Xe)}mapOnElements(e,t){var i;const n=[],o=this.currentFile;let s;if(e.children){const t=null===(i=this.querySelector(e.parent,e.query))||void 0===i?void 0:i.children;s=t||[]}else s=this.querySelectorAll(e.parent,e.query);if(s)for(let e of s)try{n.push(t(e))}catch(t){this.catchErrorOnElement(t,e)}return this.currentFile=o,n}catchErrorOnElement(e,t){const i=t?`Error when parsing an element <${t.tagName}> of file ${this.currentFile}, skip this element. \n${e.stack}`:`Error when parsing file ${this.currentFile}.`;this.warningManager.addParsingWarning([i,e.message].join("\n"))}extractAttr(e,t,i){const n=e.attributes[t];n||this.handleMissingValue(e,`attribute "${t}"`,i);const o=(null==n?void 0:n.value)?n.value:null==i?void 0:i.default;return void 0===o?void 0:new Uf(o)}extractTextContent(e,t){var i;if(void 0!==(null==t?void 0:t.default)&&"string"!=typeof t.default)throw new Error("extractTextContent default value should be a string");const n="preserve"===(null===(i=null==e?void 0:e.attributes["xml:space"])||void 0===i?void 0:i.value);let o=null==e?void 0:e.textContent;return e&&null!==o||this.handleMissingValue(e,"text content",t),o&&(o=n?o:o.trim()),o?Fm(o):null==t?void 0:t.default}extractChildAttr(e,t,i,n){var o;let s;s="number"==typeof t?e.children[t]:this.querySelector(e,t),s||this.handleMissingValue(e,"number"==typeof t?`child at index ${t}`:`child <${t}>`,n);const r=s?null===(o=this.extractAttr(s,i,n))||void 0===o?void 0:o.asString():null==n?void 0:n.default;return void 0!==r?new Uf(r):void 0}extractChildTextContent(e,t,i){if(void 0!==(null==i?void 0:i.default)&&"string"!=typeof i.default)throw new Error("extractTextContent default value should be a string");let n=this.querySelector(e,t);return n||this.handleMissingValue(e,`child <${t}>`,i),n?this.extractTextContent(n,i):null==i?void 0:i.default}handleMissingValue(e,t,i){if(null==i?void 0:i.required){if(void 0===(null==i?void 0:i.default))throw new Error(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, and no default value was set`);this.warningManager.addParsingWarning(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, replacing it by the default value ${i.default}`)}}extractColor(e,t,i){var n,o,s,r,a;if(!e)return i?{rgb:i}:void 0;const l=null===(n=this.extractAttr(e,"theme"))||void 0===n?void 0:n.asString();let c;if(void 0!==l){if(!t||!t.clrScheme)throw new Error("Color referencing a theme but no theme was provided");c=this.getThemeColor(l,t.clrScheme)}else c=null===(o=this.extractAttr(e,"rgb"))||void 0===o?void 0:o.asString();return{rgb:c,auto:null===(s=this.extractAttr(e,"auto"))||void 0===s?void 0:s.asBool(),indexed:null===(r=this.extractAttr(e,"indexed"))||void 0===r?void 0:r.asNum(),tint:null===(a=this.extractAttr(e,"tint"))||void 0===a?void 0:a.asNum()}}getTargetXmlFile(e){if(!e)throw new Error("Undefined target file");let t=e.target;t=t.replace("../",""),t=t.replace("./","");const i=this.getListOfFiles().find((e=>e.file.fileName.endsWith(t)));if(!i||!i.file)throw new Error("Cannot find target file");return i}querySelector(e,t){return t=this.areNamespaceIgnored?Lf(t):Pf(t),e.querySelector(t)}querySelectorAll(e,t){return t=this.areNamespaceIgnored?Lf(t):Pf(t),e.querySelectorAll(t)}getThemeColor(e,t){switch(e){case"0":return"FFFFFF";case"1":return"000000";case"2":return t[3].value;case"3":return t[2].value;default:return t[e].value}}}class zf extends Vf{getTheme(){return{clrScheme:this.mapOnElements({query:"a:clrScheme",parent:this.rootFile.file.xml,children:!0},(e=>({name:e.tagName,value:this.extractChildAttr(e,0,"val",{required:!0,default:qp}).asString(),lastClr:this.extractChildAttr(e,0,"lastClr",{default:qp}).asString()})))}}getSharedStrings(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"si"},(e=>"t"===e.children[0].tagName?this.extractTextContent(e)||"":this.mapOnElements({parent:e,query:"t"},(e=>this.extractTextContent(e)||"")).join("")))}}class Bf extends Vf{constructor(e,t,i,n){super(e,t,i),this.theme=n}extractConditionalFormattings(){const e=this.mapOnElements({parent:this.rootFile.file.xml,query:"worksheet > conditionalFormatting"},(e=>{var t;return{sqref:this.extractAttr(e,"sqref",{required:!0}).asString().split(" "),pivot:null===(t=this.extractAttr(e,"pivot"))||void 0===t?void 0:t.asBool(),cfRules:this.extractCFRules(e,this.theme)}}));return e.push(...this.mapOnElements({parent:this.rootFile.file.xml,query:"extLst x14:conditionalFormatting"},(e=>{var t;return{sqref:this.extractChildTextContent(e,"xm:sqref",{required:!0}).split(" "),pivot:null===(t=this.extractAttr(e,"xm:pivot"))||void 0===t?void 0:t.asBool(),cfRules:this.extractCFRules(e,this.theme)}}))),e}extractCFRules(e,t){return this.mapOnElements({parent:e,query:"cfRule, x14:cfRule"},(e=>{var i,n,o,s,r,a,l,c,h,d,u;const g=this.extractAttr(e,"type",{required:!0}).asString();if("dataBar"===g)throw new Error("Databars conditional formats are not supported.");return{type:g,priority:this.extractAttr(e,"priority",{required:!0}).asNum(),colorScale:this.extractCfColorScale(e,t),formula:this.extractCfFormula(e),iconSet:this.extractCfIconSet(e),dxfId:null===(i=this.extractAttr(e,"dxfId"))||void 0===i?void 0:i.asNum(),stopIfTrue:null===(n=this.extractAttr(e,"stopIfTrue"))||void 0===n?void 0:n.asBool(),aboveAverage:null===(o=this.extractAttr(e,"aboveAverage"))||void 0===o?void 0:o.asBool(),percent:null===(s=this.extractAttr(e,"percent"))||void 0===s?void 0:s.asBool(),bottom:null===(r=this.extractAttr(e,"bottom"))||void 0===r?void 0:r.asBool(),operator:null===(a=this.extractAttr(e,"operator"))||void 0===a?void 0:a.asString(),text:null===(l=this.extractAttr(e,"text"))||void 0===l?void 0:l.asString(),timePeriod:null===(c=this.extractAttr(e,"timePeriod"))||void 0===c?void 0:c.asString(),rank:null===(h=this.extractAttr(e,"rank"))||void 0===h?void 0:h.asNum(),stdDev:null===(d=this.extractAttr(e,"stdDev"))||void 0===d?void 0:d.asNum(),equalAverage:null===(u=this.extractAttr(e,"equalAverage"))||void 0===u?void 0:u.asBool()}}))}extractCfFormula(e){return this.mapOnElements({parent:e,query:"formula"},(e=>this.extractTextContent(e,{required:!0})))}extractCfColorScale(e,t){const i=this.querySelector(e,"colorScale");if(i)return{colors:this.mapOnElements({parent:i,query:"color"},(e=>this.extractColor(e,t,"ffffff"))),cfvos:this.extractCFVos(i)}}extractCfIconSet(e){var t,i;const n=this.querySelector(e,"iconSet, x14:iconSet");if(n)return{iconSet:this.extractAttr(n,"iconSet",{default:"3TrafficLights1"}).asString(),showValue:this.extractAttr(n,"showValue",{default:!0}).asBool(),percent:this.extractAttr(n,"percent",{default:!0}).asBool(),reverse:null===(t=this.extractAttr(n,"reverse"))||void 0===t?void 0:t.asBool(),custom:null===(i=this.extractAttr(n,"custom"))||void 0===i?void 0:i.asBool(),cfvos:this.extractCFVos(n),cfIcons:this.extractCfIcons(n)}}extractCfIcons(e){const t=this.mapOnElements({parent:e,query:"cfIcon, x14:cfIcon"},(e=>({iconSet:this.extractAttr(e,"iconSet",{required:!0}).asString(),iconId:this.extractAttr(e,"iconId",{required:!0}).asNum()})));return 0===t.length?void 0:t}extractCFVos(e){return this.mapOnElements({parent:e,query:"cfvo, x14:cfvo"},(e=>{var t,i;return{type:this.extractAttr(e,"type",{required:!0}).asString(),gte:null===(t=this.extractAttr(e,"gte",{default:!0}))||void 0===t?void 0:t.asBool(),value:e.attributes.val?null===(i=this.extractAttr(e,"val"))||void 0===i?void 0:i.asString():this.extractChildTextContent(e,"f, xm:f")}}))}}class Hf extends Vf{extractChart(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"c:chartSpace"},(e=>{const t=this.getChartType(e);if(!xm[t])throw new Error(`Unsupported chart type ${t}`);const i=this.mapOnElements({parent:e,query:"c:title a:t"},(e=>e.textContent||"")).join(""),n=this.extractChildAttr(e,"c:grouping","val",{default:"clustered"}).asString();return{title:i,type:xm[t],dataSets:this.extractChartDatasets(this.querySelector(e,`c:${t}`)),backgroundColor:this.extractChildAttr(e,"c:chartSpace > c:spPr a:srgbClr","val",{default:"ffffff"}).asString(),verticalAxisPosition:"r"===this.extractChildAttr(e,"c:valAx > c:axPos","val",{default:"l"}).asString()?"right":"left",legendPosition:ym[this.extractChildAttr(e,"c:legendPos","val",{default:"none"}).asString()],stacked:"stacked"===n,fontColor:"000000"}}))[0]}extractChartDatasets(e){return this.mapOnElements({parent:e,query:"c:ser"},(e=>({label:this.extractChildTextContent(e,"c:cat c:f"),range:this.extractChildTextContent(e,"c:val c:f",{required:!0})})))}getChartType(e){const t=this.querySelector(e,"c:plotArea");if(!t)throw new Error("Missing plot area in the chart definition.");for(let e of t.children){const t=Lf(e.tagName);if(Gp.some((e=>e===t)))return t}throw new Error("Unknown chart type")}}class Wf extends Vf{extractFigures(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"xdr:wsDr",children:!0},(e=>{if("twoCellAnchor"!==Lf(e.tagName))throw new Error("Only twoCellAnchor are supported for xlsx drawings.");const t=this.querySelector(e,"c:chart");if(!t)throw new Error("Only chart figures are currently supported.");return{anchors:[this.extractFigureAnchor("xdr:from",e),this.extractFigureAnchor("xdr:to",e)],data:this.extractChart(t)}}))}extractFigureAnchor(e,t){const i=this.querySelector(t,e);if(!i)throw new Error(`Missing anchor element ${e}`);return{col:Number(this.extractChildTextContent(i,"xdr:col",{required:!0})),colOffset:Number(this.extractChildTextContent(i,"xdr:colOff",{required:!0})),row:Number(this.extractChildTextContent(i,"xdr:row",{required:!0})),rowOffset:Number(this.extractChildTextContent(i,"xdr:rowOff",{required:!0}))}}extractChart(e){const t=this.extractAttr(e,"r:id",{required:!0}).asString(),i=this.getTargetXmlFile(this.relationships[t]),n=new Hf(i,this.xlsxFileStructure,this.warningManager).extractChart();if(!n)throw new Error("Unable to extract chart definition");return n}}class Gf extends Vf{getPivotTable(){return this.mapOnElements({query:":root",parent:this.rootFile.file.xml},(e=>({displayName:this.extractAttr(e,"name",{required:!0}).asString(),id:this.extractAttr(e,"name",{required:!0}).asString(),ref:this.extractChildAttr(e,"location","ref",{required:!0}).asString(),headerRowCount:this.extractChildAttr(e,"location","firstDataRow",{default:0}).asNum(),totalsRowCount:1,cols:[],style:{showFirstColumn:!0,showRowStripes:!0}})))[0]}}class qf extends Vf{getTable(){return this.mapOnElements({query:"table",parent:this.rootFile.file.xml},(e=>{var t;return{displayName:this.extractAttr(e,"displayName",{required:!0}).asString(),name:null===(t=this.extractAttr(e,"name"))||void 0===t?void 0:t.asString(),id:this.extractAttr(e,"id",{required:!0}).asString(),ref:this.extractAttr(e,"ref",{required:!0}).asString(),headerRowCount:this.extractAttr(e,"headerRowCount",{default:1}).asNum(),totalsRowCount:this.extractAttr(e,"totalsRowCount",{default:0}).asNum(),cols:this.extractTableCols(e),style:this.extractTableStyleInfo(e),autoFilter:this.extractTableAutoFilter(e)}}))[0]}extractTableCols(e){return this.mapOnElements({query:"tableColumn",parent:e},(e=>({id:this.extractAttr(e,"id",{required:!0}).asString(),name:this.extractAttr(e,"name",{required:!0}).asString(),colFormula:this.extractChildTextContent(e,"calculatedColumnFormula")})))}extractTableStyleInfo(e){return this.mapOnElements({query:"tableStyleInfo",parent:e},(e=>{var t,i,n,o,s;return{name:null===(t=this.extractAttr(e,"name"))||void 0===t?void 0:t.asString(),showFirstColumn:null===(i=this.extractAttr(e,"showFirstColumn"))||void 0===i?void 0:i.asBool(),showLastColumn:null===(n=this.extractAttr(e,"showLastColumn"))||void 0===n?void 0:n.asBool(),showRowStripes:null===(o=this.extractAttr(e,"showRowStripes"))||void 0===o?void 0:o.asBool(),showColumnStripes:null===(s=this.extractAttr(e,"showColumnStripes"))||void 0===s?void 0:s.asBool()}}))[0]}extractTableAutoFilter(e){return this.mapOnElements({query:"autoFilter",parent:e},(e=>({columns:this.extractFilterColumns(e),zone:this.extractAttr(e,"ref",{required:!0}).asString()})))[0]}extractFilterColumns(e){return this.mapOnElements({query:"tableColumn",parent:e},(t=>({colId:this.extractAttr(e,"colId",{required:!0}).asNum(),hiddenButton:this.extractAttr(e,"hiddenButton",{default:!1}).asBool(),filters:this.extractSimpleFilter(t)})))}extractSimpleFilter(e){return this.mapOnElements({query:"filter",parent:e},(e=>({val:this.extractAttr(e,"val",{required:!0}).asString()})))}}class Zf extends Vf{constructor(e,t,i,n){super(e,t,i),this.theme=n}getSheet(){return this.mapOnElements({query:"worksheet",parent:this.rootFile.file.xml},(e=>{const t=this.getSheetWorkbookInfo();return{sheetName:this.extractSheetName(),sheetViews:this.extractSheetViews(e),sheetFormat:this.extractSheetFormat(e),cols:this.extractCols(e),rows:this.extractRows(e),sharedFormulas:this.extractSharedFormulas(e),merges:this.extractMerges(e),cfs:this.extractConditionalFormats(),figures:this.extractFigures(e),hyperlinks:this.extractHyperLinks(e),tables:[...this.extractTables(e),...this.extractPivotTables()],isVisible:"visible"===t.state}}))[0]}extractSheetViews(e){return this.mapOnElements({parent:e,query:"sheetView"},(e=>{const t=this.querySelector(e,"pane");return{tabSelected:this.extractAttr(e,"tabSelected",{default:!1}).asBool(),showFormulas:this.extractAttr(e,"showFormulas",{default:!1}).asBool(),showGridLines:this.extractAttr(e,"showGridLines",{default:!0}).asBool(),showRowColHeaders:this.extractAttr(e,"showRowColHeaders",{default:!0}).asBool(),pane:{xSplit:t?this.extractAttr(t,"xSplit",{default:0}).asNum():0,ySplit:t?this.extractAttr(t,"ySplit",{default:0}).asNum():0}}}))}extractSheetName(){const e=Om(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find((t=>t.target===e)).id;for(let e of this.querySelectorAll(this.xlsxFileStructure.workbook.file.xml,"sheet"))if(e.attributes["r:id"].value===t)return e.attributes.name.value;throw new Error("Missing sheet name")}getSheetWorkbookInfo(){const e=Om(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find((t=>t.target===e)).id,i=this.mapOnElements({parent:this.xlsxFileStructure.workbook.file.xml,query:"sheet"},(e=>({relationshipId:this.extractAttr(e,"r:id",{required:!0}).asString(),sheetId:this.extractAttr(e,"sheetId",{required:!0}).asString(),sheetName:this.extractAttr(e,"name",{required:!0}).asString(),state:this.extractAttr(e,"state",{default:"visible"}).asString()}))).find((e=>e.relationshipId===t));if(!i)throw new Error("Cannot find corresponding workbook sheet");return i}extractConditionalFormats(){return new Bf(this.rootFile,this.xlsxFileStructure,this.warningManager,this.theme).extractConditionalFormattings()}extractFigures(e){return this.mapOnElements({parent:e,query:"drawing"},(e=>{var t;const i=null===(t=this.extractAttr(e,"r:id",{required:!0}))||void 0===t?void 0:t.asString(),n=this.getTargetXmlFile(this.relationships[i]);return new Wf(n,this.xlsxFileStructure,this.warningManager).extractFigures()}))[0]||[]}extractTables(e){return this.mapOnElements({query:"tablePart",parent:e},(e=>{var t;const i=null===(t=this.extractAttr(e,"r:id",{required:!0}))||void 0===t?void 0:t.asString(),n=this.getTargetXmlFile(this.relationships[i]);return new qf(n,this.xlsxFileStructure,this.warningManager).getTable()}))}extractPivotTables(){try{return Object.values(this.relationships).filter((e=>e.type.endsWith("pivotTable"))).map((e=>{const t=this.getTargetXmlFile(e);return new Gf(t,this.xlsxFileStructure,this.warningManager).getPivotTable()}))}catch(e){return this.catchErrorOnElement(e),[]}}extractMerges(e){return this.mapOnElements({parent:e,query:"mergeCell"},(e=>this.extractAttr(e,"ref",{required:!0}).asString()))}extractSheetFormat(e){const t=this.querySelector(e,"sheetFormatPr");if(t)return{defaultColWidth:this.extractAttr(t,"defaultColWidth",{default:im.toString()}).asNum(),defaultRowHeight:this.extractAttr(t,"defaultRowHeight",{default:nm.toString()}).asNum()}}extractCols(e){return this.mapOnElements({parent:e,query:"cols col"},(e=>{var t,i,n,o,s,r,a;return{width:null===(t=this.extractAttr(e,"width"))||void 0===t?void 0:t.asNum(),customWidth:null===(i=this.extractAttr(e,"customWidth"))||void 0===i?void 0:i.asBool(),bestFit:null===(n=this.extractAttr(e,"bestFit"))||void 0===n?void 0:n.asBool(),hidden:null===(o=this.extractAttr(e,"hidden"))||void 0===o?void 0:o.asBool(),min:null===(s=this.extractAttr(e,"min",{required:!0}))||void 0===s?void 0:s.asNum(),max:null===(r=this.extractAttr(e,"max",{required:!0}))||void 0===r?void 0:r.asNum(),styleIndex:null===(a=this.extractAttr(e,"style"))||void 0===a?void 0:a.asNum()}}))}extractRows(e){return this.mapOnElements({parent:e,query:"sheetData row"},(e=>{var t,i,n,o,s;return{index:null===(t=this.extractAttr(e,"r",{required:!0}))||void 0===t?void 0:t.asNum(),cells:this.extractCells(e),height:null===(i=this.extractAttr(e,"ht"))||void 0===i?void 0:i.asNum(),customHeight:null===(n=this.extractAttr(e,"customHeight"))||void 0===n?void 0:n.asBool(),hidden:null===(o=this.extractAttr(e,"hidden"))||void 0===o?void 0:o.asBool(),styleIndex:null===(s=this.extractAttr(e,"s"))||void 0===s?void 0:s.asNum()}}))}extractCells(e){return this.mapOnElements({parent:e,query:"c"},(e=>{var t,i,n;return{xc:null===(t=this.extractAttr(e,"r",{required:!0}))||void 0===t?void 0:t.asString(),styleIndex:null===(i=this.extractAttr(e,"s"))||void 0===i?void 0:i.asNum(),type:vm[null===(n=this.extractAttr(e,"t",{default:"n"}))||void 0===n?void 0:n.asString()],value:this.extractChildTextContent(e,"v"),formula:this.extractCellFormula(e)}}))}extractCellFormula(e){var t,i;const n=this.querySelector(e,"f");if(n)return{content:this.extractTextContent(n),sharedIndex:null===(t=this.extractAttr(n,"si"))||void 0===t?void 0:t.asNum(),ref:null===(i=this.extractAttr(n,"ref"))||void 0===i?void 0:i.asString()}}extractHyperLinks(e){return this.mapOnElements({parent:e,query:"hyperlink"},(e=>{var t,i,n,o;const s=null===(t=this.extractAttr(e,"r:id"))||void 0===t?void 0:t.asString();return{xc:null===(i=this.extractAttr(e,"ref",{required:!0}))||void 0===i?void 0:i.asString(),location:null===(n=this.extractAttr(e,"location"))||void 0===n?void 0:n.asString(),display:null===(o=this.extractAttr(e,"display"))||void 0===o?void 0:o.asString(),relTarget:s?this.relationships[s].target:void 0}}))}extractSharedFormulas(e){const t=this.querySelectorAll(e,"f[si][ref]"),i={};for(let e of t){const t=this.extractAttr(e,"si",{required:!0}).asNum(),n=this.extractTextContent(e,{required:!0});i[t]=n}const n=[];for(let e=0;e<Object.keys(i).length;e++)i[e]?n.push(i[e]):(this.warningManager.addParsingWarning(`Missing shared formula ${e}, replacing it by empty formula`),n.push(""));return n}}class jf extends Vf{constructor(e,t,i){super(e.styles,e,t),this.theme=i}getNumFormats(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"numFmt"},(e=>this.extractNumFormats(e)))}extractNumFormats(e){return{id:this.extractAttr(e,"numFmtId",{required:!0}).asNum(),format:this.extractAttr(e,"formatCode",{required:!0,default:""}).asString()}}getFonts(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"font"},(e=>this.extractFont(e)))}extractFont(e){var t,i,n,o;const s=this.extractChildAttr(e,"name","val",{default:"Arial"}).asString(),r=this.extractChildAttr(e,"sz","val",{default:G.toString()}).asNum(),a=this.extractColor(this.querySelector(e,"color"),this.theme),l=this.querySelector(e,"i")||void 0,c=l&&"0"!==(null===(t=l.attributes.val)||void 0===t?void 0:t.value),h=this.querySelector(e,"b")||void 0,d=h&&"0"!==(null===(i=h.attributes.val)||void 0===i?void 0:i.value),u=this.querySelector(e,"strike")||void 0,g=u&&"0"!==(null===(n=u.attributes.val)||void 0===n?void 0:n.value),p=this.querySelector(e,"u")||void 0;return{name:s,size:r,color:a,italic:c,bold:d,underline:p&&"none"!==(null===(o=p.attributes.val)||void 0===o?void 0:o.value),strike:g}}getFills(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"fill"},(e=>this.extractFill(e)))}extractFill(e){var t;const i=e.children[0];return"patternFill"===i.tagName?{patternType:null===(t=i.attributes.patternType)||void 0===t?void 0:t.value,bgColor:this.extractColor(this.querySelector(i,"bgColor"),this.theme),fgColor:this.extractColor(this.querySelector(i,"fgColor"),this.theme)}:{patternType:"solid",fgColor:this.extractColor(this.querySelectorAll(i,"color")[1],this.theme)}}getBorders(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"border"},(e=>this.extractBorder(e)))}extractBorder(e){var t,i;const n={left:this.extractSingleBorder(e,"left",this.theme),right:this.extractSingleBorder(e,"right",this.theme),top:this.extractSingleBorder(e,"top",this.theme),bottom:this.extractSingleBorder(e,"bottom",this.theme),diagonal:this.extractSingleBorder(e,"diagonal",this.theme)};return n.diagonal&&(n.diagonalUp=null===(t=this.extractAttr(e,"diagonalUp"))||void 0===t?void 0:t.asBool(),n.diagonalDown=null===(i=this.extractAttr(e,"diagonalDown"))||void 0===i?void 0:i.asBool()),n}extractSingleBorder(e,t,i){const n=this.querySelector(e,t);if(n&&n.attributes.style)return{style:this.extractAttr(n,"style",{required:!0,default:"thin"}).asString(),color:this.extractColor(n.children[0],i,"000000")}}extractAlignment(e){var t,i,n,o,s,r,a;return{horizontal:this.extractAttr(e,"horizontal",{default:"general"}).asString(),vertical:this.extractAttr(e,"vertical",{default:"center"}).asString(),textRotation:null===(t=this.extractAttr(e,"textRotation"))||void 0===t?void 0:t.asNum(),wrapText:null===(i=this.extractAttr(e,"wrapText"))||void 0===i?void 0:i.asBool(),indent:null===(n=this.extractAttr(e,"indent"))||void 0===n?void 0:n.asNum(),relativeIndent:null===(o=this.extractAttr(e,"relativeIndent"))||void 0===o?void 0:o.asNum(),justifyLastLine:null===(s=this.extractAttr(e,"justifyLastLine"))||void 0===s?void 0:s.asBool(),shrinkToFit:null===(r=this.extractAttr(e,"shrinkToFit"))||void 0===r?void 0:r.asBool(),readingOrder:null===(a=this.extractAttr(e,"readingOrder"))||void 0===a?void 0:a.asNum()}}getDxfs(){return this.mapOnElements({query:"dxf",parent:this.rootFile.file.xml},(e=>{const t=this.querySelector(e,"font"),i=this.querySelector(e,"fill"),n=this.querySelector(e,"border"),o=this.querySelector(e,"numFmt"),s=this.querySelector(e,"alignment");return{font:t?this.extractFont(t):void 0,fill:i?this.extractFill(i):void 0,numFmt:o?this.extractNumFormats(o):void 0,alignment:s?this.extractAlignment(s):void 0,border:n?this.extractBorder(n):void 0}}))}getStyles(){return this.mapOnElements({query:"cellXfs xf",parent:this.rootFile.file.xml},(e=>{const t=this.querySelector(e,"alignment");return{fontId:this.extractAttr(e,"fontId",{required:!0,default:0}).asNum(),fillId:this.extractAttr(e,"fillId",{required:!0,default:0}).asNum(),borderId:this.extractAttr(e,"borderId",{required:!0,default:0}).asNum(),numFmtId:this.extractAttr(e,"numFmtId",{required:!0,default:0}).asNum(),alignment:t?this.extractAlignment(t):void 0}}))}}class Yf extends Vf{getExternalBook(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"externalBook"},(e=>({rId:this.extractAttr(e,"r:id",{required:!0}).asString(),sheetNames:this.mapOnElements({parent:e,query:"sheetName"},(e=>this.extractAttr(e,"val",{required:!0}).asString())),datasets:this.extractExternalSheetData(e)})))[0]}extractExternalSheetData(e){return this.mapOnElements({parent:e,query:"sheetData"},(e=>{const t=this.mapOnElements({parent:e,query:"cell"},(e=>({xc:this.extractAttr(e,"r",{required:!0}).asString(),value:this.extractChildTextContent(e,"v",{required:!0})}))),i={};for(let e of t)i[e.xc]=e.value;return{sheetId:this.extractAttr(e,"sheetId",{required:!0}).asNum(),data:i}}))}}function Xf(e,t){const i=function(e,t){const i=t[cm],n=i.querySelectorAll(`Override[ContentType="${e}"]`),o=[];for(let e of n){const t=null==e?void 0:e.attributes.PartName.value;o.push(t.substring(1))}return o}(e,t);return function(e,t){const i=[];for(let n of e){const e=Kf(n,t);i.push({file:{fileName:n,xml:t[n]},rels:e?{fileName:e,xml:t[e]}:void 0})}return i}(i,t)}function Kf(e,t){if(e===cm)return"_rels/.rels";let i="";const n=e.split("/");for(let e=0;e<n.length-1;e++)i+=n[e]+"/";return i+="_rels/",i+=n[n.length-1]+".rels",t[i]||(i=void 0),i}class Qf{constructor(e){this.warningManager=new dm,this.xmls={};for(let t of Object.keys(e))(t.endsWith(".xml")||t.endsWith(".rels"))&&(this.xmls[t]=_f(new Wp(e[t])))}convertXlsx(){const e=this.getXlsxData();return this.convertImportedData(e)}getXlsxData(){const e=this.buildXlsxFileStructure(),t=e.theme?new zf(e.theme,e,this.warningManager).getTheme():void 0,i=e.sharedStrings?new zf(e.sharedStrings,e,this.warningManager).getSharedStrings():[],n=e.sheets.sort(((e,t)=>e.file.fileName.localeCompare(t.file.fileName,void 0,{numeric:!0}))).map((i=>new Zf(i,e,this.warningManager,t).getSheet())),o=e.externalLinks.map((t=>new Yf(t,e,this.warningManager).getExternalBook())),s=new jf(e,this.warningManager,t);return{fonts:s.getFonts(),fills:s.getFills(),borders:s.getBorders(),dxfs:s.getDxfs(),numFmts:s.getNumFormats(),styles:s.getStyles(),sheets:n,sharedStrings:i,externalBooks:o}}buildXlsxFileStructure(){const e={sheets:Xf(Kp.sheet,this.xmls),workbook:Xf(Kp.workbook,this.xmls)[0],styles:Xf(Kp.styles,this.xmls)[0],sharedStrings:Xf(Kp.sharedStrings,this.xmls)[0],theme:Xf(Kp.themes,this.xmls)[0],charts:Xf(Kp.chart,this.xmls),figures:Xf(Kp.drawing,this.xmls),tables:Xf(Kp.table,this.xmls),pivots:Xf(Kp.pivot,this.xmls),externalLinks:Xf(Kp.externalLink,this.xmls)};if(!e.workbook.rels)throw Error(s("Cannot find workbook relations file"));return e}convertImportedData(e){const t={version:12,sheets:ff(e,this.warningManager),styles:Pm(e,this.warningManager),formats:Vm(e,this.warningManager),borders:$m(e,this.warningManager),entities:{},revisionId:K};return xf(t,e),Object.keys(e.styles).map((t=>{e.styles[t]=rt(e.styles[t])})),t}}function Jf(e){const t=bg(e);let i=[];return{text:"".concat(...t.map((e=>{if("REFERENCE"===e.type&&xt.test(e.value)){const t=e.value.trim();return i.includes(t)||i.push(t),`${ie}${i.indexOf(t)}${ie}`}return e.value}))),dependencies:i}}const ev=12.5,tv="Sheet1";function iv(e,t){if(!e)return av();if(e["[Content_Types].xml"]){const i=new Qf(e);if(e=i.convertXlsx(),t)for(let e of i.warningManager.warnings.sort())console.warn(e)}return"version"in(e=Ae(e))&&e.version<ev&&(e=function(e){for(let t=nv.findIndex((t=>t.from===e.version));t<nv.length;t++)e=nv[t].applyMigration(e);return e}(e)),e=function(e){return e=function(e){if(e.uniqueFigureIds)return e;const t=new Set,i=new Mi;for(const n of e.sheets||[])for(const e of n.figures||[])t.has(e.id)&&(e.id+=i.smallUuid()),t.add(e.id);return e.uniqueFigureIds=!0,e}(e),e=function(e){e=Object.assign(av(),e,{version:ev}),e.sheets=e.sheets?e.sheets.map(((e,t)=>Object.assign(rv(`Sheet${t+1}`,`Sheet${t+1}`),e))):[],0===e.sheets.length&&e.sheets.push(rv(tv,"Sheet1"));return e}(e),e}(e),e}const nv=[{description:"add the `activeSheet` field on data",from:1,to:2,applyMigration:e=>(e.sheets&&e.sheets[0]&&(e.activeSheet=e.sheets[0].name),e)},{description:"add an id field in each sheet",from:2,to:3,applyMigration(e){if(e.sheets&&e.sheets.length)for(let t of e.sheets)t.id=t.id||t.name;return e}},{description:"activeSheet is now an id, not the name of a sheet",from:3,to:4,applyMigration(e){if(e.sheets&&e.activeSheet){const t=e.sheets.find((t=>t.name===e.activeSheet));e.activeSheet=t.id}return e}},{description:"add figures object in each sheets",from:4,to:5,applyMigration(e){for(let t of e.sheets||[])t.figures=t.figures||[];return e}},{description:"normalize the content of the cell if it is a formula to avoid parsing all the formula that vary only by the cells they use",from:5,to:6,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const i=t.cells[e];i.content&&i.content.startsWith("=")&&(i.formula=Jf(i.content))}return e}},{description:"transform chart data structure",from:6,to:7,applyMigration(e){for(let t of e.sheets||[])for(let e in t.figures||[]){const{dataSets:i,...n}=t.figures[e].data,o=[];for(let e of i)if(e.labelCell){const t=Fi(e.dataRange),i=e.labelCell+":"+Vt(t.right,t.bottom);o.push(i)}else o.push(e.dataRange);n.dataSetsHaveTitle=Boolean(i[0].labelCell),n.dataSets=o,t.figures[e].data=n}return e}},{description:"remove single quotes in sheet names",from:7,to:8,applyMigration(e){var t;const i=[],n=new RegExp(te,"g");for(let o of e.sheets||[]){if(!o.name)continue;const e=o.name,s=e.replace(n,"_");let r=1,a=s;for(;i.includes(a);)a=`${s}${r}`,r++;o.name=a,i.push(a);const l=t=>{if(void 0===t)return t;let i=t.replace(e,a),n=t;for(;n!==i;)n=i,i=n.replace(e,a);return n};for(let e in o.cells){const t=o.cells[e];t.formula&&(t.formula.dependencies=t.formula.dependencies.map(l))}for(let e of o.figures||[])if("chart"===e.type){const t=e.data.dataSets.map(l),i=l(e.data.labelRange);e.data={...e.data,dataSets:t,labelRange:i}}for(let e of o.conditionalFormats||[]){e.ranges=e.ranges.map(l);for(const i of["minimum","maximum","midpoint","upperInflectionPoint","lowerInflectionPoint"])"formula"===(null===(t=e.rule[i])||void 0===t?void 0:t.type)&&(e.rule[i].value=l(e.rule[i].value))}}return e}},{description:"transform chart data structure with design attributes",from:8,to:9,applyMigration(e){for(const t of e.sheets||[])for(const e of t.figures||[])e.data.background=w,e.data.verticalAxisPosition="left",e.data.legendPosition="top",e.data.stacked=!1;return e}},{description:"de-normalize formula to reduce exported json size (~30%)",from:9,to:10,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const i=t.cells[e];if(i.formula){let{text:e,dependencies:t}=i.formula;for(let[i,n]of Object.entries(t)){const t=`\\${ie}${i}\\${ie}`;e=e.replace(new RegExp(t,"g"),n)}i.content=e,delete i.formula}}return e}},{description:"normalize the formats of the cells",from:10,to:11,applyMigration(e){const t={};for(let i of e.sheets||[])for(let e in i.cells||[]){const n=i.cells[e];n.format&&(n.format=Je(n.format,t))}return e.formats=t,e}},{description:"Add isVisible to sheets",from:11,to:12,applyMigration(e){for(let t of e.sheets||[])t.isVisible=!0;return e}},{description:"Fix datafilter duplication",from:12,to:12.5,applyMigration(e){for(let t of e.sheets||[]){let e=[];for(let i of t.filterTables||[]){const t=Fi(i.range),n=e.findIndex((e=>Hi(e,t)));-1!==n?e[n]=t:e.push(t)}t.filterTables=e.map((e=>({range:ki(e)})))}return e}}];function ov(e,t){return t=function(e,t){if(0!==Object.keys(e).length)return t;const i=[],n=[],o=e=>{if("CREATE_SHEET"===e.type)i.push(e.sheetId);else if("sheetId"in e&&!i.includes(e.sheetId))return{...e,sheetId:tv};return e};for(const e of t)"REMOTE_REVISION"===e.type?n.push({...e,commands:e.commands.map(o)}):n.push(e);return n}(e,t),t=sv(t,"SORT_CELLS"),t=function(e,t){var i;const n=[],o={};for(const t of e.sheets||[])null===(i=t.figures)||void 0===i||i.forEach((e=>{"chart"===e.tag&&(o[e.id]=e.data)}));for(const e of t)if("REMOTE_REVISION"===e.type){const t=[];for(const i of e.commands){let e=i;switch(i.type){case"CREATE_CHART":o[i.id]=i.definition;break;case"UPDATE_CHART":if(!o[i.id]){console.log(`Fix chart definition: chart with id ${i.id} not found.`);continue}const t={...o[i.id],...i.definition};e={...i,definition:t},o[i.id]=t}t.push(e)}n.push({...e,commands:t})}else n.push(e);return n}(e,t=sv(t,"SET_DECIMAL")),t=function(e,t){var i;const n={};for(const t of e.sheets||[])n[t.id]=t.name;const o=[];for(const e of t)if("REMOTE_REVISION"===e.type){const t=[];for(const o of e.commands){switch(o.type){case"DUPLICATE_SHEET":o.sheetNameTo=null!==(i=o.sheetNameTo)&&void 0!==i?i:Oi(n[o.sheetId],Object.values(n));break;case"CREATE_SHEET":case"RENAME_SHEET":n[o.sheetId]=o.name||Ni(Object.values(n))}t.push(o)}o.push({...e,commands:t})}else o.push(e);return t}(e,t),t}function sv(e,t){const i=[];for(const n of e)"REMOTE_REVISION"===n.type?i.push({...n,commands:n.commands.filter((e=>e.type!==t))}):i.push(n);return i}function rv(e,t){return{id:e,name:t,colNumber:26,rowNumber:100,cells:{},cols:{},rows:{},merges:[],conditionalFormats:[],figures:[],filterTables:[],isVisible:!0}}function av(e="Sheet1"){return{version:ev,sheets:[rv(tv,e)],entities:{},styles:{},formats:{},borders:{},revisionId:K,uniqueFigureIds:!0}}function lv(e,t){return{...rv(e,t),charts:[]}}class cv extends Wg{constructor(e,t,i,n,o,s){super(t,n,o),this.dispatch=n,this.range=i,i.addRangeProvider(this.adaptRanges.bind(this)),this.getters=e,this.uuidGenerator=s}import(e){}export(e){}adaptRanges(e,t){}}class hv extends cv{constructor(){super(...arguments),this.borders={}}allowDispatch(e){return"SET_BORDER"===e.type?this.checkBordersUnchanged(e):0}handle(e){switch(e.type){case"ADD_MERGE":for(const t of e.target)this.addBordersToMerge(e.sheetId,t);break;case"DUPLICATE_SHEET":const t=this.borders[e.sheetId];if(t){const i=t.slice().map((e=>null==e?void 0:e.slice().map((e=>({...e})))));this.history.update("borders",e.sheetIdTo,i)}break;case"DELETE_SHEET":const i={...this.borders};delete i[e.sheetId],this.history.update("borders",i);break;case"SET_BORDER":this.setBorder(e.sheetId,e.col,e.row,e.border);break;case"SET_FORMATTING":if(e.border){const t=e.target.map((t=>this.getters.expandZone(e.sheetId,t)));this.setBorders(e.sheetId,t,e.border)}break;case"CLEAR_FORMATTING":this.clearBorders(e.sheetId,e.target);break;case"REMOVE_COLUMNS_ROWS":const n=[...e.elements].sort(((e,t)=>t-e));for(const t of Le(n))if("COL"===e.dimension){if(t[0]>=this.getters.getNumberCols(e.sheetId))for(let i=0;i<this.getters.getNumberRows(e.sheetId);i++)this.history.update("borders",e.sheetId,t[0]+1,i,"vertical",void 0);if(0===t[t.length-1])for(let t=0;t<this.getters.getNumberRows(e.sheetId);t++)this.history.update("borders",e.sheetId,0,t,"vertical",void 0);const i=this.getters.getColsZone(e.sheetId,t[t.length-1]+1,t[0]);this.clearInsideBorders(e.sheetId,[i]),this.shiftBordersHorizontally(e.sheetId,t[0]+1,-t.length)}else{if(t[0]>=this.getters.getNumberRows(e.sheetId))for(let i=0;i<this.getters.getNumberCols(e.sheetId);i++)this.history.update("borders",e.sheetId,i,t[0]+1,"horizontal",void 0);if(0===t[t.length-1])for(let t=0;t<this.getters.getNumberCols(e.sheetId);t++)this.history.update("borders",e.sheetId,t,0,"horizontal",void 0);const i=this.getters.getRowsZone(e.sheetId,t[t.length-1]+1,t[0]);this.clearInsideBorders(e.sheetId,[i]),this.shiftBordersVertically(e.sheetId,t[0]+1,-t.length)}break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumns(e):this.handleAddRows(e)}}handleAddColumns(e){let t,i;"before"===e.position?(this.shiftBordersHorizontally(e.sheetId,e.base,e.quantity,{moveFirstLeftBorder:!0}),t=e.base-1,i=e.base+e.quantity):(this.shiftBordersHorizontally(e.sheetId,e.base+1,e.quantity,{moveFirstLeftBorder:!1}),t=e.base,i=e.base+e.quantity+1),this.ensureColumnBorderContinuity(e.sheetId,t,i)}handleAddRows(e){let t,i;"before"===e.position?(this.shiftBordersVertically(e.sheetId,e.base,e.quantity,{moveFirstTopBorder:!0}),t=e.base-1,i=e.base+e.quantity):(this.shiftBordersVertically(e.sheetId,e.base+1,e.quantity,{moveFirstTopBorder:!1}),t=e.base,i=e.base+e.quantity+1),this.ensureRowBorderContinuity(e.sheetId,t,i)}getCellBorder(e,t,i){var n,o,s,r,a,l,c,h,d,u,g,p;const m={top:null===(s=null===(o=null===(n=this.borders[e])||void 0===n?void 0:n[t])||void 0===o?void 0:o[i])||void 0===s?void 0:s.horizontal,bottom:null===(l=null===(a=null===(r=this.borders[e])||void 0===r?void 0:r[t])||void 0===a?void 0:a[i+1])||void 0===l?void 0:l.horizontal,left:null===(d=null===(h=null===(c=this.borders[e])||void 0===c?void 0:c[t])||void 0===h?void 0:h[i])||void 0===d?void 0:d.vertical,right:null===(p=null===(g=null===(u=this.borders[e])||void 0===u?void 0:u[t+1])||void 0===g?void 0:g[i])||void 0===p?void 0:p.vertical};return m.bottom||m.left||m.right||m.top?m:null}ensureColumnBorderContinuity(e,t,i){const n=$e(t+1,i);for(let o=0;o<this.getters.getNumberRows(e);o++){const s=this.getCellBorder(e,t,o),r=this.getCellBorder(e,i,o);if(s&&r){const t=this.getCommonSides(s,r);for(let i of n)this.addBorder(e,i,o,t)}}}ensureRowBorderContinuity(e,t,i){const n=$e(t+1,i);for(let o=0;o<this.getters.getNumberCols(e);o++){const s=this.getCellBorder(e,o,t),r=this.getCellBorder(e,o,i);if(s&&r){const t=this.getCommonSides(s,r);for(let i of n)this.addBorder(e,o,i,t)}}}getCommonSides(e,t){const i={};for(let n of["top","bottom","left","right"])e[n]&&e[n]===t[n]&&(i[n]=e[n]);return i}getColumnsWithBorders(e){const t=this.borders[e];return t?Object.keys(t).map((e=>parseInt(e,10))):[]}getRowsWithBorders(e){var t;const i=null===(t=this.borders[e])||void 0===t?void 0:t.filter(Xe);if(!i)return[];const n=new Set;for(const e of i)for(const t in e)n.add(parseInt(t,10));return Array.from(n)}getRowsRange(e){return this.borders[e]?$e(0,this.getters.getNumberRows(e)+1):[]}shiftBordersHorizontally(e,t,i,{moveFirstLeftBorder:n}={}){this.borders[e]&&(i<0&&this.moveBordersOfColumn(e,t,i,"vertical",{destructive:!1}),this.getColumnsWithBorders(e).filter((e=>e>=t)).sort(((e,t)=>i<0?e-t:t-e)).forEach((o=>{(o===t&&n||o!==t)&&this.moveBordersOfColumn(e,o,i,"vertical"),this.moveBordersOfColumn(e,o,i,"horizontal")})))}shiftBordersVertically(e,t,i,{moveFirstTopBorder:n}={}){this.borders[e]&&(i<0&&this.moveBordersOfRow(e,t,i,"horizontal",{destructive:!1}),this.getRowsWithBorders(e).filter((e=>e>=t)).sort(((e,t)=>i<0?e-t:t-e)).forEach((o=>{(o===t&&n||o!==t)&&this.moveBordersOfRow(e,o,i,"horizontal"),this.moveBordersOfRow(e,o,i,"vertical")})))}moveBordersOfRow(e,t,i,n,{destructive:o}={destructive:!0}){const s=this.borders[e];s&&this.getColumnsWithBorders(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=s[r])||void 0===a?void 0:a[t+i])||void 0===l?void 0:l[n],u=null===(h=null===(c=s[r])||void 0===c?void 0:c[t])||void 0===h?void 0:h[n];this.history.update("borders",e,r,t+i,n,o?u:u||d),this.history.update("borders",e,r,t,n,void 0)}))}moveBordersOfColumn(e,t,i,n,{destructive:o}={destructive:!0}){const s=this.borders[e];s&&this.getRowsRange(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=s[t+i])||void 0===a?void 0:a[r])||void 0===l?void 0:l[n],u=null===(h=null===(c=s[t])||void 0===c?void 0:c[r])||void 0===h?void 0:h[n];this.history.update("borders",e,t+i,r,n,o?u:u||d),this.history.update("borders",e,t,r,n,void 0)}))}setBorder(e,t,i,n,o=!0){var s,r,a,l,c,h,d,u,g,p,m,f,v,b,S,C;!o&&(null===(l=null===(a=null===(r=null===(s=this.borders)||void 0===s?void 0:s[e])||void 0===r?void 0:r[t])||void 0===a?void 0:a[i])||void 0===l?void 0:l.vertical)||this.history.update("borders",e,t,i,"vertical",null==n?void 0:n.left),!o&&(null===(u=null===(d=null===(h=null===(c=this.borders)||void 0===c?void 0:c[e])||void 0===h?void 0:h[t])||void 0===d?void 0:d[i])||void 0===u?void 0:u.horizontal)||this.history.update("borders",e,t,i,"horizontal",null==n?void 0:n.top),!o&&(null===(f=null===(m=null===(p=null===(g=this.borders)||void 0===g?void 0:g[e])||void 0===p?void 0:p[t+1])||void 0===m?void 0:m[i])||void 0===f?void 0:f.vertical)||this.history.update("borders",e,t+1,i,"vertical",null==n?void 0:n.right),!o&&(null===(C=null===(S=null===(b=null===(v=this.borders)||void 0===v?void 0:v[e])||void 0===b?void 0:b[t])||void 0===S?void 0:S[i+1])||void 0===C?void 0:C.horizontal)||this.history.update("borders",e,t,i+1,"horizontal",null==n?void 0:n.bottom)}clearBorders(e,t){for(let i of t){for(let t=i.top;t<=i.bottom;t++){this.history.update("borders",e,i.right+1,t,"vertical",void 0);for(let n=i.left;n<=i.right;n++)this.history.update("borders",e,n,t,void 0)}for(let t=i.left;t<=i.right;t++)this.history.update("borders",e,t,i.bottom+1,"horizontal",void 0)}}clearInsideBorders(e,t){for(let i of t)for(let t=i.top;t<=i.bottom;t++)for(let n=i.left;n<=i.right;n++)this.history.update("borders",e,n,t,void 0)}addBorder(e,t,i,n){this.setBorder(e,t,i,{...this.getCellBorder(e,t,i),...n})}setBorders(e,t,i){if("clear"===i)return this.clearBorders(e,t);for(let n of t){if("h"===i||"hv"===i||"all"===i)for(let t=n.top+1;t<=n.bottom;t++)for(let i=n.left;i<=n.right;i++)this.addBorder(e,i,t,{top:Z});if("v"===i||"hv"===i||"all"===i)for(let t=n.top;t<=n.bottom;t++)for(let i=n.left+1;i<=n.right;i++)this.addBorder(e,i,t,{left:Z});if("left"===i||"all"===i||"external"===i)for(let t=n.top;t<=n.bottom;t++)this.addBorder(e,n.left,t,{left:Z});if("right"===i||"all"===i||"external"===i)for(let t=n.top;t<=n.bottom;t++)this.addBorder(e,n.right+1,t,{left:Z});if("top"===i||"all"===i||"external"===i)for(let t=n.left;t<=n.right;t++)this.addBorder(e,t,n.top,{top:Z});if("bottom"===i||"all"===i||"external"===i)for(let t=n.left;t<=n.right;t++)this.addBorder(e,t,n.bottom+1,{top:Z})}}addBordersToMerge(e,t){const{left:i,right:n,top:o,bottom:s}=t,r=this.getCellBorder(e,i,o),a=this.getCellBorder(e,n,s);this.clearBorders(e,[t]),(null==r?void 0:r.top)&&this.setBorders(e,[{...t,bottom:o}],"top"),(null==r?void 0:r.left)&&this.setBorders(e,[{...t,right:i}],"left"),((null==a?void 0:a.bottom)||(null==r?void 0:r.bottom))&&this.setBorders(e,[{...t,top:s}],"bottom"),((null==a?void 0:a.right)||(null==r?void 0:r.right))&&this.setBorders(e,[{...t,left:n}],"right")}checkBordersUnchanged(e){var t,i,n,o;const s=this.getCellBorder(e.sheetId,e.col,e.row),r=!((null===(t=e.border)||void 0===t?void 0:t.bottom)||(null===(i=e.border)||void 0===i?void 0:i.left)||(null===(n=e.border)||void 0===n?void 0:n.right)||(null===(o=e.border)||void 0===o?void 0:o.top));return!s&&r||ot(s,e.border)?89:0}import(e){if(e.borders)for(let t of e.sheets)for(let[i,n]of Object.entries(t.cells))if(null==n?void 0:n.border){const o=e.borders[n.border],{col:s,row:r}=Ut(i);this.setBorder(t.id,s,r,o,!1)}for(let t of e.sheets)if(t.merges)for(let e of t.merges)this.addBordersToMerge(t.id,Fi(e))}export(e){let t=0;const i={};function n(e){for(let[t,n]of Object.entries(i))if(ot(n,e))return parseInt(t,10);return i[++t]=e,t}for(let t of e.sheets)for(let e=0;e<t.colNumber;e++)for(let i=0;i<t.rowNumber;i++){const o=this.getCellBorder(t.id,e,i);if(o){const s=Vt(e,i),r=t.cells[s],a=n(o);r?r.border=a:t.cells[s]={border:a}}}e.borders=i}exportForExcel(e){this.export(e)}}hv.getters=["getCellBorder"];const dv={textColor:R};class uv extends cv{constructor(){super(...arguments),this.nextId=1,this.cells={},this.createCell=function(e){const t=io.getAll().sort(((e,t)=>e.sequence-t.sequence));return function(i,n,o,s){const r=t.find((e=>e.match(n,o.format)));if(!r)return new $p(i,n,o);try{return r.createCell(i,n,o,s,e)}catch(e){return new Bp(i,n,e instanceof c?e:new h(e.message||ne),o)}}}(this.getters)}adaptRanges(e,t){for(const i of Object.keys(this.cells))for(const n of Object.values(this.cells[i]||{}))if(n.isFormula())for(const o of n.dependencies)if(!t||o.sheetId===t){const t=e(o);"NONE"!==t.changeType&&this.history.update("cells",i,n.id,"dependencies",n.dependencies.indexOf(o),t.range)}}allowDispatch(e){var t;switch(e.type){case"UPDATE_CELL":return this.checkValidations(e,this.checkCellOutOfSheet,this.checkUselessUpdateCell);case"CLEAR_CELL":return this.checkValidations(e,this.checkCellOutOfSheet,this.checkUselessClearCell);case"UPDATE_CELL_POSITION":return!e.cellId||(null===(t=this.cells[e.sheetId])||void 0===t?void 0:t[e.cellId])?0:28;default:return 0}}handle(e){switch(e.type){case"SET_FORMATTING":"style"in e&&this.setStyle(e.sheetId,e.target,e.style),"format"in e&&void 0!==e.format&&this.setFormatter(e.sheetId,e.target,e.format);break;case"CLEAR_FORMATTING":this.clearFormatting(e.sheetId,e.target);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumnsRows(e,this.copyColumnStyle.bind(this)):this.handleAddColumnsRows(e,this.copyRowStyle.bind(this));break;case"UPDATE_CELL":this.updateCell(e.sheetId,e.col,e.row,e);break;case"CLEAR_CELL":this.dispatch("UPDATE_CELL",{sheetId:e.sheetId,col:e.col,row:e.row,content:"",style:null,format:""});break;case"DELETE_SHEET":this.history.update("cells",e.sheetId,void 0)}}setFormatter(e,t,i){for(let n of t)for(let t=n.top;t<=n.bottom;t++)for(let o=n.left;o<=n.right;o++)this.dispatch("UPDATE_CELL",{sheetId:e,col:o,row:t,format:i})}clearFormatting(e,t){for(let i of t)for(let t=i.left;t<=i.right;t++)for(let n=i.top;n<=i.bottom;n++)this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:n,style:null,format:""})}handleAddColumnsRows(e,t){let i,n;"before"===e.position?(i=$e(e.base,e.base+e.quantity),n=e.base+e.quantity):(i=$e(e.base+1,e.base+e.quantity+1),n=e.base),t(e.sheetId,n,i)}import(e){for(let t of e.sheets)for(let i in t.cells){const n=t.cells[i],{col:o,row:s}=Ut(i);if((null==n?void 0:n.content)||(null==n?void 0:n.format)||(null==n?void 0:n.style)){const i=this.importCell(t.id,n,e.styles,e.formats);this.history.update("cells",t.id,i.id,i),this.dispatch("UPDATE_CELL_POSITION",{cellId:i.id,col:o,row:s,sheetId:t.id})}}}export(e){const t={},i={};for(let n of e.sheets){const e={},o=Object.keys(this.cells[n.id]||{}).map((e=>this.getters.getCellPosition(e))).sort(((e,t)=>e.col===t.col?e.row-t.row:e.col-t.col));for(const{col:s,row:r}of o){const o=this.getters.getCell(n.id,s,r);e[Vt(s,r)]={style:o.style?Je(o.style,t):void 0,format:o.format?Je(o.format,i):void 0,content:o.content||void 0}}n.cells=e}e.styles=t,e.formats=i}importCell(e,t,i,n){const o=t.style&&i[t.style]||void 0,s=t.format&&n[t.format]||void 0,r=this.getNextUid(),a={format:s,style:o};return this.createCell(r,(null==t?void 0:t.content)||"",a,e)}exportForExcel(e){this.export(e);for(let t of e.sheets)for(const e in t.cells){const{col:i,row:n}=Ut(e),o=this.getters.getCell(t.id,i,n),s=t.cells[e];s.value=o.evaluated.value,s.isFormula=o.isFormula(),o.isFormula()&&(s.content=this.buildFormulaContent(t.id,o,o.dependencies,!0)),o.format!==o.evaluated.format&&(s.computedFormat=o.evaluated.format)}}getCells(e){return this.cells[e]||{}}getCellById(e){const t=this.getters.getCellPosition(e);return this.cells[t.sheetId][e]}buildFormulaContent(e,t,i,n=!1){const o=i||t.dependencies;let s=0;return et(t.compiledFormula.tokens.map((t=>{if("REFERENCE"===t.type){const t=o[s++];return this.getters.getRangeString(t,e,n)}return t.value})))}getFormulaCellContent(e,t){return this.buildFormulaContent(e,t)}getCellStyle(e){if(!e)return{};return{...e.isLink()?dv:{},...e.style}}zoneToXC(e,t,i=[{colFixed:!1,rowFixed:!1}]){const n=Vt((t=this.getters.expandZone(e,t)).left,t.top,i[0]),o=Vt(t.right,t.bottom,i.length>1?i[1]:i[0]),s=this.getters.getMainCellPosition(e,t.left,t.top),r=this.getters.getMainCellPosition(e,t.right,t.bottom),a=s.col===r.col&&s.row===r.row;return n==o||a?n:n+":"+o}setStyle(e,t,i){for(let n of t)for(let t=n.left;t<=n.right;t++)for(let o=n.top;o<=n.bottom;o++){const n=this.getters.getCell(e,t,o);this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:o,style:i?{...null==n?void 0:n.style,...i}:void 0})}}copyColumnStyle(e,t,i){for(let n=0;n<this.getters.getNumberRows(e);n++){const o=this.getFormat(e,t,n);if(o.style||o.format)for(let t of i)this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:n,...o})}}copyRowStyle(e,t,i){for(let n=0;n<this.getters.getNumberCols(e);n++){const o=this.getFormat(e,n,t);if(o.style||o.format)for(let t of i)this.dispatch("UPDATE_CELL",{sheetId:e,col:n,row:t,...o})}}getFormat(e,t,i){const n={},{col:o,row:s}=this.getters.getMainCellPosition(e,t,i),r=this.getters.getCell(e,o,s);return r&&(r.style&&(n.style=r.style),r.format&&(n.format=r.format)),n}getNextUid(){const e=this.nextId.toString();return this.history.update("nextId",this.nextId+1),e}updateCell(e,t,i,n){const o=this.getters.getCell(e,t,i),s="content"in n||"formula"in n,r=(s?n.content:null==o?void 0:o.content)||"";let a;a=void 0!==n.style?n.style||void 0:o?o.style:void 0;let l=("format"in n?n.format:o&&o.format)||undefined;if((s&&!r&&!n.formula||!s&&(!o||o.isEmpty()))&&!a&&!l)return void(o&&(this.history.update("cells",e,o.id,void 0),this.dispatch("UPDATE_CELL_POSITION",{cellId:void 0,col:t,row:i,sheetId:e})));const c=(null==o?void 0:o.id)||this.getNextUid(),h=s,d={format:l,style:a},u=this.createCell(c,r,d,e);o&&!h&&u.isFormula()&&u.assignEvaluation(tt(o.evaluated)),this.history.update("cells",e,u.id,u),this.dispatch("UPDATE_CELL_POSITION",{cellId:u.id,col:t,row:i,sheetId:e})}checkCellOutOfSheet(e){const{sheetId:t,col:i,row:n}=e;if(!this.getters.tryGetSheet(t))return 27;return Wi(i,n,this.getters.getSheetZone(t))?0:18}checkUselessClearCell(e){const t=this.getters.getCell(e.sheetId,e.col,e.row);return t&&(t.content||t.style||t.format)?0:89}checkUselessUpdateCell(e){const t=this.getters.getCell(e.sheetId,e.col,e.row),i="style"in e,n="format"in e;return("content"in e||"formula"in e)&&(null==t?void 0:t.content)!==e.content||i&&!ot(null==t?void 0:t.style,e.style)||n&&(null==t?void 0:t.format)!==e.format?0:89}}uv.getters=["zoneToXC","getCells","getFormulaCellContent","getCellStyle","buildFormulaContent","getCellById"];class gv extends cv{constructor(){super(...arguments),this.charts={},this.createChart=function(e){const t=rn.getAll();return function(i,n,o){const s=t.find((e=>e.match(n.type)));if(!s)throw new Error(`No builder for this chart: ${n.type}`);return s.createChart(n,o,e)}}(this.getters),this.validateChartDefinition=e=>function(e,t){const i=rn.getAll().find((e=>e.match(t.type)));if(!i)throw new Error("Unknown chart type.");return i.validateChartDefinition(e,t)}(this,e.definition)}adaptRanges(e){for(const[t,i]of Object.entries(this.charts))this.history.update("charts",t,null==i?void 0:i.updateRanges(e))}allowDispatch(e){switch(e.type){case"CREATE_CHART":return this.checkValidations(e,this.chainValidations(this.validateChartDefinition,this.checkChartDuplicate));case"UPDATE_CHART":return this.checkValidations(e,this.chainValidations(this.validateChartDefinition,this.checkChartExists));default:return 0}}handle(e){var t;switch(e.type){case"CREATE_CHART":this.addFigure(e.id,e.sheetId,e.position,e.size),this.addChart(e.id,e.definition);break;case"UPDATE_CHART":this.addChart(e.id,e.definition);break;case"DUPLICATE_SHEET":{const i=this.getters.getFigures(e.sheetId);for(const n of i)if("chart"===n.tag){const i=n.id.split("??").pop(),o=`${e.sheetIdTo}??${i}`,s=null===(t=this.charts[n.id])||void 0===t?void 0:t.copyForSheetId(e.sheetIdTo);s&&this.dispatch("CREATE_CHART",{id:o,position:{x:n.x,y:n.y},size:{width:n.width,height:n.height},definition:s.getDefinition(),sheetId:e.sheetIdTo})}break}case"DELETE_FIGURE":this.history.update("charts",e.id,void 0);break;case"DELETE_SHEET":for(let t of this.getChartIds(e.sheetId))this.history.update("charts",t,void 0)}}getContextCreationChart(e){var t;return null===(t=this.charts[e])||void 0===t?void 0:t.getContextCreation()}getChart(e){return this.charts[e]}getChartType(e){var t;const i=null===(t=this.charts[e])||void 0===t?void 0:t.type;if(!i)throw new Error("Chart not defined.");return i}isChartDefined(e){return e in this.charts&&void 0!==this.charts}getChartIds(e){return Object.entries(this.charts).filter((([,t])=>(null==t?void 0:t.sheetId)===e)).map((([e])=>e))}getChartDefinition(e){var t;const i=null===(t=this.charts[e])||void 0===t?void 0:t.getDefinition();if(!i)throw new Error(`There is no chart with the given figureId: ${e}`);return i}import(e){for(let t of e.sheets)if(t.figures)for(let e of t.figures)"chart"===e.tag&&(this.charts[e.id]=this.createChart(e.id,e.data,t.id))}export(e){var t;if(e.sheets)for(let i of e.sheets){const e=this.getters.getFigures(i.id),n=[];for(let i of e){const e=i;if(e&&"chart"===e.tag){const i=null===(t=this.charts[e.id])||void 0===t?void 0:t.getDefinition();i&&(e.data=i,n.push(e))}else n.push(e)}i.figures=n}}exportForExcel(e){var t;for(let i of e.sheets){const e=this.getters.getFigures(i.id),n=[];for(let i of e)if(i&&"chart"===i.tag){const e=null===(t=this.charts[i.id])||void 0===t?void 0:t.getDefinitionForExcel();e&&n.push({...i,data:e})}i.charts=n}}addFigure(e,t,i={x:0,y:0},n={width:536,height:335}){if(this.getters.getFigure(t,e))return;const o={id:e,x:i.x,y:i.y,width:n.width,height:n.height,tag:"chart"};this.dispatch("CREATE_FIGURE",{sheetId:t,figure:o})}addChart(e,t){const i=this.getters.getFigureSheetId(e);i&&this.history.update("charts",e,this.createChart(e,t,i))}checkChartDuplicate(e){return this.getters.getFigureSheetId(e.id)?85:0}checkChartExists(e){return this.isChartDefined(e.id)?0:86}}function pv(e){return""===e?NaN:Number(e)}gv.getters=["isChartDefined","getChartDefinition","getChartType","getChartIds","getChart","getContextCreationChart"];class mv extends cv{constructor(){super(...arguments),this.cfRules={}}loopThroughRangesOfSheet(e,t){for(const i of this.cfRules[e])for(const n of i.ranges){const o=t(n);switch(o.changeType){case"REMOVE":let t=i.ranges.slice();t.splice(i.ranges.indexOf(n),1),t.length>=1?this.history.update("cfRules",e,this.cfRules[e].indexOf(i),"ranges",t):this.removeConditionalFormatting(i.id,e);break;case"RESIZE":case"MOVE":case"CHANGE":this.history.update("cfRules",e,this.cfRules[e].indexOf(i),"ranges",i.ranges.indexOf(n),o.range)}}}adaptRanges(e,t){if(t)this.loopThroughRangesOfSheet(t,e);else for(const t of Object.keys(this.cfRules))this.loopThroughRangesOfSheet(t,e)}allowDispatch(e){switch(e.type){case"ADD_CONDITIONAL_FORMAT":return this.checkValidations(e,this.checkCFRule,this.checkEmptyRange);case"MOVE_CONDITIONAL_FORMAT":return this.checkValidReordering(e.cfId,e.direction,e.sheetId)}return 0}handle(e){switch(e.type){case"CREATE_SHEET":this.cfRules[e.sheetId]=[];break;case"DUPLICATE_SHEET":this.history.update("cfRules",e.sheetIdTo,[]);for(const t of this.getConditionalFormats(e.sheetId))this.addConditionalFormatting(t,e.sheetIdTo);break;case"DELETE_SHEET":const t=Object.assign({},this.cfRules);delete t[e.sheetId],this.history.update("cfRules",t);break;case"ADD_CONDITIONAL_FORMAT":const i={...e.cf,ranges:e.ranges.map((t=>this.getters.getRangeString(this.getters.getRangeFromRangeData(t),e.sheetId)))};this.addConditionalFormatting(i,e.sheetId);break;case"REMOVE_CONDITIONAL_FORMAT":this.removeConditionalFormatting(e.id,e.sheetId);break;case"MOVE_CONDITIONAL_FORMAT":this.reorderConditionalFormatting(e.cfId,e.direction,e.sheetId)}}import(e){for(let t of e.sheets)this.cfRules[t.id]=t.conditionalFormats.map((e=>this.mapToConditionalFormatInternal(t.id,e)))}export(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map((e=>this.mapToConditionalFormat(t.id,e))))}exportForExcel(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map((e=>this.mapToConditionalFormat(t.id,e,{useFixedReference:!0}))))}getConditionalFormats(e){var t;return(null===(t=this.cfRules[e])||void 0===t?void 0:t.map((t=>this.mapToConditionalFormat(e,t))))||[]}getRulesSelection(e,t){const i=new Set;return t.forEach((t=>{this.getRulesByZone(e,t).forEach((e=>{i.add(e)}))})),Array.from(i)}getRulesByZone(e,t){const i=new Set;for(let n=t.top;n<=t.bottom;n++)for(let o=t.left;o<=t.right;o++){this.getRulesByCell(e,o,n).forEach((e=>{i.add(e.id)}))}return i}getRulesByCell(e,t,i){const n=[];for(let o of this.cfRules[e])for(let e of o.ranges)Wi(t,i,e.zone)&&n.push(o);return new Set(n.map((t=>this.mapToConditionalFormat(e,t))))}mapToConditionalFormat(e,t,i={useFixedReference:!1}){return{...t,ranges:t.ranges.map((t=>this.getters.getRangeString(t,e,i.useFixedReference)))}}mapToConditionalFormatInternal(e,t){const i={...t,ranges:t.ranges.map((t=>this.getters.getRangeFromSheetXC(e,t)))};return i}addConditionalFormatting(e,t){const i=this.cfRules[t].slice(),n=i.findIndex((t=>t.id===e.id)),o=this.mapToConditionalFormatInternal(t,e);n>-1?i.splice(n,1,o):i.push(o),this.history.update("cfRules",t,i)}checkValidReordering(e,t,i){if(!this.cfRules[i])return 27;const n=this.cfRules[i].findIndex((t=>t.id===e));if(-1===n)return 72;const o="up"===t?n-1:n+1;return o<0||o>=this.cfRules[i].length?72:0}checkEmptyRange(e){return e.ranges.length?0:24}checkCFRule(e){const t=e.cf.rule;switch(t.type){case"CellIsRule":return this.checkValidations(t,this.checkOperatorArgsNumber(2,["Between","NotBetween"]),this.checkOperatorArgsNumber(1,["BeginsWith","ContainsText","EndsWith","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","NotContains"]),this.checkOperatorArgsNumber(0,["IsEmpty","IsNotEmpty"]));case"ColorScaleRule":return this.checkValidations(t,this.chainValidations(this.checkThresholds(this.checkFormulaCompilation)),this.chainValidations(this.checkThresholds(this.checkNaN),this.batchValidations(this.checkMinBiggerThanMax,this.checkMinBiggerThanMid,this.checkMidBiggerThanMax)));case"IconSetRule":return this.checkValidations(t,this.chainValidations(this.checkInflectionPoints(this.checkNaN),this.checkLowerBiggerThanUpper),this.chainValidations(this.checkInflectionPoints(this.checkFormulaCompilation)))}return 0}checkOperatorArgsNumber(e,t){if(e>2)throw new Error("Checking more than 2 arguments is currently not supported. Add the appropriate CommandResult if you want to.");return i=>{if(t.includes(i.operator)){const t=[],n=e=>void 0===e||""===e;return e>=1&&n(i.values[0])&&t.push(52),e>=2&&n(i.values[1])&&t.push(53),t.length?t:0}return 0}}checkNaN(e,t){if(["number","percentage","percentile"].includes(e.type)&&(""===e.value||isNaN(e.value)))switch(t){case"min":return 54;case"max":return 56;case"mid":return 55;case"upperInflectionPoint":return 57;case"lowerInflectionPoint":return 58}return 0}checkFormulaCompilation(e,t){if("formula"!==e.type)return 0;try{Ug(e.value||"")}catch(e){switch(t){case"min":return 59;case"max":return 61;case"mid":return 60;case"upperInflectionPoint":return 62;case"lowerInflectionPoint":return 63}}return 0}checkThresholds(e){return this.batchValidations((t=>e(t.minimum,"min")),(t=>e(t.maximum,"max")),(t=>t.midpoint?e(t.midpoint,"mid"):0))}checkInflectionPoints(e){return this.batchValidations((t=>e(t.lowerInflectionPoint,"lowerInflectionPoint")),(t=>e(t.upperInflectionPoint,"upperInflectionPoint")))}checkLowerBiggerThanUpper(e){const t=e.lowerInflectionPoint.value,i=e.upperInflectionPoint.value;return["number","percentage","percentile"].includes(e.lowerInflectionPoint.type)&&e.lowerInflectionPoint.type===e.upperInflectionPoint.type&&Number(t)>Number(i)?49:0}checkMinBiggerThanMax(e){const t=e.minimum.value,i=e.maximum.value;return["number","percentage","percentile"].includes(e.minimum.type)&&e.minimum.type===e.maximum.type&&pv(t)>=pv(i)?48:0}checkMidBiggerThanMax(e){var t;const i=null===(t=e.midpoint)||void 0===t?void 0:t.value,n=e.maximum.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.midpoint.type===e.maximum.type&&pv(i)>=pv(n)?50:0}checkMinBiggerThanMid(e){var t;const i=e.minimum.value,n=null===(t=e.midpoint)||void 0===t?void 0:t.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.minimum.type===e.midpoint.type&&pv(i)>=pv(n)?51:0}removeConditionalFormatting(e,t){const i=this.cfRules[t].findIndex((t=>t.id===e));if(-1!==i){const e=this.cfRules[t].slice();e.splice(i,1),this.history.update("cfRules",t,e)}}reorderConditionalFormatting(e,t,i){const n=this.cfRules[i].findIndex((t=>t.id===e)),o="up"===t?n-1:n+1;if(!(o<0||o>=this.cfRules[i].length)&&-1!==n&&-1!==o){const e=[...this.cfRules[i]],t=e[n];e[n]=e[o],e[o]=t,this.history.update("cfRules",i,e)}}}mv.getters=["getConditionalFormats","getRulesSelection","getRulesByCell"];class fv extends cv{constructor(){super(...arguments),this.figures={}}allowDispatch(e){switch(e.type){case"CREATE_FIGURE":return this.checkFigureDuplicate(e.figure.id);case"UPDATE_FIGURE":case"DELETE_FIGURE":return this.checkFigureExists(e.sheetId,e.id);default:return 0}}beforeHandle(e){if("DELETE_SHEET"===e.type)this.getters.getFigures(e.sheetId).forEach((t=>{this.dispatch("DELETE_FIGURE",{id:t.id,sheetId:e.sheetId})}))}handle(e){switch(e.type){case"CREATE_SHEET":this.figures[e.sheetId]={};break;case"DELETE_SHEET":this.deleteSheet(e.sheetId);break;case"CREATE_FIGURE":this.addFigure(e.figure,e.sheetId);break;case"UPDATE_FIGURE":const{type:t,sheetId:i,...n}=e,o=n;this.updateFigure(i,o);break;case"DELETE_FIGURE":this.removeFigure(e.id,e.sheetId)}}updateFigure(e,t){if("id"in t)for(const[i,n]of Object.entries(t))switch(i){case"x":case"y":void 0!==n&&this.history.update("figures",e,t.id,i,Math.max(n,0));break;case"width":case"height":void 0!==n&&this.history.update("figures",e,t.id,i,n)}}addFigure(e,t){this.history.update("figures",t,e.id,e)}deleteSheet(e){this.history.update("figures",e,void 0)}removeFigure(e,t){this.history.update("figures",t,e,void 0)}checkFigureExists(e,t){var i;return void 0===(null===(i=this.figures[e])||void 0===i?void 0:i[t])?71:0}checkFigureDuplicate(e){return Object.values(this.figures).find((t=>null==t?void 0:t[e]))?83:0}getFigures(e){return Object.values(this.figures[e]||{}).filter(Xe)}getFigure(e,t){var i;return null===(i=this.figures[e])||void 0===i?void 0:i[t]}getFigureSheetId(e){return Object.keys(this.figures).find((t=>{var i;return void 0!==(null===(i=this.figures[t])||void 0===i?void 0:i[e])}))}import(e){for(let t of e.sheets){const e={};t.figures.forEach((t=>{e[t.id]=t})),this.figures[t.id]=e}}export(e){for(const t of e.sheets)for(const e of this.getFigures(t.id)){const i=void 0;t.figures.push({...e,data:i})}}exportForExcel(e){this.export(e)}}fv.getters=["getFigures","getFigure","getFigureSheetId"];class vv{constructor(e){this.filters=[],this.zone=e;const t=new Mi;this.id=t.smallUuid();for(const i of $e(e.left,e.right+1)){const e={...this.zone,left:i,right:i};this.filters.push(new bv(t.smallUuid(),e))}}get contentZone(){if(this.zone.bottom!==this.zone.top)return{...this.zone,top:this.zone.top+1}}getFilterId(e){var t;return null===(t=this.filters.find((t=>t.col===e)))||void 0===t?void 0:t.id}clone(){return new vv(this.zone)}}class bv{constructor(e,t){if(t.left!==t.right)throw new Error("Can only define a filter on a single column");this.id=e,this.zoneWithHeaders=t}get col(){return this.zoneWithHeaders.left}get filteredZone(){const e=this.zoneWithHeaders;if(e.bottom!==e.top)return{...e,top:e.top+1}}}class Sv extends cv{constructor(){super(...arguments),this.tables={}}allowDispatch(e){switch(e.type){case"CREATE_FILTER_TABLE":if(!on(...e.target))return 82;const t=Vi(...e.target),i=()=>this.getFilterTables(e.sheetId).some((e=>Hi(e.zone,t)))?79:0,n=()=>{const i=this.getters.getMergesInZone(e.sheetId,t);for(let e of i)if(Hi(t,e))return 81;return 0};return this.checkValidations(e,i,n);case"ADD_MERGE":for(let t of e.target)for(let i of this.getFilterTables(e.sheetId))if(Hi(i.zone,t))return 81}return 0}handle(e){switch(e.type){case"CREATE_SHEET":this.history.update("tables",e.sheetId,{});break;case"DELETE_SHEET":const t={...this.tables};delete t[e.sheetId],this.history.update("tables",t);break;case"DUPLICATE_SHEET":const i={};for(const t of Object.values(this.tables[e.sheetId]||{}))if(t){const e=Ae(t);i[e.id]=e}this.history.update("tables",e.sheetIdTo,i);break;case"ADD_COLUMNS_ROWS":this.onAddColumnsRows(e);break;case"REMOVE_COLUMNS_ROWS":this.onDeleteColumnsRows(e);break;case"CREATE_FILTER_TABLE":{const t=Vi(...e.target),i=this.createFilterTable(t);this.history.update("tables",e.sheetId,i.id,i);break}case"REMOVE_FILTER_TABLE":{const t={};for(const i of this.getFilterTables(e.sheetId))e.target.every((e=>!zi(e,i.zone)))&&(t[i.id]=i);this.history.update("tables",e.sheetId,t);break}case"UPDATE_CELL":{const t=e.sheetId;for(let i of this.getFilterTables(t))this.canUpdateCellCmdExtendTable(e,i)&&this.extendTableDown(t,i);break}}}getFilters(e){return this.getFilterTables(e).map((e=>e.filters)).flat()}getFilterTables(e){return this.tables[e]?Object.values(this.tables[e]).filter(Xe):[]}getFilter(e,t,i){var n;return null===(n=this.getFilterTable(e,t,i))||void 0===n?void 0:n.filters.find((e=>e.col===t))}getFilterId(e,t,i){var n;return null===(n=this.getFilter(e,t,i))||void 0===n?void 0:n.id}getFilterTable(e,t,i){return this.getFilterTables(e).find((e=>Wi(t,i,e.zone)))}getFilterTablesInZone(e,t){return this.getFilterTables(e).filter((e=>Gi(e.zone,t)))}doesZonesContainFilter(e,t){for(const i of t)for(const t of this.getFilterTables(e))if(zi(i,t.zone))return!0;return!1}onAddColumnsRows(e){for(const t of this.getFilterTables(e.sheetId)){const i=$i(t.zone,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity),n=[];for(const i of t.filters){const t=$i(i.zoneWithHeaders,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);n.push(new bv(i.id,t))}if(n.length<ji(i).width){for(let e=i.left;e<=i.right;e++)n.find((t=>t.col===e))||n.push(new bv(this.uuidGenerator.smallUuid(),{...i,left:e,right:e}));n.sort(((e,t)=>e.col-t.col))}this.history.update("tables",e.sheetId,t.id,"zone",i),this.history.update("tables",e.sheetId,t.id,"filters",n)}}onDeleteColumnsRows(e){for(const t of this.getFilterTables(e.sheetId)){if("ROW"===e.dimension&&e.elements.includes(t.zone.top)){const i={...this.tables[e.sheetId]};delete i[t.id],this.history.update("tables",e.sheetId,i);continue}const i=Ui(t.zone,"COL"===e.dimension?"left":"top",e.elements);if(i){if(ki(i)!==ki(t.zone)){const n=[];for(const i of t.filters){const t=Ui(i.zoneWithHeaders,"COL"===e.dimension?"left":"top",e.elements);t&&n.push(new bv(i.id,t))}this.history.update("tables",e.sheetId,t.id,"zone",i),this.history.update("tables",e.sheetId,t.id,"filters",n)}}else{const i={...this.tables[e.sheetId]};delete i[t.id],this.history.update("tables",e.sheetId,i)}}}createFilterTable(e){return new vv(e)}extendTableDown(e,t){const i={...t.zone,bottom:t.zone.bottom+1};this.history.update("tables",e,t.id,"zone",i);for(let i=0;i<t.filters.length;i++){const n=t.filters[i],o={...n.zoneWithHeaders,bottom:n.zoneWithHeaders.bottom+1};this.history.update("tables",e,t.id,"filters",i,"zoneWithHeaders",o)}}canUpdateCellCmdExtendTable({content:e,sheetId:t,col:i,row:n},o){var s;if(!e)return;const r=o.zone;if(!(r.bottom+1===n&&i>=r.left&&i<=r.right))return!1;for(const e of $e(r.left,r.right+1)){if(null===(s=this.getters.getCell(t,e,n))||void 0===s?void 0:s.content)return!1;if(this.getters.getFilter(t,e,n))return!1;if(this.getters.isInMerge(t,e,n))return!1}return!0}import(e){for(const t of e.sheets)for(const e of t.filterTables||[]){const i=this.createFilterTable(Fi(e.range));this.history.update("tables",t.id,i.id,i)}}export(e){for(const t of e.sheets)for(const e of this.getFilterTables(t.id))t.filterTables.push({range:ki(e.zone)})}exportForExcel(e){for(const t of e.sheets)for(const e of this.getFilterTables(t.id))1!==ji(e.zone).height&&t.filterTables.push({range:ki(e.zone),filters:[]})}}Sv.getters=["doesZonesContainFilter","getFilter","getFilters","getFilterTable","getFilterTables","getFilterTablesInZone","getFilterId"];class Cv extends cv{constructor(){super(...arguments),this.sizes={}}handle(e){var t,i;switch(e.type){case"CREATE_SHEET":{const t=this.computeSheetSizes(e.sheetId),i={COL:t.COL.map((e=>({manualSize:void 0,computedSize:tt(e)}))),ROW:t.ROW.map((e=>({manualSize:void 0,computedSize:tt(e)})))};this.history.update("sizes",e.sheetId,i);break}case"DUPLICATE_SHEET":for(const t of this.sizes[e.sheetId].ROW)t.computedSize();for(const t of this.sizes[e.sheetId].COL)t.computedSize();this.history.update("sizes",e.sheetIdTo,Ae(this.sizes[e.sheetId]));break;case"DELETE_SHEET":const n={...this.sizes};delete n[e.sheetId],this.history.update("sizes",n);break;case"REMOVE_COLUMNS_ROWS":{let t=[...this.sizes[e.sheetId][e.dimension]];for(let i of[...e.elements].sort(((e,t)=>t-e)))t.splice(i,1);const i=ct(e.elements);t=t.map(((t,n)=>"ROW"===e.dimension&&n>=i?{manualSize:t.manualSize,computedSize:tt((()=>this.getRowTallestCellSize(e.sheetId,n)))}:t)),this.history.update("sizes",e.sheetId,e.dimension,t);break}case"ADD_COLUMNS_ROWS":{let t=[...this.sizes[e.sheetId][e.dimension]];const i=nt(e.position,e.base),n=t[e.base],o=$e(0,e.quantity).map((()=>({manualSize:n.manualSize,computedSize:tt(n.computedSize())})));t.splice(i,0,...o),t=t.map(((t,i)=>"ROW"===e.dimension&&i>e.base+e.quantity?{manualSize:t.manualSize,computedSize:tt((()=>this.getRowTallestCellSize(e.sheetId,i)))}:t)),this.history.update("sizes",e.sheetId,e.dimension,t);break}case"RESIZE_COLUMNS_ROWS":for(let t of e.elements)if("ROW"===e.dimension){const i=this.getRowTallestCellSize(e.sheetId,t);this.history.update("sizes",e.sheetId,e.dimension,t,{manualSize:e.size||void 0,computedSize:tt(i)})}else this.history.update("sizes",e.sheetId,e.dimension,t,{manualSize:e.size||void 0,computedSize:tt(e.size||_)});break;case"UPDATE_CELL":const o=null===(i=null===(t=this.sizes[e.sheetId])||void 0===t?void 0:t.ROW)||void 0===i?void 0:i[e.row];if(o&&!o.manualSize){const{sheetId:t,row:i}=e;this.history.update("sizes",t,"ROW",i,"computedSize",tt((()=>this.getRowTallestCellSize(t,i))))}break;case"ADD_MERGE":case"REMOVE_MERGE":for(let t of e.target)for(let i of $e(t.top,t.bottom+1)){const t=this.getRowTallestCellSize(e.sheetId,i);t!==this.getRowSize(e.sheetId,i)&&this.history.update("sizes",e.sheetId,"ROW",i,"computedSize",tt(t))}}}getColSize(e,t){return this.getHeaderSize(e,"COL",t)}getRowSize(e,t){return this.getHeaderSize(e,"ROW",t)}getHeaderSize(e,t,i){var n,o,s,r;return Math.round((null===(o=null===(n=this.sizes[e])||void 0===n?void 0:n[t][i])||void 0===o?void 0:o.manualSize)||(null===(r=null===(s=this.sizes[e])||void 0===s?void 0:s[t][i])||void 0===r?void 0:r.computedSize())||this.getDefaultHeaderSize(t))}computeSheetSizes(e){var t,i;const n={COL:[],ROW:[]};for(let t of $e(0,this.getters.getNumberCols(e)))n.COL.push(this.getHeaderSize(e,"COL",t));for(let o of $e(0,this.getters.getNumberRows(e))){let s=null===(i=null===(t=this.sizes[e])||void 0===t?void 0:t.ROW)||void 0===i?void 0:i[o].manualSize;if(!s){s=this.getRowTallestCellSize(e,o)}n.ROW.push(s)}return n}getDefaultHeaderSize(e){return"COL"===e?_:F}getCellHeight(e,t,i){const n=this.getters.getMerge(e,t,i);if(n&&n.bottom!==n.top)return F;const o=this.getters.getCell(e,t,i);return(null==(s=null==o?void 0:o.style)?void 0:s.fontSize)?(r||1)*(ke(s)+P)-P+2*U:F;var s,r}getRowTallestCellSize(e,t){const i=this.getters.getRowCells(e,t);let n=0;for(let t=0;t<i.length;t++){const o=this.getters.getCellById(i[t]);if(!o)continue;const{col:s,row:r}=this.getters.getCellPosition(o.id),a=this.getCellHeight(e,s,r);a>n&&a>F&&(n=a)}return n<=F?F:n}import(e){for(let t of e.sheets){const e={COL:[],ROW:[]};for(let[i,n]of Object.entries(t.rows))n.size&&(e.ROW[i]=n.size);for(let[i,n]of Object.entries(t.cols))n.size&&(e.COL[i]=n.size);const i=this.computeSheetSizes(t.id);this.sizes[t.id]={COL:i.COL.map(((t,i)=>({manualSize:e.COL[i],computedSize:tt(t)}))),ROW:i.ROW.map(((t,i)=>({manualSize:e.ROW[i],computedSize:tt(t)})))}}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){var i,n;for(let o of e.sheets){void 0===o.rows&&(o.rows={});for(let e of $e(0,this.getters.getNumberRows(o.id)))(t||(null===(i=this.sizes[o.id].ROW[e])||void 0===i?void 0:i.manualSize))&&(o.rows[e]={...o.rows[e],size:this.getRowSize(o.id,e)});void 0===o.cols&&(o.cols={});for(let e of $e(0,this.getters.getNumberCols(o.id)))(t||(null===(n=this.sizes[o.id].COL[e])||void 0===n?void 0:n.manualSize))&&(o.cols[e]={...o.cols[e],size:this.getColSize(o.id,e)})}}}Cv.getters=["getRowSize","getColSize"];class Ev extends cv{constructor(){super(...arguments),this.hiddenHeaders={}}allowDispatch(e){switch(e.type){case"HIDE_COLUMNS_ROWS":{if(!this.getters.tryGetSheet(e.sheetId))return 27;const t="COL"===e.dimension?this.getHiddenColsGroups(e.sheetId):this.getHiddenRowsGroups(e.sheetId),i="COL"===e.dimension?this.getters.getNumberCols(e.sheetId):this.getters.getNumberRows(e.sheetId);return new Set((t||[]).flat().concat(e.elements)).size>=i?67:ct(e.elements)<0||lt(e.elements)>i?87:0}case"REMOVE_COLUMNS_ROWS":return this.getters.tryGetSheet(e.sheetId)?this.checkElementsIncludeAllVisibleHeaders(e.sheetId,e.dimension,e.elements)?8:0:27}return 0}handle(e){switch(e.type){case"CREATE_SHEET":const t={COL:Array(this.getters.getNumberCols(e.sheetId)).fill(!1),ROW:Array(this.getters.getNumberRows(e.sheetId)).fill(!1)};this.history.update("hiddenHeaders",e.sheetId,t);break;case"DUPLICATE_SHEET":this.history.update("hiddenHeaders",e.sheetIdTo,Ae(this.hiddenHeaders[e.sheetId]));break;case"DELETE_SHEET":this.history.update("hiddenHeaders",e.sheetId,void 0);break;case"REMOVE_COLUMNS_ROWS":{const t=[...this.hiddenHeaders[e.sheetId][e.dimension]];for(let i of[...e.elements].sort(((e,t)=>t-e)))t.splice(i,1);this.history.update("hiddenHeaders",e.sheetId,e.dimension,t);break}case"ADD_COLUMNS_ROWS":{const t=[...this.hiddenHeaders[e.sheetId][e.dimension]],i=nt(e.position,e.base);t.splice(i,0,...Array(e.quantity).fill(!1)),this.history.update("hiddenHeaders",e.sheetId,e.dimension,t);break}case"HIDE_COLUMNS_ROWS":for(let t of e.elements)this.history.update("hiddenHeaders",e.sheetId,e.dimension,t,!0);break;case"UNHIDE_COLUMNS_ROWS":for(let t of e.elements)this.history.update("hiddenHeaders",e.sheetId,e.dimension,t,!1)}}checkElementsIncludeAllVisibleHeaders(e,t,i){return st(i,this.getAllVisibleHeaders(e,t))}isRowHiddenByUser(e,t){return this.hiddenHeaders[e].ROW[t]}isColHiddenByUser(e,t){return this.hiddenHeaders[e].COL[t]}getHiddenColsGroups(e){const t=[[]],i=this.hiddenHeaders[e].COL;for(let e=0;e<i.length;e++){i[e]?t[t.length-1].push(e):0!==t[t.length-1].length&&t.push([])}return 0===t[t.length-1].length&&t.pop(),t}getHiddenRowsGroups(e){const t=[[]],i=this.hiddenHeaders[e].ROW;for(let e=0;e<i.length;e++){i[e]?t[t.length-1].push(e):0!==t[t.length-1].length&&t.push([])}return 0===t[t.length-1].length&&t.pop(),t}getAllVisibleHeaders(e,t){return $e(0,this.hiddenHeaders[e][t].length).filter((i=>!this.hiddenHeaders[e][t][i]))}import(e){var t,i;for(let n of e.sheets){this.hiddenHeaders[n.id]={COL:[],ROW:[]};for(let e=0;e<n.rowNumber;e++)this.hiddenHeaders[n.id].ROW[e]=Boolean(null===(t=n.rows[e])||void 0===t?void 0:t.isHidden);for(let e=0;e<n.colNumber;e++)this.hiddenHeaders[n.id].COL[e]=Boolean(null===(i=n.cols[e])||void 0===i?void 0:i.isHidden)}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){for(let i of e.sheets){void 0===i.rows&&(i.rows={});for(let e=0;e<this.getters.getNumberRows(i.id);e++)(t||this.hiddenHeaders[i.id].ROW[e])&&(void 0===i.rows[e]&&(i.rows[e]={}),i.rows[e].isHidden=this.hiddenHeaders[i.id].ROW[e]);void 0===i.cols&&(i.cols={});for(let e=0;e<this.getters.getNumberCols(i.id);e++)(t||this.hiddenHeaders[i.id].COL[e])&&(void 0===i.cols[e]&&(i.cols[e]={}),i.cols[e].isHidden=this.hiddenHeaders[i.id].COL[e])}}}Ev.getters=["checkElementsIncludeAllVisibleHeaders","getHiddenColsGroups","getHiddenRowsGroups","isRowHiddenByUser","isColHiddenByUser"];class wv extends cv{constructor(){super(...arguments),this.nextId=1,this.merges={},this.mergeCellMap={}}allowDispatch(e){const t="force"in e&&!!e.force;switch(e.type){case"ADD_MERGE":return t?this.checkValidations(e,this.checkFrozenPanes):this.checkValidations(e,this.checkDestructiveMerge,this.checkOverlap,this.checkFrozenPanes);case"UPDATE_CELL":return this.checkMergedContentUpdate(e);case"REMOVE_MERGE":return this.checkMergeExists(e);default:return 0}}handle(e){switch(e.type){case"CREATE_SHEET":case"DELETE_SHEET":this.history.update("merges",e.sheetId,{}),this.history.update("mergeCellMap",e.sheetId,{});break;case"DUPLICATE_SHEET":const t=this.merges[e.sheetId];if(!t)break;for(const i of Object.values(t).filter(Xe))this.addMerge(e.sheetIdTo,i.zone);break;case"ADD_MERGE":for(const t of e.target)this.addMerge(e.sheetId,t);break;case"REMOVE_MERGE":for(const t of e.target)this.removeMerge(e.sheetId,t)}}adaptRanges(e,t){const i=t?[t]:Object.keys(this.merges);for(const t of i)this.applyRangeChangeOnSheet(t,e)}getMerges(e){return Object.keys(this.merges[e]||{}).map((t=>this.getMergeById(e,parseInt(t,10)))).filter(Xe)}getMerge(e,t,i){var n;const o=this.mergeCellMap[e],s=o?t in o&&(null===(n=o[t])||void 0===n?void 0:n[i]):void 0;return s?this.getMergeById(e,s):void 0}getMergesInZone(e,t){var i;const n=this.mergeCellMap[e];if(!n)return[];const o=new Set;for(const{col:e,row:s}of Xi(t)){const t=null===(i=n[e])||void 0===i?void 0:i[s];t&&o.add(t)}return Array.from(o).map((t=>this.getMergeById(e,t))).filter(Xe)}doesIntersectMerge(e,t){const{left:i,right:n,top:o,bottom:s}=t;for(let t=o;t<=s;t++)for(let o=i;o<=n;o++)if(this.getMerge(e,o,t))return!0;return!1}doesColumnsHaveCommonMerges(e,t,i){const n=this.getters.getSheet(e);for(let o=0;o<this.getters.getNumberRows(e);o++)if(this.isInSameMerge(n.id,t,o,i,o))return!0;return!1}doesRowsHaveCommonMerges(e,t,i){const n=this.getters.getSheet(e);for(let o=0;o<=this.getters.getNumberCols(e);o++)if(this.isInSameMerge(n.id,o,t,o,i))return!0;return!1}expandZone(e,t){let{left:i,right:n,top:o,bottom:s}=t,r={left:i,right:n,top:o,bottom:s};for(let t in this.merges[e]){const i=this.getMergeById(e,parseInt(t));i&&Hi(i,r)&&(r=Vi(i,r))}return Bi(r,t)?r:this.expandZone(e,r)}isInSameMerge(e,t,i,n,o){const s=this.getMerge(e,t,i),r=this.getMerge(e,n,o);return!(!s||!r)&&Bi(s,r)}isInMerge(e,t,i){var n;const o=this.mergeCellMap[e];return!!o&&(t in o&&Boolean(null===(n=o[t])||void 0===n?void 0:n[i]))}getMainCellPosition(e,t,i){if(!this.isInMerge(e,t,i))return{col:t,row:i};const n=this.getMerge(e,t,i).topLeft;return{col:n.col,row:n.row}}getBottomLeftCell(e,t,i){if(!this.isInMerge(e,t,i))return{col:t,row:i};const{bottom:n,left:o}=this.getMerge(e,t,i);return{col:o,row:n}}isMergeHidden(e,t){const i=this.getters.getHiddenColsGroups(e),n=this.getters.getHiddenRowsGroups(e);for(let e of i)if(t.left>=e[0]&&t.right<=e[e.length-1])return!0;for(let e of n)if(t.top>=e[0]&&t.bottom<=e[e.length-1])return!0;return!1}isSingleCellOrMerge(e,t){const i=this.getMerge(e,t.left,t.top);if(i)return Bi(t,i);const{width:n,height:o}=ji(t);return 1===n&&1===o}isMergeDestructive(e,t){let{left:i,right:n,top:o,bottom:s}=t;n=Me(n,0,this.getters.getNumberCols(e)-1),s=Me(s,0,this.getters.getNumberRows(e)-1);for(let t=o;t<=s;t++)for(let s=i;s<=n;s++)if(s!==i||t!==o){const i=this.getters.getCell(e,s,t);if(i&&!i.isEmpty())return!0}return!1}getMergeById(e,t){var i;const n=null===(i=this.merges[e])||void 0===i?void 0:i[t];return void 0!==n?xv(t,n):void 0}checkDestructiveMerge({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return 0;return t.some((t=>this.isMergeDestructive(e,t)))?3:0}checkOverlap({target:e}){for(const t of e)for(const i of e)if(t!==i&&Hi(t,i))return 66;return 0}checkFrozenPanes({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return 0;const{xSplit:i,ySplit:n}=this.getters.getPaneDivisions(e);for(const e of t)if(e.left<i&&e.right>=i||e.top<n&&e.bottom>=n)return 76;return 0}checkMergedContentUpdate(e){const{col:t,row:i,sheetId:n,content:o}=e;if(void 0===o)return 0;const{col:s,row:r}=this.getMainCellPosition(n,t,i);return s===t&&r===i?0:4}checkMergeExists(e){const{sheetId:t,target:i}=e;for(const e of i){const{left:i,top:n}=e,o=this.getMerge(t,i,n);if(void 0===o||!Bi(e,o))return 5}return 0}addMerge(e,t){let{left:i,right:n,top:o,bottom:s}=t;n=Me(n,0,this.getters.getNumberCols(e)-1),s=Me(s,0,this.getters.getNumberRows(e)-1);if(Vt(i,o)===Vt(n,s))return;const r=this.getters.getCell(e,i,o);let a=this.nextId++;this.history.update("merges",e,a,this.getters.getRangeFromSheetXC(e,ki({left:i,top:o,right:n,bottom:s})));let l=new Set;for(let t=o;t<=s;t++)for(let s=i;s<=n;s++){s===i&&t===o||this.dispatch("UPDATE_CELL",{sheetId:e,col:s,row:t,style:r?r.style:null,content:""});const n=this.getMerge(e,s,t);n&&l.add(n.id),this.history.update("mergeCellMap",e,s,t,a)}for(let t of l){const{top:i,bottom:n,left:o,right:s}=this.getMergeById(e,t);for(let t=i;t<=n;t++)for(let i=o;i<=s;i++){const n=this.getMerge(e,i,t);n&&n.id===a||(this.history.update("mergeCellMap",e,i,t,void 0),this.dispatch("CLEAR_CELL",{sheetId:e,col:i,row:t}))}this.history.update("merges",e,t,void 0)}}removeMerge(e,t){const{left:i,top:n,bottom:o,right:s}=t,r=this.getMerge(e,i,n);if(void 0!==r&&Bi(t,r)){this.history.update("merges",e,r.id,void 0);for(let t=n;t<=o;t++)for(let n=i;n<=s;n++)this.history.update("mergeCellMap",e,n,t,void 0)}}applyRangeChangeOnSheet(e,t){const i=Object.entries(this.merges[e]||{});for(const[n,o]of i)if(o){const i=o.zone,s=t(o);switch(s.changeType){case"NONE":break;case"REMOVE":this.removeMerge(e,i);break;default:const{width:t,height:o}=ji(s.range.zone);1===t&&1===o?this.removeMerge(e,i):this.history.update("merges",e,parseInt(n,10),s.range)}}this.history.update("mergeCellMap",e,{});for(const t of this.getMerges(e))for(const{col:i,row:n}of Xi(t))this.history.update("mergeCellMap",e,i,n,t.id)}import(e){const t=e.sheets||[];for(let e of t)this.history.update("merges",e.id,{}),this.history.update("mergeCellMap",e.id,{}),e.merges&&this.importMerges(e.id,e.merges)}importMerges(e,t){for(let i of t)this.addMerge(e,Fi(i))}export(e){for(let t of e.sheets){const e=this.merges[t.id];e&&t.merges.push(...yv(e))}}exportForExcel(e){this.export(e)}}function yv(e){return Object.entries(e).map((([e,t])=>t?xv(parseInt(e,10),t):void 0)).filter(Xe).map((e=>Vt(e.left,e.top)+":"+Vt(e.right,e.bottom)))}function xv(e,t){return{...t.zone,topLeft:{col:t.zone.left,row:t.zone.top},id:e}}wv.getters=["isInMerge","isInSameMerge","isMergeHidden","getMainCellPosition","getBottomLeftCell","expandZone","doesIntersectMerge","doesColumnsHaveCommonMerges","doesRowsHaveCommonMerges","getMerges","getMerge","getMergesInZone","isSingleCellOrMerge"];class Rv extends cv{constructor(){super(...arguments),this.sheetIdsMapName={},this.orderedSheetIds=[],this.sheets={},this.cellPosition={}}allowDispatch(e){const t=this.chainValidations(this.checkSheetExists,this.checkZones)(e);if(0!==t)return t;switch(e.type){case"HIDE_SHEET":return 1===this.getVisibleSheetIds().length?9:0;case"CREATE_SHEET":return this.checkValidations(e,this.checkSheetName,this.checkSheetPosition);case"DUPLICATE_SHEET":return this.sheets[e.sheetIdTo]?12:this.orderedSheetIds.map(this.getSheetName.bind(this)).includes(e.sheetNameTo)?11:0;case"MOVE_SHEET":const t=this.orderedSheetIds.indexOf(e.sheetId);if("left"===e.direction){return this.orderedSheetIds.slice(0,t).map((e=>!this.isSheetVisible(e))).every((e=>e))?14:0}return this.orderedSheetIds.slice(t+1).map((e=>!this.isSheetVisible(e))).every((e=>e))?14:0;case"RENAME_SHEET":return this.isRenameAllowed(e);case"DELETE_SHEET":return this.getVisibleSheetIds().length>1?0:9;case"ADD_COLUMNS_ROWS":const i="COL"===e.dimension?this.getNumberCols(e.sheetId):this.getNumberRows(e.sheetId);return e.base<0||e.base>=i?87:e.quantity<=0?88:0;case"REMOVE_COLUMNS_ROWS":{const t="COL"===e.dimension?this.getNumberCols(e.sheetId):this.getNumberRows(e.sheetId);return ct(e.elements)<0||lt(e.elements)>t?87:this.checkElementsIncludeAllNonFrozenHeaders(e.sheetId,e.dimension,e.elements)?8:0}case"FREEZE_ROWS":return this.checkValidations(e,this.checkRowFreezeQuantity,this.checkRowFreezeOverlapMerge);case"FREEZE_COLUMNS":return this.checkValidations(e,this.checkColFreezeQuantity,this.checkColFreezeOverlapMerge);default:return 0}}handle(e){switch(e.type){case"SET_GRID_LINES_VISIBILITY":this.setGridLinesVisibility(e.sheetId,e.areGridLinesVisible);break;case"DELETE_CONTENT":this.clearZones(e.sheetId,e.target);break;case"CREATE_SHEET":const t=this.createSheet(e.sheetId,e.name||this.getNextSheetName(),e.cols||26,e.rows||100,e.position);this.history.update("sheetIdsMapName",t.name,t.id);break;case"MOVE_SHEET":this.moveSheet(e.sheetId,e.direction);break;case"RENAME_SHEET":this.renameSheet(this.sheets[e.sheetId],e.name);break;case"HIDE_SHEET":this.hideSheet(e.sheetId);break;case"SHOW_SHEET":this.showSheet(e.sheetId);break;case"DUPLICATE_SHEET":this.duplicateSheet(e.sheetId,e.sheetIdTo,e.sheetNameTo);break;case"DELETE_SHEET":this.deleteSheet(this.sheets[e.sheetId]);break;case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.removeColumns(this.sheets[e.sheetId],[...e.elements]):this.removeRows(this.sheets[e.sheetId],[...e.elements]);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.addColumns(this.sheets[e.sheetId],e.base,e.position,e.quantity):this.addRows(this.sheets[e.sheetId],e.base,e.position,e.quantity);break;case"UPDATE_CELL_POSITION":this.updateCellPosition(e);break;case"FREEZE_COLUMNS":this.setPaneDivisions(e.sheetId,e.quantity,"COL");break;case"FREEZE_ROWS":this.setPaneDivisions(e.sheetId,e.quantity,"ROW");break;case"UNFREEZE_ROWS":this.setPaneDivisions(e.sheetId,0,"ROW");break;case"UNFREEZE_COLUMNS":this.setPaneDivisions(e.sheetId,0,"COL");break;case"UNFREEZE_COLUMNS_ROWS":this.setPaneDivisions(e.sheetId,0,"COL"),this.setPaneDivisions(e.sheetId,0,"ROW")}}import(e){var t,i;for(let t of e.sheets)this.sheetIdsMapName[t.name]=t.id;for(let n of e.sheets){const e=n.name||o("Sheet")+(Object.keys(this.sheets).length+1),{colNumber:s,rowNumber:r}=this.getImportedSheetSize(n),a={id:n.id,name:e,numberOfCols:s,rows:Ti(r),areGridLinesVisible:void 0===n.areGridLinesVisible||n.areGridLinesVisible,isVisible:n.isVisible,panes:{xSplit:(null===(t=n.panes)||void 0===t?void 0:t.xSplit)||0,ySplit:(null===(i=n.panes)||void 0===i?void 0:i.ySplit)||0}};this.orderedSheetIds.push(a.id),this.sheets[a.id]=a}}exportSheets(e){e.sheets=this.orderedSheetIds.filter(Xe).map((e=>{const t=this.sheets[e],i={id:t.id,name:t.name,colNumber:t.numberOfCols,rowNumber:this.getters.getNumberRows(t.id),rows:{},cols:{},merges:[],cells:{},conditionalFormats:[],figures:[],filterTables:[],areGridLinesVisible:void 0===t.areGridLinesVisible||t.areGridLinesVisible,isVisible:t.isVisible};return(t.panes.xSplit||t.panes.ySplit)&&(i.panes=t.panes),i}))}export(e){this.exportSheets(e)}exportForExcel(e){this.exportSheets(e)}getGridLinesVisibility(e){return this.getSheet(e).areGridLinesVisible}tryGetSheet(e){return this.sheets[e]}getSheet(e){const t=this.sheets[e];if(!t)throw new Error(`Sheet ${e} not found.`);return t}isSheetVisible(e){return this.getSheet(e).isVisible}getSheetName(e){return this.getSheet(e).name}getCellsInZone(e,t){return Xi(t).map((({col:t,row:i})=>this.getCell(e,t,i)))}tryGetSheetName(e){var t;return null===(t=this.tryGetSheet(e))||void 0===t?void 0:t.name}getSheetIdByName(e){if(e){const t=Ne(e);for(const e in this.sheetIdsMapName)if(Ai(e,t))return this.sheetIdsMapName[e]}}getSheetIds(){return this.orderedSheetIds}getVisibleSheetIds(){return this.orderedSheetIds.filter(this.isSheetVisible.bind(this))}getEvaluationSheets(){return this.sheets}doesHeaderExist(e,t,i){return"COL"===t?i>=0&&i<this.getNumberCols(e):i>=0&&i<this.getNumberRows(e)}getRow(e,t){const i=this.getSheet(e).rows[t];if(!i)throw new Error(`Row ${i} not found.`);return i}getCell(e,t,i){var n;const o=this.tryGetSheet(e),s=null===(n=null==o?void 0:o.rows[i])||void 0===n?void 0:n.cells[t];if(void 0!==s)return this.getters.getCellById(s)}getColCells(e,t){return this.getSheet(e).rows.map((e=>e.cells[t])).filter(Xe).map((e=>this.getters.getCellById(e))).filter(Xe)}getColsZone(e,t,i){return{top:0,bottom:this.getNumberRows(e)-1,left:t,right:i}}getRowCells(e,t){var i;return Object.values(null===(i=this.getSheet(e).rows[t])||void 0===i?void 0:i.cells).filter(Xe)}getRowsZone(e,t,i){return{top:t,bottom:i,left:0,right:this.getSheet(e).numberOfCols-1}}getCellPosition(e){const t=this.cellPosition[e];if(!t)throw new Error(`asking for a cell position that doesn't exist, cell id: ${e}`);return t}getNumberCols(e){return this.getSheet(e).numberOfCols}getNumberRows(e){return this.getSheet(e).rows.length}getNumberHeaders(e,t){return"COL"===t?this.getNumberCols(e):this.getNumberRows(e)}getNextSheetName(e="Sheet"){return Ni(this.orderedSheetIds.map(this.getSheetName.bind(this)),e)}getSheetSize(e){return{height:this.getNumberRows(e),width:this.getNumberCols(e)}}getSheetZone(e){return{top:0,left:0,bottom:this.getNumberRows(e)-1,right:this.getNumberCols(e)-1}}getPaneDivisions(e){return this.getSheet(e).panes}setPaneDivisions(e,t,i){const n={...this.getPaneDivisions(e)};"COL"===i?n.xSplit=t:"ROW"===i&&(n.ySplit=t),this.history.update("sheets",e,"panes",n)}checkElementsIncludeAllNonFrozenHeaders(e,t,i){const n=this.getters.getPaneDivisions(e),o="ROW"===t?n.ySplit:n.xSplit,s=this.getters.getNumberHeaders(e,t);if(!o)return!1;return st(i,$e(o,s))}isEmpty(e,t){return this.getCellsInZone(e,t).flat().every((e=>!e||e.isEmpty()))}updateCellPosition(e){const{sheetId:t,cellId:i,col:n,row:o}=e;i?this.setNewPosition(i,t,n,o):this.clearPosition(t,n,o)}setNewPosition(e,t,i,n){const o=this.cellPosition[e];o&&this.clearPosition(t,o.col,o.row),this.history.update("cellPosition",e,{row:n,col:i,sheetId:t}),this.history.update("sheets",t,"rows",n,"cells",i,e)}clearPosition(e,t,i){var n;const o=null===(n=this.sheets[e])||void 0===n?void 0:n.rows[i].cells[t];o&&(this.history.update("cellPosition",o,void 0),this.history.update("sheets",e,"rows",i,"cells",t,void 0))}setGridLinesVisibility(e,t){this.history.update("sheets",e,"areGridLinesVisible",t)}clearZones(e,t){for(let i of t)for(let t=i.left;t<=i.right;t++)for(let n=i.top;n<=i.bottom;n++){this.sheets[e].rows[n].cells[t]&&this.dispatch("UPDATE_CELL",{sheetId:e,content:"",col:t,row:n})}}createSheet(e,t,i,n,o){const s={id:e,name:t,numberOfCols:i,rows:Ti(n),areGridLinesVisible:!0,isVisible:!0,panes:{xSplit:0,ySplit:0}},r=this.orderedSheetIds.slice();r.splice(o,0,s.id);const a=this.sheets;return this.history.update("orderedSheetIds",r),this.history.update("sheets",Object.assign({},a,{[s.id]:s})),s}moveSheet(e,t){const i=this.orderedSheetIds.slice(),n=i.findIndex((t=>t===e)),o=i.splice(n,1);let s="left"===t?this.findIndexOfPreviousVisibleSheet(n-1,i):this.findIndexOfNextVisibleSheet(n+1,i);void 0===s&&(s=i.length),i.splice(s,0,o[0]),this.history.update("orderedSheetIds",i)}findIndexOfPreviousVisibleSheet(e,t){for(;e>=0&&!this.isSheetVisible(t[e]);)e--;if(-1===e)throw new Error("There is no previous visible sheet");return e}findIndexOfNextVisibleSheet(e,t){for(;e<t.length&&!this.isSheetVisible(t[e]);)e++;if(e!==t.length-1||this.isSheetVisible(t[e-1]))return e}checkSheetName(e){const{orderedSheetIds:t,sheets:i}=this,n=e.name&&e.name.trim().toLowerCase();return t.find((e=>{var t;return Ai(null===(t=i[e])||void 0===t?void 0:t.name,n)}))?11:te.test(n)?13:0}checkSheetPosition(e){const{orderedSheetIds:t}=this;return e.position>t.length||e.position<0?15:0}checkRowFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberRows(e.sheetId)?0:75}checkColFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberCols(e.sheetId)?0:75}checkRowFreezeOverlapMerge(e){const t=this.getters.getMerges(e.sheetId);for(let i of t)if(i.top<e.quantity&&e.quantity<=i.bottom)return 66;return 0}checkColFreezeOverlapMerge(e){const t=this.getters.getMerges(e.sheetId);for(let i of t)if(i.left<e.quantity&&e.quantity<=i.right)return 66;return 0}isRenameAllowed(e){return e.name&&e.name.trim().toLowerCase()?this.checkSheetName(e):10}renameSheet(e,t){const i=e.name;this.history.update("sheets",e.id,"name",t.trim());const n=Object.assign({},this.sheetIdsMapName);n[t]=e.id,delete n[i],this.history.update("sheetIdsMapName",n)}hideSheet(e){this.history.update("sheets",e,"isVisible",!1)}showSheet(e){this.history.update("sheets",e,"isVisible",!0)}duplicateSheet(e,t,i){const n=Ae(this.getSheet(e));n.id=t,n.name=i;for(let e=0;e<=n.numberOfCols;e++)for(let t=0;t<=n.rows.length;t++)n.rows[t]&&(n.rows[t].cells[e]=void 0);const o=this.orderedSheetIds.slice(),s=o.indexOf(e);o.splice(s+1,0,n.id),this.history.update("orderedSheetIds",o),this.history.update("sheets",Object.assign({},this.sheets,{[n.id]:n}));for(const t of Object.values(this.getters.getCells(e))){const{col:e,row:i}=this.getCellPosition(t.id);this.dispatch("UPDATE_CELL",{sheetId:n.id,col:e,row:i,content:t.content,format:t.format,style:t.style})}const r=Object.assign({},this.sheetIdsMapName);r[n.name]=n.id,this.history.update("sheetIdsMapName",r)}getDuplicateSheetName(e){return Oi(e,this.orderedSheetIds.map(this.getSheetName.bind(this)))}deleteSheet(e){const t=e.name,i=Object.assign({},this.sheets);delete i[e.id],this.history.update("sheets",i);const n=this.orderedSheetIds.slice(),o=n.indexOf(e.id);n.splice(o,1),this.history.update("orderedSheetIds",n);const s=Object.assign({},this.sheetIdsMapName);delete s[t],this.history.update("sheetIdsMapName",s)}removeColumns(e,t){t.sort(((e,t)=>t-e));for(let i of t)this.moveCellOnColumnsDeletion(e,i);const i=this.sheets[e.id].numberOfCols;this.history.update("sheets",e.id,"numberOfCols",i-t.length);const n=t.filter((t=>t<e.panes.xSplit)).length;n&&this.setPaneDivisions(e.id,e.panes.xSplit-n,"COL")}removeRows(e,t){t.sort(((e,t)=>t-e));for(let i of Le(t)){const t=i[i.length-1],n=i[0];this.moveCellOnRowsDeletion(e,t,n),this.updateRowsStructureOnDeletion(e,t,n)}const i=t.filter((t=>t<e.panes.ySplit)).length;i&&this.setPaneDivisions(e.id,e.panes.ySplit-i,"ROW")}addColumns(e,t,i,n){const o="before"===i?t:t+1;this.moveCellsOnAddition(e,o,n,"columns");const s=this.sheets[e.id].numberOfCols;this.history.update("sheets",e.id,"numberOfCols",s+n),o<e.panes.xSplit&&this.setPaneDivisions(e.id,e.panes.xSplit+n,"COL")}addRows(e,t,i,n){const o="before"===i?t:t+1;this.addEmptyRows(e,n),this.moveCellsOnAddition(e,o,n,"rows"),o<e.panes.ySplit&&this.setPaneDivisions(e.id,e.panes.ySplit+n,"ROW")}moveCellOnColumnsDeletion(e,t){for(let i=0;i<e.rows.length;i++){const n=e.rows[i];for(let o in n.cells){const s=Number(o),r=n.cells[o];r&&(s===t&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:s,row:i}),s>t&&this.setNewPosition(r,e.id,s-1,i))}}}moveCellsOnAddition(e,t,i,n){const o=[];for(let s=0;s<e.rows.length;s++){const r=e.rows[s];if("rows"!==n||s>=t)for(let a in r.cells){const l=Number(a),c=r.cells[a];c&&("rows"===n||l>=t)&&o.push({sheetId:e.id,cellId:c,col:l+("columns"===n?i:0),row:s+("rows"===n?i:0),type:"UPDATE_CELL_POSITION"})}}for(let e of o.reverse())this.updateCellPosition(e)}moveCellOnRowsDeletion(e,t,i){const n=i-t+1;for(let o=0;o<e.rows.length;o++){const s=e.rows[o];if(o>=t&&o<=i)for(let t in s.cells){const i=Number(t);s.cells[t]&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:i,row:o})}if(o>i)for(let t in s.cells){const i=Number(t),r=s.cells[t];r&&this.setNewPosition(r,e.id,i,o-n)}}}updateRowsStructureOnDeletion(e,t,i){const n=[],o=e.rows.map((e=>e.cells)).reverse();for(let s in e.rows){const e=Number(s);e>=t&&e<=i||n.push({cells:o.pop()})}this.history.update("sheets",e.id,"rows",n)}addEmptyRows(e,t){const i=e.rows.slice();for(let e=0;e<t;e++)i.push({cells:{}});this.history.update("sheets",e.id,"rows",i)}getImportedSheetSize(e){const t=Object.keys(e.cells).map(Ut);let i=e.rowNumber,n=e.colNumber;for(let{col:e,row:o}of t)i=Math.max(i,o+1),n=Math.max(n,e+1);return{rowNumber:i,colNumber:n}}checkSheetExists(e){return"CREATE_SHEET"!==e.type&&"sheetId"in e&&void 0===this.sheets[e.sheetId]?27:"CREATE_SHEET"===e.type&&void 0!==this.sheets[e.sheetId]?12:0}checkZones(e){const t=[];if("zone"in e&&t.push(e.zone),"target"in e&&Array.isArray(e.target)&&t.push(...e.target),"ranges"in e&&Array.isArray(e.ranges)){if(e.ranges.some((e=>!this.getters.tryGetSheet(e._sheetId))))return 27;t.push(...e.ranges.map((e=>this.getters.getRangeFromRangeData(e).zone)))}if(!t.every(Di))return 25;if(t.length&&"sheetId"in e){const i=this.getSheetZone(e.sheetId);return t.every((e=>Gi(e,i)))?0:18}return 0}}Rv.getters=["getSheetName","tryGetSheetName","getSheet","tryGetSheet","getSheetIdByName","getSheetIds","getVisibleSheetIds","isSheetVisible","getEvaluationSheets","doesHeaderExist","getCell","getCellsInZone","getCellPosition","getColCells","getColsZone","getRowCells","getRowsZone","getNumberCols","getNumberRows","getNumberHeaders","getGridLinesVisibility","getNextSheetName","isEmpty","getSheetSize","getSheetZone","getPaneDivisions","checkElementsIncludeAllNonFrozenHeaders","getDuplicateSheetName"];class Iv{constructor(e,t,i){this.index=0,this.cells=e,this.getters=t,this.direction=i}next(){const e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:i,tooltip:n}=cn.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:i,tooltip:n,origin:{col:e.data.col,row:e.data.row}}}}class Tv extends Gg{constructor(){super(...arguments),this.lastCellSelected={}}allowDispatch(e){switch(e.type){case"AUTOFILL_SELECT":const t=this.getters.getActiveSheetId();return this.lastCellSelected.col=-1===e.col?this.lastCellSelected.col:Me(e.col,0,this.getters.getNumberCols(t)),this.lastCellSelected.row=-1===e.row?this.lastCellSelected.row:Me(e.row,0,this.getters.getNumberRows(t)),void 0!==this.lastCellSelected.col&&void 0!==this.lastCellSelected.row?0:46;case"AUTOFILL_AUTO":const i=this.getters.getSelectedZone();return i.top===i.bottom?0:1}return 0}handle(e){switch(e.type){case"AUTOFILL":this.autofill(!0);break;case"AUTOFILL_SELECT":this.select(e.col,e.row);break;case"AUTOFILL_AUTO":this.autofillAuto();break;case"AUTOFILL_CELL":this.autoFillMerge(e.originCol,e.originRow,e.col,e.row);const t=this.getters.getActiveSheetId();this.dispatch("UPDATE_CELL",{sheetId:t,col:e.col,row:e.row,style:e.style||null,content:e.content||"",format:e.format||""}),this.dispatch("SET_BORDER",{sheetId:t,col:e.col,row:e.row,border:e.border})}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||!this.steps||void 0===this.direction)return void(this.tooltip=void 0);const t=this.getters.getSelectedZone(),i=this.autofillZone;switch(this.direction){case"down":for(let n=t.left;n<=t.right;n++){const o=[];for(let e=t.top;e<=t.bottom;e++)o.push(Vt(n,e));const s=this.createGenerator(o);for(let t=i.top;t<=i.bottom;t++)this.computeNewCell(s,n,t,e)}break;case"up":for(let n=t.left;n<=t.right;n++){const o=[];for(let e=t.bottom;e>=t.top;e--)o.push(Vt(n,e));const s=this.createGenerator(o);for(let t=i.bottom;t>=i.top;t--)this.computeNewCell(s,n,t,e)}break;case"left":for(let n=t.top;n<=t.bottom;n++){const o=[];for(let e=t.right;e>=t.left;e--)o.push(Vt(e,n));const s=this.createGenerator(o);for(let t=i.right;t>=i.left;t--)this.computeNewCell(s,t,n,e)}break;case"right":for(let n=t.top;n<=t.bottom;n++){const o=[];for(let e=t.left;e<=t.right;e++)o.push(Vt(e,n));const s=this.createGenerator(o);for(let t=i.left;t<=i.right;t++)this.computeNewCell(s,t,n,e)}}e&&(this.autofillZone=void 0,this.selection.resizeAnchorZone(this.direction,this.steps),this.lastCellSelected={},this.direction=void 0,this.steps=0,this.tooltip=void 0)}select(e,t){const i=this.getters.getSelectedZone();if(Wi(e,t,i))this.autofillZone=void 0;else{switch(this.direction=this.getDirection(e,t),this.direction){case"up":this.saveZone(t,i.top-1,i.left,i.right),this.steps=i.top-t;break;case"down":this.saveZone(i.bottom+1,t,i.left,i.right),this.steps=t-i.bottom;break;case"left":this.saveZone(i.top,i.bottom,e,i.left-1),this.steps=i.left-e;break;case"right":this.saveZone(i.top,i.bottom,i.right+1,e),this.steps=e-i.right}this.autofill(!1)}}autofillAuto(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();let i=e.left,n=e.bottom;if(i>0){let e=this.getters.getCell(t,i-1,n);for(;e&&!e.isEmpty();)n+=1,e=this.getters.getCell(t,i-1,n)}if(n===e.bottom&&(i=e.right,i<=this.getters.getNumberCols(t))){let e=this.getters.getCell(t,i+1,n);for(;e&&!e.isEmpty();)n+=1,e=this.getters.getCell(t,i+1,n)}n!==e.bottom&&(this.select(e.left,n-1),this.autofill(!0))}computeNewCell(e,t,i,n){const{cellData:o,tooltip:s,origin:r}=e.next(),{content:a,style:l,border:c,format:h}=o;this.tooltip=s,n&&this.dispatch("AUTOFILL_CELL",{originCol:r.col,originRow:r.row,col:t,row:i,content:a,style:l,border:c,format:h})}getRule(e,t){const i=En.getAll().sort(((e,t)=>e.sequence-t.sequence)).find((i=>i.condition(e,t)));return i&&this.direction&&i.generateRule(e,t,this.direction)}createGenerator(e){const t=[],i=[],n=this.getters.getActiveSheetId();for(let t of e){const{col:e,row:o}=Ut(t),s=this.getters.getCell(n,e,o);i.push({col:e,row:o,cell:s,sheetId:n})}const o=i.map((e=>e.cell));for(let e of i){let i={type:"COPY_MODIFIER"};if(e&&e.cell){i=this.getRule(e.cell,o)||i}const{sheetId:n,col:s,row:r}=e,a=this.getters.getCellBorder(n,s,r)||void 0;t.push({data:{...e,border:a},rule:i})}return new Iv(t,this.getters,this.direction)}saveZone(e,t,i,n){this.autofillZone={top:e,bottom:t,left:i,right:n}}getDirection(e,t){const i=this.getters.getSelectedZone(),n={up:{number:i.top-t,value:"up"},down:{number:t-i.bottom,value:"down"},left:{number:i.left-e,value:"left"},right:{number:e-i.right,value:"right"}};if(1===Object.values(n).map((e=>e.number>0?1:0)).reduce(((e,t)=>e+t)))return Object.values(n).find((e=>e.number>0?1:0)).value;const o=n.up.number>0?"up":"down",s=n.left.number>0?"left":"right";return Math.abs(n[o].number)>=Math.abs(n[s].number)?n[o].value:n[s].value}autoFillMerge(e,t,i,n){const o=this.getters.getActiveSheet();if(this.getters.isInMerge(o.id,i,n)&&!this.getters.isInMerge(o.id,e,t)){const e=this.getters.getMerge(o.id,i,n);e&&this.dispatch("REMOVE_MERGE",{sheetId:o.id,target:[e]})}const s=this.getters.getMerge(o.id,e,t);(null==s?void 0:s.topLeft.col)===e&&(null==s?void 0:s.topLeft.row)===t&&this.dispatch("ADD_MERGE",{sheetId:o.id,target:[{top:n,bottom:n+s.bottom-s.top,left:i,right:i+s.right-s.left}]})}drawGrid(e){if(!this.autofillZone)return;const{ctx:t,thinLineWidth:i}=e,{x:n,y:o,width:s,height:r}=this.getters.getVisibleRect(this.autofillZone);s>0&&r>0&&(t.strokeStyle="black",t.lineWidth=i,t.setLineDash([3]),t.strokeRect(n,o,s,r),t.setLineDash([]))}}Tv.layers=[6],Tv.getters=["getAutofillTooltip"];class Av extends Gg{handle(e){if("SUM_SELECTION"===e.type){const e=this.getters.getActiveSheetId(),{zones:t,anchor:i}=this.getters.getSelection();for(const n of t){const t=this.getAutomaticSums(e,n,i.cell);this.dispatchCellUpdates(e,t)}}}getAutomaticSums(e,t,i){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,i):this.sumData(e,t)}sumData(e,t){const i=this.dimensionsToSum(e,t),n=this.sumDimensions(e,t,i).filter((({zone:t})=>!this.getters.isEmpty(e,t)));return i.has("ROW")&&i.has("COL")&&n.push(this.sumTotal(t)),n}sumAdjacentData(e,t,i){const{col:n,row:o}=Wi(i.col,i.row,t)?i:{col:t.left,row:t.top},s=this.findAdjacentData(e,n,o);return s?this.getters.isSingleCellOrMerge(e,t)||Yi(Vi(s,t))?[{position:{col:n,row:o},zone:s}]:this.sumDimensions(e,Vi(s,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,i){const n=this.getters.getSheet(e),o=this.getters.getMainCellPosition(e,t,i),s=this.findSuitableZoneToSum(n,o.col,o.row);if(s)return this.getters.expandZone(e,s)}findSuitableZoneToSum(e,t,i){const n=this.getters.getCell(e.id,t,i-1),o=this.getters.getCell(e.id,t-1,i);if(this.isNumber(o)&&!this.isNumber(n))return this.findHorizontalZone(e,t,i);const s=this.findVerticalZone(e,t,i);if(this.isZoneValid(s))return s;const r=this.findHorizontalZone(e,t,i);return this.isZoneValid(r)?r:void 0}findVerticalZone(e,t,i){const n={top:0,bottom:i-1,left:t,right:t},o=this.reduceZoneStart(e,n,n.bottom);return{...n,top:o}}findHorizontalZone(e,t,i){const n={top:i,bottom:i,left:0,right:t-1},o=this.reduceZoneStart(e,n,n.right);return{...n,left:o}}reduceZoneStart(e,t,i){const n=this.getters.getCellsInZone(e.id,t),o=$e(i,-1,-1),s=lt(o.filter((e=>{var t;return n[e]&&!(null===(t=n[e])||void 0===t?void 0:t.isAutoSummable)}))),r=Le(o.filter((e=>this.isNumber(n[e]))))[0]||[];return lt(r)<s?1/0:ct(r)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){var t;return(null==e?void 0:e.evaluated.type)===hn.number&&!(null===(t=e.evaluated.format)||void 0===t?void 0:t.match(Y))}isZoneValid(e){return e.bottom>=e.top&&e.right>=e.left}lastColIsEmpty(e,t){return this.getters.isEmpty(e,{...t,left:t.right})}lastRowIsEmpty(e,t){return this.getters.isEmpty(e,{...t,top:t.bottom})}dimensionsToSum(e,t){const i=new Set;return Yi(t)?(i.add(1===ji(t).width?"COL":"ROW"),i):(this.lastColIsEmpty(e,t)&&i.add("ROW"),this.lastRowIsEmpty(e,t)&&i.add("COL"),0===i.size&&i.add("COL"),i)}sumDimensions(e,t,i){return[...i.has("COL")?this.sumColumns(t,e):[],...i.has("ROW")?this.sumRows(t,e):[]]}sumTotal(e){const{bottom:t,right:i}=e;return{position:{col:i,row:t},zone:{...e,top:t,right:i-1}}}sumColumns(e,t){const i=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,i.bottom-1)},Xi(i).map((t=>({position:t,zone:{...e,right:t.col,left:t.col}})))}sumRows(e,t){const i=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,i.right-1)},Xi(i).map((t=>({position:t,zone:{...e,top:t.row,bottom:t.row}})))}dispatchCellUpdates(e,t){for(const i of t){const{col:t,row:n}=i.position;this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:n,content:`=SUM(${this.getters.zoneToXC(e,i.zone)})`})}}nextEmptyRow(e,t){let i=t.bottom+1;const{left:n,right:o}=t;for(;!this.getters.isEmpty(e,{bottom:i,top:i,left:n,right:o});)i++;return{...t,top:i,bottom:i}}nextEmptyCol(e,t){let i=t.right+1;const{top:n,bottom:o}=t;for(;!this.getters.isEmpty(e,{left:i,right:i,top:n,bottom:o});)i++;return{...t,left:i,right:i}}transpose(e){return new Set([...e.values()].map((e=>"COL"===e?"ROW":"COL")))}}Av.getters=["getAutomaticSums"];class Nv extends Gg{allowDispatch(e){if("OPEN_CELL_POPOVER"===e.type){try{to.get(e.popoverType)}catch(e){return 73}return 0}return 0}handle(e){switch(e.type){case"ACTIVATE_SHEET":case"CLOSE_CELL_POPOVER":this.persistentPopover=void 0;break;case"OPEN_CELL_POPOVER":this.persistentPopover={col:e.col,row:e.row,type:e.popoverType}}}getCellPopover({col:e,row:t}){var i,n;const o=this.getters.getActiveSheetId();if(this.persistentPopover&&this.getters.isVisibleInViewport(o,this.persistentPopover.col,this.persistentPopover.row)){const e=this.getters.getMainCellPosition(o,this.persistentPopover.col,this.persistentPopover.row),t=null===(n=(i=to.get(this.persistentPopover.type)).onOpen)||void 0===n?void 0:n.call(i,e,this.getters);return(null==t?void 0:t.isOpen)?{...t,...this.computePopoverProps(this.persistentPopover,t.cellCorner)}:{isOpen:!1}}if(void 0===e||void 0===t||!this.getters.isVisibleInViewport(o,e,t))return{isOpen:!1};const s=this.getters.getMainCellPosition(o,e,t),r=to.getAll().map((e=>{var t;return null===(t=e.onHover)||void 0===t?void 0:t.call(e,s,this.getters)})).find((e=>null==e?void 0:e.isOpen));return(null==r?void 0:r.isOpen)?{...r,...this.computePopoverProps(s,r.cellCorner)}:{isOpen:!1}}getPersistentPopoverTypeAtPosition({col:e,row:t}){if(this.persistentPopover&&this.persistentPopover.col===e&&this.persistentPopover.row===t)return this.persistentPopover.type}computePopoverProps({col:e,row:t},i){const{width:n,height:o}=this.getters.getVisibleRect(en({col:e,row:t}));return{coordinates:this.computePopoverPosition({col:e,row:t},i),cellWidth:-n,cellHeight:-o}}computePopoverPosition({col:e,row:t},i){const n=this.getters.getActiveSheetId(),o=this.getters.getMerge(n,e,t);o&&(e="TopRight"===i?o.right:o.left,t="TopRight"===i?o.top:o.bottom);const{x:s,y:r,width:a,height:l}=this.getters.getVisibleRect(en({col:e,row:t}));switch(i){case"BottomLeft":return{x:s,y:r+l};case"TopRight":return{x:s+a,y:r}}}}Nv.getters=["getCellPopover","getPersistentPopoverTypeAtPosition"],Nv.modes=["normal"];class Ov{constructor(e,t,i,n){this.getters=t,this.dispatch=i,this.selection=n,this.operation=e,this.sheetId=t.getActiveSheetId()}isCutAllowed(e){return 0}isPasteAllowed(e,t){return 0}addMissingDimensions(e,t,i,n){const o=this.getters.getActiveSheetId(),s=t+n-this.getters.getNumberRows(o);s>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"ROW",base:this.getters.getNumberRows(o)-1,sheetId:o,quantity:s,position:"after"});const r=e+i-this.getters.getNumberCols(o);r>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"COL",base:this.getters.getNumberCols(o)-1,sheetId:o,quantity:r,position:"after"})}isColRowDirtyingClipboard(e,t){return!1}drawClipboard(e){}}class Mv extends Ov{constructor(e,t,i,n,o){if(super(t,i,n,o),!e.length)return this.cells=[[]],this.zones=[],void(this.copiedTables=[]);const s=new Set(e.map((e=>e.left))),r=new Set(e.map((e=>e.right))),a=new Set(e.map((e=>e.top))),l=new Set(e.map((e=>e.bottom))),c=1===a.size&&1===l.size||1===s.size&&1===r.size?function(e){return e.reduce(((e,t)=>{const i=e.length;for(let n=0;n<i;n++)if(Hi(e[n],t))return e[n]=Vi(e[n],t),e;return e[i]=t,e}),[])}(e):[e[e.length-1]],h=c.map((e=>Xi(e))).flat(),d=[...new Set(h.map((e=>e.col)))].sort(((e,t)=>e-t)),u=[...new Set(h.map((e=>e.row)))].sort(((e,t)=>e-t)),g=[],p=i.getActiveSheetId();for(let e of u){let t=[];for(let n of d)t.push({cell:i.getCell(p,n,e),border:i.getCellBorder(p,n,e)||void 0,position:{col:n,row:e,sheetId:p}});g.push(t)}const m=[];for(const t of e)for(const e of this.getters.getFilterTablesInZone(p,t)){const t=[];for(const i of $e(e.zone.left,e.zone.right+1))t.push(this.getters.getFilterValues(p,i,e.zone.top));m.push({filtersValues:t,zone:e.zone})}this.cells=g,this.zones=c,this.copiedTables=m}isCutAllowed(e){return 1!==e.length?19:0}isPasteAllowed(e,t){const i=this.getters.getActiveSheetId();if("CUT"===this.operation&&void 0!==(null==t?void 0:t.pasteOption))return 21;if(e.length>1&&(this.cells.length>1||this.cells[0].length>1))return 20;const n=this.cells.length,o=this.cells[0].length;for(let t of this.getPasteZones(e))if(this.getters.doesIntersectMerge(i,t)&&(e.length>1||!this.getters.isSingleCellOrMerge(i,e[0])||n*o!=1))return 2;const{xSplit:s,ySplit:r}=this.getters.getPaneDivisions(i);for(const t of this.getPasteZones(e))if(t.left<s&&t.right>=s||t.top<r&&t.bottom>=r)return 76;return 0}paste(e,t){"COPY"===this.operation?this.pasteFromCopy(e,t):this.pasteFromCut(e,t);const i=this.cells.length,n=this.cells[0].length,o="CUT"===this.operation;(null==t?void 0:t.selectTarget)&&this.selectPastedZone(n,i,o,e)}pasteFromCopy(e,t){if(1===e.length){const i=this.cells.length,n=this.cells[0].length,o=this.pastedZones(e,n,i);for(const e of o)this.pasteZone(e.left,e.top,t)}else for(const i of e)for(let e=i.left;e<=i.right;e++)for(let n=i.top;n<=i.bottom;n++)this.pasteZone(e,n,t);void 0===(null==t?void 0:t.pasteOption)&&this.pasteCopiedTables(e)}pasteFromCut(e,t){this.clearClippedZones();const i=e[0];this.pasteZone(i.left,i.top,t),this.dispatch("MOVE_RANGES",{target:this.zones,sheetId:this.sheetId,targetSheetId:this.getters.getActiveSheetId(),col:i.left,row:i.top});for(const e of this.copiedTables)this.dispatch("REMOVE_FILTER_TABLE",{sheetId:this.sheetId,target:[e.zone]});this.pasteCopiedTables(e)}pastedZones(e,t,i){const n=e[0],o=Math.max(1,Math.floor((n.right+1-n.left)/t)),s=Math.max(1,Math.floor((n.bottom+1-n.top)/i)),r=[];for(let e=0;e<o;e++)for(let o=0;o<s;o++){const s=n.top+o*i,a=n.left+e*t;r.push({left:a,top:s,bottom:s+i-1,right:a+t-1})}return r}getPasteZones(e){const t=this.cells;if(!t.length||!t[0].length)return e;const i=[],n=t.length,o=t[0].length,s=e[e.length-1],r=s.left,a=s.top,l=Math.max(1,Math.floor((s.right+1-r)/o)),c=Math.max(1,Math.floor((s.bottom+1-a)/n));for(let e=1;e<=l;e++)for(let t=1;t<=c;t++)i.push({left:r,top:a,right:r-1+e*o,bottom:a-1+t*n});return i}selectPastedZone(e,t,i,n){const o=n[0],s=o.left,r=o.top;if(t>1||e>1||i){const o=this.pastedZones(n,e,t),a=i?o[0]:Vi(...o);this.selection.selectZone({cell:{col:s,row:r},zone:a})}}clearClippedZones(){for(const e of this.cells)for(const t of e)t.cell&&this.dispatch("CLEAR_CELL",t.position);this.dispatch("CLEAR_FORMATTING",{sheetId:this.sheetId,target:this.zones})}pasteZone(e,t,i){const n=this.cells.length,o=this.cells[0].length,s="onlyValue"!==(null==i?void 0:i.pasteOption)&&(null==i?void 0:i.shouldPasteCF),r=this.getters.getActiveSheetId();this.addMissingDimensions(o,n,e,t);for(let a=0;a<n;a++){const n=this.cells[a];for(let l=0;l<o;l++){const o=n[l],c={col:e+l,row:t+a,sheetId:r};this.pasteMergeIfExist(o.position,c,this.operation),this.pasteCell(o,c,this.operation,i),s&&this.dispatch("PASTE_CONDITIONAL_FORMAT",{origin:o.position,target:c,operation:this.operation})}}}pasteCell(e,t,i,n){const{sheetId:o,col:s,row:r}=t,a=this.getters.getCell(o,s,r);if("onlyValue"!==(null==n?void 0:n.pasteOption)){const t=this.getters.getCellBorder(o,s,r),i=e.border,n={top:(null==t?void 0:t.top)||(null==i?void 0:i.top),bottom:(null==t?void 0:t.bottom)||(null==i?void 0:i.bottom),left:(null==t?void 0:t.left)||(null==i?void 0:i.left),right:(null==t?void 0:t.right)||(null==i?void 0:i.right)};this.dispatch("SET_BORDER",{sheetId:o,col:s,row:r,border:n})}if(e.cell){if("onlyFormat"===(null==n?void 0:n.pasteOption))return void this.dispatch("UPDATE_CELL",{...t,style:e.cell.style,format:e.cell.evaluated.format||e.cell.format});if("onlyValue"===(null==n?void 0:n.pasteOption)){const i=Qt(e.cell.evaluated.value);return void this.dispatch("UPDATE_CELL",{...t,content:i})}let a=e.cell.content;if(e.cell.isFormula()&&"COPY"===i){const t=s-e.position.col,n=r-e.position.row;a=this.getUpdatedContent(o,e.cell,t,n,i)}this.dispatch("UPDATE_CELL",{...t,content:a,style:e.cell.style||null,format:e.cell.format})}else a&&("onlyValue"===(null==n?void 0:n.pasteOption)?this.dispatch("UPDATE_CELL",{...t,content:""}):"onlyFormat"===(null==n?void 0:n.pasteOption)?this.dispatch("UPDATE_CELL",{...t,style:null,format:""}):this.dispatch("CLEAR_CELL",t))}getUpdatedContent(e,t,i,n,o){const s=this.getters.createAdaptedRanges(t.dependencies,i,n,e);return this.getters.buildFormulaContent(e,t,s)}pasteMergeIfExist(e,t,i){let{sheetId:n,col:o,row:s}=e;const{col:r,row:a}=this.getters.getMainCellPosition(n,o,s);if(r===o&&a===s){const e=this.getters.getMerge(n,o,s);if(!e)return;"CUT"===i&&this.dispatch("REMOVE_MERGE",{sheetId:n,target:[e]}),({sheetId:n,col:o,row:s}=t),this.dispatch("ADD_MERGE",{sheetId:n,force:!0,target:[{left:o,top:s,right:o+e.right-e.left,bottom:s+e.bottom-e.top}]})}}pasteCopiedTables(e){const t=this.getters.getActiveSheetId(),i=e[0],n=this.zones[0],o=[i.left-n.left,i.top-n.top];for(const e of this.copiedTables){const i=Ki(e.zone,"both","MOVE",o);this.dispatch("CREATE_FILTER_TABLE",{sheetId:t,target:[i]});for(const n of $e(0,e.filtersValues.length))this.dispatch("UPDATE_FILTER",{sheetId:t,col:i.left+n,row:i.top,values:e.filtersValues[n]})}}getClipboardContent(){return this.cells.map((e=>e.map((e=>e.cell?this.getters.getCellText(e.cell,this.getters.shouldShowFormulas()):"")).join("\t"))).join("\n")||"\t"}isColRowDirtyingClipboard(e,t){if(!this.zones)return!1;for(let i of this.zones){if("COL"===t&&e<=i.right)return!0;if("ROW"===t&&e<=i.bottom)return!0}return!1}drawClipboard(e){const{ctx:t,thinLineWidth:i}=e;if(this.sheetId===this.getters.getActiveSheetId()&&this.zones&&this.zones.length){t.setLineDash([8,5]),t.strokeStyle=E,t.lineWidth=3.3*i;for(const e of this.zones){const{x:i,y:n,width:o,height:s}=this.getters.getVisibleRect(e);o>0&&s>0&&t.strokeRect(i,n,o,s)}}}}class _v{constructor(e,t,i){this.getters=t,this.dispatch=i,this.sheetId=t.getActiveSheetId();const n=t.getSelectedFigureId();if(!n)throw new Error("No figure selected");const o=t.getFigure(this.sheetId,n);if(!o)throw new Error(`No figure for the given id: ${n}`);this.copiedFigure={...o};const s=t.getChart(n);if(!s)throw new Error(`No chart for the given id: ${n}`);this.copiedChart=s.copyInSheetId(this.sheetId),this.operation=e}isCutAllowed(e){return 0}isPasteAllowed(e,t){return 0===e.length?74:void 0!==(null==t?void 0:t.pasteOption)?22:0}paste(e){const t=this.getters.getActiveSheetId(),i={x:this.getters.getColDimensions(t,e[0].left).start,y:this.getters.getRowDimensions(t,e[0].top).start},n=this.copiedChart.copyInSheetId(t),o=(new Mi).smallUuid();this.dispatch("CREATE_CHART",{id:o,sheetId:t,position:i,size:{height:this.copiedFigure.height,width:this.copiedFigure.width},definition:n.getDefinition()}),"CUT"===this.operation&&this.dispatch("DELETE_FIGURE",{sheetId:this.copiedChart.sheetId,id:this.copiedFigure.id}),this.dispatch("SELECT_FIGURE",{id:o})}getClipboardContent(){return"\t"}isColRowDirtyingClipboard(e,t){return!1}drawClipboard(e){}}class Fv extends Ov{constructor(e,t,i,n){super("COPY",t,i,n),this.values=e.replace(/\r/g,"").split("\n").map((e=>e.split("\t")))}isPasteAllowed(e,t){const i=this.getters.getActiveSheetId(),n=this.getPasteZone(e);return this.getters.doesIntersectMerge(i,n)?2:0}paste(e){const t=this.values,i=this.getPasteZone(e),{left:n,top:o}=i,{width:s,height:r}=ji(i),a=this.getters.getActiveSheetId();this.addMissingDimensions(s,r,n,o);for(let e=0;e<t.length;e++)for(let i=0;i<t[e].length;i++)this.dispatch("UPDATE_CELL",{row:o+e,col:n+i,content:t[e][i],sheetId:a});const l={left:n,top:o,right:n+s-1,bottom:o+r-1};this.selection.selectZone({cell:{col:n,row:o},zone:l})}getClipboardContent(){return this.values.map((e=>e.join("\t"))).join("\n")}getPasteZone(e){const t=this.values.length,i=Math.max(...this.values.map((e=>e.length))),{left:n,top:o}=e[0];return{top:o,left:n,bottom:o+t-1,right:n+i-1}}}class Dv extends Gg{constructor(){super(...arguments),this.status="invisible",this._isPaintingFormat=!1}allowDispatch(e){switch(e.type){case"CUT":const t=this.getters.getSelectedZones();return this.getClipboardState(t,e.type).isCutAllowed(t);case"PASTE":if(!this.state)return 23;const i=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);return this.state.isPasteAllowed(e.target,{pasteOption:i});case"PASTE_FROM_OS_CLIPBOARD":return new Fv(e.text,this.getters,this.dispatch,this.selection).isPasteAllowed(e.target);case"INSERT_CELL":{const{cut:t,paste:i}=this.getInsertCellsTargets(e.zone,e.shiftDimension);return this.getClipboardStateForCopyCells(t,"CUT").isPasteAllowed(i)}case"DELETE_CELL":{const{cut:t,paste:i}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);return this.getClipboardStateForCopyCells(t,"CUT").isPasteAllowed(i)}}return 0}handle(e){var t,i,n,o;switch(e.type){case"COPY":case"CUT":const s=this.getters.getSelectedZones();this.state=this.getClipboardState(s,e.type),this.status="visible";break;case"PASTE":if(!this.state)break;const r=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);this._isPaintingFormat=!1,this.state.paste(e.target,{pasteOption:r,shouldPasteCF:!0,selectTarget:!0}),"CUT"===this.state.operation&&(this.state=void 0),this.status="invisible";break;case"DELETE_CELL":{const{cut:t,paste:i}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);if(!Di(t[0])){for(const{col:t,row:i}of Xi(e.zone))this.dispatch("CLEAR_CELL",{col:t,row:i,sheetId:this.getters.getActiveSheetId()});break}this.getClipboardStateForCopyCells(t,"CUT").paste(i);break}case"INSERT_CELL":{const{cut:t,paste:i}=this.getInsertCellsTargets(e.zone,e.shiftDimension);this.getClipboardStateForCopyCells(t,"CUT").paste(i);break}case"ADD_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(t=this.state)||void 0===t?void 0:t.operation)||e.sheetId!==(null===(i=this.state)||void 0===i?void 0:i.sheetId))return;this.state.isColRowDirtyingClipboard("before"===e.position?e.base:e.base+1,e.dimension)&&(this.state=void 0);break;case"REMOVE_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(n=this.state)||void 0===n?void 0:n.operation)||e.sheetId!==(null===(o=this.state)||void 0===o?void 0:o.sheetId))return;for(let t of e.elements){if(this.state.isColRowDirtyingClipboard(t,e.dimension)){this.state=void 0;break}}this.status="invisible";break;case"PASTE_FROM_OS_CLIPBOARD":new Fv(e.text,this.getters,this.dispatch,this.selection).paste(e.target),this.status="invisible";break;case"ACTIVATE_PAINT_FORMAT":{const e=this.getters.getSelectedZones();this.state=this.getClipboardStateForCopyCells(e,"COPY"),this._isPaintingFormat=!0,this.status="visible";break}default:mn(e)&&(this.status="invisible")}}getClipboardContent(){var e;return(null===(e=this.state)||void 0===e?void 0:e.getClipboardContent())||"\t"}isCutOperation(){return!!this.state&&"CUT"===this.state.operation}isPaintingFormat(){return this._isPaintingFormat}getDeleteCellsTargets(e,t){const i=this.getters.getActiveSheetId();let n;return n="COL"===t?{...e,left:e.right+1,right:this.getters.getNumberCols(i)-1}:{...e,top:e.bottom+1,bottom:this.getters.getNumberRows(i)-1},{cut:[n],paste:[e]}}getInsertCellsTargets(e,t){const i=this.getters.getActiveSheetId();let n,o;return"COL"===t?(n={...e,right:this.getters.getNumberCols(i)-1},o={...e,left:e.right+1,right:e.right+1}):(n={...e,bottom:this.getters.getNumberRows(i)-1},o={...e,top:e.bottom+1,bottom:this.getters.getNumberRows(i)-1}),{cut:[n],paste:[o]}}getClipboardStateForCopyCells(e,t){return new Mv(e,t,this.getters,this.dispatch,this.selection)}getClipboardState(e,t){return this.getters.getSelectedFigureId()?new _v(t,this.getters,this.dispatch):new Mv(e,t,this.getters,this.dispatch,this.selection)}drawGrid(e){"visible"===this.status&&this.state&&this.state.drawClipboard(e)}}Dv.layers=[2],Dv.getters=["getClipboardContent","isCutOperation","isPaintingFormat"];class kv extends Gg{constructor(){super(...arguments),this.customColors=new Set,this.shouldUpdateColors=!1}handle(e){switch(e.type){case"UPDATE_CELL":case"UPDATE_CHART":case"CREATE_CHART":case"ADD_CONDITIONAL_FORMAT":this.shouldUpdateColors=!0}}finalize(){if(this.shouldUpdateColors){this.shouldUpdateColors=!1;for(const e of this.getCustomColors())this.tryToAddColor(e)}}getCustomColors(){let e=[];for(const t of this.getters.getSheetIds()){const i=Object.values(this.getters.getCells(t));e=e.concat(this.getColorsFromCells(i),this.getFormattingColors(t),this.getChartColors(t))}return function(e){const t=[{leadColor:bt(255,0,0),colors:[]},{leadColor:bt(255,128,0),colors:[]},{leadColor:bt(128,128,0),colors:[]},{leadColor:bt(128,255,0),colors:[]},{leadColor:bt(0,255,0),colors:[]},{leadColor:bt(0,255,128),colors:[]},{leadColor:bt(0,255,255),colors:[]},{leadColor:bt(0,127,255),colors:[]},{leadColor:bt(0,0,255),colors:[]},{leadColor:bt(127,0,255),colors:[]},{leadColor:bt(128,0,128),colors:[]},{leadColor:bt(255,0,128),colors:[]}];for(const i of e.map(Et)){let e=500,n=0;t.forEach(((t,o)=>{const s=(r=i,a=t.leadColor,Math.sqrt(Math.pow(r.r-a.r,2)+Math.pow(r.g-a.g,2)+Math.pow(r.b-a.b,2)));var r,a;e>s&&(e=s,n=o)})),t[n].colors.push(i)}return t.map((e=>e.colors.sort(((e,t)=>yt(e).s-yt(t).s)))).flat().map(Ct)}([...new Set([...new Set([...e,...this.customColors])].filter(ft).map(mt))]).filter((e=>!N.includes(e)))}getColorsFromCells(e){var t,i;const n=new Set;for(const o of e)(null===(t=o.style)||void 0===t?void 0:t.textColor)&&n.add(o.style.textColor),(null===(i=o.style)||void 0===i?void 0:i.fillColor)&&n.add(o.style.fillColor);return[...n]}getFormattingColors(e){const t=this.getters.getConditionalFormats(e),i=[];for(const e of t){const t=e.rule;"CellIsRule"===t.type?(i.push(t.style.textColor),i.push(t.style.fillColor)):"ColorScaleRule"===t.type&&(i.push(gt(t.minimum.color)),i.push(t.midpoint?gt(t.midpoint.color):void 0),i.push(gt(t.maximum.color)))}return i.filter(Xe)}getChartColors(e){const t=this.getters.getChartIds(e).map((e=>this.getters.getChart(e)));let i=new Set;for(let e of t){if(void 0===e)continue;const t=e.getDefinition().background;switch(void 0!==t&&i.add(t),e.type){case"gauge":const t=e.sectionRule.colors;i.add(t.lowerColor),i.add(t.middleColor),i.add(t.upperColor);break;case"scorecard":const n=e;i.add(n.baselineColorDown),i.add(n.baselineColorUp)}}return[...i]}tryToAddColor(e){const t=mt(e);e&&!N.includes(t)&&this.customColors.add(t)}}kv.getters=["getCustomColors"];const $v=Yu.mapping;class Lv extends Gg{constructor(e,t,i,n,o){super(e,t,i,n,o),this.isUpToDate=!1,this.evalContext=n.evalContext}handle(e){switch(dn.has(e.type)&&(this.isUpToDate=!1),e.type){case"UPDATE_CELL":("content"in e||"format"in e)&&(this.isUpToDate=!1);break;case"EVALUATE_CELLS":this.evaluate()}}finalize(){this.isUpToDate||this.evaluate()}evaluateFormula(e,t=this.getters.getActiveSheetId()){try{const i=Ug(e),n=this.getCompilationParameters((()=>{})),o=[];for(let e of i.dependencies)o.push(this.getters.getRangeFromSheetXC(t,e));return i.execute(o,...n).value}catch(e){return e instanceof c?e.errorType:a.GenericError}}getRangeFormattedValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[]:this.getters.getCellsInZone(t.id,e.zone).map((e=>(null==e?void 0:e.formattedValue)||""))}getRangeValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[]:this.getters.getCellsInZone(t.id,e.zone).map((e=>null==e?void 0:e.evaluated.value))}*getAllCells(){for(const e of this.getters.getSheetIds()){const t=this.getters.getCells(e);for(const e in t)yield t[e]}}evaluate(){const e=this.getCompilationParameters(i),t={};for(const e of this.getAllCells())i(e);function i(i){if(!i.isFormula())return;const n=i.id,o=tt((()=>{if(e[2].__originCellXC=()=>{const t=e[2].getters.getCellPosition(n);return Vt(t.col,t.row)},n in t)return null===t[n]?new d:i.evaluated;t[n]=null;try{const o=i.compiledFormula.execute(i.dependencies,...e);if(t[n]=!0,Array.isArray(o.value))throw new Error(s("This formula depends on invalid values"));return{value:o.value,format:i.format||o.format}}catch(i){return t[n]=!0,function(t){t instanceof Error||(t=new Error(t));const i=(null==t?void 0:t.errorType)||a.GenericError,n=e[2].__lastFnCalled||"";return new c(i,t.message.replace("[[FUNCTION_NAME]]",n),void 0!==t.logLevel?t.logLevel:l.error)}(i)}}));i.assignEvaluation(o)}this.isUpToDate=!0}getCompilationParameters(e){const t=Object.assign(Object.create($v),this.evalContext,{getters:this.getters}),i=this.getters;function n(e){if(e.evaluated.type===hn.error)throw new c(e.evaluated.value,e.evaluated.error.message,e.evaluated.error.logLevel);return e.evaluated}const o={};function r(e){if(!Di(e.zone))throw new u;if(e.invalidSheetName)throw new Error(s("Invalid sheet name: %s",e.invalidSheetName))}return[function(e,t,o,a){if(r(e),t)return{value:ki(e.zone)};if(e.zone.bottom!==e.zone.top||e.zone.left!==e.zone.right)throw new Error(a?s("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",o.toString(),a.toString()):s("Function %s expects its parameters to be single values or single cell references, not ranges.",o.toString()));return function(e){let t;if(!i.tryGetSheet(e.sheetId))throw new Error(s("Invalid sheet name"));return t=i.getCell(e.sheetId,e.zone.left,e.zone.top),!t||t.isEmpty()?{value:null,format:null==t?void 0:t.format}:n(t)}(e)},function(e){r(e);const s=e.sheetId,a=i.getSheetZone(s),l=zi(e.zone,a);if(!l)return[[]];const{top:c,left:h,bottom:d,right:u}=l,g=`${s}-${c}-${h}-${d}-${u}`;if(g in o)return o[g];const p=new Array(u-h+1);for(let i=h;i<=u;i++){const o=new Array(d-c+1);for(let s=c;s<=d;s++){const r=t.getters.getCell(e.sheetId,i,s);o[s-c]=r?n(r):void 0}p[i-h]=o}return o[g]=p,p},t]}}Lv.getters=["evaluateFormula","getRangeFormattedValues","getRangeValues"];class Pv extends Gg{constructor(){super(...arguments),this.charts={},this.createRuntimeChart=function(e){const t=rn.getAll();return function(i){const n=t.find((e=>e.match(i.type)));if(!n)throw new Error("No runtime builder for this chart.");return n.getChartRuntime(i,e)}}(this.getters)}handle(e){if(dn.has(e.type)||un.has(e.type)||"EVALUATE_CELLS"===e.type||"UPDATE_CELL"===e.type)for(const e in this.charts)this.charts[e]=void 0;switch(e.type){case"UPDATE_CHART":case"CREATE_CHART":case"DELETE_FIGURE":this.charts[e.id]=void 0;break;case"DELETE_SHEET":for(let e in this.charts)this.getters.isChartDefined(e)||(this.charts[e]=void 0)}}getChartRuntime(e){if(!this.charts[e]){const t=this.getters.getChart(e);if(!t)throw new Error(`No chart for the given id: ${e}`);this.charts[e]=this.createRuntimeChart(t)}return this.charts[e]}getStyleOfSingleCellChart(e,t){if(e)return{background:e,fontColor:Rs(e)};if(!t)return{background:w,fontColor:Rs(w)};const i=t.zone.left,n=t.zone.top,o=t.sheetId,s=this.getters.getCellComputedStyle(o,i,n),r=s.fillColor||w;return{background:r,fontColor:s.textColor||Rs(r)}}}Pv.getters=["getChartRuntime","getStyleOfSingleCellChart"];class Uv extends Gg{constructor(){super(...arguments),this.isStale=!0,this.computedStyles={},this.computedIcons={},this.uuidGenerator=new Mi,this.rulePredicate={CellIsRule:(e,t)=>{if(e&&e.evaluated.type===hn.error)return!1;const i=t.values.map(Hp);switch(t.operator){case"IsEmpty":return!Xe(e)||""===e.evaluated.value.toString().trim();case"IsNotEmpty":return Xe(e)&&""!==e.evaluated.value.toString().trim();case"BeginsWith":return!(!e&&""===i[0])&&(Xe(e)&&(null==e?void 0:e.evaluated.value.toString().startsWith(i[0].toString())));case"EndsWith":return!(!e&&""===i[0])&&(Xe(e)&&e.evaluated.value.toString().endsWith(i[0].toString()));case"Between":return Xe(e)&&e.evaluated.value>=i[0]&&e.evaluated.value<=i[1];case"NotBetween":return!(Xe(e)&&e.evaluated.value>=i[0]&&e.evaluated.value<=i[1]);case"ContainsText":return Xe(e)&&e.evaluated.value.toString().indexOf(i[0].toString())>-1;case"NotContains":return!Xe(e)||!e.evaluated.value||-1==e.evaluated.value.toString().indexOf(i[0].toString());case"GreaterThan":return Xe(e)&&e.evaluated.value>i[0];case"GreaterThanOrEqual":return Xe(e)&&e.evaluated.value>=i[0];case"LessThan":return Xe(e)&&e.evaluated.value<i[0];case"LessThanOrEqual":return Xe(e)&&e.evaluated.value<=i[0];case"NotEqual":return!(!Xe(e)&&""===i[0])&&(Xe(e)&&e.evaluated.value!==i[0]);case"Equal":return!e&&""===i[0]||Xe(e)&&e.evaluated.value===i[0];default:console.warn(s("Not implemented operator %s for kind of conditional formatting: %s",t.operator,t.type))}return!1}}}handle(e){switch((un.has(e.type)||"UPDATE_CELL"===e.type&&"content"in e)&&(this.isStale=!0),e.type){case"ACTIVATE_SHEET":const t=e.sheetIdTo;this.computedStyles[t]=this.computedStyles[t]||{},this.computedIcons[t]=this.computedIcons[t]||{},this.isStale=!0;break;case"AUTOFILL_CELL":const i=this.getters.getActiveSheetId(),n=this.getters.getRulesByCell(i,e.originCol,e.originRow);for(const t of n)this.adaptRules(i,t,[Vt(e.col,e.row)],[]);break;case"PASTE_CONDITIONAL_FORMAT":this.pasteCf(e.origin,e.target,e.operation)}}finalize(){this.isStale&&(this.computeStyles(),this.isStale=!1)}getCellComputedStyle(e,t,i){var n;const o=this.getters.getCell(e,t,i),s=this.computedStyles[e],r=s&&(null===(n=s[t])||void 0===n?void 0:n[i]),a={...null==o?void 0:o.style,...r};return this.getters.isFilterHeader(e,t,i)&&(a.bold=!0),a}getConditionalIcon(e,t){var i;const n=this.getters.getActiveSheetId(),o=this.computedIcons[n];return o&&(null===(i=o[e])||void 0===i?void 0:i[t])}computeStyles(){var e;const t=this.getters.getActiveSheetId();this.computedStyles[t]={},this.computedIcons[t]={};const i=this.computedStyles[t];for(let n of this.getters.getConditionalFormats(t).reverse())switch(n.rule.type){case"ColorScaleRule":for(let e of n.ranges)this.applyColorScale(e,n.rule);break;case"IconSetRule":for(let e of n.ranges)this.applyIcon(e,n.rule);break;default:for(let o of n.ranges){const s=this.getters.getRangeFromSheetXC(t,o).zone;for(let o=s.top;o<=s.bottom;o++)for(let r=s.left;r<=s.right;r++){const s=this.rulePredicate[n.rule.type];let a=this.getters.getCell(t,r,o);s&&s(a,n.rule)&&(i[r]||(i[r]=[]),i[r][o]=Object.assign((null===(e=i[r])||void 0===e?void 0:e[o])||{},n.rule.style))}}}}parsePoint(e,t,i){const n=this.getters.getActiveSheetId(),o=this.getters.getRangeValues(this.getters.getRangeFromSheetXC(n,e)).filter(this.isCellValueNumber);switch(t.type){case"value":return"max"===i?lt(o):ct(o);case"number":return Number(t.value);case"percentage":const e=ct(o);return e+(lt(o)-e)*Number(t.value)/100;case"percentile":return yi(o,Number(t.value)/100,!0);case"formula":const n=t.value&&this.getters.evaluateFormula(t.value);return"number"==typeof n?n:null;default:return null}}applyIcon(e,t){const i=this.parsePoint(e,t.lowerInflectionPoint),n=this.parsePoint(e,t.upperInflectionPoint);if(null===i||null===n||i>n)return;const o=this.getters.getActiveSheetId(),s=this.getters.getRangeFromSheetXC(o,e).zone,r=this.computedIcons[o],a=[t.icons.upper,t.icons.middle,t.icons.lower];for(let e=s.top;e<=s.bottom;e++)for(let l=s.left;l<=s.right;l++){const s=this.getters.getCell(o,l,e);if((null==s?void 0:s.evaluated.type)!==hn.number)continue;const c=this.computeIcon(s.evaluated.value,n,t.upperInflectionPoint.operator,i,t.lowerInflectionPoint.operator,a);r[l]||(r[l]=[]),r[l][e]=c}}computeIcon(e,t,i,n,o,s){return"ge"===i&&e>=t||"gt"===i&&e>t?s[0]:"ge"===o&&e>=n||"gt"===o&&e>n?s[1]:s[2]}applyColorScale(e,t){var i;const n=this.parsePoint(e,t.minimum,"min"),o=t.midpoint?this.parsePoint(e,t.midpoint):null,s=this.parsePoint(e,t.maximum,"max");if(null===n||null===s||n>=s||o&&(n>=o||o>=s))return;const r=this.getters.getActiveSheetId(),a=this.getters.getRangeFromSheetXC(r,e).zone,l=this.computedStyles[r],c=[];t.midpoint&&o?(c.push({minValue:n,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(n,o,t.minimum.color,t.midpoint.color)}),c.push({minValue:o,minColor:t.midpoint.color,colorDiffUnit:this.computeColorDiffUnits(o,s,t.midpoint.color,t.maximum.color)})):c.push({minValue:n,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(n,s,t.minimum.color,t.maximum.color)});for(let e=a.top;e<=a.bottom;e++)for(let t=a.left;t<=a.right;t++){const a=this.getters.getCell(r,t,e);if((null==a?void 0:a.evaluated.type)===hn.number){const r=Me(a.evaluated.value,n,s);let h;h=2===c.length&&o?r<=o?this.colorCell(r,c[0].minValue,c[0].minColor,c[0].colorDiffUnit):this.colorCell(r,c[1].minValue,c[1].minColor,c[1].colorDiffUnit):this.colorCell(r,c[0].minValue,c[0].minColor,c[0].colorDiffUnit),l[t]||(l[t]=[]),l[t][e]=(null===(i=l[t])||void 0===i?void 0:i[e])||{},l[t][e].fillColor=gt(h)}}}computeColorDiffUnits(e,t,i,n){const o=t-e;return[((i>>16)%256-(n>>16)%256)/o,((i>>8)%256-(n>>8)%256)/o,(i%256-n%256)/o]}colorCell(e,t,i,n){const[o,s,r]=n;return Math.round((i>>16)%256-o*(e-t))<<16|Math.round((i>>8)%256-s*(e-t))<<8|Math.round(i%256-r*(e-t))}adaptRules(e,t,i,n){if(0===i.length&&0===n.length)return;const o=this.getters.getConditionalFormats(e),s=o.findIndex((e=>e.id===t.id));let r=[];s>-1&&(r=o[s].ranges),r=r.concat(i);const a=qi(r,n);0!==a.length?this.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{id:t.id,rule:t.rule,stopIfTrue:t.stopIfTrue},ranges:a.map((t=>this.getters.getRangeDataFromXc(e,t))),sheetId:e}):this.dispatch("REMOVE_CONDITIONAL_FORMAT",{id:t.id,sheetId:e})}pasteCf(e,t,i){const n=Vt(t.col,t.row);for(let o of this.getters.getConditionalFormats(e.sheetId))for(let s of o.ranges)if(Wi(e.col,e.row,this.getters.getRangeFromSheetXC(e.sheetId,s).zone)){const s=o,r=[];if("CUT"===i&&r.push(Vt(e.col,e.row)),e.sheetId===t.sheetId)this.adaptRules(e.sheetId,s,[n],r);else{this.adaptRules(e.sheetId,s,[],r);const i=this.getCFToCopyTo(t.sheetId,s);this.adaptRules(t.sheetId,i,[n],[])}}}isCellValueNumber(e){return"number"==typeof e}getCFToCopyTo(e,t){const i=this.getters.getConditionalFormats(e).find((e=>e.stopIfTrue===t.stopIfTrue&&ot(e.rule,t.rule)));return i||{...t,id:this.uuidGenerator.smallUuid(),ranges:[]}}}Uv.getters=["getConditionalIcon","getCellComputedStyle"];class Vv extends Gg{constructor(){super(...arguments),this.filterValues={},this.hiddenRows=new Set,this.isEvaluationDirty=!1}allowDispatch(e){if("UPDATE_FILTER"===e.type)if(!this.getters.getFilterId(e.sheetId,e.col,e.row))return 80;return 0}handle(e){switch(e.type){case"UNDO":case"REDO":case"UPDATE_CELL":case"EVALUATE_CELLS":case"ACTIVATE_SHEET":case"REMOVE_FILTER_TABLE":this.isEvaluationDirty=!0;break;case"START":for(const e of this.getters.getSheetIds()){this.filterValues[e]={};for(const t of this.getters.getFilters(e))this.filterValues[e][t.id]=[]}break;case"CREATE_SHEET":this.filterValues[e.sheetId]={};break;case"HIDE_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"REMOVE_COLUMNS_ROWS":this.updateHiddenRows();break;case"UPDATE_FILTER":this.updateFilter(e),this.updateHiddenRows();break;case"DUPLICATE_SHEET":const t={};for(const i of this.getters.getFilters(e.sheetIdTo)){const n=i.zoneWithHeaders;t[i.id]=this.getFilterValues(e.sheetId,n.left,n.top)}this.filterValues[e.sheetIdTo]=t}}finalize(){this.isEvaluationDirty&&(this.updateHiddenRows(),this.isEvaluationDirty=!1)}isRowFiltered(e,t){return e===this.getters.getActiveSheetId()&&this.hiddenRows.has(t)}getCellBorderWithFilterBorder(e,t,i){let n;for(let o of this.getters.getFilterTables(e)){const s=o.zone;if(Wi(t,i,s)){const o=this.intersectZoneWithViewport(e,s);n={top:i===o.top?j:void 0,bottom:i===o.bottom?j:void 0,left:t===o.left?j:void 0,right:t===o.right?j:void 0}}}const o=this.getters.getCellBorder(e,t,i),s={...n,...rt(o||{})};return Qe(s)?null:s}getFilterHeaders(e){const t=[];for(let i of this.getters.getFilterTables(e)){const n=i.zone;if(!n)continue;const o=n.top;for(let i=n.left;i<=n.right;i++)this.getters.isColHidden(e,i)||this.getters.isRowHidden(e,o)||t.push({col:i,row:o})}return t}getFilterValues(e,t,i){const n=this.getters.getFilterId(e,t,i);return n&&this.filterValues[e]&&this.filterValues[e][n]||[]}isFilterHeader(e,t,i){return this.getFilterHeaders(e).some((e=>e.col===t&&e.row===i))}isFilterActive(e,t,i){var n,o;const s=this.getters.getFilterId(e,t,i);return Boolean(s&&(null===(o=null===(n=this.filterValues[e])||void 0===n?void 0:n[s])||void 0===o?void 0:o.length))}intersectZoneWithViewport(e,t){return{left:this.getters.findVisibleHeader(e,"COL",t.left,t.right),right:this.getters.findVisibleHeader(e,"COL",t.right,t.left),top:this.getters.findVisibleHeader(e,"ROW",t.top,t.bottom),bottom:this.getters.findVisibleHeader(e,"ROW",t.bottom,t.top)}}updateFilter({col:e,row:t,values:i,sheetId:n}){const o=this.getters.getFilterId(n,e,t);o&&(this.filterValues[n]||(this.filterValues[n]={}),this.filterValues[n][o]=i)}updateHiddenRows(){var e,t;const i=this.getters.getActiveSheetId(),n=this.getters.getFilters(i).sort(((e,t)=>e.zoneWithHeaders.top-t.zoneWithHeaders.top)),o=new Set;for(let s of n){if(this.getters.isRowHiddenByUser(i,s.zoneWithHeaders.top))continue;if(o.has(s.zoneWithHeaders.top))continue;const n=null===(t=null===(e=this.filterValues[i])||void 0===e?void 0:e[s.id])||void 0===t?void 0:t.map(at);if(!n||!s.filteredZone)continue;const r=new Set(n);for(let e=s.filteredZone.top;e<=s.filteredZone.bottom;e++){const t=this.getCellValueAsString(i,s.col,e);r.has(t)&&o.add(e)}}this.hiddenRows=o}getCellValueAsString(e,t,i){var n;const o=null===(n=this.getters.getCell(e,t,i))||void 0===n?void 0:n.formattedValue;return(null==o?void 0:o.toLowerCase())||""}exportForExcel(e){var t;for(const i of e.sheets)for(const e of i.filterTables){const n=Fi(e.range),o=[],s=[];for(const e of $e(0,ji(n).width)){const r=this.getFilterValues(i.id,n.left+e,n.top),a=this.getters.getFilter(i.id,n.left+e,n.top);if(!a)continue;const l=a.filteredZone?Xi(a.filteredZone).map((e=>{var t;return null===(t=this.getters.getCell(i.id,e.col,e.row))||void 0===t?void 0:t.formattedValue})):[];if(r.length){const t=l.filter(Ke).filter((e=>!r.includes(e)));o.push({colId:e,displayedValues:[...new Set(t)],displayBlanks:!r.includes("")&&l.some((e=>!e))})}const c={col:a.col,row:a.zoneWithHeaders.top},h=null===(t=this.getters.getCell(i.id,c.col,c.row))||void 0===t?void 0:t.formattedValue,d=this.getUniqueColNameForExcel(e,h,s);s.push(d),i.cells[Vt(c.col,c.row)]={...i.cells[Vt(c.col,c.row)],content:d,value:d,isFormula:!1}}e.filters=o}}getUniqueColNameForExcel(e,t,i){t||(t=`Column${e}`);let n=t,o=2;for(;i.includes(n);)n=t+String(o),o++;return n}}Vv.getters=["getCellBorderWithFilterBorder","getFilterHeaders","getFilterValues","isFilterHeader","isRowFiltered","isFilterActive"];var zv;!function(e){e[e.previous=-1]="previous",e[e.current=0]="current",e[e.next=1]="next"}(zv||(zv={}));class Bv extends Gg{constructor(){super(...arguments),this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1},this.toSearch="",this.isSearchDirty=!1}handle(e){switch(e.type){case"UPDATE_SEARCH":this.updateSearch(e.toSearch,e.searchOptions);break;case"CLEAR_SEARCH":this.clearSearch();break;case"SELECT_SEARCH_PREVIOUS_MATCH":this.selectNextCell(zv.previous);break;case"SELECT_SEARCH_NEXT_MATCH":this.selectNextCell(zv.next);break;case"REPLACE_SEARCH":this.replace(e.replaceWith);break;case"REPLACE_ALL_SEARCH":this.replaceAll(e.replaceWith);break;case"EVALUATE_CELLS":case"UPDATE_CELL":case"REMOVE_FILTER_TABLE":case"UPDATE_FILTER":this.isSearchDirty=!0;break;case"UNDO":case"REDO":case"REMOVE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"ACTIVATE_SHEET":this.refreshSearch()}}finalize(){this.isSearchDirty&&(this.refreshSearch(),this.isSearchDirty=!1)}getSearchMatches(){return this.searchMatches}getCurrentSelectedMatchIndex(){return this.selectedMatchIndex}updateSearch(e,t){this.searchOptions=t,e!==this.toSearch&&(this.selectedMatchIndex=null),this.toSearch=e,this.updateRegex(),this.refreshSearch()}refreshSearch(){const e=this.findMatches();this.searchMatches=e,this.selectNextCell(zv.current)}updateRegex(){let e=Te(this.toSearch);const t=this.searchOptions.matchCase?"":"i";this.searchOptions.exactMatch&&(e=`^${e}$`),this.currentSearchRegex=RegExp(e,t)}findMatches(){const e=this.getters.getActiveSheetId(),t=this.getters.getCells(e),i=[];if(this.toSearch)for(const n of Object.values(t)){const{col:t,row:o}=this.getters.getCellPosition(n.id),s=this.getters.isColHidden(e,t),r=this.getters.isRowHidden(e,o);if(!s&&!r&&(n&&this.currentSearchRegex&&this.currentSearchRegex.test(this.searchOptions.searchFormulas?n.content:String(n.evaluated.value)))){const e=this.getters.getCellPosition(n.id),t={col:e.col,row:e.row,selected:!1};i.push(t)}}return i.sort(this.sortByRowThenColumn)}sortByRowThenColumn(e,t){return e.row===t.row?e.col-t.col:e.row>t.row?1:-1}selectNextCell(e){const t=this.searchMatches;if(!t.length)return void(this.selectedMatchIndex=null);let i;i=null===this.selectedMatchIndex?0:this.selectedMatchIndex+e,i=(i%t.length+t.length)%t.length,null!==this.selectedMatchIndex&&this.selectedMatchIndex===i||(this.selectedMatchIndex=i,this.selection.selectCell(t[i].col,t[i].row));for(let e=0;e<this.searchMatches.length;e++)this.searchMatches[e].selected=e===this.selectedMatchIndex}clearSearch(){this.toSearch="",this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1}}replace(e){if(null===this.selectedMatchIndex||!this.currentSearchRegex)return;const t=this.searchMatches[this.selectedMatchIndex],i=this.getters.getActiveSheetId(),n=this.getters.getCell(i,t.col,t.row),o=this.toReplace(n,i);if(n&&o){const i=new RegExp(this.currentSearchRegex.source,this.currentSearchRegex.flags+"g"),n=o.toString().replace(i,e);this.dispatch("UPDATE_CELL",{sheetId:this.getters.getActiveSheetId(),col:t.col,row:t.row,content:n}),this.searchMatches.splice(this.selectedMatchIndex,1),this.selectNextCell(zv.current)}else this.selectNextCell(zv.next)}replaceAll(e){const t=this.searchMatches.length;for(let i=0;i<t;i++)this.replace(e)}toReplace(e,t){if(e){if(this.searchOptions.searchFormulas&&e.isFormula())return e.content;if(this.searchOptions.searchFormulas||!e.isFormula())return e.evaluated.value.toString()}return null}drawGrid(e){const{ctx:t}=e,i=this.getters.getActiveSheetId();for(const e of this.searchMatches){const n=this.getters.getMerge(i,e.col,e.row),o=n?n.left:e.col,s=n?n.right:e.col,r=n?n.top:e.row,a=n?n.bottom:e.row,{x:l,y:c,width:h,height:d}=this.getters.getVisibleRect({top:r,left:o,right:s,bottom:a});h>0&&d>0&&(t.fillStyle="#8B008B33",t.fillRect(l,c,h,d),e.selected&&(t.strokeStyle="#8B008B",t.strokeRect(l,c,h,d)))}}}Bv.layers=[3],Bv.getters=["getSearchMatches","getCurrentSelectedMatchIndex"];class Hv extends Gg{handle(e){if("SET_DECIMAL"===e.type)this.setDecimal(e.sheetId,e.target,e.step)}setDecimal(e,t,i){const n=this.searchNumberFormat(e,t);if(void 0!==n){const o=function(e,t){const i=Kt(e).map((e=>"NUMBER"===e.type?{...e,format:ci(e.format,t)}:e)),n=gi(i);return Xt[n]=i,n}(n,i);this.dispatch("SET_FORMATTING",{sheetId:e,target:t,format:o})}}searchNumberFormat(e,t){var i;for(let n of t)for(let t=n.top;t<=n.bottom;t++)for(let o=n.left;o<=n.right;o++){const n=this.getters.getCell(e,o,t);if((null==n?void 0:n.evaluated.type)===hn.number&&!(null===(i=n.evaluated.format)||void 0===i?void 0:i.match(Y)))return n.evaluated.format||ai(n.evaluated.value)}}}Hv.modes=["normal"];class Wv extends Gg{isRowHidden(e,t){return this.getters.isRowHiddenByUser(e,t)||this.getters.isRowFiltered(e,t)}isColHidden(e,t){return this.getters.isColHiddenByUser(e,t)}isHeaderHidden(e,t,i){return"COL"===t?this.isColHidden(e,i):this.isRowHidden(e,i)}getNextVisibleCellPosition(e,t,i){return{col:this.findVisibleHeader(e,"COL",t,this.getters.getNumberCols(e)-1),row:this.findVisibleHeader(e,"ROW",i,this.getters.getNumberRows(e)-1)}}findVisibleHeader(e,t,i,n){if(i<=n)for(let o=i;o<=n;o++)if(this.getters.doesHeaderExist(e,t,o)&&!this.isHeaderHidden(e,t,o))return o;if(i>n)for(let o=i;o>=n;o--)if(this.getters.doesHeaderExist(e,t,o)&&!this.isHeaderHidden(e,t,o))return o}findLastVisibleColRowIndex(e,t,i){let n;for(n=i.last;n>=i.first;n--)if(!this.isHeaderHidden(e,t,n))return n;return n}findFirstVisibleColRowIndex(e,t){const i=this.getters.getNumberHeaders(e,t);for(let n=0;n<i;n++){if("COL"===t&&!this.isColHidden(e,n))return n;if("ROW"===t&&!this.isRowHidden(e,n))return n}}exportForExcel(e){for(const t of e.sheets)for(const[e,i]of Object.entries(t.rows)){const n=this.isRowHidden(t.id,Number(e));i.isHidden=n}}}Wv.getters=["getNextVisibleCellPosition","findVisibleHeader","findLastVisibleColRowIndex","findFirstVisibleColRowIndex","isRowHidden","isColHidden","isHeaderHidden"];class Gv extends Gg{getHighlights(){return this.prepareHighlights(this.getters.getComposerHighlights().concat(this.getters.getSelectionInputHighlights()))}prepareHighlights(e){return e.filter((e=>e.zone.top>=0&&e.zone.left>=0&&e.zone.bottom<this.getters.getNumberRows(e.sheetId)&&e.zone.right<this.getters.getNumberCols(e.sheetId))).map((e=>{const{height:t,width:i}=ji(e.zone),n=t*i==1?this.getters.expandZone(e.sheetId,e.zone):e.zone;return{...e,zone:n}}))}drawGrid(e){const{ctx:t,thinLineWidth:i}=e,n=this.getters.getActiveSheetId(),o=3*i;t.lineWidth=o;const s=this.getHighlights();for(let e of s.filter(((e,t)=>s.findIndex((t=>Bi(t.zone,e.zone)&&t.sheetId===n))===t))){const{x:i,y:n,width:s,height:r}=this.getters.getVisibleRect(e.zone);s>0&&r>0&&(t.strokeStyle=e.color,t.strokeRect(i+o/2,n+o/2,s-o,r-o),t.globalCompositeOperation="source-over",t.fillStyle=e.color+"20",t.fillRect(i+o,n+o,s-2*o,r-2*o))}}}Gv.layers=[1],Gv.getters=["getHighlights"];class qv extends Gg{constructor(){super(...arguments),this.boxes=[]}getColDimensionsInViewport(e,t){const i=Math.min(...this.getters.getSheetViewVisibleCols()),n=this.getters.getColRowOffsetInViewport("COL",i,t),o=this.getters.getColSize(e,t);return{start:n,size:o,end:n+(this.getters.isColHidden(e,t)?0:o)}}getRowDimensionsInViewport(e,t){const i=Math.min(...this.getters.getSheetViewVisibleRows()),n=this.getters.getColRowOffsetInViewport("ROW",i,t),o=this.getters.getRowSize(e,t);return{start:n,size:o,end:n+(this.getters.isRowHidden(e,t)?0:o)}}getHeaderOffset(e,t,i){let n=this.getters.getColRowOffsetInViewport(e,t,i);return this.getters.isDashboard()||(n+="ROW"===e?O:M),n}drawGrid(e,t){switch(t){case 0:this.drawBackground(e);for(const t of this.getters.getAllActiveViewportsZones()){const{ctx:i}=e;i.save(),i.beginPath();const n=this.getters.getVisibleRect(t);i.rect(n.x,n.y,n.width,n.height),i.clip(),this.boxes=this.getGridBoxes(t),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e),this.drawIcon(e),i.restore()}this.drawFrozenPanes(e);break;case 7:this.getters.isDashboard()||(this.drawHeaders(e),this.drawFrozenPanesHeaders(e))}}drawBackground(e){const{ctx:t,thinLineWidth:i}=e,{width:n,height:o}=this.getters.getSheetViewDimensionWithHeaders(),s=this.getters.getActiveSheetId();t.fillStyle="#ffffff",t.fillRect(0,0,n+m,o+m);const r=this.getters.getSheetViewVisibleCols(),a=r[0],l=r[r.length-1],c=this.getters.getSheetViewVisibleRows(),h=c[0],d=c[c.length-1];if(this.getters.getGridLinesVisibility(s)&&!this.getters.isDashboard()){t.lineWidth=2*i,t.strokeStyle="#E2E3E3",t.beginPath();for(const e of r){const i={top:h,bottom:d,left:e,right:e},{x:n,width:s,height:r}=this.getters.getVisibleRect(i);t.moveTo(n+s,0),t.lineTo(n+s,Math.min(o,r+(this.getters.isDashboard()?0:O)))}for(const e of c){const i={left:a,right:l,top:e,bottom:e},{y:o,width:s,height:r}=this.getters.getVisibleRect(i);t.moveTo(0,o+r),t.lineTo(Math.min(n,s+(this.getters.isDashboard()?0:M)),o+r)}t.stroke()}}drawCellBackground(e){const{ctx:t,thinLineWidth:i}=e,n=!this.getters.isDashboard()&&this.getters.getGridLinesVisibility(this.getters.getActiveSheetId());t.lineWidth=n?.3*i:i;const o=n?.1*i:0;t.strokeStyle="#111";for(let e of this.boxes){let s=e.style;(s.fillColor&&"#ffffff"!==s.fillColor||e.isMerge)&&(t.fillStyle=s.fillColor||"#ffffff",n?(t.fillRect(e.x,e.y,e.width,e.height),t.strokeRect(e.x+o,e.y+o,e.width-2*o,e.height-2*o)):t.fillRect(e.x-i,e.y-i,e.width+2*i,e.height+2*i)),e.error&&(t.fillStyle="red",t.beginPath(),t.moveTo(e.x+e.width-5,e.y),t.lineTo(e.x+e.width,e.y),t.lineTo(e.x+e.width,e.y+5),t.fill())}}drawBorders(e){const{ctx:t,thinLineWidth:i}=e;for(let e of this.boxes){const t=e.border;if(t){const{x:i,y:o,width:s,height:r}=e;t.left&&n(t.left,i,o,i,o+r),t.top&&n(t.top,i,o,i+s,o),t.right&&n(t.right,i+s,o,i+s,o+r),t.bottom&&n(t.bottom,i,o+r,i+s,o+r)}}function n([e,n],o,s,r,a){t.strokeStyle=n,t.lineWidth=("thin"===e?2:3)*i,t.beginPath(),t.moveTo(o,s),t.lineTo(r,a),t.stroke()}}drawTexts(e){const{ctx:t,thinLineWidth:i}=e;let n;t.textBaseline="top";for(let e of this.boxes)if(e.content){const o=e.style||{},s=e.content.align||"left",r=De(o);let a;r!==n&&(n=r,t.font=r),t.fillStyle=o.textColor||"#000";let l=e.y+e.height/2+1;if(a="left"===s?e.x+(e.image?e.image.size+2*L:P):"right"===s?e.x+e.width-P-(e.isFilterHeader?20:0):e.x+e.width/2,t.textAlign=s,e.clipRect){t.save(),t.beginPath();const{x:i,y:n,width:o,height:s}=e.clipRect;t.rect(i,n,o,s),t.clip()}const c=e.content.multiLineText.length,h=ke(o);let d=l-(c*(h+P)-P)/2;for(let n of e.content.multiLineText){if(t.fillText(n,Math.round(a),Math.round(d)),o.strikethrough||o.underline){const e=_e(t,n,o);let r=a;"right"===s?r-=e:"center"===s&&(r-=e/2),o.strikethrough&&t.fillRect(r,d+h/2,e,2.6*i),o.underline&&t.fillRect(r,d+h+1,e,1.3*i)}d+=P+h}e.clipRect&&t.restore()}}drawIcon(e){const{ctx:t}=e;for(const e of this.boxes)if(e.image){const i=e.image.image,n=e.image.size,o=(e.height-n)/2;if(e.image.clipIcon){t.save(),t.beginPath();const{x:i,y:n,width:o,height:s}=e.image.clipIcon;t.rect(i,n,o,s),t.clip()}t.drawImage(i,e.x+L,e.y+o,n,n),e.image.clipIcon&&t.restore()}}drawHeaders(e){const{ctx:t,thinLineWidth:i}=e,n=this.getters.getSheetViewVisibleCols(),o=n[0],s=this.getters.getSheetViewVisibleRows(),r=s[0],{width:a,height:l}=this.getters.getSheetViewDimensionWithHeaders(),c=this.getters.getSelectedZones(),h=function(e){const t=new Set;for(let i of e)for(let e of $e(i.left,i.right+1))t.add(e);return t}(c),d=function(e){const t=new Set;for(let i of e)for(let e of $e(i.top,i.bottom+1))t.add(e);return t}(c),u=this.getters.getActiveSheetId(),g=this.getters.getNumberCols(u),p=this.getters.getNumberRows(u),m=this.getters.getActiveCols(),f=this.getters.getActiveRows();t.font=`400 11px ${q}`,t.textAlign="center",t.textBaseline="middle",t.lineWidth=i,t.strokeStyle="#333";for(const e of n){const i={left:e,right:e,top:0,bottom:p-1},{x:n,width:o}=this.getters.getVisibleRect(i),s=this.getters.doesZonesContainFilter(u,[i]),r=m.has(e),a=h.has(e);t.fillStyle=r?s?I:S:a?s?A:b:s?T:v,t.fillRect(n,0,o,O)}for(const e of s){const i={top:e,bottom:e,left:0,right:g-1},{y:n,height:o}=this.getters.getVisibleRect(i),s=this.getters.doesZonesContainFilter(u,[i]),r=f.has(e),a=d.has(e);t.fillStyle=r?s?I:S:a?s?A:b:s?T:v,t.fillRect(0,n,M,o)}t.beginPath(),t.moveTo(M,0),t.lineTo(M,l),t.moveTo(0,O),t.lineTo(a,O),t.strokeStyle="#C0C0C0",t.stroke(),t.beginPath();for(const e of n){const i=this.getters.getColSize(u,e),n=Lt(e);t.fillStyle=m.has(e)?"#fff":C;let s=this.getHeaderOffset("COL",o,e);t.fillText(n,s+i/2,13),t.moveTo(s+i,0),t.lineTo(s+i,O)}for(const e of s){const i=this.getters.getRowSize(u,e);t.fillStyle=f.has(e)?"#fff":C;let n=this.getHeaderOffset("ROW",r,e);t.fillText(String(e+1),24,n+i/2),t.moveTo(0,n+i),t.lineTo(M,n+i)}t.stroke()}drawFrozenPanesHeaders(e){const{ctx:t,thinLineWidth:i}=e,{x:n,y:o}=this.getters.getMainViewportCoordinates(),s=this.getters.isDashboard()?0:M,r=this.getters.isDashboard()?0:O;t.lineWidth=6*i,t.strokeStyle="#BCBCBC",t.beginPath(),n&&(t.moveTo(s+n,0),t.lineTo(s+n,r)),o&&(t.moveTo(0,r+o),t.lineTo(s,r+o)),t.stroke()}drawFrozenPanes(e){const{ctx:t,thinLineWidth:i}=e,{x:n,y:o}=this.getters.getMainViewportCoordinates(),s=this.getters.getSheetViewVisibleCols(),r=s[0],a=s[s.length-1],l=this.getters.getSheetViewVisibleRows(),c={left:r,right:a,top:l[0],bottom:l[l.length-1]},h=this.getters.getVisibleRect(c),d=this.getters.isDashboard()?0:M,u=this.getters.isDashboard()?0:O;t.lineWidth=6*i,t.strokeStyle="#DADFE8",t.beginPath(),n&&(t.moveTo(d+n,u),t.lineTo(d+n,h.height+u)),o&&(t.moveTo(d,u+o),t.lineTo(h.width+d,u+o)),t.stroke()}hasContent(e,t){const i=this.getters.getActiveSheetId(),n=this.getters.getCell(i,e,t);return n&&!n.isEmpty()||this.getters.isInMerge(i,e,t)}findNextEmptyCol(e,t,i){let n=e;for(;n<t&&!this.hasContent(n+1,i);)n++;return n}findPreviousEmptyCol(e,t,i){let n=e;for(;n>t&&!this.hasContent(n-1,i);)n--;return n}computeCellAlignment(e,t){if(e.isFormula()&&this.getters.shouldShowFormulas())return"left";const{align:i}=this.getters.getCellStyle(e);return t&&e.evaluated.type===hn.number?"center"!==i?"left":i:i||e.defaultAlign}createZoneBox(e,t,i){const{left:n,right:o}=i,s=t.left,r=t.top,a=this.getters.getCell(e,s,r),c=this.getters.shouldShowFormulas(),{x:h,y:d,width:u,height:g}=this.getters.getRect(t),p={x:h,y:d,width:u,height:g,border:this.getters.getCellBorderWithFilterBorder(e,s,r)||void 0,style:this.getters.getCellComputedStyle(e,s,r)};if(!a)return p;const m=this.getters.getConditionalIcon(s,r),f=ke(p.style),v=m?2*L+f:0;m&&(p.image={type:"icon",size:f,clipIcon:{x:p.x,y:p.y,width:Math.min(v,u),height:g},image:Sr[m].img}),p.isFilterHeader=this.getters.isFilterHeader(e,s,r);const b=p.isFilterHeader?19:0,S=this.getters.getCellText(a,c),C=this.getters.getTextWidth(a),E=this.getters.getCellStyle(a).wrapping||"overflow",w="wrap"===E?this.getters.getCellMultiLineText(a,u-2*P):[S],y=v+C+b,x=this.computeCellAlignment(a,y>u);p.content={multiLineText:w,width:"overflow"===E?C:u,align:x},a.evaluated.type===hn.error&&a.evaluated.error.logLevel>l.silent&&(p.error=a.evaluated.error.message);const R=y>u||f>g;if(m||p.isFilterHeader)p.clipRect={x:p.x+v,y:p.y,width:Math.max(0,u-v-b),height:g};else if(R&&"overflow"===E){let i,a;switch(this.getters.isInMerge(e,s,r)?(i=this.getters.getMerge(e,s,r).right,a=s):(i=this.findNextEmptyCol(s,o,r),a=this.findPreviousEmptyCol(s,n,r)),x){case"left":{const e=en({col:i,row:r}),{x:n,y:o,width:s,height:a}=this.getters.getVisibleRect(Vi(t,e));(s<C||f>a)&&(p.clipRect={x:n,y:o,width:s,height:a});break}case"right":{const e=en({col:a,row:r}),{x:i,y:n,width:o,height:s}=this.getters.getVisibleRect(Vi(t,e));(o<C||f>s)&&(p.clipRect={x:i,y:n,width:o,height:s});break}case"center":{const e={...t,right:i,left:a},{x:n,y:o,width:r,height:l}=this.getters.getVisibleRect(e);(r<C||a===s||i===s||f>l)&&(p.clipRect={x:n,y:o,width:r,height:l});break}}}else"clip"!==E&&"wrap"!==E||(p.clipRect={x:p.x,y:p.y,width:u,height:g});return p}getGridBoxes(e){const t=[],i=this.getters.getSheetViewVisibleCols().filter((t=>t>=e.left&&t<=e.right)),n=i[0],o=i[i.length-1],s=this.getters.getSheetViewVisibleRows().filter((t=>t>=e.top&&t<=e.bottom)),r={left:n,right:o,top:s[0],bottom:s[s.length-1]},a=this.getters.getActiveSheetId();for(const e of s)for(const n of i)this.getters.isInMerge(a,n,e)||t.push(this.createZoneBox(a,en({col:n,row:e}),r));for(const e of this.getters.getMerges(a))if(!this.getters.isMergeHidden(a,e)&&Hi(e,r)){const i=this.createZoneBox(a,e,r),n=this.getters.getCellBorder(a,e.right,e.bottom);i.border={...i.border,bottom:n?n.bottom:void 0,right:n?n.right:void 0},i.isMerge=!0,t.push(i)}return t}}qv.layers=[0,7],qv.getters=["getColDimensionsInViewport","getRowDimensionsInViewport"];const Zv=[{name:s("Sum"),types:[hn.number],compute:e=>pl.compute([e])},{name:s("Avg"),types:[hn.number],compute:e=>Rl.compute([e])},{name:s("Min"),types:[hn.number],compute:e=>Bl.compute([e])},{name:s("Max"),types:[hn.number],compute:e=>Pl.compute([e])},{name:s("Count"),types:[hn.number,hn.text,hn.boolean,hn.error],compute:e=>Fl.compute([e])},{name:s("Count Numbers"),types:[hn.number,hn.text,hn.boolean,hn.error],compute:e=>_l.compute([e])}];class jv extends Gg{constructor(e,t,i,n,o){super(e,t,i,n,o),this.gridSelection={anchor:{cell:{col:0,row:0},zone:{top:0,left:0,bottom:0,right:0}},zones:[{top:0,left:0,bottom:0,right:0}]},this.selectedFigureId=null,this.sheetsData={},this.activeSheet=null,this.moveClient=n.moveClient}allowDispatch(e){switch(e.type){case"ACTIVATE_SHEET":try{this.getters.getSheet(e.sheetIdTo);break}catch(e){return 27}case"MOVE_COLUMNS_ROWS":return this.isMoveElementAllowed(e)}return 0}handleEvent(e){const t=e.anchor;let i=[];switch(e.mode){case"overrideSelection":i=[t.zone];break;case"updateAnchor":i=[...this.gridSelection.zones];const n=i.findIndex((t=>Bi(t,e.previousAnchor.zone)));n>=0&&(i[n]=t.zone);break;case"newAnchor":i=[...this.gridSelection.zones,t.zone]}this.setSelectionMixin(e.anchor,i),this.selection.resetDefaultAnchor(this,Ae(this.gridSelection.anchor));const{col:n,row:o}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.getters.getActiveSheetId(),col:n,row:o}),this.selectedFigureId=null}handle(e){switch(e.type){case"START_EDITION":case"ACTIVATE_SHEET":this.selectedFigureId=null;break;case"DELETE_FIGURE":this.selectedFigureId===e.id&&(this.selectedFigureId=null);break;case"DELETE_SHEET":this.selectedFigureId&&this.getters.getFigure(e.sheetId,this.selectedFigureId)&&(this.selectedFigureId=null)}switch(e.type){case"START":const t=this.getters.getVisibleSheetIds()[0];this.dispatch("ACTIVATE_SHEET",{sheetIdTo:t,sheetIdFrom:t});const{col:i,row:n}=this.getters.getNextVisibleCellPosition(t,0,0);this.selectCell(i,n),this.selection.registerAsDefault(this,this.gridSelection.anchor,{handleEvent:this.handleEvent.bind(this)}),this.moveClient({sheetId:t,col:0,row:0});break;case"ACTIVATE_SHEET":{if(this.getters.isSheetVisible(e.sheetIdTo)||this.dispatch("SHOW_SHEET",{sheetId:e.sheetIdTo}),this.setActiveSheet(e.sheetIdTo),this.sheetsData[e.sheetIdFrom]={gridSelection:Ae(this.gridSelection)},e.sheetIdTo in this.sheetsData)Object.assign(this,this.sheetsData[e.sheetIdTo]),this.selection.resetDefaultAnchor(this,Ae(this.gridSelection.anchor));else{const{col:t,row:i}=this.getters.getNextVisibleCellPosition(e.sheetIdTo,0,0);this.selectCell(t,i)}const{col:t,row:i}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.activeSheet.id,col:t,row:i});break}case"REMOVE_COLUMNS_ROWS":{const t=this.getters.getActiveSheetId();if(e.sheetId===t){"COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e);const{col:i,row:n}=this.gridSelection.anchor.cell;this.moveClient({sheetId:t,col:i,row:n})}break}case"ADD_COLUMNS_ROWS":{const t=this.getters.getActiveSheetId();if(e.sheetId===t){this.onAddElements(e);const{col:i,row:n}=this.gridSelection.anchor.cell;this.moveClient({sheetId:t,col:i,row:n})}break}case"MOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onMoveElements(e);break;case"SELECT_FIGURE":this.selectedFigureId=e.id;break;case"ACTIVATE_NEXT_SHEET":this.activateNextSheet("right");break;case"ACTIVATE_PREVIOUS_SHEET":this.activateNextSheet("left");break;case"HIDE_SHEET":e.sheetId===this.getActiveSheetId()&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e.sheetId,sheetIdTo:this.getters.getVisibleSheetIds()[0]});break;case"UNDO":case"REDO":case"DELETE_SHEET":const o=Object.keys(this.sheetsData).filter((e=>!this.getters.tryGetSheet(e)));for(const e of o)delete this.sheetsData[e];for(const e in this.sheetsData){const t=this.clipSelection(e,this.sheetsData[e].gridSelection);this.sheetsData[e]={gridSelection:Ae(t)}}this.fallbackToVisibleSheet();const s=this.getters.getActiveSheetId();this.gridSelection.zones=this.gridSelection.zones.map((e=>this.getters.expandZone(s,e))),this.gridSelection.anchor.zone=this.getters.expandZone(s,this.gridSelection.anchor.zone),this.setSelectionMixin(this.gridSelection.anchor,this.gridSelection.zones),this.selectedFigureId=null}}finalize(){this.fallbackToVisibleSheet(),this.selection.resetDefaultAnchor(this,Ae(this.gridSelection.anchor))}isGridSelectionActive(){return this.selection.isListening(this)}getActiveSheet(){return this.activeSheet}getActiveSheetId(){return this.activeSheet.id}getActiveCell(){const e=this.getters.getActiveSheetId(),{col:t,row:i}=this.gridSelection.anchor.cell,{col:n,row:o}=this.getters.getMainCellPosition(e,t,i);return this.getters.getCell(e,n,o)}getActiveCols(){const e=new Set;for(let t of this.gridSelection.zones)if(0===t.top&&t.bottom===this.getters.getNumberRows(this.getters.getActiveSheetId())-1)for(let i=t.left;i<=t.right;i++)e.add(i);return e}getActiveRows(){const e=new Set,t=this.getters.getActiveSheetId();for(let i of this.gridSelection.zones)if(0===i.left&&i.right===this.getters.getNumberCols(t)-1)for(let t=i.top;t<=i.bottom;t++)e.add(t);return e}getCurrentStyle(){const e=this.getters.getActiveCell();return e?this.getters.getCellStyle(e):{}}getSelectedZones(){return Ae(this.gridSelection.zones)}getSelectedZone(){return Ae(this.gridSelection.anchor.zone)}getSelection(){return Ae(this.gridSelection)}getSelectedFigureId(){return this.selectedFigureId}getPosition(){return{col:this.gridSelection.anchor.cell.col,row:this.gridSelection.anchor.cell.row}}getSheetPosition(e){if(e===this.getters.getActiveSheetId())return this.getPosition();{const t=this.sheetsData[e];return t?{col:t.gridSelection.anchor.cell.col,row:t.gridSelection.anchor.cell.row}:this.getters.getNextVisibleCellPosition(e,0,0)}}getStatisticFnResults(){const e=this.getters.getActiveSheetId(),t=new Set(this.gridSelection.zones.map((t=>this.getters.getCellsInZone(e,t))).flat().filter((t=>{if(!t)return!1;const{col:i,row:n}=this.getters.getCellPosition(null==t?void 0:t.id);return!this.getters.isRowHidden(e,n)&&!this.getters.isColHidden(e,i)})));let i=new Set,n=[];for(let e of t)i.add(e.evaluated.type),n.push(e.evaluated.value);let o={};for(let e of Zv){let t;e.types.some((e=>i.has(e)))&&(t=e.compute(n)),o[e.name]=t}return o}getAggregate(){let e=0,t=0;const i=this.getters.getActiveSheetId(),n=this.gridSelection.zones.map(Xi).flat();for(const{col:o,row:s}of n){const n=this.getters.getCell(i,o,s);(null==n?void 0:n.evaluated.type)===hn.number&&(t++,e+=n.evaluated.value)}return t<2?null:Qt(e)}isSelected(e){return!!this.getters.getSelectedZones().find((t=>Bi(t,e)))}getElementsFromSelection(e){if("COL"===e&&0===this.getters.getActiveCols().size)return[];if("ROW"===e&&0===this.getters.getActiveRows().size)return[];const t=this.getters.getSelectedZones();let i=[];const n="COL"===e?"left":"top",o="COL"===e?"right":"bottom";for(const e of t){const t=Array.from({length:e[o]-e[n]+1},((t,i)=>e[n]+i));i=i.concat(t)}return[...new Set(i)].sort()}setSelectionMixin(e,t){const{anchor:i,zones:n}=this.clipSelection(this.getters.getActiveSheetId(),{anchor:e,zones:t});this.gridSelection.anchor=i,this.gridSelection.zones=function(e){return e.reverse().filter(((e,t,i)=>t===i.findIndex((t=>t.top===e.top&&t.bottom===e.bottom&&t.left===e.left&&t.right===e.right)))).reverse()}(n)}selectCell(e,t){const i=this.getters.getActiveSheetId(),n=this.getters.expandZone(i,{left:e,right:e,top:t,bottom:t});this.setSelectionMixin({zone:n,cell:{col:e,row:t}},[n])}setActiveSheet(e){const t=this.getters.getSheet(e);this.activeSheet=t}activateNextSheet(e){const t=this.getters.getSheetIds(),i=(t.findIndex((e=>e===this.activeSheet.id))+("left"===e?t.length-1:1))%t.length;this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getActiveSheetId(),sheetIdTo:t[i]})}onColumnsRemoved(e){const{cell:t,zone:i}=this.gridSelection.anchor,n=Pi(i,"left",[...e.elements]);let o={left:t.col,right:t.col,top:t.row,bottom:t.row};o=Pi(o,"left",[...e.elements]);const s={cell:{col:o.left,row:o.top},zone:n};this.setSelectionMixin(s,[n])}onRowsRemoved(e){const{cell:t,zone:i}=this.gridSelection.anchor,n=Pi(i,"top",[...e.elements]);let o={left:t.col,right:t.col,top:t.row,bottom:t.row};o=Pi(o,"top",[...e.elements]);const s={cell:{col:o.left,row:o.top},zone:n};this.setSelectionMixin(s,[n])}onAddElements(e){const t=Li(this.gridSelection.anchor.zone,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity),i={cell:{col:t.left,row:t.top},zone:t};this.setSelectionMixin(i,[t])}onMoveElements(e){const t=e.elements.length;this.dispatch("ADD_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,base:e.base,quantity:t,position:e.position});const i="COL"===e.dimension,n=e.elements[0],o=e.elements[t-1],s=e.base<n,r=s&&i?t:0,a=s&&!i?t:0,l=[{left:i?n+r:0,right:i?o+r:this.getters.getNumberCols(e.sheetId)-1,top:i?0:n+a,bottom:i?this.getters.getNumberRows(e.sheetId)-1:o+a}],c=new Mv(l,"CUT",this.getters,this.dispatch,this.selection),h=s?e.base:e.base+1,d=[{left:i?h:0,right:i?h+t-1:this.getters.getNumberCols(e.sheetId)-1,top:i?0:h,bottom:i?this.getters.getNumberRows(e.sheetId)-1:h+t-1}];c.paste(d,{selectTarget:!0});const u=s?e.elements.map((e=>e+t)):e.elements;let g=s?e.base:e.base+1;for(const t of u){const i="COL"===e.dimension?this.getters.getColSize(e.sheetId,t):this.getters.getRowSize(e.sheetId,t);this.dispatch("RESIZE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,size:i,elements:[g]}),g+=1}this.dispatch("REMOVE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,elements:u})}isMoveElementAllowed(e){const t="COL"===e.dimension,i=e.elements[0],n=e.elements[e.elements.length-1],o=e.sheetId,s=t?this.getters.doesColumnsHaveCommonMerges:this.getters.doesRowsHaveCommonMerges;if(s(o,i-1,i)||s(o,n,n+1)||s(o,e.base-1,e.base))return 2;const r=[e.base,...e.elements],a=t?this.getters.getNumberCols(o):this.getters.getNumberRows(o);return r.some((e=>e<0||e>=a))?87:0}fallbackToVisibleSheet(){if(!this.getters.tryGetSheet(this.getters.getActiveSheetId())){const e=this.getters.getVisibleSheetIds();if(this.activeSheet=this.getters.getSheet(e[0]),this.activeSheet.id in this.sheetsData){const{anchor:e}=this.clipSelection(this.activeSheet.id,this.sheetsData[this.activeSheet.id].gridSelection);this.selectCell(e.cell.col,e.cell.row)}else this.selectCell(0,0);const{col:t,row:i}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.getters.getActiveSheetId(),col:t,row:i})}}clipSelection(e,t){const i=this.getters.getNumberCols(e)-1,n=this.getters.getNumberRows(e)-1;return{zones:t.zones.map((e=>({left:Me(e.left,0,i),right:Me(e.right,0,i),top:Me(e.top,0,n),bottom:Me(e.bottom,0,n)}))),anchor:{cell:{col:Me(t.anchor.cell.col,0,i),row:Me(t.anchor.cell.row,0,n)},zone:{left:Me(t.anchor.zone.left,0,i),right:Me(t.anchor.zone.right,0,i),top:Me(t.anchor.zone.top,0,n),bottom:Me(t.anchor.zone.bottom,0,n)}}}}drawGrid(e){if(this.getters.isDashboard())return;const{ctx:t,thinLineWidth:i}=e,n=this.getSelectedZones();t.fillStyle="#f3f7fe";const o=1===n.length&&n[0].left===n[0].right&&n[0].top===n[0].bottom;t.fillStyle=o?"#f3f7fe":"#e9f0ff",t.strokeStyle=E,t.lineWidth=1.5*i,t.globalCompositeOperation="multiply";for(const e of n){const{x:i,y:n,width:o,height:s}=this.getters.getVisibleRect(e);t.fillRect(i,n,o,s),t.strokeRect(i,n,o,s)}t.globalCompositeOperation="source-over";const s=this.getters.getActiveSheetId(),{col:r,row:a}=this.getPosition();let l;t.strokeStyle=E,t.lineWidth=3*i,l=this.getters.isInMerge(s,r,a)?this.getters.getMerge(s,r,a):{top:a,bottom:a,left:r,right:r};const{x:c,y:h,width:d,height:u}=this.getters.getVisibleRect(l);d>0&&u>0&&t.strokeRect(c,h,d,u)}}jv.layers=[5],jv.getters=["getActiveSheet","getActiveSheetId","getActiveCell","getActiveCols","getActiveRows","getCurrentStyle","getSelectedZones","getSelectedZone","getStatisticFnResults","getAggregate","getSelectedFigureId","getSelection","getPosition","getSheetPosition","isSelected","getElementsFromSelection","isGridSelectionActive"];const Yv=new Mi;class Xv extends Gg{constructor(e,t,i,n,o,s,r){if(r&&s.length>1)throw new Error("Input with a single range cannot be instantiated with several range references.");super(e,t,i,n,o),this.inputHasSingleRange=r,this.ranges=[],this.focusedRangeIndex=null,this.willAddNewRange=!1,this.insertNewRange(0,s),this.activeSheet=this.getters.getActiveSheetId(),0===this.ranges.length&&(this.insertNewRange(this.ranges.length,[""]),this.focusLast())}handleEvent(e){const t=ki(e.anchor.zone),i=this.activeSheet,n=this.getters.getActiveSheetId(),o=this.getters.getSheetName(n);this.add([n===i?t:`${Oe(o)}!${t}`])}handle(e){switch(e.type){case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"FOCUS_RANGE":this.focus(this.getIndex(e.rangeId));break;case"CHANGE_RANGE":{const t=this.getIndex(e.rangeId);if(null!==t&&this.focusedRangeIndex!==t&&this.focus(t),null!==t){const i=e.value.split(",").map((e=>e.trim()));this.setRange(t,i)}break}case"ADD_EMPTY_RANGE":this.insertNewRange(this.ranges.length,[""]),this.focusLast();break;case"REMOVE_RANGE":const t=this.getIndex(e.rangeId);null!==t&&this.removeRange(t);break;case"STOP_SELECTION_INPUT":this.willAddNewRange=!1;break;case"PREPARE_SELECTION_INPUT_EXPANSION":{const e=this.focusedRangeIndex;null===e||this.inputHasSingleRange||(this.willAddNewRange=""!==this.ranges[e].xc.trim());break}case"ACTIVATE_SHEET":if(e.sheetIdFrom!==e.sheetIdTo){const{col:t,row:i}=this.getters.getNextVisibleCellPosition(e.sheetIdTo,0,0),n=this.getters.expandZone(e.sheetIdTo,en({col:t,row:i}));this.selection.resetAnchor(this,{cell:{col:t,row:i},zone:n})}}}getSelectionInputValue(){return this.cleanInputs(this.ranges.map((e=>e.xc?e.xc:"")))}getSelectionInputHighlights(){return this.ranges.map((e=>this.inputToHighlights(e))).flat()}focus(e){this.focusedRangeIndex=e}focusLast(){this.focus(this.ranges.length-1)}unfocus(){this.focusedRangeIndex=null}add(e){null!==this.focusedRangeIndex&&0!==e.length&&(this.willAddNewRange?(this.insertNewRange(this.ranges.length,e),this.focusLast(),this.willAddNewRange=!1):this.setRange(this.focusedRangeIndex,e))}setContent(e,t){this.ranges[e]={...this.ranges[e],id:Yv.smallUuid(),xc:t}}insertNewRange(e,t){this.ranges.splice(e,0,...t.map(((e,t)=>({xc:e,id:(this.ranges.length+t+1).toString(),color:(pt=++pt%ut.length,ut[pt])}))))}setRange(e,t){const[,...i]=t;this.setContent(e,t[0]),this.insertNewRange(e+1,i),i.length&&this.focus(e+i.length)}removeRange(e){this.ranges.splice(e,1),null!==this.focusedRangeIndex&&this.focusLast()}inputToHighlights({xc:e,color:t}){const i=this.cleanInputs([e]).filter((e=>this.getters.isRangeValid(e))).filter((e=>this.shouldBeHighlighted(this.activeSheet,e)));return i.map((e=>{const{sheetName:i}=$t(e);return{zone:this.getters.getRangeFromSheetXC(this.activeSheet,e).zone,sheetId:i&&this.getters.getSheetIdByName(i)||this.activeSheet,color:t}}))}cleanInputs(e){return e.map((e=>e.split(","))).flat().map((e=>e.trim())).filter((e=>""!==e))}shouldBeHighlighted(e,t){const{sheetName:i}=$t(t),n=this.getters.getSheetIdByName(i),o=this.getters.getActiveSheet().id;return this.getters.isRangeValid(t)&&(n===o||void 0===n&&o===e)}getIndex(e){const t=this.ranges.findIndex((t=>t.id===e));return t>=0?t:null}}Xv.layers=[1],Xv.getters=[];class Kv extends Gg{get currentInput(){return this.focusedInputId?this.inputs[this.focusedInputId]:null}constructor(e,t,i,n,o){super(e,t,i,n,o),this.state=t,this.config=n,this.inputs={},this.focusedInputId=null}allowDispatch(e){var t,i;switch(e.type){case"FOCUS_RANGE":case"CHANGE_RANGE":case"ADD_EMPTY_RANGE":case"REMOVE_RANGE":if(!this.inputs[e.id])return 31}switch(e.type){case"FOCUS_RANGE":const n=null===(t=this.currentInput)||void 0===t?void 0:t.getIndex(e.rangeId);if(this.focusedInputId===e.id&&(null===(i=this.currentInput)||void 0===i?void 0:i.focusedRangeIndex)===n)return 29;break;case"ADD_EMPTY_RANGE":const o=this.inputs[e.id];if(o.inputHasSingleRange&&1===o.ranges.length)return 30;break;case"CHANGE_RANGE":if(this.inputs[e.id].inputHasSingleRange&&e.value.split(",").length>1)return 30;break}return 0}handle(e){var t;switch(e.type){case"ENABLE_NEW_SELECTION_INPUT":this.initInput(e.id,e.initialRanges||[],e.hasSingleRange);break;case"DISABLE_SELECTION_INPUT":this.focusedInputId===e.id&&this.unfocus(),delete this.inputs[e.id];break;case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"ADD_EMPTY_RANGE":case"REMOVE_RANGE":case"FOCUS_RANGE":case"CHANGE_RANGE":if(e.id!==this.focusedInputId){const t=this.inputs[e.id];this.selection.capture(t,{cell:{col:0,row:0},zone:en({col:0,row:0})},{handleEvent:t.handleEvent.bind(t)}),this.focusedInputId=e.id}}null===(t=this.currentInput)||void 0===t||t.handle(e)}getSelectionInput(e){return this.inputs[e]?this.inputs[e].ranges.map(((t,i)=>Object.assign({},t,{color:this.focusedInputId===e&&null!==this.inputs[e].focusedRangeIndex&&this.isRangeValid(t.xc)?t.color:null,isFocused:this.focusedInputId===e&&this.inputs[e].focusedRangeIndex===i}))):[]}isRangeValid(e){if(!e)return!1;const{xc:t,sheetName:i}=$t(e);return null!==t.match(Ot)&&(!i||void 0!==this.getters.getSheetIdByName(i))}getSelectionInputValue(e){return this.inputs[e].getSelectionInputValue()}getSelectionInputHighlights(){return this.focusedInputId?this.inputs[this.focusedInputId].getSelectionInputHighlights():[]}initInput(e,t,i=!1){if(this.inputs[e]=new Xv(this.getters,this.state,this.dispatch,this.config,this.selection,t,i),0===t.length){const t=this.inputs[e],i={zone:en({col:0,row:0}),cell:{col:0,row:0}};this.selection.capture(t,i,{handleEvent:t.handleEvent.bind(t)}),this.focusedInputId=e}}unfocus(){this.selection.release(this.currentInput),this.focusedInputId=null}}Kv.layers=[1],Kv.getters=["getSelectionInput","getSelectionInputValue","isRangeValid","getSelectionInputHighlights"];class Qv{constructor(){this.subscriptions={}}on(e,t,i){if(!i)throw new Error("Missing callback");this.subscriptions[e]||(this.subscriptions[e]=[]),this.subscriptions[e].push({owner:t,callback:i})}trigger(e,t){const i=this.subscriptions[e]||[];for(let e=0,n=i.length;e<n;e++){const n=i[e];n.callback.call(n.owner,t)}}off(e,t){const i=this.subscriptions[e];i&&(this.subscriptions[e]=i.filter((e=>e.owner!==t)))}clear(){this.subscriptions={}}}function Jv(e,t){return{...e,definition:Us(e.definition,t)}}function eb(e,t){if(e.sheetId!==t.sheetId)return e;if(("FREEZE_COLUMNS"===e.type?"COL":"ROW")!==t.dimension)return e;let i=e.quantity;if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));for(let t of e)i>t&&i--}if("ADD_COLUMNS_ROWS"===t.type){i=i>("before"===t.position?t.base-1:t.base)?i+t.quantity:i}return i>0?{...e,quantity:i}:void 0}as.addTransformation("ADD_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],Jv),as.addTransformation("REMOVE_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],Jv),as.addTransformation("DELETE_SHEET",["MOVE_RANGES"],(function(e,t){const i=t.sheetId;if(e.targetSheetId===i||e.sheetId===i)return;return e})),as.addTransformation("DELETE_FIGURE",["UPDATE_FIGURE","UPDATE_CHART"],(function(e,t){if(e.id===t.id)return;return e})),as.addTransformation("CREATE_SHEET",["CREATE_SHEET"],(function(e,t){var i;e.sheetId===t.sheetId&&(e={...e,sheetId:`${e.sheetId}~`});if(e.name===t.name)return{...e,name:(null===(i=e.name)||void 0===i?void 0:i.match(/\d+/))?e.name.replace(/\d+/,(e=>(parseInt(e)+1).toString())):`${e.name}~`,position:e.position+1};return e})),as.addTransformation("ADD_MERGE",["ADD_MERGE","REMOVE_MERGE","CREATE_FILTER_TABLE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;const i=[];for(const n of e.target)t.target.every((e=>!Hi(n,e)))&&i.push(n);if(i.length)return{...e,target:i};return})),as.addTransformation("ADD_COLUMNS_ROWS",["FREEZE_COLUMNS","FREEZE_ROWS"],eb),as.addTransformation("REMOVE_COLUMNS_ROWS",["FREEZE_COLUMNS","FREEZE_ROWS"],eb),as.addTransformation("CREATE_FILTER_TABLE",["CREATE_FILTER_TABLE","ADD_MERGE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;for(const i of e.target)for(const e of t.target)if(Hi(e,i))return;return e}));const tb=[{match:function(e){return"sheetId"in e},fn:ob},{match:function(e){return"target"in e&&"sheetId"in e},fn:function(e,t){const i=ob(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;const n=[];for(const i of e.target){const e=ps(i,t);e&&n.push(e)}if(!n.length)return"IGNORE_COMMAND";return{...e,target:n}}},{match:function(e){return"col"in e&&"row"in e&&"sheetId"in e},fn:function(e,t){const i=ob(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type)return function(e,t){const i="COL"===t.dimension?"col":"row";let n=e[i];if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));if(e.includes(n))return"IGNORE_COMMAND";for(let t of e)n>=t&&n--}"ADD_COLUMNS_ROWS"===t.type&&(n>t.base||n===t.base&&"before"===t.position)&&(n+=t.quantity);return{...e,[i]:n}}(e,t);if("ADD_MERGE"===t.type)return function(e,t){for(const i of t.target){if(!(e.col===i.left&&e.row===i.top)&&Wi(e.col,e.row,i))return"IGNORE_COMMAND"}return e}(e,t);return"SKIP_TRANSFORMATION"}},{match:function(e){return"dimension"in e&&"sheetId"in e},fn:function(e,t){const i=ob(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type){if(t.dimension!==e.dimension)return e;const i="ADD_COLUMNS_ROWS"===e.type,n=i?"base":"elements";let o=i?[e[n]]:e[n];if("REMOVE_COLUMNS_ROWS"===t.type&&(o=o.map((e=>{if(t.elements.includes(e))return;const i=t.elements.sort(((e,t)=>t-e));for(let t of i)e>t&&e--;return e})).filter(Xe)),"ADD_COLUMNS_ROWS"===t.type){const e="before"===t.position?t.base-1:t.base;o=o.map((i=>i>e?i+t.quantity:i))}if(o.length){let t=o;return i&&(t=o[0]),{...e,[n]:t}}return"IGNORE_COMMAND"}return"SKIP_TRANSFORMATION"}},{match:function(e){return"ranges"in e},fn:function(e,t){const i=[],n="DELETE_SHEET"===t.type&&t.sheetId;for(const o of e.ranges)if(o._sheetId!==t.sheetId)i.push({...o,_zone:o._zone});else{const e=ps(o._zone,t);e&&n!==o._sheetId&&i.push({...o,_zone:e})}if(!i.length)return"IGNORE_COMMAND";return{...e,ranges:i}}}];function ib(e,t){const i=as.getTransformation(e.type,t.type);return i?i(e,t):function(e,t){for(const{match:i,fn:n}of tb)if(i(e)){const i=n(e,t);if("SKIP_TRANSFORMATION"===i)continue;if("IGNORE_COMMAND"===i)return;e=i}return e}(e,t)}function nb(e,t){let i=[...e];const n=new Set(as.getKeys());for(const e of t)n.has(e.type)&&(i=i.reduce(((t,i)=>{const n=ib(i,e);return n&&t.push(n),t}),[]));return i}function ob(e,t){const i="DELETE_SHEET"===t.type&&t.sheetId;return e.sheetId===i?"IGNORE_COMMAND":"CREATE_SHEET"===e.type||"CREATE_SHEET"===t.type||e.sheetId!==t.sheetId?e:"SKIP_TRANSFORMATION"}class sb{constructor(e,t,i,n){this._commands=[],this._changes=[],this.id=e,this.clientId=t,this._commands=[...i],this._changes=n?[...n]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}}class rb extends Error{}class ab extends Qv{constructor(e,t,i=K){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=i,this.clients={},this.clientId="local",this.pendingMessages=[],this.waitingAck=!1,this.waitingUndoRedoAck=!1,this.isReplayingInitialRevisions=!1,this.processedRevisions=new Set,this.uuidGenerator=new Mi,this.debouncedMove=function(e,t,i){let n;return function(){const o=this,s=arguments,r=i&&!n;clearTimeout(n),n=setTimeout((function(){n=null,i||e.apply(o,s)}),t),r&&e.apply(o,s)}}(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t){if(!e.length||!t.length||!this.canApplyOptimisticUpdate())return;const i=new sb(this.uuidGenerator.uuidv4(),this.clientId,e,t);this.revisions.append(i.id,i),this.trigger("new-local-state-update",{id:i.id}),this.sendUpdateMessage({type:"REMOTE_REVISION",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:i.id,clientId:i.clientId,commands:i.commands})}undo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_UNDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),undoneRevisionId:e})}redo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_REDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),redoneRevisionId:e})}move(e){this.debouncedMove(e)}join(e){e?(this.clients[e.id]=e,this.clientId=e.id):(this.clients.local={id:"local",name:"local"},this.clientId="local"),this.transportService.onNewMessage(this.clientId,this.onMessageReceived.bind(this))}loadInitialMessages(e){this.isReplayingInitialRevisions=!0;for(const t of e)this.onMessageReceived(t);this.isReplayingInitialRevisions=!1}leave(){delete this.clients[this.clientId],this.transportService.leave(this.clientId),this.transportService.sendMessage({type:"CLIENT_LEFT",clientId:this.clientId,version:1})}snapshot(e){const t=this.uuidGenerator.uuidv4();this.transportService.sendMessage({type:"SNAPSHOT",nextRevisionId:t,serverRevisionId:this.serverRevisionId,data:{...e,revisionId:t},version:1})}getClient(){const e=this.clients[this.clientId];if(!e)throw new rb("The client left the session");return e}getConnectedClients(){return new Set(Object.values(this.clients).filter(Xe))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return 0===this.pendingMessages.length}_move(e){var t;if(!this.clients[this.clientId])return;const i=null===(t=this.clients[this.clientId])||void 0===t?void 0:t.position;if((null==i?void 0:i.col)===e.col&&i.row===e.row&&i.sheetId===e.sheetId)return;const n=i?"CLIENT_MOVED":"CLIENT_JOINED",o=this.getClient();this.clients[this.clientId]={...o,position:e},this.transportService.sendMessage({type:n,version:1,client:{...o,position:e}})}onMessageReceived(e){if(!this.isAlreadyProcessed(e))if(this.isWrongServerRevisionId(e))this.trigger("unexpected-revision-id");else{switch(e.type){case"CLIENT_MOVED":this.onClientMoved(e);break;case"CLIENT_JOINED":this.onClientJoined(e);break;case"CLIENT_LEFT":this.onClientLeft(e);break;case"REVISION_REDONE":this.revisions.redo(e.redoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-redone",{revisionId:e.redoneRevisionId,commands:this.revisions.get(e.redoneRevisionId).commands});break;case"REVISION_UNDONE":this.revisions.undo(e.undoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-undone",{revisionId:e.undoneRevisionId,commands:this.revisions.get(e.undoneRevisionId).commands});break;case"REMOTE_REVISION":const{clientId:t,commands:i}=e,n=new sb(e.nextRevisionId,t,i);if(n.clientId!==this.clientId){this.revisions.insert(n.id,n,e.serverRevisionId);const t=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.commands)).flat();this.trigger("remote-revision-received",{commands:nb(i,t)})}break;case"SNAPSHOT_CREATED":{const t=new sb(e.nextRevisionId,"server",[]);this.revisions.insert(t.id,t,e.serverRevisionId),this.dropPendingHistoryMessages(),this.trigger("snapshot");break}}this.acknowledge(e),this.trigger("collaborative-event-received")}}onClientMoved(e){e.client.id!==this.clientId&&(this.clients[e.client.id]=e.client)}onClientJoined(e){if(e.client.id!==this.clientId){this.clients[e.client.id]=e.client;const t=this.clients[this.clientId];if(t){const{position:e}=t;e&&this.transportService.sendMessage({type:"CLIENT_MOVED",version:1,client:{...t,position:e}})}}}onClientLeft(e){e.clientId!==this.clientId&&delete this.clients[e.clientId]}sendUpdateMessage(e){this.pendingMessages.push(e),this.waitingAck||this.sendPendingMessage()}sendPendingMessage(){let e=this.pendingMessages[0];if(e){if("REMOTE_REVISION"===e.type){let t=this.revisions.get(e.nextRevisionId);0===t.commands.length&&(this.revisions.rebase(t.id),t=this.revisions.get(e.nextRevisionId)),e={...e,clientId:t.clientId,commands:t.commands}}if(this.isReplayingInitialRevisions)throw new Error(`Trying to send a new revision while replaying initial revision. This can lead to endless dispatches every time the spreadsheet is open.\n ${JSON.stringify(e)}`);this.waitingAck=!0,this.transportService.sendMessage({...e,serverRevisionId:this.serverRevisionId})}}acknowledge(e){switch("REVISION_UNDONE"!==e.type&&"REVISION_REDONE"!==e.type||(this.waitingUndoRedoAck=!1),e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"SNAPSHOT_CREATED":this.waitingAck=!1,this.pendingMessages=this.pendingMessages.filter((t=>t.nextRevisionId!==e.nextRevisionId)),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.sendPendingMessage();break;case"REVISION_UNDONE":{this.waitingAck=!1,this.pendingMessages=this.pendingMessages.filter((t=>t.nextRevisionId!==e.nextRevisionId));const t=this.pendingMessages.findIndex((e=>"REMOTE_REVISION"===e.type));-1!==t&&this.revisions.rebase(this.pendingMessages[t].nextRevisionId),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.sendPendingMessage();break}}}isAlreadyProcessed(e){if("CLIENT_MOVED"===e.type&&e.client.id===this.clientId)return!0;switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":return this.processedRevisions.has(e.nextRevisionId);default:return!1}}isWrongServerRevisionId(e){switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":return e.serverRevisionId!==this.serverRevisionId;default:return!1}}dropPendingHistoryMessages(){this.waitingUndoRedoAck=!1,this.pendingMessages=this.pendingMessages.filter((({type:e})=>"REVISION_REDONE"!==e&&"REVISION_UNDONE"!==e))}}const lb=["#ff851b","#0074d9","#7fdbff","#b10dc9","#39cccc","#f012be","#3d9970","#111111","#ff4136","#aaaaaa","#85144b","#001f3f"];class cb extends Gg{constructor(){super(...arguments),this.availableColors=new Set(lb),this.colors={}}isPositionValid(e){return e.row<this.getters.getNumberRows(e.sheetId)&&e.col<this.getters.getNumberCols(e.sheetId)}chooseNewColor(){0===this.availableColors.size&&(this.availableColors=new Set(lb));const e=(t=[...this.availableColors.values()])[Math.floor(Math.random()*t.length)];var t;return this.availableColors.delete(e),e}getClientsToDisplay(){try{this.getters.getClient()}catch(e){if(e instanceof rb)return[];throw e}const e=this.getters.getActiveSheetId(),t=[];for(const i of this.getters.getConnectedClients())if(i.id!==this.getters.getClient().id&&i.position&&i.position.sheetId===e&&this.isPositionValid(i.position)){const e=i.position;this.colors[i.id]||(this.colors[i.id]=this.chooseNewColor());const n=this.colors[i.id];t.push({...i,position:e,color:n})}return t}drawGrid(e){if(this.getters.isDashboard())return;const{ctx:t,thinLineWidth:i}=e,n=this.getters.getActiveSheetId();for(const e of this.getClientsToDisplay()){const{row:o,col:s}=e.position,r=this.getters.expandZone(n,{top:o,bottom:o,left:s,right:s}),{x:a,y:l,width:c,height:h}=this.getters.getVisibleRect(r);if(c<=0||h<=0)continue;const d=e.color,u=`${d}10`;t.fillStyle=u,t.lineWidth=4*i,t.strokeStyle=d,t.globalCompositeOperation="multiply",t.fillRect(a,l,c,h),t.globalCompositeOperation="source-over",t.strokeRect(a,l,c,h),t.font=`bold ${G+1}px ${q}`}}}cb.getters=["getClientsToDisplay"],cb.layers=[5];class hb{constructor(e,t,i,n,o,s){if(this.getters=e,this.sheetId=t,this.boundaries=i,n.width<0||n.height<0)throw new Error("Viewport size cannot be negative");this.viewportWidth=n.height&&n.width,this.viewportHeight=n.width&&n.height,this.top=i.top,this.bottom=i.bottom,this.left=i.left,this.right=i.right,this.offsetX=s.x,this.offsetY=s.y,this.offsetScrollbarX=s.x,this.offsetScrollbarY=s.y,this.canScrollVertically=o.canScrollVertically,this.canScrollHorizontally=o.canScrollHorizontally,this.offsetCorrectionX=this.getters.getColDimensions(this.sheetId,this.boundaries.left).start,this.offsetCorrectionY=this.getters.getRowDimensions(this.sheetId,this.boundaries.top).start,this.adjustViewportOffsetX(),this.adjustViewportOffsetY()}getMaxSize(){const e=this.getters.findLastVisibleColRowIndex(this.sheetId,"COL",{first:this.boundaries.left,last:this.boundaries.right}),t=this.getters.findLastVisibleColRowIndex(this.sheetId,"ROW",{first:this.boundaries.top,last:this.boundaries.bottom}),{end:i,size:n}=this.getters.getColDimensions(this.sheetId,e),{end:o,size:s}=this.getters.getRowDimensions(this.sheetId,t),r=this.searchHeaderIndex("COL",i-this.viewportWidth,0),a=this.getters.getColSize(this.sheetId,r),l=this.searchHeaderIndex("ROW",o-this.viewportHeight,0),c=this.getters.getRowSize(this.sheetId,l);let h=i-this.offsetCorrectionX;this.canScrollHorizontally&&(h+=Math.max(_,Math.min(a,this.viewportWidth-n)),h=Math.max(h,this.viewportWidth));let d=o-this.offsetCorrectionY;return this.canScrollVertically&&(d+=Math.max(F+5,Math.min(c,this.viewportHeight-s)),d=Math.max(d,this.viewportHeight)),{width:h,height:d}}getColIndex(e,t=!1){return e<this.offsetCorrectionX||e>this.offsetCorrectionX+this.viewportWidth?-1:this.searchHeaderIndex("COL",e-this.offsetCorrectionX,this.left,t)}getRowIndex(e,t=!1){return e<this.offsetCorrectionY||e>this.offsetCorrectionY+this.viewportHeight?-1:this.searchHeaderIndex("ROW",e-this.offsetCorrectionY,this.top,t)}adjustPosition(e){const t=this.sheetId;e||(e=this.getters.getSheetPosition(t));const i=this.getters.getMainCellPosition(t,e.col,e.row),{col:n,row:o}=this.getters.getNextVisibleCellPosition(t,i.col,i.row);Wi(n,this.boundaries.top,this.boundaries)&&this.adjustPositionX(n),Wi(this.boundaries.left,o,this.boundaries)&&this.adjustPositionY(o)}adjustPositionX(e){const t=this.sheetId,{end:i}=this.getters.getColDimensions(t,e),n=this.getters.getNumberCols(t);if(this.offsetX+this.offsetCorrectionX+this.viewportWidth<i){let i=e;for(;this.getters.isColHidden(t,i)&&e<n;)i++;const o=this.getters.getColDimensions(t,i).end,s=this.searchHeaderIndex("COL",o-this.viewportWidth-this.offsetCorrectionX,this.boundaries.left,!0);this.offsetX=this.getters.getColDimensions(t,s).end-this.offsetCorrectionX,this.offsetScrollbarX=this.offsetX,this.adjustViewportZoneX()}else if(this.left>e){let i=e;for(;this.getters.isColHidden(t,i)&&e>0;)i--;this.offsetX=this.getters.getColDimensions(t,i).start-this.offsetCorrectionX,this.offsetScrollbarX=this.offsetX,this.adjustViewportZoneX()}}adjustPositionY(e){const t=this.sheetId,{end:i}=this.getters.getRowDimensions(t,e),n=this.getters.getNumberRows(t);if(this.offsetY+this.viewportHeight+this.offsetCorrectionY<i){let i=e;for(;this.getters.isRowHidden(t,i)&&e<n;)i++;const o=this.getters.getRowDimensions(t,i).end,s=this.searchHeaderIndex("ROW",o-this.viewportHeight-this.offsetCorrectionY,this.boundaries.top,!0);this.offsetY=this.getters.getRowDimensions(t,s).end-this.offsetCorrectionY,this.offsetScrollbarY=this.offsetY,this.adjustViewportZoneY()}else if(this.top>e){let i=e;for(;this.getters.isRowHidden(t,i)&&e>0;)i--;this.offsetY=this.getters.getRowDimensions(t,i).start-this.offsetCorrectionY,this.offsetScrollbarY=this.offsetY,this.adjustViewportZoneY()}}setViewportOffset(e,t){this.setViewportOffsetX(e),this.setViewportOffsetY(t)}adjustViewportZone(){this.adjustViewportZoneX(),this.adjustViewportZoneY()}getVisibleRect(e){const t=zi(e,this.zone);if(t){return{x:this.getters.getColRowOffset("COL",this.zone.left,t.left)+this.offsetCorrectionX,y:this.getters.getColRowOffset("ROW",this.zone.top,t.top)+this.offsetCorrectionY,width:Math.min(this.getters.getColRowOffset("COL",t.left,t.right+1),this.viewportWidth),height:Math.min(this.getters.getColRowOffset("ROW",t.top,t.bottom+1),this.viewportHeight)}}}getFullRect(e){if(zi(e,this.zone)){return{x:this.getters.getColRowOffset("COL",this.zone.left,e.left)+this.offsetCorrectionX,y:this.getters.getColRowOffset("ROW",this.zone.top,e.top)+this.offsetCorrectionY,width:this.getters.getColRowOffset("COL",e.left,e.right+1),height:this.getters.getColRowOffset("ROW",e.top,e.bottom+1)}}}isVisible(e,t){return t<=this.bottom&&t>=this.top&&e>=this.left&&e<=this.right&&!this.getters.isColHidden(this.sheetId,e)&&!this.getters.isRowHidden(this.sheetId,t)}searchHeaderIndex(e,t,i=0,n=!1){if(this.viewportWidth<=0||this.viewportHeight<=0)return-1;let o=0;const s=this.sheetId,r=this.getters.getNumberHeaders(s,e);for(let a=i;a<=r-1;a++){const i=n||"COL"!==e?a<this.top&&a>this.bottom:a<this.left&&a>this.right;if(!this.getters.isHeaderHidden(s,e,a)&&!i&&(o+="COL"===e?this.getters.getColSize(s,a):this.getters.getRowSize(s,a),o>t))return a}return-1}get zone(){return{left:this.left,right:this.right,top:this.top,bottom:this.bottom}}setViewportOffsetX(e){this.canScrollHorizontally&&(this.offsetScrollbarX=e,this.adjustViewportZoneX())}setViewportOffsetY(e){this.canScrollVertically&&(this.offsetScrollbarY=e,this.adjustViewportZoneY())}adjustViewportOffsetX(){if(this.canScrollHorizontally){const{width:e}=this.getMaxSize();this.viewportWidth+this.offsetScrollbarX>e&&(this.offsetScrollbarX=Math.max(0,e-this.viewportWidth))}this.left=this.getColIndex(this.offsetScrollbarX,!0),this.right=this.getColIndex(this.offsetScrollbarX+this.viewportWidth,!0),-1===this.right&&(this.right=this.boundaries.right),this.adjustViewportZoneX()}adjustViewportOffsetY(){if(this.canScrollVertically){const{height:e}=this.getMaxSize();this.viewportHeight+this.offsetScrollbarY>e&&(this.offsetScrollbarY=Math.max(0,e-this.viewportHeight))}this.top=this.getRowIndex(this.offsetScrollbarY,!0),this.bottom=this.getRowIndex(this.offsetScrollbarY+this.viewportWidth,!0),-1===this.bottom&&(this.bottom=this.boundaries.bottom),this.adjustViewportZoneY()}adjustViewportZoneX(){const e=this.sheetId;this.left=this.searchHeaderIndex("COL",this.offsetScrollbarX,this.boundaries.left),this.right=Math.min(this.boundaries.right,this.searchHeaderIndex("COL",this.viewportWidth,this.left)),this.viewportWidth&&(-1===this.left&&(this.left=this.boundaries.left),-1===this.right&&(this.right=this.boundaries.right),this.offsetX=this.getters.getColDimensions(e,this.left).start-this.getters.getColDimensions(e,this.boundaries.left).start)}adjustViewportZoneY(){const e=this.sheetId;this.top=this.searchHeaderIndex("ROW",this.offsetScrollbarY,this.boundaries.top),this.bottom=Math.min(this.boundaries.bottom,this.searchHeaderIndex("ROW",this.viewportHeight,this.top)),this.viewportHeight&&(-1===this.top&&(this.top=this.boundaries.top),-1===this.bottom&&(this.bottom=this.boundaries.bottom),this.offsetY=this.getters.getRowDimensions(e,this.top).start-this.getters.getRowDimensions(e,this.boundaries.top).start)}}class db extends Gg{constructor(){super(...arguments),this.viewports={},this.sheetViewWidth=1e3,this.sheetViewHeight=1e3,this.gridOffsetX=0,this.gridOffsetY=0,this.sheetsWithDirtyViewports=new Set}allowDispatch(e){switch(e.type){case"SET_VIEWPORT_OFFSET":return this.checkScrollingDirection(e);case"RESIZE_SHEETVIEW":return this.chainValidations(this.checkValuesAreDifferent,this.checkPositiveDimension)(e);default:return 0}}handleEvent(e){switch(e.type){case"HeadersSelected":case"AlterZoneCorner":break;case"ZonesSelected":const t=this.getters.getActiveSheetId();let{col:i,row:n}=Qi(e.previousAnchor.zone,e.anchor.zone);if("updateAnchor"===e.mode){const o=e.previousAnchor.zone,s=e.anchor.zone,{top:r,bottom:a,left:l,right:c}=this.getMainInternalViewport(t);o.left===s.left&&o.right===s.right&&(i=l>i||i>c?l:i),o.top===s.top&&o.bottom===s.bottom&&(n=r>n||n>a?r:n)}i=Math.min(i,this.getters.getNumberCols(t)-1),n=Math.min(n,this.getters.getNumberRows(t)-1),this.refreshViewport(t,{col:i,row:n})}}handle(e){var t;switch(e.type){case"START":this.selection.observe(this,{handleEvent:this.handleEvent.bind(this)}),this.resetViewports(this.getters.getActiveSheetId());break;case"UNDO":case"REDO":this.resetSheetViews();break;case"RESIZE_SHEETVIEW":this.resizeSheetView(e.height,e.width,e.gridOffsetX,e.gridOffsetY);break;case"SET_VIEWPORT_OFFSET":this.setSheetViewOffset(e.offsetX,e.offsetY);break;case"SHIFT_VIEWPORT_DOWN":const i=this.getters.getActiveSheetId(),{top:n,viewportHeight:o,offsetCorrectionY:s}=this.getMainInternalViewport(i),r=this.getters.getRowDimensions(i,n);this.shiftVertically(r.start+o-s);break;case"SHIFT_VIEWPORT_UP":{const e=this.getters.getActiveSheetId(),{top:t,viewportHeight:i,offsetCorrectionY:n}=this.getMainInternalViewport(e),o=this.getters.getRowDimensions(e,t);this.shiftVertically(o.end-n-i);break}case"REMOVE_COLUMNS_ROWS":case"RESIZE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"UPDATE_FILTER":this.resetViewports(e.sheetId);break;case"UPDATE_CELL":("content"in e||"format"in e||void 0!==(null===(t=e.style)||void 0===t?void 0:t.fontSize))&&this.sheetsWithDirtyViewports.add(e.sheetId);break;case"DELETE_SHEET":this.cleanViewports(),this.sheetsWithDirtyViewports.delete(e.sheetId);break;case"ACTIVATE_SHEET":this.setViewports(),this.refreshViewport(e.sheetIdTo);break;case"UNFREEZE_ROWS":case"UNFREEZE_COLUMNS":case"FREEZE_COLUMNS":case"FREEZE_ROWS":case"UNFREEZE_COLUMNS_ROWS":this.resetViewports(this.getters.getActiveSheetId());break;case"START_EDITION":const{col:a,row:l}=this.getters.getPosition();this.refreshViewport(this.getters.getActiveSheetId(),{col:a,row:l})}}finalize(){for(const e of this.sheetsWithDirtyViewports)this.resetViewports(e);this.sheetsWithDirtyViewports=new Set,this.setViewports()}setViewports(){var e;const t=this.getters.getSheetIds();for(const i of t)(null===(e=this.viewports[i])||void 0===e?void 0:e.bottomRight)||this.resetViewports(i)}getColIndex(e){const t=this.getters.getActiveSheetId();return Math.max(...this.getSubViewports(t).map((t=>t.getColIndex(e))))}getRowIndex(e){const t=this.getters.getActiveSheetId();return Math.max(...this.getSubViewports(t).map((t=>t.getRowIndex(e))))}getSheetViewDimensionWithHeaders(){return{width:this.sheetViewWidth+this.gridOffsetX,height:this.sheetViewHeight+this.gridOffsetY}}getSheetViewDimension(){return{width:this.sheetViewWidth,height:this.sheetViewHeight}}getActiveMainViewport(){const e=this.getters.getActiveSheetId();return this.getMainViewport(e)}getActiveSheetScrollInfo(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e);return{scrollX:t.offsetX,scrollY:t.offsetY}}getActiveSheetDOMScrollInfo(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e);return{scrollX:t.offsetScrollbarX,scrollY:t.offsetScrollbarY}}getSheetViewVisibleCols(){const e=this.getters.getActiveSheetId(),t=this.getSubViewports(e);return[...new Set(t.map((e=>$e(e.left,e.right+1))).flat())].filter((t=>t>=0&&!this.getters.isHeaderHidden(e,"COL",t)))}getSheetViewVisibleRows(){const e=this.getters.getActiveSheetId(),t=this.getSubViewports(e);return[...new Set(t.map((e=>$e(e.top,e.bottom+1))).flat())].filter((t=>t>=0&&!this.getters.isHeaderHidden(e,"ROW",t)))}getMainViewportRect(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e),{xSplit:i,ySplit:n}=this.getters.getPaneDivisions(e);let{width:o,height:s}=t.getMaxSize();return{x:this.getters.getColDimensions(e,i).start,y:this.getters.getRowDimensions(e,n).start,width:o,height:s}}getMaximumSheetOffset(){const e=this.getters.getActiveSheetId(),{width:t,height:i}=this.getMainViewportRect(),n=this.getMainInternalViewport(e);return{maxOffsetX:Math.max(0,t-n.viewportWidth+1),maxOffsetY:Math.max(0,i-n.viewportHeight+1)}}getColRowOffsetInViewport(e,t,i){if(i<t)return-this.getColRowOffsetInViewport(e,i,t);const n=this.getters.getActiveSheetId(),o="COL"===e?this.getters.getSheetViewVisibleCols():this.getters.getSheetViewVisibleRows(),s=o.findIndex((e=>t>=e));let r=o.findIndex((e=>i<=e));r=-1===r?o.length:r;const a=o.slice(s,r);let l=0;for(const t of a)l+="COL"===e?this.getters.getColSize(n,t):this.getters.getRowSize(n,t);return l}isVisibleInViewport(e,t,i){return this.getSubViewports(e).some((e=>e.isVisible(t,i)))}getEdgeScrollCol(e,t,i){let n=!1,o=0,s=0;const{xSplit:r}=this.getters.getPaneDivisions(this.getters.getActiveSheetId()),{width:a}=this.getSheetViewDimension(),{x:l}=this.getMainViewportCoordinates(),c=this.getActiveSheetScrollInfo().scrollX;return e>a?(n=!0,s=Wt(e-a),o=1):e<l&&i>=l&&c>0?(n=!0,s=Wt(l-e),o=-1):r&&t<l&&e>l&&(n=!0,s=Wt(e),o="reset"),{canEdgeScroll:n,direction:o,delay:s}}getEdgeScrollRow(e,t,i){let n=!1,o=0,s=0;const{ySplit:r}=this.getters.getPaneDivisions(this.getters.getActiveSheetId()),{height:a}=this.getSheetViewDimension(),{y:l}=this.getMainViewportCoordinates(),c=this.getActiveSheetScrollInfo().scrollY;return e>a?(n=!0,s=Wt(e-a),o=1):e<l&&i>=l&&c>0?(n=!0,s=Wt(l-e),o=-1):r&&t<l&&e>l&&(n=!0,s=Wt(e),o="reset"),{canEdgeScroll:n,direction:o,delay:s}}getVisibleRect(e){const t=this.getters.getActiveSheetId();return this.mapViewportsToRect(t,(t=>t.getVisibleRect(e)))}getRect(e){const t=this.getters.getActiveSheetId();return this.mapViewportsToRect(t,(t=>t.getFullRect(e)))}getMainViewportCoordinates(){const e=this.getters.getActiveSheetId(),{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e);return{x:this.getters.getColDimensions(e,t).start,y:this.getters.getRowDimensions(e,i).start}}getAllActiveViewportsZones(){const e=this.getters.getActiveSheetId();return this.getSubViewports(e)}ensureMainViewportExist(e){this.viewports[e]||this.resetViewports(e)}getSubViewports(e){return this.ensureMainViewportExist(e),Object.values(this.viewports[e]).filter(Xe)}checkPositiveDimension(e){return e.width<0||e.height<0?69:0}checkValuesAreDifferent(e){const{height:t,width:i}=this.getSheetViewDimension();return e.gridOffsetX===this.gridOffsetX&&e.gridOffsetY===this.gridOffsetY&&e.width===i&&e.height===t?77:0}checkScrollingDirection({offsetX:e,offsetY:t}){const i=this.getMainInternalViewport(this.getters.getActiveSheetId());return!i.canScrollHorizontally&&e>0||!i.canScrollVertically&&t>0?70:0}getMainViewport(e){const t=this.getMainInternalViewport(e);return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}getMainInternalViewport(e){return this.ensureMainViewportExist(e),this.viewports[e].bottomRight}cleanViewports(){const e={};for(const t of this.getters.getSheetIds())e[t]=this.viewports[t];this.viewports=e}resetSheetViews(){this.cleanViewports();for(let e of Object.keys(this.viewports)){const t=this.getters.getSheetPosition(e);this.resetViewports(e);const i=this.getSubViewports(e);Object.values(i).forEach((e=>{e.adjustPosition(t)}))}}resizeSheetView(e,t,i=0,n=0){this.sheetViewHeight=e,this.sheetViewWidth=t,this.gridOffsetX=i,this.gridOffsetY=n,this.recomputeViewports()}recomputeViewports(){for(const e of this.getters.getSheetIds())this.resetViewports(e)}setSheetViewOffset(e,t){const i=this.getters.getActiveSheetId(),{maxOffsetX:n,maxOffsetY:o}=this.getMaximumSheetOffset();this.getSubViewports(i).forEach((i=>i.setViewportOffset(Me(e,0,n),Me(t,0,o))))}getViewportOffset(e){var t,i;return{x:(null===(t=this.viewports[e])||void 0===t?void 0:t.bottomRight.offsetScrollbarX)||0,y:(null===(i=this.viewports[e])||void 0===i?void 0:i.bottomRight.offsetScrollbarY)||0}}resetViewports(e){if(!this.getters.tryGetSheet(e))return;const{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e),n=this.getters.getNumberCols(e),o=this.getters.getNumberRows(e),s=Math.min(this.getters.getColRowOffset("COL",0,t,e),this.sheetViewWidth),r=Math.min(this.getters.getColRowOffset("ROW",0,i,e),this.sheetViewHeight),a=Math.max(this.sheetViewWidth-s,0),l=Math.max(this.sheetViewHeight-r,0),{xRatio:c,yRatio:h}=this.getFrozenSheetViewRatio(e),d=c<1,u=h<1,g=this.getViewportOffset(e),p={topLeft:i&&t&&new hb(this.getters,e,{left:0,right:t-1,top:0,bottom:i-1},{width:s,height:r},{canScrollHorizontally:!1,canScrollVertically:!1},{x:0,y:0})||void 0,topRight:i&&new hb(this.getters,e,{left:t,right:n-1,top:0,bottom:i-1},{width:a,height:r},{canScrollHorizontally:d,canScrollVertically:!1},{x:d?g.x:0,y:0})||void 0,bottomLeft:t&&new hb(this.getters,e,{left:0,right:t-1,top:i,bottom:o-1},{width:s,height:l},{canScrollHorizontally:!1,canScrollVertically:u},{x:0,y:u?g.y:0})||void 0,bottomRight:new hb(this.getters,e,{left:t,right:n-1,top:i,bottom:o-1},{width:a,height:l},{canScrollHorizontally:d,canScrollVertically:u},{x:d?g.x:0,y:u?g.y:0})};this.viewports[e]=p}refreshViewport(e,t){this.getSubViewports(e).forEach((e=>{e.adjustViewportZone(),e.adjustPosition(t)}))}shiftVertically(e){const t=this.getters.getActiveSheetId(),{top:i}=this.getMainInternalViewport(t),{scrollX:n}=this.getActiveSheetScrollInfo();this.setSheetViewOffset(n,e);const{anchor:o}=this.getters.getSelection();if(o.cell.row>=this.getters.getPaneDivisions(t).ySplit){const e=this.getMainInternalViewport(t).top-i;this.selection.selectCell(o.cell.col,o.cell.row+e)}}getVisibleFigures(){const e=this.getters.getActiveSheetId(),t=[],i=this.getters.getFigures(e),{scrollX:n,scrollY:o}=this.getActiveSheetScrollInfo(),{x:s,y:r}=this.getters.getMainViewportCoordinates(),{width:a,height:l}=this.getters.getSheetViewDimensionWithHeaders();for(const e of i)e.x>=s&&(e.x+e.width<=s+n||e.x>=a+n+s)||e.y>=r&&(e.y+e.height<=r+o||e.y>=l+o+r)||t.push(e);return t}getFrozenSheetViewRatio(e){const{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e),n=this.getters.getColDimensions(e,t).start,o=this.getters.getRowDimensions(e,i).start;return{xRatio:n/(this.sheetViewWidth+this.gridOffsetX),yRatio:o/(this.sheetViewHeight+this.gridOffsetY)}}mapViewportsToRect(e,t){let i=1/0,n=1/0,o=0,s=0,r=!1;for(const a of this.getSubViewports(e)){const e=t(a);e&&(r=!0,i=Math.min(i,e.x),n=Math.min(n,e.y),o=Math.max(o,e.x+e.width),s=Math.max(s,e.y+e.height))}return r?{x:i+this.gridOffsetX,y:n+this.gridOffsetY,width:o-i,height:s-n}:{x:0,y:0,width:0,height:0}}}db.getters=["getColIndex","getRowIndex","getActiveMainViewport","getSheetViewDimension","getSheetViewDimensionWithHeaders","getMainViewportRect","isVisibleInViewport","getEdgeScrollCol","getEdgeScrollRow","getVisibleFigures","getVisibleRect","getColRowOffsetInViewport","getMainViewportCoordinates","getActiveSheetScrollInfo","getActiveSheetDOMScrollInfo","getSheetViewVisibleCols","getSheetViewVisibleRows","getFrozenSheetViewRatio","getAllActiveViewportsZones","getRect"];class ub extends Gg{allowDispatch(e){if("SORT_CELLS"===e.type){if(!Wi(e.col,e.row,e.zone))throw new Error(s("The anchor must be part of the provided zone"));return this.checkValidations(e,this.checkMerge,this.checkMergeSizes)}return 0}handle(e){if("SORT_CELLS"===e.type)this.sortZone(e.sheetId,e,e.zone,e.sortDirection,e.sortOptions||{})}checkMerge({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;for(let i=t.top;i<=t.bottom;i++)for(let n=t.left;n<=t.right;n++)if(!this.getters.isInMerge(e,n,i))return 64;return 0}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;const i=this.getters.getMerges(e).filter((e=>Hi(e,t))),n=ji(i[0]);let[o,s]=[n.width,n.height];return i.every((e=>{let[t,i]=[e.right-e.left+1,e.bottom-e.top+1];return t===o&&i===s}))?0:64}expand(e,t){const{left:i,right:n,top:o,bottom:s}=this.getters.expandZone(e,t);return{left:Math.max(0,i),right:Math.min(this.getters.getNumberCols(e)-1,n),top:Math.max(0,o),bottom:Math.min(this.getters.getNumberRows(e)-1,s)}}checkExpandedValues(e,t){const i=this.expand(e,t);let n;if(this.getters.doesIntersectMerge(e,i)){const{left:t,right:o,top:s,bottom:r}=i;for(let i=t;i<=o;i++)for(let t=s;t<=r;t++){const{col:o,row:s}=this.getters.getMainCellPosition(e,i,t);if(n=this.getters.getCell(e,o,s),null==n?void 0:n.formattedValue)return!0}}else for(let t of this.getters.getCellsInZone(e,i))if(null==t?void 0:t.formattedValue)return!0;return!1}getContiguousZone(e,t){let i,{top:n,bottom:o,left:s,right:r}=t,a=!1;for(;!a;)a=!0,n>0&&(i=this.checkExpandedValues(e,{left:s-1,right:r+1,top:n-1,bottom:n-1}),i&&(a=!1,n--)),s>0&&(i=this.checkExpandedValues(e,{left:s-1,right:s-1,top:n-1,bottom:o+1}),i&&(a=!1,s--)),r<this.getters.getNumberCols(e)-1&&(i=this.checkExpandedValues(e,{left:r+1,right:r+1,top:n-1,bottom:o+1}),i&&(a=!1,r++)),o<this.getters.getNumberRows(e)-1&&(i=this.checkExpandedValues(e,{left:s-1,right:r+1,top:o+1,bottom:o+1}),i&&(a=!1,o++));return{left:s,right:r,top:n,bottom:o}}hasHeader(e){if(1===e[0].length)return!1;let t=e.map((e=>e.map((e=>(null==e?void 0:e.evaluated.type)||hn.empty))));return t[0][0]===hn.empty&&(t=t.slice(1)),!t.some((e=>e[0]===hn.empty))&&!!t.some((e=>e[1]!==hn.empty&&e[0]!==e[1]))}sortZone(e,t,i,n,o){const[s,r]=this.mainCellsSteps(e,i);let a=this.getters.getMainCellPosition(e,t.col,t.row).col,l=Object.assign({},i),c=this.mainCells(e,i);!o.sortHeaders&&this.hasHeader(c)&&(l.top+=r),c=this.mainCells(e,l);const h=function(e,t,i){const n=e.map(lo);let o=n.filter((e=>e.type===hn.empty)),s=n.filter((e=>e.type!==hn.empty));i&&(s.push(...o.map((e=>({...e,type:hn.number,value:0})))),o=[]);const r="descending"===t?-1:1;return s.sort(((e,t)=>{let i=ao.indexOf(e.type)-ao.indexOf(t.type);return 0===i&&(i=e.type===hn.text||e.type===hn.error?e.value.localeCompare(t.value):e.value-t.value),r*i})).concat(o)}(c[a-l.left],n,Boolean(o.emptyCellAsZero)),d=h.map((e=>e.index)),[u,g]=[c.length,c[0].length],p=[];for(let t=0;t<u;t++)for(let i=0;i<g;i++){let n=c[t][d[i]],o=l.left+t*s,a=l.top+i*r,h={sheetId:e,col:o,row:a,content:""};if(n){let t=n.content;if(n.isFormula()){const i=a-this.getters.getCellPosition(n.id).row,o=this.getters.createAdaptedRanges(n.dependencies,0,i,e);t=this.getters.buildFormulaContent(e,n,o)}h.style=n.style,h.content=t,h.format=n.format}p.push(h)}p.forEach((e=>this.dispatch("UPDATE_CELL",e)))}mainCellsSteps(e,t){const i=this.getters.getMerge(e,t.left,t.top);return[i?i.right-i.left+1:1,i?i.bottom-i.top+1:1]}mainCells(e,t){const[i,n]=this.mainCellsSteps(e,t),o=[],s=$e(t.left,t.right+1,i),r=$e(t.top,t.bottom+1,n);for(const t of s){const i=[];o.push(i);for(const n of r)i.push(this.getters.getCell(e,t,n))}return o}}ub.getters=["getContiguousZone"];class gb extends Gg{constructor(){super(...arguments),this.showFormulas=!1}handle(e){if("SET_FORMULA_VISIBILITY"===e.type)this.showFormulas=e.show}shouldShowFormulas(){return this.showFormulas}}gb.getters=["shouldShowFormulas"];class pb extends Gg{constructor(){super(...arguments),this.ctx=document.createElement("canvas").getContext("2d")}allowDispatch(e){switch(e.type){case"AUTORESIZE_ROWS":case"AUTORESIZE_COLUMNS":try{this.getters.getSheet(e.sheetId);break}catch(e){return 27}}return 0}handle(e){switch(e.type){case"AUTORESIZE_COLUMNS":for(let t of e.cols){const i=this.getColMaxWidth(e.sheetId,t);0!==i&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"COL",size:i,sheetId:e.sheetId})}break;case"AUTORESIZE_ROWS":this.dispatch("RESIZE_COLUMNS_ROWS",{elements:e.rows,dimension:"ROW",size:null,sheetId:e.sheetId})}}getCellWidth(e,{col:t,row:i}){const n=this.getters.getCell(e,t,i);let o=0;n&&(o+=this.getTextWidth(n));this.getters.getConditionalIcon(t,i)&&(o+=ke(this.getters.getCellStyle(n))+2*L);if(this.getters.isFilterHeader(e,t,i)&&(o+=20),o>0&&(o+=2*V,"wrap"===this.getters.getCellStyle(n).wrapping)){const e=en({col:t,row:i}),n=this.getters.getColSize(this.getters.getActiveSheetId(),e.left);return Math.min(n,o)}return o}getTextWidth(e){const t=this.getters.getCellText(e,this.getters.shouldShowFormulas()),{sheetId:i,col:n,row:o}=this.getters.getCellPosition(e.id);return _e(this.ctx,t,this.getters.getCellComputedStyle(i,n,o))}getCellText(e,t=!1){return t&&(e.isFormula()||e.evaluated.type===hn.error)?e.content:e.formattedValue}getCellMultiLineText(e,t){const i=this.getters.getCellStyle(e),n=this.getters.getCellText(e).split(" "),o=[];let s="",r=t;for(let e of n){const n=this.splitWordToSpecificWidth(this.ctx,e,t,i),a=n.pop(),l=_e(this.ctx,a,i);if(n.length)""!==s&&(o.push(s),s="",r=t),n.forEach((e=>{o.push(e)})),s=a,r=t-l;else{const e=""===s?a:" "+a,n=_e(this.ctx,e,i);n<=r?(s+=e,r-=n):(o.push(s),s=a,r=t-l)}}return""!==s&&o.push(s),o}getColDimensions(e,t){const i=this.getColRowOffset("COL",0,t,e),n=this.getters.getColSize(e,t);return{start:i,size:n,end:i+(this.getters.isColHidden(e,t)?0:n)}}getRowDimensions(e,t){const i=this.getColRowOffset("ROW",0,t,e),n=this.getters.getRowSize(e,t);return{start:i,size:n,end:i+(this.getters.isRowHidden(e,t)?0:n)}}getColRowOffset(e,t,i,n=this.getters.getActiveSheetId()){if(i<t)return-this.getColRowOffset(e,i,t);let o=0;for(let s=t;s<i;s++)this.getters.isHeaderHidden(n,e,s)||(o+="COL"===e?this.getters.getColSize(n,s):this.getters.getRowSize(n,s));return o}getColMaxWidth(e,t){const i=Xi(this.getters.getColsZone(e,t,t)).map((t=>this.getCellWidth(e,t)));return Math.max(0,lt(i))}splitWordToSpecificWidth(e,t,i,n){if(_e(e,t,n)<=i)return[t];const o=[];let s="";for(let r of t){_e(e,s+r,n)>i?(o.push(s),s=r):s+=r}return o.push(s),o}}pb.getters=["getCellWidth","getTextWidth","getCellText","getCellMultiLineText","getColDimensions","getRowDimensions","getColRowOffset"];const mb=(new sn).add("sheet",Rv).add("header visibility",Ev).add("filters",Sv).add("cell",uv).add("merge",wv).add("headerSize",Cv).add("borders",hv).add("conditional formatting",mv).add("figures",fv).add("chart",gv),fb=(new sn).add("selection",jv).add("ui_sheet",pb).add("header_visibility_ui",Wv).add("ui_options",gb).add("evaluation",Lv).add("evaluation_filter",Vv).add("evaluation_cf",Uv).add("evaluation_chart",Pv).add("clipboard",Dv).add("edition",Zg).add("selectionInputManager",Kv).add("highlight",Gv).add("viewport",db).add("grid renderer",qv).add("autofill",Tv).add("find_and_replace",Bv).add("sort",ub).add("automatic_sum",Av).add("format",Hv).add("cell_popovers",Nv).add("selection_multiuser",cb).add("custom_colors",kv),vb=new sn;vb.add("link",{condition:e=>e.isLink(),action:(e,t)=>{e.action(t)},sequence:5});class bb{constructor(){this.focusableElement=void 0}setFocusableElement(e){this.focusableElement=e}focus(){var e;null===(e=this.focusableElement)||void 0===e||e.focus()}}xn`
|
|
1391
1391
|
.o-spreadsheet-bottom-bar {
|
|
1392
1392
|
background-color: ${f};
|
|
1393
1393
|
padding-left: ${M}px;
|
|
@@ -1476,12 +1476,12 @@
|
|
|
1476
1476
|
opacity: 0;
|
|
1477
1477
|
}
|
|
1478
1478
|
}
|
|
1479
|
-
`;class
|
|
1479
|
+
`;class Sb extends t.Component{constructor(){super(...arguments),this.bottomBarRef=t.useRef("bottomBar"),this.menuState=t.useState({isOpen:!1,menuId:void 0,position:null,menuItems:[]}),this.selectedStatisticFn=""}setup(){t.onMounted((()=>this.focusSheet())),t.onPatched((()=>this.focusSheet()))}focusSheet(){const e=this.bottomBarRef.el.querySelector(`[data-id="${this.env.model.getters.getActiveSheetId()}"]`);e&&e.scrollIntoView&&e.scrollIntoView()}addSheet(){const e=this.env.model.getters.getActiveSheetId(),t=this.env.model.getters.getSheetIds().findIndex((t=>t===e))+1,i=this.env.model.uuidGenerator.smallUuid(),n=this.env.model.getters.getNextSheetName(this.env._t("Sheet"));this.env.model.dispatch("CREATE_SHEET",{sheetId:i,position:t,name:n}),this.env.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e,sheetIdTo:i})}getVisibleSheets(){return this.env.model.getters.getVisibleSheetIds().map((e=>this.env.model.getters.getSheet(e)))}listSheets(e){const t=new Kn,i=this.env.model.getters.getActiveSheetId();let n=0;for(const e of this.env.model.getters.getSheetIds()){const o=this.env.model.getters.getSheet(e);t.add(e,{name:o.name,sequence:n,isReadonlyAllowed:!0,textColor:o.isVisible?void 0:"grey",action:t=>{t.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:i,sheetIdTo:e})}}),n++}const o=e.currentTarget,{top:s,left:r}=o.getBoundingClientRect();this.openContextMenu(r,s,t)}activateSheet(e){this.env.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.env.model.getters.getActiveSheetId(),sheetIdTo:e})}onDblClick(e){Ko(this.env,e)}openContextMenu(e,t,i,n){this.menuState.isOpen=!0,this.menuState.menuItems=i.getAll(),this.menuState.position={x:e,y:t},this.menuState.menuId=n}onIconClick(e,t){if(this.env.model.getters.getActiveSheetId()!==e&&this.activateSheet(e),t.closedMenuId===e)this.menuState.isOpen=!1,this.menuState.menuId=void 0;else{const i=t.currentTarget.parentElement,{top:n,left:o}=i.getBoundingClientRect();this.openContextMenu(o,n,Qo,e)}}onContextMenu(e,t){this.env.model.getters.getActiveSheetId()!==e&&this.activateSheet(e);const i=t.currentTarget,{top:n,left:o}=i.getBoundingClientRect();this.openContextMenu(o,n,Qo,e)}getSelectedStatistic(){const e=this.env.model.getters.getStatisticFnResults();if(!Object.values(e).every((e=>void 0===e)))return""===this.selectedStatisticFn&&(this.selectedStatisticFn=Object.keys(e)[0]),this.getComposedFnName(this.selectedStatisticFn,e[this.selectedStatisticFn])}listSelectionStatistics(e){const t=new Kn;let i=0;for(let[e,n]of Object.entries(this.env.model.getters.getStatisticFnResults()))t.add(e,{name:this.getComposedFnName(e,n),sequence:i,isReadonlyAllowed:!0,action:()=>{this.selectedStatisticFn=e}}),i++;const n=e.currentTarget,{top:o,left:s,width:r}=n.getBoundingClientRect();this.openContextMenu(s+r,o,t)}getComposedFnName(e,t){return e+": "+(void 0!==t?Qt(t):"__")}}Sb.template="o-spreadsheet-BottomBar",Sb.components={Menu:Gn},xn`
|
|
1480
1480
|
.o-dashboard-clickable-cell {
|
|
1481
1481
|
position: absolute;
|
|
1482
1482
|
cursor: pointer;
|
|
1483
1483
|
}
|
|
1484
|
-
`;class
|
|
1484
|
+
`;class Cb extends t.Component{setup(){const e=t.useRef("grid");this.canvasPosition=Hn(e),this.hoveredCell=t.useState({col:void 0,row:void 0}),Ep("canvas",this.env.model,(()=>this.env.model.getters.getSheetViewDimension())),this.onMouseWheel=wp(((e,t)=>{this.moveCanvas(e,t),this.hoveredCell.col=void 0,this.hoveredCell.row=void 0}))}onCellHovered({col:e,row:t}){this.hoveredCell.col=e,this.hoveredCell.row=t}get gridContainer(){const e=this.env.model.getters.getActiveSheetId(),{right:t}=this.env.model.getters.getSheetZone(e),{end:i}=this.env.model.getters.getColDimensions(e,t);return`\n max-width: ${i}px;\n `}get gridOverlayDimensions(){return"\n height: 100%;\n width: 100%\n "}getCellClickableStyle(e){return`\n top: ${e.y}px;\n left: ${e.x}px;\n width: ${e.width}px;\n height: ${e.height}px;\n `}getClickableCells(){const e=[],t=this.env.model.getters.getActiveSheetId();for(const i of this.env.model.getters.getSheetViewVisibleCols())for(const n of this.env.model.getters.getSheetViewVisibleRows()){const o=this.env.model.getters.getCell(t,i,n);if(o){const s=this.getClickableAction(o);if(!s)continue;let r;r=this.env.model.getters.isInMerge(t,i,n)?this.env.model.getters.getMerge(t,i,n):en({col:i,row:n});const a=this.env.model.getters.getVisibleRect(r);e.push({coordinates:a,cell:o,action:s})}}return e}getClickableAction(e){for(const t of vb.getAll().sort(((e,t)=>e.sequence-t.sequence)))if(t.condition(e,this.env))return t.action;return!1}selectClickableCell(e){const{cell:t,action:i}=e;i(t,this.env)}onClosePopover(){this.env.model.dispatch("CLOSE_CELL_POPOVER")}onGridResized({height:e,width:t}){this.env.model.dispatch("RESIZE_SHEETVIEW",{width:t,height:e,gridOffsetX:0,gridOffsetY:0})}moveCanvas(e,t){const{scrollX:i,scrollY:n}=this.env.model.getters.getActiveSheetDOMScrollInfo();this.env.model.dispatch("SET_VIEWPORT_OFFSET",{offsetX:i+e,offsetY:n+t})}}Cb.template="o-spreadsheet-SpreadsheetDashboard",Cb.components={GridOverlay:mp,GridPopover:fp,Popover:Wn,VerticalScrollBar:Np,HorizontalScrollBar:Ap,FilterIconsOverlay:dp},xn`
|
|
1485
1485
|
.o-sidePanel {
|
|
1486
1486
|
display: flex;
|
|
1487
1487
|
flex-direction: column;
|
|
@@ -1724,7 +1724,7 @@
|
|
|
1724
1724
|
}
|
|
1725
1725
|
}
|
|
1726
1726
|
}
|
|
1727
|
-
`;class
|
|
1727
|
+
`;class Eb extends t.Component{setup(){this.state=t.useState({panel:Rr.get(this.props.component)}),t.onWillUpdateProps((e=>this.state.panel=Rr.get(e.component)))}getTitle(){return"function"==typeof this.state.panel.title?this.state.panel.title(this.env):this.state.panel.title}}Eb.template="o-spreadsheet-SidePanel";const wb={MergeIsDestructive:s("Merging these cells will only preserve the top-leftmost value. Merge anyway?"),MergeInFilter:s("You can't merge cells inside of an existing filter.")};const yb=[{name:"automatic",text:is.Automatic},{name:"number",text:is.Number,description:"1,000.12",value:"#,##0.00"},{name:"percent",text:is.Percent,description:"10.12%",value:"0.00%"},{name:"currency",text:is.Currency,description:"$1,000.12",value:"[$$]#,##0.00"},{name:"currency_rounded",text:is.CurrencyRounded,description:"$1,000",value:"[$$]#,##0"},{name:"date",text:is.Date,description:"9/26/2008",value:"m/d/yyyy"},{name:"time",text:is.Time,description:"10:43:00 PM",value:"hh:mm:ss a"},{name:"datetime",text:is.DateTime,description:"9/26/2008 22:43:00",value:"m/d/yyyy hh:mm:ss"},{name:"duration",text:is.Duration,description:"27:51:38",value:"hhhh:mm:ss"}],xb=[{name:"custom_currency",text:is.CustomCurrency,sidePanel:"CustomCurrency"}];xn`
|
|
1728
1728
|
.o-spreadsheet-topbar {
|
|
1729
1729
|
background-color: white;
|
|
1730
1730
|
line-height: 1.2;
|
|
@@ -1918,7 +1918,7 @@
|
|
|
1918
1918
|
}
|
|
1919
1919
|
}
|
|
1920
1920
|
}
|
|
1921
|
-
`;class
|
|
1921
|
+
`;class Rb extends t.Component{constructor(){super(...arguments),this.DEFAULT_FONT_SIZE=G,this.commonFormats=yb,this.customFormats=xb,this.currentFormatName="automatic",this.fontSizes=se,this.style={},this.state=t.useState({menuState:{isOpen:!1,position:null,menuItems:[]},activeTool:""}),this.isSelectingMenu=!1,this.openedEl=null,this.inMerge=!1,this.cannotMerge=!1,this.undoTool=!1,this.redoTool=!1,this.paintFormatTool=!1,this.fillColor="#ffffff",this.textColor="#000000",this.menus=[],this.composerStyle="\n line-height: 34px;\n padding-left: 8px;\n height: 34px;\n background-color: white;\n "}get dropdownStyle(){return`max-height:${this.props.dropdownMaxHeight}px`}setup(){t.useExternalListener(window,"click",this.onClick),t.onWillStart((()=>this.updateCellState())),t.onWillUpdateProps((()=>this.updateCellState()))}get topbarComponents(){return Ir.getAll().filter((e=>!e.isVisible||e.isVisible(this.env)))}onClick(e){this.openedEl&&Ln(this.openedEl,e)||this.closeMenus()}toogleStyle(e){Eo(this.env,{[e]:!this.style[e]})}toogleFormat(e){const t=yb.find((t=>t.name===e)),i=t&&t.value||"";Co(this.env,i)}toggleAlign(e){Eo(this.env,{align:e})}onMenuMouseOver(e,t){this.isSelectingMenu&&this.toggleContextMenu(e,t)}toggleDropdownTool(e,t){const i=this.state.activeTool===e;this.closeMenus(),this.state.activeTool=i?"":e,this.openedEl=i?null:t.target}toggleContextMenu(e,t){this.closeMenus();const{left:i,top:n,height:o}=t.target.getBoundingClientRect();this.state.menuState.isOpen=!0,this.state.menuState.position={x:i,y:n+o},this.state.menuState.menuItems=Fn(e,this.env),this.state.menuState.parentMenu=e,this.isSelectingMenu=!0,this.openedEl=t.target,this.env.model.dispatch("STOP_EDITION")}closeMenus(){this.state.activeTool="",this.state.menuState.isOpen=!1,this.state.menuState.parentMenu=void 0,this.isSelectingMenu=!1,this.openedEl=null}updateCellState(){const e=this.env.model.getters.getSelectedZones(),t=this.env.model.getters.getActiveSheetId();this.inMerge=!1;const{top:i,left:n,right:o,bottom:s}=this.env.model.getters.getSelectedZone(),{xSplit:r,ySplit:a}=this.env.model.getters.getPaneDivisions(t);if(this.cannotMerge=e.length>1||i===s&&n===o||n<r&&r<=o||i<a&&a<=s,!this.cannotMerge){const{col:i,row:n}=this.env.model.getters.getPosition(),o=this.env.model.getters.expandZone(t,{left:i,right:i,top:n,bottom:n});this.inMerge=Bi(e[0],o)}this.undoTool=this.env.model.getters.canUndo(),this.redoTool=this.env.model.getters.canRedo(),this.paintFormatTool=this.env.model.getters.isPaintingFormat();const l=this.env.model.getters.getActiveCell();if(l&&l.format){const e=this.commonFormats.find((e=>e.value===l.format));this.currentFormatName=e?e.name:""}else this.currentFormatName="automatic";this.style={...this.env.model.getters.getCurrentStyle()},this.style.align=this.style.align||(null==l?void 0:l.defaultAlign),this.fillColor=this.style.fillColor||"#ffffff",this.textColor=this.style.textColor||"#000000",this.menus=rs.getAll()}getMenuName(e){return Dn(e,this.env)}toggleMerge(){if(this.cannotMerge)return;const e=this.env.model.getters.getSelectedZones(),t=[e[e.length-1]],i=this.env.model.getters.getActiveSheetId();this.inMerge?this.env.model.dispatch("REMOVE_MERGE",{sheetId:i,target:t}):function(e,t,i){const n=e.model.dispatch("ADD_MERGE",{sheetId:t,target:i});n.isCancelledBecause(81)?e.raiseError(wb.MergeInFilter):n.isCancelledBecause(3)&&e.askConfirmation(wb.MergeIsDestructive,(()=>{e.model.dispatch("ADD_MERGE",{sheetId:t,target:i,force:!0})}))}(this.env,i,t)}setColor(e,t){Eo(this.env,{[e]:t})}setBorder(e){this.env.model.dispatch("SET_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),border:e})}setFormat(e){const t=e.target.dataset.format;if(t)return void this.toogleFormat(t);const i=e.target.dataset.custom;i&&this.openCustomFormatSidePanel(i)}openCustomFormatSidePanel(e){const t=xb.find((t=>t.name===e)),i=t&&t.sidePanel||"";this.env.openSidePanel(i)}setDecimal(e){this.env.model.dispatch("SET_DECIMAL",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),step:e})}paintFormat(){this.env.model.dispatch("ACTIVATE_PAINT_FORMAT",{target:this.env.model.getters.getSelectedZones()})}clearFormatting(){this.env.model.dispatch("CLEAR_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones()})}setSize(e){const t=parseFloat(e.target.dataset.size);Eo(this.env,{fontSize:t})}doAction(e){e(this.env),this.closeMenus()}undo(){this.env.model.dispatch("REQUEST_UNDO")}redo(){this.env.model.dispatch("REQUEST_REDO")}get selectionContainsFilter(){const e=this.env.model.getters.getActiveSheetId(),t=this.env.model.getters.getSelectedZones();return this.env.model.getters.doesZonesContainFilter(e,t)}get cannotCreateFilter(){return!on(...this.env.model.getters.getSelectedZones())}createFilter(){if(this.cannotCreateFilter)return;const e=this.env.model.getters.getActiveSheetId(),t=this.env.model.getters.getSelectedZones();go(this.env,e,t)}removeFilter(){this.env.model.dispatch("REMOVE_FILTER_TABLE",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones()})}}Rb.template="o-spreadsheet-TopBar",Rb.components={ColorPicker:ar,Menu:Gn,Composer:sp},xn`
|
|
1922
1922
|
.o-spreadsheet {
|
|
1923
1923
|
position: relative;
|
|
1924
1924
|
display: grid;
|
|
@@ -1992,23 +1992,23 @@
|
|
|
1992
1992
|
outline: none;
|
|
1993
1993
|
}
|
|
1994
1994
|
}
|
|
1995
|
-
`;class Rb extends t.Component{constructor(){super(...arguments),this.isViewportTooSmall=!1}getStyle(){return this.env.isDashboard()?"grid-template-rows: auto;":"grid-template-rows: 63px auto 37px"}setup(){var e,i;null===(i=(e=this.props).exposeSpreadsheet)||void 0===i||i.call(e,this),this.model=this.props.model,this.sidePanel=t.useState({isOpen:!1,panelProps:{}}),this.composer=t.useState({topBarFocus:"inactive",gridFocusMode:"inactive"}),this.keyDownMapping={"CTRL+H":()=>this.toggleSidePanel("FindAndReplace",{}),"CTRL+F":()=>this.toggleSidePanel("FindAndReplace",{})},t.useSubEnv({model:this.model,isDashboard:()=>this.model.getters.isDashboard(),openSidePanel:this.openSidePanel.bind(this),toggleSidePanel:this.toggleSidePanel.bind(this),_t:Rb._t,clipboard:navigator.clipboard,focusableElement:new vb}),t.useExternalListener(window,"resize",(()=>this.render(!0))),t.useExternalListener(window,"beforeunload",this.unbindModelEvents.bind(this)),t.useExternalListener(document.body,"wheel",(()=>{})),this.bindModelEvents(),t.onMounted((()=>{this.checkViewportSize()})),t.onWillUnmount((()=>this.unbindModelEvents())),t.onPatched((()=>{this.checkViewportSize()}))}get focusTopBarComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.topBarFocus}get focusGridComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.gridFocusMode}bindModelEvents(){this.model.on("update",this,(()=>this.render(!0))),this.model.on("notify-ui",this,this.onNotifyUI)}unbindModelEvents(){this.model.off("update",this),this.model.off("notify-ui",this)}checkViewportSize(){const{xRatio:e,yRatio:t}=this.env.model.getters.getFrozenSheetViewRatio(this.env.model.getters.getActiveSheetId());if(t>.85||e>.85){if(this.isViewportTooSmall)return;this.env.notifyUser({text:s("The current window is too small to display this sheet properly. Consider resizing your browser window or adjusting frozen rows and columns."),tag:"viewportTooSmall"}),this.isViewportTooSmall=!0}else this.isViewportTooSmall=!1}onNotifyUI(e){if("ERROR"===e.type)this.env.raiseError(e.text)}openSidePanel(e,t){this.sidePanel.component=e,this.sidePanel.panelProps=t,this.sidePanel.isOpen=!0}closeSidePanel(){this.sidePanel.isOpen=!1,this.focusGrid()}toggleSidePanel(e,t){this.sidePanel.isOpen&&e===this.sidePanel.component?(this.sidePanel.isOpen=!1,this.focusGrid()):this.openSidePanel(e,t)}focusGrid(){if(!this._focusGrid)throw new Error("_focusGrid should be exposed by the grid component");this._focusGrid()}save(){var e,t;null===(t=(e=this.props).onContentSaved)||void 0===t||t.call(e,this.model.exportData())}onKeydown(e){let t="";zn(e)&&(t+="CTRL+"),t+=e.key.toUpperCase();let i=this.keyDownMapping[t];if(i)return e.preventDefault(),e.stopPropagation(),void i()}onTopBarComposerFocused(e){this.model.getters.isReadonly()||(this.model.dispatch("UNFOCUS_SELECTION_INPUT"),this.composer.topBarFocus="contentFocus",this.composer.gridFocusMode="inactive",this.setComposerContent({selection:e}))}onGridComposerContentFocused(e){this.model.getters.isReadonly()||(this.model.dispatch("UNFOCUS_SELECTION_INPUT"),this.composer.topBarFocus="inactive",this.composer.gridFocusMode="contentFocus",this.setComposerContent({selection:e}))}onGridComposerCellFocused(e,t){this.model.getters.isReadonly()||(this.model.dispatch("UNFOCUS_SELECTION_INPUT"),this.composer.topBarFocus="inactive",this.composer.gridFocusMode="cellFocus",this.setComposerContent({content:e,selection:t}||{}))}setComposerContent({content:e,selection:t}){"inactive"===this.model.getters.getEditionMode()?this.model.dispatch("START_EDITION",{text:e,selection:t}):e&&this.model.dispatch("SET_CURRENT_CONTENT",{content:e,selection:t})}get gridHeight(){const{height:e}=this.env.model.getters.getSheetViewDimension();return e}}Rb.template="o-spreadsheet-Spreadsheet",Rb.components={TopBar:xb,Grid:Mp,BottomBar:bb,SidePanel:Cb,SpreadsheetDashboard:Sb},Rb._t=e=>e;class Ib{constructor(){this.listeners=[]}sendMessage(e){for(const{callback:t}of this.listeners)t(e)}onNewMessage(e,t){this.listeners.push({id:e,callback:t})}leave(e){this.listeners=this.listeners.filter((t=>t.id!==e))}}function Tb(e){return so.get(e.type)(e)}function Ab(e){if("string"==typeof e)return{};if("number"==typeof e)return[];throw new Error("Cannot create new node")}class Nb{constructor(e,t=[]){this.buildTransformation=e,this.operations=t}getOperations(){return this.operations}getOperation(e){const t=this.operations.find((t=>t.id===e));if(!t)throw new Error(`Operation ${e} not found`);return t}getLastOperationId(){var e;return null===(e=this.operations[this.operations.length-1])||void 0===e?void 0:e.id}getFirstOperationAmong(e,t){for(const i of this.operations){if(i.id===e)return e;if(i.id===t)return t}throw new Error(`Operation ${e} and ${t} not found`)}contains(e){return!!this.operations.find((t=>t.id===e))}prepend(e){const t=this.buildTransformation.with(e.data);this.operations=[e,...this.operations.map((e=>e.transformed(t)))]}insert(e,t){const i=this.buildTransformation.with(e.data),{before:n,operation:o,after:s}=this.locateOperation(t);this.operations=[...n,o,e,...s.map((e=>e.transformed(i)))]}append(e){this.operations.push(e)}appendBranch(e){this.operations=this.operations.concat(e.operations)}fork(e){const{after:t}=this.locateOperation(e);return new Nb(this.buildTransformation,t)}transform(e){this.operations=this.operations.map((t=>t.transformed(e)))}cutBefore(e){this.operations=this.locateOperation(e).before}cutAfter(e){const{before:t,operation:i}=this.locateOperation(e);this.operations=t.concat([i])}locateOperation(e){const t=this.operations.findIndex((t=>t.id===e));if(-1===t)throw new Error(`Operation ${e} not found`);return{before:this.operations.slice(0,t),operation:this.operations[t],after:this.operations.slice(t+1)}}}class Ob{constructor(e,t){this.id=e,this.data=t}transformed(e){return new Mb(this.id,tt((()=>e(this.data))))}}class Mb{constructor(e,t){this.id=e,this.lazyData=t}get data(){return this.lazyData()}transformed(e){return new Mb(this.id,this.lazyData.map(e))}}class _b{constructor(e){this.operations=e}[Symbol.iterator](){return this.operations[Symbol.iterator]()}stopWith(e){return new _b(function*(e,t){for(const i of e)if(yield i,i.operation.id===t)return}(this.operations,e))}stopBefore(e){return new _b(function*(e,t){for(const i of e){if(i.operation.id===t)return;yield i}}(this.operations,e))}startAfter(e){return new _b(function*(e,t){let i=!0;for(const n of e)i||(yield n),n.operation.id===t&&(i=!1)}(this.operations,e))}}class Fb{constructor(e,t){this.buildTransformation=e,this.branchingOperationIds=new Map,this.branches=[t]}getLastBranch(){return this.branches[this.branches.length-1]}execution(e){return new _b(Pe(this._execution(e),this._execution(e)))}revertedExecution(e){return new _b(Pe(this._revertedExecution(e),this._revertedExecution(e)))}insertOperationLast(e,t){var i;const n=e.getLastOperationId()||(null===(i=this.previousBranch(e))||void 0===i?void 0:i.getLastOperationId());e.append(t),n&&this.insertPrevious(e,t,n)}insertOperationAfter(e,t,i){e.insert(t,i),this.updateNextWith(e,t,i),this.insertPrevious(e,t,i)}undo(e,t){const i=this.buildTransformation.without(t.data),n=this.branchingOperationIds.get(e);this.branchingOperationIds.set(e,t.id);const o=e.fork(t.id);n&&this.branchingOperationIds.set(o,n),this.insertBranchAfter(e,o),this.transform(o,i)}redo(e){const t=this.nextBranch(e);if(!t)return;const i=this.nextBranch(t);this.removeBranchFromTree(t);const n=this.branchingOperationIds.get(t);n?this.branchingOperationIds.set(e,n):this.branchingOperationIds.delete(e),i&&this.rebaseUp(i)}drop(e){for(const t of this.branches)t.contains(e)&&t.cutBefore(e)}findOperation(e,t){for(const i of this.revertedExecution(e))if(i.operation.id===t)return i;throw new Error(`Operation ${t} not found`)}rebaseUp(e){const{previousBranch:t,branchingOperation:i}=this.findPreviousBranchingOperation(e);if(!t||!i)return;const n=this.buildTransformation.without(i.data),o=t.fork(i.id);this.branchingOperationIds.set(o,this.branchingOperationIds.get(e)),this.removeBranchFromTree(e),this.insertBranchAfter(t,o),o.transform(n);const s=this.nextBranch(o);s&&this.rebaseUp(s)}removeBranchFromTree(e){const t=this.branches.findIndex((t=>t===e));this.branches.splice(t,1)}insertBranchAfter(e,t){const i=this.branches.findIndex((t=>t===e));this.branches.splice(i+1,0,t)}updateNextWith(e,t,i){const n=this.branchingOperationIds.get(e),o=this.nextBranch(e);if(n&&o)if(e.getFirstOperationAmong(i,n)===n){const s=this.addToNextBranch(e,o,n,t,i);this.updateNextWith(o,s,i)}else{const e=this.buildTransformation.with(t.data);this.transform(o,e)}}addToNextBranch(e,t,i,n,o){let s=n;return o===i?(s=this.getTransformedOperation(e,i,n),t.prepend(s)):t.contains(o)?(s=this.getTransformedOperation(e,i,n),t.insert(s,o)):t.append(n),s}getTransformedOperation(e,t,i){const n=e.getOperation(t),o=this.buildTransformation.without(n.data);return i.transformed(o)}shouldExecute(e,t){return t.id!==this.branchingOperationIds.get(e)}transform(e,t){e.transform(t);const i=this.nextBranch(e);i&&this.transform(i,t)}insertPrevious(e,t,i){const{previousBranch:n,branchingOperation:o}=this.findPreviousBranchingOperation(e);if(!n||!o)return;const s=this.buildTransformation.with(o.data),r=e.fork(i);r.transform(s),n.cutAfter(i),n.appendBranch(r);const a=t.transformed(s);this.insertPrevious(n,a,i)}findPreviousBranchingOperation(e){const t=this.previousBranch(e);if(!t)return{previousBranch:void 0,branchingOperation:void 0};const i=this.branchingOperationIds.get(t);return i?{previousBranch:t,branchingOperation:t.getOperation(i)}:{previousBranch:void 0,branchingOperation:void 0}}nextBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t+1]}previousBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t-1]}*_revertedExecution(e){const t=this.branchingOperationIds.get(e);let i=!!t;const n=e.getOperations();for(let o=n.length-1;o>=0;o--){const s=n[o];s.id===t&&(i=!1),i||(yield{operation:s,branch:e,isCancelled:!this.shouldExecute(e,s)})}const o=this.previousBranch(e);yield*o?this._revertedExecution(o):[]}*_execution(e){for(const t of e.getOperations())if(yield{operation:t,branch:e,isCancelled:!this.shouldExecute(e,t)},t.id===this.branchingOperationIds.get(e)){const t=this.nextBranch(e);return void(yield*t?this._execution(t):[])}if(!this.branchingOperationIds.get(e)){const t=this.nextBranch(e);yield*t?this._execution(t):[]}}}class Db{constructor(e,t,i,n,o){this.applyOperation=t,this.revertOperation=i,this.buildEmpty=n,this.buildTransformation=o,this.HEAD_BRANCH=new Nb(this.buildTransformation),this.tree=new Fb(o,this.HEAD_BRANCH);const s=new Ob(e,n(e));this.tree.insertOperationLast(this.HEAD_BRANCH,s),this.HEAD_OPERATION=s}get(e){return this.tree.findOperation(this.HEAD_BRANCH,e).operation.data}append(e,t){const i=new Ob(e,t),n=this.tree.getLastBranch();this.tree.insertOperationLast(n,i),this.HEAD_BRANCH=n,this.HEAD_OPERATION=i}insert(e,t,i){const n=new Ob(e,t);this.revertTo(i),this.tree.insertOperationAfter(this.HEAD_BRANCH,n,i),this.fastForward()}undo(e,t,i){const{branch:n,operation:o}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.undo(n,o),this.fastForward(),this.insert(t,this.buildEmpty(t),i)}redo(e,t,i){const{branch:n}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.redo(n),this.fastForward(),this.insert(t,this.buildEmpty(t),i)}rebase(e){const t=this.get(e),i=[...this.tree.execution(this.HEAD_BRANCH).startAfter(e)];this.revertBefore(e);const n=this.HEAD_OPERATION.id;this.tree.drop(e),this.insert(e,t,n);for(const{operation:e}of i)this.insert(e.id,e.data,this.HEAD_OPERATION.id)}revertBefore(e){const t=this.tree.revertedExecution(this.HEAD_BRANCH).stopWith(e);this.revert(t)}revertTo(e){const t=e?this.tree.revertedExecution(this.HEAD_BRANCH).stopBefore(e):this.tree.revertedExecution(this.HEAD_BRANCH);this.revert(t)}revert(e){for(const{next:t,operation:i,isCancelled:n}of e)n||this.revertOperation(i.data),t&&(this.HEAD_BRANCH=t.branch,this.HEAD_OPERATION=t.operation)}fastForward(){const e=this.HEAD_OPERATION?this.tree.execution(this.HEAD_BRANCH).startAfter(this.HEAD_OPERATION.id):this.tree.execution(this.HEAD_BRANCH);for(const{operation:t,branch:i,isCancelled:n}of e)n||this.applyOperation(t.data),this.HEAD_OPERATION=t,this.HEAD_BRANCH=i}}function kb(e,t,i){return new Db(e,(e=>{const n=e.commands.slice(),{changes:o}=t((()=>{for(const e of n)i(e)}));e.setChanges(o)}),(e=>function(e){for(const t of e.slice().reverse())for(let e=t.changes.length-1;e>=0;e--){$b(t.changes[e],"before")}}([e])),(e=>new ob(e,"empty",[],[])),{with:e=>t=>new ob(t.id,t.clientId,ib(t.commands,e.commands)),without:e=>t=>new ob(t.id,t.clientId,ib(t.commands,e.commands.map(Tb).flat()))})}function $b(e,t){let i=e.path[0];const n=e.path[e.path.length-1];for(let t=1;t<e.path.slice(0,-1).length;t++){const n=e.path[t];if(void 0===i[n]){const o=e.path[t+1];i[n]=Ab(o)}i=i[n]}void 0===e[t]?delete i[n]:i[n]=e[t]}class Lb extends t.EventBus{constructor(e,t){super(),this.dispatch=e,this.session=t,this.undoStack=[],this.redoStack=[],this.session.on("new-local-state-update",this,this.onNewLocalStateUpdate),this.session.on("revision-undone",this,(({commands:e})=>this.selectiveUndo(e))),this.session.on("revision-redone",this,(({commands:e})=>this.selectiveRedo(e))),this.session.on("snapshot",this,(()=>{this.undoStack=[],this.redoStack=[]}))}allowDispatch(e){switch(e.type){case"REQUEST_UNDO":if(!this.canUndo())return 6;break;case"REQUEST_REDO":if(!this.canRedo())return 7}return 0}beforeHandle(e){}handle(e){switch(e.type){case"REQUEST_UNDO":case"REQUEST_REDO":this.requestHistoryChange("REQUEST_UNDO"===e.type?"UNDO":"REDO")}}finalize(){}requestHistoryChange(e){const t="UNDO"===e?this.undoStack.pop():this.redoStack.pop();t&&("UNDO"===e?(this.session.undo(t),this.redoStack.push(t)):(this.session.redo(t),this.undoStack.push(t)))}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}onNewLocalStateUpdate({id:e}){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>99&&this.undoStack.shift()}selectiveUndo(e){this.dispatch("UNDO",{commands:e})}selectiveRedo(e){this.dispatch("REDO",{commands:e})}}class Pb{constructor(e){this.providers=[],this.getters=e}allowDispatch(e){return"MOVE_RANGES"===e.type?1===e.target.length?0:26:0}beforeHandle(e){}handle(e){switch(e.type){case"REMOVE_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",i="COL"===e.dimension?"right":"bottom",n="COL"===e.dimension?"columns":"rows";const o=[...e.elements];o.sort(((e,t)=>t-e));const s=Le(o);this.executeOnAllRanges((o=>{if(o.sheetId!==e.sheetId)return{changeType:"NONE"};let r=o,a="NONE";for(let e of s){const s=ct(e),l=lt(e);if(o.zone[t]<=s&&s<=o.zone[i]){const e=Math.min(o.zone[i],l)-s+1;a="RESIZE",r=this.createAdaptedRange(r,n,a,-e)}else if(o.zone[t]>=s&&o.zone[i]<=l)a="REMOVE",r=o.clone({...this.getInvalidRange()});else if(o.zone[t]<=l&&o.zone[i]>=l){const e=l-o.zone[t]+1;a="RESIZE",r=this.createAdaptedRange(r,n,a,-e),r=this.createAdaptedRange(r,n,"MOVE",-(o.zone[t]-s))}else s<o.zone[t]&&(a="MOVE",r=this.createAdaptedRange(r,n,a,-(l-s+1)))}return"NONE"!==a?{changeType:a,range:r}:{changeType:"NONE"}}),e.sheetId);break}case"ADD_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",i="COL"===e.dimension?"right":"bottom",n="COL"===e.dimension?"columns":"rows";this.executeOnAllRanges((o=>{if(o.sheetId!==e.sheetId)return{changeType:"NONE"};if("after"===e.position){if(o.zone[t]<=e.base&&e.base<o.zone[i])return{changeType:"RESIZE",range:this.createAdaptedRange(o,n,"RESIZE",e.quantity)};if(e.base<o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,n,"MOVE",e.quantity)}}else{if(o.zone[t]<e.base&&e.base<=o.zone[i])return{changeType:"RESIZE",range:this.createAdaptedRange(o,n,"RESIZE",e.quantity)};if(e.base<=o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,n,"MOVE",e.quantity)}}return{changeType:"NONE"}}),e.sheetId);break}case"DELETE_SHEET":this.executeOnAllRanges((t=>{if(t.sheetId!==e.sheetId)return{changeType:"NONE"};const i=this.getters.getSheetName(e.sheetId);return{changeType:"REMOVE",range:t=t.clone({...this.getInvalidRange(),invalidSheetName:i})}}),e.sheetId);break;case"RENAME_SHEET":this.executeOnAllRanges((t=>{if(t.sheetId===e.sheetId)return{changeType:"CHANGE",range:t};if(Ai(t.invalidSheetName,e.name)){const i=void 0,n=e.sheetId;return{changeType:"CHANGE",range:t.clone({sheetId:n,invalidSheetName:i})}}return{changeType:"NONE"}}));break;case"MOVE_RANGES":{const t=e.target[0];this.executeOnAllRanges((i=>{if(i.sheetId!==e.sheetId||!Gi(i.zone,t))return{changeType:"NONE"};const n=e.targetSheetId,o=e.col-t.left,s=e.row-t.top,r=this.createAdaptedRange(i,"both","MOVE",[o,s]),a=e.sheetId!==n||r.prefixSheet;return{changeType:"MOVE",range:r.clone({sheetId:n,prefixSheet:a})}}));break}}}finalize(){}verifyRangeRemoved(e){return t=>{const i=e(t);return"NONE"===i.changeType||Di(i.range.zone)?i:{range:i.range,changeType:"REMOVE"}}}createAdaptedRange(e,t,i,n){const o=Ki(e.unboundedZone,t,i,n);return e.clone({zone:o})}executeOnAllRanges(e,t){const i=this.verifyRangeRemoved(e);for(const e of this.providers)e(i,t)}addRangeProvider(e){this.providers.push(e)}createAdaptedRanges(e,t,i,n){const o=e.map((e=>xi.fromRange(e,this.getters)));return o.map((e=>{if(!Di(e.zone))return e;const o=e.prefixSheet?e.sheetId:n,s={...e.unboundedZone,left:e.isFullRow&&!e.unboundedZone.hasHeader?e.unboundedZone.left:e.unboundedZone.left+(e.parts[0].colFixed?0:t),right:e.isFullRow?e.unboundedZone.right:e.unboundedZone.right+((e.parts[1]||e.parts[0]).colFixed?0:t),top:e.isFullCol&&!e.unboundedZone.hasHeader?e.unboundedZone.top:e.unboundedZone.top+(e.parts[0].rowFixed?0:i),bottom:e.isFullCol?e.unboundedZone.bottom:e.unboundedZone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:i)};return(e=e.clone({sheetId:o,zone:s})).orderZone(),e}))}getRangeFromSheetXC(e,t){if(!Ot.test(t)||!this.getters.tryGetSheet(e))return new xi({sheetId:"",zone:{left:-1,top:-1,right:-1,bottom:-1},parts:[],invalidXc:t,prefixSheet:!1},this.getters.getSheetSize);let i,n=t,o=!1;t.includes("!")&&(({xc:n,sheetName:i}=$t(t)),i&&(o=!0));const s=_i(n),r=xi.getRangeParts(n,s),a=i&&!this.getters.getSheetIdByName(i)?i:void 0,l=this.getters.getSheetIdByName(i)||e,c=new xi({prefixSheet:o,zone:s,sheetId:l,invalidSheetName:a,parts:r},this.getters.getSheetSize);return c.orderZone(),c}getSelectionRangeString(e,t){const i=xi.fromRange(e,this.getters),n=this.getters.expandZone(i.sheetId,i.zone),o=i.clone({zone:{...n,bottom:i.isFullCol?void 0:n.bottom,right:i.isFullRow?void 0:n.right}});return this.getRangeString(o,t)}getRangeString(e,t,i=!1){if(!e)return X;if(e.invalidXc)return e.invalidXc;if(!this.getters.tryGetSheet(e.sheetId))return X;if(e.zone.bottom-e.zone.top<0||e.zone.right-e.zone.left<0)return X;if(e.zone.left<0||e.zone.top<0)return X;const n=xi.fromRange(e,this.getters);let o=n.sheetId!==t||n.invalidSheetName||n.prefixSheet,s="";if(o&&(s=n.invalidSheetName?n.invalidSheetName:Oe(this.getters.getSheetName(n.sheetId))),o&&!s)return X;let r=this.getRangePartString(n,0,i);return n.parts&&2===n.parts.length&&(n.zone.top!==n.zone.bottom||n.zone.left!==n.zone.right||n.parts[0].rowFixed||n.parts[0].colFixed||n.parts[1].rowFixed||n.parts[1].colFixed)&&(r+=":",r+=this.getRangePartString(n,1,i)),`${o?s+"!":""}${r}`}getRangeDataFromXc(e,t){return this.getters.getRangeFromSheetXC(e,t).rangeData}getRangeDataFromZone(e,t){return{_sheetId:e,_zone:t}}getRangeFromRangeData(e){const t={prefixSheet:!1,zone:e._zone,sheetId:e._sheetId,invalidSheetName:void 0,parts:[{colFixed:!1,rowFixed:!1},{colFixed:!1,rowFixed:!1}]};return new xi(t,this.getters.getSheetSize)}getRangePartString(e,t,i=!1){var n,o;const s=e.parts&&(null===(n=e.parts[t])||void 0===n?void 0:n.colFixed)?"$":"",r=Lt(0===t?e.zone.left:e.zone.right),a=e.parts&&(null===(o=e.parts[t])||void 0===o?void 0:o.rowFixed)?"$":"",l=String(0===t?e.zone.top+1:e.zone.bottom+1);let c="";return c=e.isFullCol&&!i?0===t&&e.unboundedZone.hasHeader?s+r+a+l:s+r:e.isFullRow&&!i?0===t&&e.unboundedZone.hasHeader?s+r+a+l:a+l:s+r+a+l,c}getInvalidRange(){return{parts:[],prefixSheet:!1,zone:{left:-1,top:-1,right:-1,bottom:-1},sheetId:"",invalidXc:X}}}Pb.getters=["getRangeString","getSelectionRangeString","getRangeFromSheetXC","createAdaptedRanges","getRangeDataFromXc","getRangeDataFromZone","getRangeFromRangeData"];class Ub{constructor(){this.observers=[]}registerAsDefault(e,t){this.defaultSubscription={owner:e,callbacks:t},this.mainSubscription||(this.mainSubscription=this.defaultSubscription)}observe(e,t){this.observers.push({owner:e,callbacks:t})}capture(e,t){var i,n,o;if(this.observers.find((t=>t.owner===e)))throw new Error("You are already subscribed forever");(null===(i=this.mainSubscription)||void 0===i?void 0:i.owner)&&this.mainSubscription.owner!==e&&(null===(o=(n=this.mainSubscription.callbacks).release)||void 0===o||o.call(n)),this.mainSubscription={owner:e,callbacks:t}}release(e){var t;(null===(t=this.mainSubscription)||void 0===t?void 0:t.owner)!==e||this.observers.find((t=>t.owner===e))||(this.mainSubscription=this.defaultSubscription)}getBackToDefault(){var e,t,i;this.mainSubscription!==this.defaultSubscription&&(null===(i=null===(e=this.mainSubscription)||void 0===e?void 0:(t=e.callbacks).release)||void 0===i||i.call(t),this.mainSubscription=this.defaultSubscription)}isListening(e){var t;return(null===(t=this.mainSubscription)||void 0===t?void 0:t.owner)===e}send(e){var t;null===(t=this.mainSubscription)||void 0===t||t.callbacks.handleEvent(e),[...this.observers].forEach((t=>t.callbacks.handleEvent(e)))}}class Vb{constructor(e){this.getters=e,this.stream=new Ub,this.anchor={cell:{col:0,row:0},zone:en({col:0,row:0})},this.defaultAnchor=this.anchor}capture(e,t,i){this.stream.capture(e,i),this.anchor=t}registerAsDefault(e,t,i){this.checkAnchorZoneOrThrow(t),this.stream.registerAsDefault(e,i),this.defaultAnchor=t,this.capture(e,t,i)}resetDefaultAnchor(e,t){this.checkAnchorZoneOrThrow(t),this.stream.isListening(e)&&(this.anchor=t),this.defaultAnchor=t}resetAnchor(e,t){this.checkAnchorZoneOrThrow(t),this.stream.isListening(e)&&(this.anchor=t)}observe(e,t){this.stream.observe(e,t)}release(e){this.stream.isListening(e)&&(this.stream.release(e),this.anchor=this.defaultAnchor)}getBackToDefault(){this.stream.getBackToDefault()}selectZone(e){const t=this.getters.getActiveSheetId();return e={...e,zone:this.getters.expandZone(t,e.zone)},this.processEvent({type:"ZonesSelected",anchor:e,mode:"overrideSelection"})}selectCell(e,t){const i=en({col:e,row:t});return this.selectZone({zone:i,cell:{col:e,row:t}})}moveAnchorCell(e,t=1){if("end"!==t&&t<=0)return new fn(84);const{col:i,row:n}=this.getNextAvailablePosition(e,t);return this.selectCell(i,n)}setAnchorCorner(e,t){const i=this.getters.getActiveSheetId(),{col:n,row:o}=this.anchor.cell,s={left:Math.min(n,e),top:Math.min(o,t),right:Math.max(n,e),bottom:Math.max(o,t)},r={zone:this.getters.expandZone(i,s),cell:{col:n,row:o}};return this.processEvent({type:"AlterZoneCorner",mode:"updateAnchor",anchor:r})}addCellToSelection(e,t){const i=this.getters.getActiveSheetId();({col:e,row:t}=this.getters.getMainCellPosition(i,e,t));const n=this.getters.expandZone(i,en({col:e,row:t}));return this.processEvent({type:"ZonesSelected",anchor:{zone:n,cell:{col:e,row:t}},mode:"newAnchor"})}resizeAnchorZone(e,t=1){if("end"!==t&&t<=0)return new fn(84);const i=this.getters.getActiveSheetId(),n=this.anchor,{col:o,row:s}=n.cell,{left:r,right:a,top:l,bottom:c}=n.zone,h=this.getStartingPosition(e);let[d,u]=this.deltaToTarget(h,e,t);if(0===d&&0===u)return fn.Success;let g=n.zone;const p=e=>{e=Ji(e);const{left:t,right:n,top:o,bottom:s}=this.getters.expandZone(i,e);return{left:Math.max(0,t),right:Math.min(this.getters.getNumberCols(i)-1,n),top:Math.max(0,o),bottom:Math.min(this.getters.getNumberRows(i)-1,s)}},{cell:m,zone:f}=this.getReferenceAnchor(),{col:v,row:b}=m;let S=0;for(;null!==g;){if(S++,d<0){const e=this.getNextAvailableCol(d,a-(S-1),b);g=f.right<=a-S?p({top:l,left:r,bottom:c,right:e}):null}if(d>0){const e=this.getNextAvailableCol(d,r+(S-1),b);g=r+S<=f.left?p({top:l,left:e,bottom:c,right:a}):null}if(u<0){const e=this.getNextAvailableRow(u,v,c-(S-1));g=f.bottom<=c-S?p({top:l,left:r,bottom:e,right:a}):null}if(u>0){const e=this.getNextAvailableRow(u,v,l+(S-1));g=l+S<=f.top?p({top:e,left:r,bottom:c,right:a}):null}if(g=g?Ji(g):g,g&&!Bi(g,n.zone))return this.processEvent({type:"ZonesSelected",mode:"updateAnchor",anchor:{zone:g,cell:{col:o,row:s}}})}g=p(Vi({top:s,bottom:s,left:o,right:o},Ji({top:this.getNextAvailableRow(u,v,l),left:this.getNextAvailableCol(d,r,b),bottom:this.getNextAvailableRow(u,v,c),right:this.getNextAvailableCol(d,a,b)})));const C={zone:g,cell:{col:o,row:s}};return this.processEvent({type:"ZonesSelected",anchor:C,mode:"updateAnchor"})}selectColumn(e,t){const i=this.getters.getActiveSheetId(),n=this.getters.getNumberRows(i)-1;let o={left:e,right:e,top:0,bottom:n};const s=this.getters.findFirstVisibleColRowIndex(i,"ROW");let r,a;switch(t){case"overrideSelection":case"newAnchor":r=e,a=s;break;case"updateAnchor":({col:r,row:a}=this.anchor.cell),o=Vi(o,{left:r,right:r,top:s,bottom:n})}return this.processEvent({type:"HeadersSelected",anchor:{zone:o,cell:{col:r,row:a}},mode:t})}selectRow(e,t){const i=this.getters.getActiveSheetId(),n=this.getters.getNumberCols(i)-1;let o={top:e,bottom:e,left:0,right:n};const s=this.getters.findFirstVisibleColRowIndex(i,"COL");let r,a;switch(t){case"overrideSelection":case"newAnchor":r=s,a=e;break;case"updateAnchor":({col:r,row:a}=this.anchor.cell),o=Vi(o,{left:s,right:n,top:a,bottom:a})}return this.processEvent({type:"HeadersSelected",anchor:{zone:o,cell:{col:r,row:a}},mode:t})}loopSelection(){const e=this.getters.getActiveSheetId(),t=this.anchor,i=e=>{for(const t of $e(e.left,e.right+1)){if(!this.isCellEmpty({col:t,row:e.top-1}))return{...e,top:e.top-1};if(!this.isCellEmpty({col:t,row:e.bottom+1}))return{...e,bottom:e.bottom+1}}for(const t of $e(e.top,e.bottom+1)){if(!this.isCellEmpty({col:e.left-1,row:t}))return{...e,left:e.left-1};if(!this.isCellEmpty({col:e.right+1,row:t}))return{...e,right:e.right+1}}return e};if(Bi(this.anchor.zone,this.getters.getSheetZone(e)))return this.selectZone({...t,zone:en(t.cell)});let n=!1,o=!1,s=t.zone;do{o=o||n,n=!1;const e=i(s);Bi(s,e)||(n=!0,s=e)}while(n);return o?this.selectZone({...t,zone:s}):this.selectAll()}selectAll(){const e=this.getters.getActiveSheetId(),t={left:0,top:0,bottom:this.getters.getNumberRows(e)-1,right:this.getters.getNumberCols(e)-1};return this.processEvent({type:"HeadersSelected",mode:"overrideSelection",anchor:{zone:t,cell:this.anchor.cell}})}isListening(e){return this.stream.isListening(e)}processEvent(e){const t={...e,previousAnchor:Ae(this.anchor)},i=this.checkEventAnchorZone(t);return 0!==i?new fn(i):(this.anchor=t.anchor,this.stream.send(t),fn.Success)}checkEventAnchorZone(e){return this.checkAnchorZone(e.anchor)}checkAnchorZone(e){const{cell:t,zone:i}=e;if(!Wi(t.col,t.row,i))return 16;const{left:n,right:o,top:s,bottom:r}=i,a=this.getters.getActiveSheetId(),l=this.getters.findVisibleHeader(a,"COL",n,o);return void 0===this.getters.findVisibleHeader(a,"ROW",s,r)||void 0===l?17:0}checkAnchorZoneOrThrow(e){if(16===this.checkAnchorZone(e))throw new Error(o("The provided anchor is invalid. The cell must be part of the zone."))}getNextAvailablePosition(e,t=1){const{col:i,row:n}=this.anchor.cell,o=this.deltaToTarget({col:i,row:n},e,t);return{col:this.getNextAvailableCol(o[0],i,n),row:this.getNextAvailableRow(o[1],i,n)}}getNextAvailableCol(e,t,i){const n=this.getters.getActiveSheetId(),o={col:t,row:i};return this.getNextAvailableHeader(e,"COL",t,o,(e=>this.getters.isInSameMerge(n,t,i,e,i)))}getNextAvailableRow(e,t,i){const n=this.getters.getActiveSheetId(),o={col:t,row:i};return this.getNextAvailableHeader(e,"ROW",i,o,(e=>this.getters.isInSameMerge(n,t,i,t,e)))}getNextAvailableHeader(e,t,i,n,o){const s=this.getters.getActiveSheetId();if(0===e)return i;const r=Math.sign(e);let a=i+e;for(;o(a);)a+=r;for(;this.getters.isHeaderHidden(s,t,a);)a+=r;return a<0||a>this.getters.getNumberHeaders(s,t)-1?this.getters.isHeaderHidden(s,t,i)?this.getNextAvailableHeader(-r,t,i,n,o):i:a}getReferenceAnchor(){const e=this.getters.getActiveSheetId(),t=this.anchor,{left:i,right:n,top:o,bottom:s}=t.zone,{col:r,row:a}=t.cell,l=this.getters.isColHidden(e,r)&&this.getters.findVisibleHeader(e,"COL",i,n)||r,c=this.getters.isRowHidden(e,a)&&this.getters.findVisibleHeader(e,"ROW",o,s)||a;return{cell:{col:l,row:c},zone:this.getters.expandZone(e,{left:l,right:l,top:c,bottom:c})}}deltaToTarget(e,t,i){switch(t){case"up":return"end"!==i?[0,-i]:[0,this.getEndOfCluster(e,"rows",-1)-e.row];case"down":return"end"!==i?[0,i]:[0,this.getEndOfCluster(e,"rows",1)-e.row];case"left":return"end"!==i?[-i,0]:[this.getEndOfCluster(e,"cols",-1)-e.col,0];case"right":return"end"!==i?[i,0]:[this.getEndOfCluster(e,"cols",1)-e.col,0]}}getStartingPosition(e){let{col:t,row:i}=this.getPosition();const n=this.anchor.zone;switch(e){case"down":case"up":i=i===n.top?n.bottom:n.top;break;case"left":case"right":t=t===n.right?n.left:n.right}return{col:t,row:i}}getEndOfCluster(e,t,i){const n=this.getters.getActiveSheet();let o=e;const s=this.getNextCellPosition(e,t,i);let r=this.isCellEmpty(o,n.id)||this.isCellEmpty(s,n.id)?"nextCluster":"endOfCluster";for(;;){const e=this.getNextCellPosition(o,t,i);if(o.col===e.col&&o.row===e.row)break;const s=this.isCellEmpty(e,n.id);if("endOfCluster"===r&&s)break;if("nextCluster"===r&&!s){o=e;break}o=e}return"cols"===t?o.col:o.row}isCellEmpty({col:e,row:t},i=this.getters.getActiveSheetId()){const n=this.getters.getMainCellPosition(i,e,t),o=this.getters.getCell(i,n.col,n.row);return!o||o.isEmpty()}getNextCellPosition(e,t,i){const n="cols"===t?"col":"row",o={...e},s="cols"===t?this.getNextAvailableCol(i,o.col,o.row):this.getNextAvailableRow(i,o.col,o.row);return o[n]=s,{col:o.col,row:o.row}}getPosition(){return{...this.anchor.cell}}}class zb{constructor(){this.changes=[],this.commands=[]}recordChanges(e){return this.changes=[],this.commands=[],e(),{changes:this.changes,commands:this.commands}}addCommand(e){this.commands.push(e)}addChange(...e){const t=e.pop();let i=e[0],n=e[e.length-1];const o=e.length-2;for(let t=1;t<=o;t++){const n=e[t];if(void 0===i[n]){const o=e[t+1];i[n]=Ab(o)}i=i[n]}i[n]!==t&&(this.changes.push({path:e,before:i[n],after:t}),void 0===t?delete i[n]:i[n]=t)}}const Bb=17781237,Hb=88853993;function Wb(e,t,i){const n=[["xmlns:r",Jp],["xmlns:a",Yp],["xmlns:c",Xp]],o=Gb({backgroundColor:e.data.backgroundColor,line:{color:"000000"}});let s=kf``;e.data.title&&(s=kf`
|
|
1995
|
+
`;class Ib extends t.Component{constructor(){super(...arguments),this.isViewportTooSmall=!1}getStyle(){return this.env.isDashboard()?"grid-template-rows: auto;":"grid-template-rows: 63px auto 37px"}setup(){var e,i;null===(i=(e=this.props).exposeSpreadsheet)||void 0===i||i.call(e,this),this.model=this.props.model,this.sidePanel=t.useState({isOpen:!1,panelProps:{}}),this.composer=t.useState({topBarFocus:"inactive",gridFocusMode:"inactive"}),this.keyDownMapping={"CTRL+H":()=>this.toggleSidePanel("FindAndReplace",{}),"CTRL+F":()=>this.toggleSidePanel("FindAndReplace",{})},t.useSubEnv({model:this.model,isDashboard:()=>this.model.getters.isDashboard(),openSidePanel:this.openSidePanel.bind(this),toggleSidePanel:this.toggleSidePanel.bind(this),_t:Ib._t,clipboard:navigator.clipboard,focusableElement:new bb}),t.useExternalListener(window,"resize",(()=>this.render(!0))),t.useExternalListener(window,"beforeunload",this.unbindModelEvents.bind(this)),t.useExternalListener(document.body,"wheel",(()=>{})),this.bindModelEvents(),t.onMounted((()=>{this.checkViewportSize()})),t.onWillUnmount((()=>this.unbindModelEvents())),t.onPatched((()=>{this.checkViewportSize()}))}get focusTopBarComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.topBarFocus}get focusGridComposer(){return"inactive"===this.model.getters.getEditionMode()?"inactive":this.composer.gridFocusMode}bindModelEvents(){this.model.on("update",this,(()=>this.render(!0))),this.model.on("notify-ui",this,this.onNotifyUI)}unbindModelEvents(){this.model.off("update",this),this.model.off("notify-ui",this)}checkViewportSize(){const{xRatio:e,yRatio:t}=this.env.model.getters.getFrozenSheetViewRatio(this.env.model.getters.getActiveSheetId());if(t>.85||e>.85){if(this.isViewportTooSmall)return;this.env.notifyUser({text:s("The current window is too small to display this sheet properly. Consider resizing your browser window or adjusting frozen rows and columns."),tag:"viewportTooSmall"}),this.isViewportTooSmall=!0}else this.isViewportTooSmall=!1}onNotifyUI(e){if("ERROR"===e.type)this.env.raiseError(e.text)}openSidePanel(e,t){this.sidePanel.component=e,this.sidePanel.panelProps=t,this.sidePanel.isOpen=!0}closeSidePanel(){this.sidePanel.isOpen=!1,this.focusGrid()}toggleSidePanel(e,t){this.sidePanel.isOpen&&e===this.sidePanel.component?(this.sidePanel.isOpen=!1,this.focusGrid()):this.openSidePanel(e,t)}focusGrid(){if(!this._focusGrid)throw new Error("_focusGrid should be exposed by the grid component");this._focusGrid()}save(){var e,t;null===(t=(e=this.props).onContentSaved)||void 0===t||t.call(e,this.model.exportData())}onKeydown(e){let t="";zn(e)&&(t+="CTRL+"),t+=e.key.toUpperCase();let i=this.keyDownMapping[t];if(i)return e.preventDefault(),e.stopPropagation(),void i()}onTopBarComposerFocused(e){this.model.getters.isReadonly()||(this.model.dispatch("UNFOCUS_SELECTION_INPUT"),this.composer.topBarFocus="contentFocus",this.composer.gridFocusMode="inactive",this.setComposerContent({selection:e}))}onGridComposerContentFocused(e){this.model.getters.isReadonly()||(this.model.dispatch("UNFOCUS_SELECTION_INPUT"),this.composer.topBarFocus="inactive",this.composer.gridFocusMode="contentFocus",this.setComposerContent({selection:e}))}onGridComposerCellFocused(e,t){this.model.getters.isReadonly()||(this.model.dispatch("UNFOCUS_SELECTION_INPUT"),this.composer.topBarFocus="inactive",this.composer.gridFocusMode="cellFocus",this.setComposerContent({content:e,selection:t}||{}))}setComposerContent({content:e,selection:t}){"inactive"===this.model.getters.getEditionMode()?this.model.dispatch("START_EDITION",{text:e,selection:t}):e&&this.model.dispatch("SET_CURRENT_CONTENT",{content:e,selection:t})}get gridHeight(){const{height:e}=this.env.model.getters.getSheetViewDimension();return e}}Ib.template="o-spreadsheet-Spreadsheet",Ib.components={TopBar:Rb,Grid:Mp,BottomBar:Sb,SidePanel:Eb,SpreadsheetDashboard:Cb},Ib._t=e=>e;class Tb{constructor(){this.listeners=[]}sendMessage(e){for(const{callback:t}of this.listeners)t(e)}onNewMessage(e,t){this.listeners.push({id:e,callback:t})}leave(e){this.listeners=this.listeners.filter((t=>t.id!==e))}}function Ab(e){return so.get(e.type)(e)}function Nb(e){if("string"==typeof e)return{};if("number"==typeof e)return[];throw new Error("Cannot create new node")}class Ob{constructor(e,t=[]){this.buildTransformation=e,this.operations=t}getOperations(){return this.operations}getOperation(e){const t=this.operations.find((t=>t.id===e));if(!t)throw new Error(`Operation ${e} not found`);return t}getLastOperationId(){var e;return null===(e=this.operations[this.operations.length-1])||void 0===e?void 0:e.id}getFirstOperationAmong(e,t){for(const i of this.operations){if(i.id===e)return e;if(i.id===t)return t}throw new Error(`Operation ${e} and ${t} not found`)}contains(e){return!!this.operations.find((t=>t.id===e))}prepend(e){const t=this.buildTransformation.with(e.data);this.operations=[e,...this.operations.map((e=>e.transformed(t)))]}insert(e,t){const i=this.buildTransformation.with(e.data),{before:n,operation:o,after:s}=this.locateOperation(t);this.operations=[...n,o,e,...s.map((e=>e.transformed(i)))]}append(e){this.operations.push(e)}appendBranch(e){this.operations=this.operations.concat(e.operations)}fork(e){const{after:t}=this.locateOperation(e);return new Ob(this.buildTransformation,t)}transform(e){this.operations=this.operations.map((t=>t.transformed(e)))}cutBefore(e){this.operations=this.locateOperation(e).before}cutAfter(e){const{before:t,operation:i}=this.locateOperation(e);this.operations=t.concat([i])}locateOperation(e){const t=this.operations.findIndex((t=>t.id===e));if(-1===t)throw new Error(`Operation ${e} not found`);return{before:this.operations.slice(0,t),operation:this.operations[t],after:this.operations.slice(t+1)}}}class Mb{constructor(e,t){this.id=e,this.data=t}transformed(e){return new _b(this.id,tt((()=>e(this.data))))}}class _b{constructor(e,t){this.id=e,this.lazyData=t}get data(){return this.lazyData()}transformed(e){return new _b(this.id,this.lazyData.map(e))}}class Fb{constructor(e){this.operations=e}[Symbol.iterator](){return this.operations[Symbol.iterator]()}stopWith(e){return new Fb(function*(e,t){for(const i of e)if(yield i,i.operation.id===t)return}(this.operations,e))}stopBefore(e){return new Fb(function*(e,t){for(const i of e){if(i.operation.id===t)return;yield i}}(this.operations,e))}startAfter(e){return new Fb(function*(e,t){let i=!0;for(const n of e)i||(yield n),n.operation.id===t&&(i=!1)}(this.operations,e))}}class Db{constructor(e,t){this.buildTransformation=e,this.branchingOperationIds=new Map,this.branches=[t]}getLastBranch(){return this.branches[this.branches.length-1]}execution(e){return new Fb(Pe(this._execution(e),this._execution(e)))}revertedExecution(e){return new Fb(Pe(this._revertedExecution(e),this._revertedExecution(e)))}insertOperationLast(e,t){var i;const n=e.getLastOperationId()||(null===(i=this.previousBranch(e))||void 0===i?void 0:i.getLastOperationId());e.append(t),n&&this.insertPrevious(e,t,n)}insertOperationAfter(e,t,i){e.insert(t,i),this.updateNextWith(e,t,i),this.insertPrevious(e,t,i)}undo(e,t){const i=this.buildTransformation.without(t.data),n=this.branchingOperationIds.get(e);this.branchingOperationIds.set(e,t.id);const o=e.fork(t.id);n&&this.branchingOperationIds.set(o,n),this.insertBranchAfter(e,o),this.transform(o,i)}redo(e){const t=this.nextBranch(e);if(!t)return;const i=this.nextBranch(t);this.removeBranchFromTree(t);const n=this.branchingOperationIds.get(t);n?this.branchingOperationIds.set(e,n):this.branchingOperationIds.delete(e),i&&this.rebaseUp(i)}drop(e){for(const t of this.branches)t.contains(e)&&t.cutBefore(e)}findOperation(e,t){for(const i of this.revertedExecution(e))if(i.operation.id===t)return i;throw new Error(`Operation ${t} not found`)}rebaseUp(e){const{previousBranch:t,branchingOperation:i}=this.findPreviousBranchingOperation(e);if(!t||!i)return;const n=this.buildTransformation.without(i.data),o=t.fork(i.id);this.branchingOperationIds.set(o,this.branchingOperationIds.get(e)),this.removeBranchFromTree(e),this.insertBranchAfter(t,o),o.transform(n);const s=this.nextBranch(o);s&&this.rebaseUp(s)}removeBranchFromTree(e){const t=this.branches.findIndex((t=>t===e));this.branches.splice(t,1)}insertBranchAfter(e,t){const i=this.branches.findIndex((t=>t===e));this.branches.splice(i+1,0,t)}updateNextWith(e,t,i){const n=this.branchingOperationIds.get(e),o=this.nextBranch(e);if(n&&o)if(e.getFirstOperationAmong(i,n)===n){const s=this.addToNextBranch(e,o,n,t,i);this.updateNextWith(o,s,i)}else{const e=this.buildTransformation.with(t.data);this.transform(o,e)}}addToNextBranch(e,t,i,n,o){let s=n;return o===i?(s=this.getTransformedOperation(e,i,n),t.prepend(s)):t.contains(o)?(s=this.getTransformedOperation(e,i,n),t.insert(s,o)):t.append(n),s}getTransformedOperation(e,t,i){const n=e.getOperation(t),o=this.buildTransformation.without(n.data);return i.transformed(o)}shouldExecute(e,t){return t.id!==this.branchingOperationIds.get(e)}transform(e,t){e.transform(t);const i=this.nextBranch(e);i&&this.transform(i,t)}insertPrevious(e,t,i){const{previousBranch:n,branchingOperation:o}=this.findPreviousBranchingOperation(e);if(!n||!o)return;const s=this.buildTransformation.with(o.data),r=e.fork(i);r.transform(s),n.cutAfter(i),n.appendBranch(r);const a=t.transformed(s);this.insertPrevious(n,a,i)}findPreviousBranchingOperation(e){const t=this.previousBranch(e);if(!t)return{previousBranch:void 0,branchingOperation:void 0};const i=this.branchingOperationIds.get(t);return i?{previousBranch:t,branchingOperation:t.getOperation(i)}:{previousBranch:void 0,branchingOperation:void 0}}nextBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t+1]}previousBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t-1]}*_revertedExecution(e){const t=this.branchingOperationIds.get(e);let i=!!t;const n=e.getOperations();for(let o=n.length-1;o>=0;o--){const s=n[o];s.id===t&&(i=!1),i||(yield{operation:s,branch:e,isCancelled:!this.shouldExecute(e,s)})}const o=this.previousBranch(e);yield*o?this._revertedExecution(o):[]}*_execution(e){for(const t of e.getOperations())if(yield{operation:t,branch:e,isCancelled:!this.shouldExecute(e,t)},t.id===this.branchingOperationIds.get(e)){const t=this.nextBranch(e);return void(yield*t?this._execution(t):[])}if(!this.branchingOperationIds.get(e)){const t=this.nextBranch(e);yield*t?this._execution(t):[]}}}class kb{constructor(e,t,i,n,o){this.applyOperation=t,this.revertOperation=i,this.buildEmpty=n,this.buildTransformation=o,this.HEAD_BRANCH=new Ob(this.buildTransformation),this.tree=new Db(o,this.HEAD_BRANCH);const s=new Mb(e,n(e));this.tree.insertOperationLast(this.HEAD_BRANCH,s),this.HEAD_OPERATION=s}get(e){return this.tree.findOperation(this.HEAD_BRANCH,e).operation.data}append(e,t){const i=new Mb(e,t),n=this.tree.getLastBranch();this.tree.insertOperationLast(n,i),this.HEAD_BRANCH=n,this.HEAD_OPERATION=i}insert(e,t,i){const n=new Mb(e,t);this.revertTo(i),this.tree.insertOperationAfter(this.HEAD_BRANCH,n,i),this.fastForward()}undo(e,t,i){const{branch:n,operation:o}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.undo(n,o),this.fastForward(),this.insert(t,this.buildEmpty(t),i)}redo(e,t,i){const{branch:n}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.redo(n),this.fastForward(),this.insert(t,this.buildEmpty(t),i)}rebase(e){const t=this.get(e),i=[...this.tree.execution(this.HEAD_BRANCH).startAfter(e)];this.revertBefore(e);const n=this.HEAD_OPERATION.id;this.tree.drop(e),this.insert(e,t,n);for(const{operation:e}of i)this.insert(e.id,e.data,this.HEAD_OPERATION.id)}revertBefore(e){const t=this.tree.revertedExecution(this.HEAD_BRANCH).stopWith(e);this.revert(t)}revertTo(e){const t=e?this.tree.revertedExecution(this.HEAD_BRANCH).stopBefore(e):this.tree.revertedExecution(this.HEAD_BRANCH);this.revert(t)}revert(e){for(const{next:t,operation:i,isCancelled:n}of e)n||this.revertOperation(i.data),t&&(this.HEAD_BRANCH=t.branch,this.HEAD_OPERATION=t.operation)}fastForward(){const e=this.HEAD_OPERATION?this.tree.execution(this.HEAD_BRANCH).startAfter(this.HEAD_OPERATION.id):this.tree.execution(this.HEAD_BRANCH);for(const{operation:t,branch:i,isCancelled:n}of e)n||this.applyOperation(t.data),this.HEAD_OPERATION=t,this.HEAD_BRANCH=i}}function $b(e,t,i){return new kb(e,(e=>{const n=e.commands.slice(),{changes:o}=t((()=>{for(const e of n)i(e)}));e.setChanges(o)}),(e=>function(e){for(const t of e.slice().reverse())for(let e=t.changes.length-1;e>=0;e--){Lb(t.changes[e],"before")}}([e])),(e=>new sb(e,"empty",[],[])),{with:e=>t=>new sb(t.id,t.clientId,nb(t.commands,e.commands)),without:e=>t=>new sb(t.id,t.clientId,nb(t.commands,e.commands.map(Ab).flat()))})}function Lb(e,t){let i=e.path[0];const n=e.path[e.path.length-1];for(let t=1;t<e.path.slice(0,-1).length;t++){const n=e.path[t];if(void 0===i[n]){const o=e.path[t+1];i[n]=Nb(o)}i=i[n]}void 0===e[t]?delete i[n]:i[n]=e[t]}class Pb extends t.EventBus{constructor(e,t){super(),this.dispatch=e,this.session=t,this.undoStack=[],this.redoStack=[],this.session.on("new-local-state-update",this,this.onNewLocalStateUpdate),this.session.on("revision-undone",this,(({commands:e})=>this.selectiveUndo(e))),this.session.on("revision-redone",this,(({commands:e})=>this.selectiveRedo(e))),this.session.on("snapshot",this,(()=>{this.undoStack=[],this.redoStack=[]}))}allowDispatch(e){switch(e.type){case"REQUEST_UNDO":if(!this.canUndo())return 6;break;case"REQUEST_REDO":if(!this.canRedo())return 7}return 0}beforeHandle(e){}handle(e){switch(e.type){case"REQUEST_UNDO":case"REQUEST_REDO":this.requestHistoryChange("REQUEST_UNDO"===e.type?"UNDO":"REDO")}}finalize(){}requestHistoryChange(e){const t="UNDO"===e?this.undoStack.pop():this.redoStack.pop();t&&("UNDO"===e?(this.session.undo(t),this.redoStack.push(t)):(this.session.redo(t),this.undoStack.push(t)))}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}onNewLocalStateUpdate({id:e}){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>99&&this.undoStack.shift()}selectiveUndo(e){this.dispatch("UNDO",{commands:e})}selectiveRedo(e){this.dispatch("REDO",{commands:e})}}class Ub{constructor(e){this.providers=[],this.getters=e}allowDispatch(e){return"MOVE_RANGES"===e.type?1===e.target.length?0:26:0}beforeHandle(e){}handle(e){switch(e.type){case"REMOVE_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",i="COL"===e.dimension?"right":"bottom",n="COL"===e.dimension?"columns":"rows";const o=[...e.elements];o.sort(((e,t)=>t-e));const s=Le(o);this.executeOnAllRanges((o=>{if(o.sheetId!==e.sheetId)return{changeType:"NONE"};let r=o,a="NONE";for(let e of s){const s=ct(e),l=lt(e);if(o.zone[t]<=s&&s<=o.zone[i]){const e=Math.min(o.zone[i],l)-s+1;a="RESIZE",r=this.createAdaptedRange(r,n,a,-e)}else if(o.zone[t]>=s&&o.zone[i]<=l)a="REMOVE",r=o.clone({...this.getInvalidRange()});else if(o.zone[t]<=l&&o.zone[i]>=l){const e=l-o.zone[t]+1;a="RESIZE",r=this.createAdaptedRange(r,n,a,-e),r=this.createAdaptedRange(r,n,"MOVE",-(o.zone[t]-s))}else s<o.zone[t]&&(a="MOVE",r=this.createAdaptedRange(r,n,a,-(l-s+1)))}return"NONE"!==a?{changeType:a,range:r}:{changeType:"NONE"}}),e.sheetId);break}case"ADD_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",i="COL"===e.dimension?"right":"bottom",n="COL"===e.dimension?"columns":"rows";this.executeOnAllRanges((o=>{if(o.sheetId!==e.sheetId)return{changeType:"NONE"};if("after"===e.position){if(o.zone[t]<=e.base&&e.base<o.zone[i])return{changeType:"RESIZE",range:this.createAdaptedRange(o,n,"RESIZE",e.quantity)};if(e.base<o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,n,"MOVE",e.quantity)}}else{if(o.zone[t]<e.base&&e.base<=o.zone[i])return{changeType:"RESIZE",range:this.createAdaptedRange(o,n,"RESIZE",e.quantity)};if(e.base<=o.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(o,n,"MOVE",e.quantity)}}return{changeType:"NONE"}}),e.sheetId);break}case"DELETE_SHEET":this.executeOnAllRanges((t=>{if(t.sheetId!==e.sheetId)return{changeType:"NONE"};const i=this.getters.getSheetName(e.sheetId);return{changeType:"REMOVE",range:t=t.clone({...this.getInvalidRange(),invalidSheetName:i})}}),e.sheetId);break;case"RENAME_SHEET":this.executeOnAllRanges((t=>{if(t.sheetId===e.sheetId)return{changeType:"CHANGE",range:t};if(Ai(t.invalidSheetName,e.name)){const i=void 0,n=e.sheetId;return{changeType:"CHANGE",range:t.clone({sheetId:n,invalidSheetName:i})}}return{changeType:"NONE"}}));break;case"MOVE_RANGES":{const t=e.target[0];this.executeOnAllRanges((i=>{if(i.sheetId!==e.sheetId||!Gi(i.zone,t))return{changeType:"NONE"};const n=e.targetSheetId,o=e.col-t.left,s=e.row-t.top,r=this.createAdaptedRange(i,"both","MOVE",[o,s]),a=e.sheetId!==n||r.prefixSheet;return{changeType:"MOVE",range:r.clone({sheetId:n,prefixSheet:a})}}));break}}}finalize(){}verifyRangeRemoved(e){return t=>{const i=e(t);return"NONE"===i.changeType||Di(i.range.zone)?i:{range:i.range,changeType:"REMOVE"}}}createAdaptedRange(e,t,i,n){const o=Ki(e.unboundedZone,t,i,n);return e.clone({zone:o})}executeOnAllRanges(e,t){const i=this.verifyRangeRemoved(e);for(const e of this.providers)e(i,t)}addRangeProvider(e){this.providers.push(e)}createAdaptedRanges(e,t,i,n){const o=e.map((e=>xi.fromRange(e,this.getters)));return o.map((e=>{if(!Di(e.zone))return e;const o=e.prefixSheet?e.sheetId:n,s={...e.unboundedZone,left:e.isFullRow&&!e.unboundedZone.hasHeader?e.unboundedZone.left:e.unboundedZone.left+(e.parts[0].colFixed?0:t),right:e.isFullRow?e.unboundedZone.right:e.unboundedZone.right+((e.parts[1]||e.parts[0]).colFixed?0:t),top:e.isFullCol&&!e.unboundedZone.hasHeader?e.unboundedZone.top:e.unboundedZone.top+(e.parts[0].rowFixed?0:i),bottom:e.isFullCol?e.unboundedZone.bottom:e.unboundedZone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:i)};return(e=e.clone({sheetId:o,zone:s})).orderZone(),e}))}getRangeFromSheetXC(e,t){if(!Ot.test(t)||!this.getters.tryGetSheet(e))return new xi({sheetId:"",zone:{left:-1,top:-1,right:-1,bottom:-1},parts:[],invalidXc:t,prefixSheet:!1},this.getters.getSheetSize);let i,n=t,o=!1;t.includes("!")&&(({xc:n,sheetName:i}=$t(t)),i&&(o=!0));const s=_i(n),r=xi.getRangeParts(n,s),a=i&&!this.getters.getSheetIdByName(i)?i:void 0,l=this.getters.getSheetIdByName(i)||e,c=new xi({prefixSheet:o,zone:s,sheetId:l,invalidSheetName:a,parts:r},this.getters.getSheetSize);return c.orderZone(),c}getSelectionRangeString(e,t){const i=xi.fromRange(e,this.getters),n=this.getters.expandZone(i.sheetId,i.zone),o=i.clone({zone:{...n,bottom:i.isFullCol?void 0:n.bottom,right:i.isFullRow?void 0:n.right}});return this.getRangeString(o,t)}getRangeString(e,t,i=!1){if(!e)return X;if(e.invalidXc)return e.invalidXc;if(!this.getters.tryGetSheet(e.sheetId))return X;if(e.zone.bottom-e.zone.top<0||e.zone.right-e.zone.left<0)return X;if(e.zone.left<0||e.zone.top<0)return X;const n=xi.fromRange(e,this.getters);let o=n.sheetId!==t||n.invalidSheetName||n.prefixSheet,s="";if(o&&(s=n.invalidSheetName?n.invalidSheetName:Oe(this.getters.getSheetName(n.sheetId))),o&&!s)return X;let r=this.getRangePartString(n,0,i);return n.parts&&2===n.parts.length&&(n.zone.top!==n.zone.bottom||n.zone.left!==n.zone.right||n.parts[0].rowFixed||n.parts[0].colFixed||n.parts[1].rowFixed||n.parts[1].colFixed)&&(r+=":",r+=this.getRangePartString(n,1,i)),`${o?s+"!":""}${r}`}getRangeDataFromXc(e,t){return this.getters.getRangeFromSheetXC(e,t).rangeData}getRangeDataFromZone(e,t){return{_sheetId:e,_zone:t}}getRangeFromRangeData(e){const t={prefixSheet:!1,zone:e._zone,sheetId:e._sheetId,invalidSheetName:void 0,parts:[{colFixed:!1,rowFixed:!1},{colFixed:!1,rowFixed:!1}]};return new xi(t,this.getters.getSheetSize)}getRangePartString(e,t,i=!1){var n,o;const s=e.parts&&(null===(n=e.parts[t])||void 0===n?void 0:n.colFixed)?"$":"",r=Lt(0===t?e.zone.left:e.zone.right),a=e.parts&&(null===(o=e.parts[t])||void 0===o?void 0:o.rowFixed)?"$":"",l=String(0===t?e.zone.top+1:e.zone.bottom+1);let c="";return c=e.isFullCol&&!i?0===t&&e.unboundedZone.hasHeader?s+r+a+l:s+r:e.isFullRow&&!i?0===t&&e.unboundedZone.hasHeader?s+r+a+l:a+l:s+r+a+l,c}getInvalidRange(){return{parts:[],prefixSheet:!1,zone:{left:-1,top:-1,right:-1,bottom:-1},sheetId:"",invalidXc:X}}}Ub.getters=["getRangeString","getSelectionRangeString","getRangeFromSheetXC","createAdaptedRanges","getRangeDataFromXc","getRangeDataFromZone","getRangeFromRangeData"];class Vb{constructor(){this.observers=[]}registerAsDefault(e,t){this.defaultSubscription={owner:e,callbacks:t},this.mainSubscription||(this.mainSubscription=this.defaultSubscription)}observe(e,t){this.observers.push({owner:e,callbacks:t})}capture(e,t){var i,n,o;if(this.observers.find((t=>t.owner===e)))throw new Error("You are already subscribed forever");(null===(i=this.mainSubscription)||void 0===i?void 0:i.owner)&&this.mainSubscription.owner!==e&&(null===(o=(n=this.mainSubscription.callbacks).release)||void 0===o||o.call(n)),this.mainSubscription={owner:e,callbacks:t}}release(e){var t;(null===(t=this.mainSubscription)||void 0===t?void 0:t.owner)!==e||this.observers.find((t=>t.owner===e))||(this.mainSubscription=this.defaultSubscription)}getBackToDefault(){var e,t,i;this.mainSubscription!==this.defaultSubscription&&(null===(i=null===(e=this.mainSubscription)||void 0===e?void 0:(t=e.callbacks).release)||void 0===i||i.call(t),this.mainSubscription=this.defaultSubscription)}isListening(e){var t;return(null===(t=this.mainSubscription)||void 0===t?void 0:t.owner)===e}send(e){var t;null===(t=this.mainSubscription)||void 0===t||t.callbacks.handleEvent(e),[...this.observers].forEach((t=>t.callbacks.handleEvent(e)))}}class zb{constructor(e){this.getters=e,this.stream=new Vb,this.anchor={cell:{col:0,row:0},zone:en({col:0,row:0})},this.defaultAnchor=this.anchor}capture(e,t,i){this.stream.capture(e,i),this.anchor=t}registerAsDefault(e,t,i){this.checkAnchorZoneOrThrow(t),this.stream.registerAsDefault(e,i),this.defaultAnchor=t,this.capture(e,t,i)}resetDefaultAnchor(e,t){this.checkAnchorZoneOrThrow(t),this.stream.isListening(e)&&(this.anchor=t),this.defaultAnchor=t}resetAnchor(e,t){this.checkAnchorZoneOrThrow(t),this.stream.isListening(e)&&(this.anchor=t)}observe(e,t){this.stream.observe(e,t)}release(e){this.stream.isListening(e)&&(this.stream.release(e),this.anchor=this.defaultAnchor)}getBackToDefault(){this.stream.getBackToDefault()}selectZone(e){const t=this.getters.getActiveSheetId();return e={...e,zone:this.getters.expandZone(t,e.zone)},this.processEvent({type:"ZonesSelected",anchor:e,mode:"overrideSelection"})}selectCell(e,t){const i=en({col:e,row:t});return this.selectZone({zone:i,cell:{col:e,row:t}})}moveAnchorCell(e,t=1){if("end"!==t&&t<=0)return new fn(84);const{col:i,row:n}=this.getNextAvailablePosition(e,t);return this.selectCell(i,n)}setAnchorCorner(e,t){const i=this.getters.getActiveSheetId(),{col:n,row:o}=this.anchor.cell,s={left:Math.min(n,e),top:Math.min(o,t),right:Math.max(n,e),bottom:Math.max(o,t)},r={zone:this.getters.expandZone(i,s),cell:{col:n,row:o}};return this.processEvent({type:"AlterZoneCorner",mode:"updateAnchor",anchor:r})}addCellToSelection(e,t){const i=this.getters.getActiveSheetId();({col:e,row:t}=this.getters.getMainCellPosition(i,e,t));const n=this.getters.expandZone(i,en({col:e,row:t}));return this.processEvent({type:"ZonesSelected",anchor:{zone:n,cell:{col:e,row:t}},mode:"newAnchor"})}resizeAnchorZone(e,t=1){if("end"!==t&&t<=0)return new fn(84);const i=this.getters.getActiveSheetId(),n=this.anchor,{col:o,row:s}=n.cell,{left:r,right:a,top:l,bottom:c}=n.zone,h=this.getStartingPosition(e);let[d,u]=this.deltaToTarget(h,e,t);if(0===d&&0===u)return fn.Success;let g=n.zone;const p=e=>{e=Ji(e);const{left:t,right:n,top:o,bottom:s}=this.getters.expandZone(i,e);return{left:Math.max(0,t),right:Math.min(this.getters.getNumberCols(i)-1,n),top:Math.max(0,o),bottom:Math.min(this.getters.getNumberRows(i)-1,s)}},{cell:m,zone:f}=this.getReferenceAnchor(),{col:v,row:b}=m;let S=0;for(;null!==g;){if(S++,d<0){const e=this.getNextAvailableCol(d,a-(S-1),b);g=f.right<=a-S?p({top:l,left:r,bottom:c,right:e}):null}if(d>0){const e=this.getNextAvailableCol(d,r+(S-1),b);g=r+S<=f.left?p({top:l,left:e,bottom:c,right:a}):null}if(u<0){const e=this.getNextAvailableRow(u,v,c-(S-1));g=f.bottom<=c-S?p({top:l,left:r,bottom:e,right:a}):null}if(u>0){const e=this.getNextAvailableRow(u,v,l+(S-1));g=l+S<=f.top?p({top:e,left:r,bottom:c,right:a}):null}if(g=g?Ji(g):g,g&&!Bi(g,n.zone))return this.processEvent({type:"ZonesSelected",mode:"updateAnchor",anchor:{zone:g,cell:{col:o,row:s}}})}g=p(Vi({top:s,bottom:s,left:o,right:o},Ji({top:this.getNextAvailableRow(u,v,l),left:this.getNextAvailableCol(d,r,b),bottom:this.getNextAvailableRow(u,v,c),right:this.getNextAvailableCol(d,a,b)})));const C={zone:g,cell:{col:o,row:s}};return this.processEvent({type:"ZonesSelected",anchor:C,mode:"updateAnchor"})}selectColumn(e,t){const i=this.getters.getActiveSheetId(),n=this.getters.getNumberRows(i)-1;let o={left:e,right:e,top:0,bottom:n};const s=this.getters.findFirstVisibleColRowIndex(i,"ROW");let r,a;switch(t){case"overrideSelection":case"newAnchor":r=e,a=s;break;case"updateAnchor":({col:r,row:a}=this.anchor.cell),o=Vi(o,{left:r,right:r,top:s,bottom:n})}return this.processEvent({type:"HeadersSelected",anchor:{zone:o,cell:{col:r,row:a}},mode:t})}selectRow(e,t){const i=this.getters.getActiveSheetId(),n=this.getters.getNumberCols(i)-1;let o={top:e,bottom:e,left:0,right:n};const s=this.getters.findFirstVisibleColRowIndex(i,"COL");let r,a;switch(t){case"overrideSelection":case"newAnchor":r=s,a=e;break;case"updateAnchor":({col:r,row:a}=this.anchor.cell),o=Vi(o,{left:s,right:n,top:a,bottom:a})}return this.processEvent({type:"HeadersSelected",anchor:{zone:o,cell:{col:r,row:a}},mode:t})}loopSelection(){const e=this.getters.getActiveSheetId(),t=this.anchor,i=e=>{for(const t of $e(e.left,e.right+1)){if(!this.isCellEmpty({col:t,row:e.top-1}))return{...e,top:e.top-1};if(!this.isCellEmpty({col:t,row:e.bottom+1}))return{...e,bottom:e.bottom+1}}for(const t of $e(e.top,e.bottom+1)){if(!this.isCellEmpty({col:e.left-1,row:t}))return{...e,left:e.left-1};if(!this.isCellEmpty({col:e.right+1,row:t}))return{...e,right:e.right+1}}return e};if(Bi(this.anchor.zone,this.getters.getSheetZone(e)))return this.selectZone({...t,zone:en(t.cell)});let n=!1,o=!1,s=t.zone;do{o=o||n,n=!1;const e=i(s);Bi(s,e)||(n=!0,s=e)}while(n);return o?this.selectZone({...t,zone:s}):this.selectAll()}selectAll(){const e=this.getters.getActiveSheetId(),t={left:0,top:0,bottom:this.getters.getNumberRows(e)-1,right:this.getters.getNumberCols(e)-1};return this.processEvent({type:"HeadersSelected",mode:"overrideSelection",anchor:{zone:t,cell:this.anchor.cell}})}isListening(e){return this.stream.isListening(e)}processEvent(e){const t={...e,previousAnchor:Ae(this.anchor)},i=this.checkEventAnchorZone(t);return 0!==i?new fn(i):(this.anchor=t.anchor,this.stream.send(t),fn.Success)}checkEventAnchorZone(e){return this.checkAnchorZone(e.anchor)}checkAnchorZone(e){const{cell:t,zone:i}=e;if(!Wi(t.col,t.row,i))return 16;const{left:n,right:o,top:s,bottom:r}=i,a=this.getters.getActiveSheetId(),l=this.getters.findVisibleHeader(a,"COL",n,o);return void 0===this.getters.findVisibleHeader(a,"ROW",s,r)||void 0===l?17:0}checkAnchorZoneOrThrow(e){if(16===this.checkAnchorZone(e))throw new Error(o("The provided anchor is invalid. The cell must be part of the zone."))}getNextAvailablePosition(e,t=1){const{col:i,row:n}=this.anchor.cell,o=this.deltaToTarget({col:i,row:n},e,t);return{col:this.getNextAvailableCol(o[0],i,n),row:this.getNextAvailableRow(o[1],i,n)}}getNextAvailableCol(e,t,i){const n=this.getters.getActiveSheetId(),o={col:t,row:i};return this.getNextAvailableHeader(e,"COL",t,o,(e=>this.getters.isInSameMerge(n,t,i,e,i)))}getNextAvailableRow(e,t,i){const n=this.getters.getActiveSheetId(),o={col:t,row:i};return this.getNextAvailableHeader(e,"ROW",i,o,(e=>this.getters.isInSameMerge(n,t,i,t,e)))}getNextAvailableHeader(e,t,i,n,o){const s=this.getters.getActiveSheetId();if(0===e)return i;const r=Math.sign(e);let a=i+e;for(;o(a);)a+=r;for(;this.getters.isHeaderHidden(s,t,a);)a+=r;return a<0||a>this.getters.getNumberHeaders(s,t)-1?this.getters.isHeaderHidden(s,t,i)?this.getNextAvailableHeader(-r,t,i,n,o):i:a}getReferenceAnchor(){const e=this.getters.getActiveSheetId(),t=this.anchor,{left:i,right:n,top:o,bottom:s}=t.zone,{col:r,row:a}=t.cell,l=this.getters.isColHidden(e,r)&&this.getters.findVisibleHeader(e,"COL",i,n)||r,c=this.getters.isRowHidden(e,a)&&this.getters.findVisibleHeader(e,"ROW",o,s)||a;return{cell:{col:l,row:c},zone:this.getters.expandZone(e,{left:l,right:l,top:c,bottom:c})}}deltaToTarget(e,t,i){switch(t){case"up":return"end"!==i?[0,-i]:[0,this.getEndOfCluster(e,"rows",-1)-e.row];case"down":return"end"!==i?[0,i]:[0,this.getEndOfCluster(e,"rows",1)-e.row];case"left":return"end"!==i?[-i,0]:[this.getEndOfCluster(e,"cols",-1)-e.col,0];case"right":return"end"!==i?[i,0]:[this.getEndOfCluster(e,"cols",1)-e.col,0]}}getStartingPosition(e){let{col:t,row:i}=this.getPosition();const n=this.anchor.zone;switch(e){case"down":case"up":i=i===n.top?n.bottom:n.top;break;case"left":case"right":t=t===n.right?n.left:n.right}return{col:t,row:i}}getEndOfCluster(e,t,i){const n=this.getters.getActiveSheet();let o=e;const s=this.getNextCellPosition(e,t,i);let r=this.isCellEmpty(o,n.id)||this.isCellEmpty(s,n.id)?"nextCluster":"endOfCluster";for(;;){const e=this.getNextCellPosition(o,t,i);if(o.col===e.col&&o.row===e.row)break;const s=this.isCellEmpty(e,n.id);if("endOfCluster"===r&&s)break;if("nextCluster"===r&&!s){o=e;break}o=e}return"cols"===t?o.col:o.row}isCellEmpty({col:e,row:t},i=this.getters.getActiveSheetId()){const n=this.getters.getMainCellPosition(i,e,t),o=this.getters.getCell(i,n.col,n.row);return!o||o.isEmpty()}getNextCellPosition(e,t,i){const n="cols"===t?"col":"row",o={...e},s="cols"===t?this.getNextAvailableCol(i,o.col,o.row):this.getNextAvailableRow(i,o.col,o.row);return o[n]=s,{col:o.col,row:o.row}}getPosition(){return{...this.anchor.cell}}}class Bb{constructor(){this.changes=[],this.commands=[]}recordChanges(e){return this.changes=[],this.commands=[],e(),{changes:this.changes,commands:this.commands}}addCommand(e){this.commands.push(e)}addChange(...e){const t=e.pop();let i=e[0],n=e[e.length-1];const o=e.length-2;for(let t=1;t<=o;t++){const n=e[t];if(void 0===i[n]){const o=e[t+1];i[n]=Nb(o)}i=i[n]}i[n]!==t&&(this.changes.push({path:e,before:i[n],after:t}),void 0===t?delete i[n]:i[n]=t)}}const Hb=17781237,Wb=88853993;function Gb(e,t,i){const n=[["xmlns:r",Jp],["xmlns:a",Yp],["xmlns:c",Xp]],o=qb({backgroundColor:e.data.backgroundColor,line:{color:"000000"}});let s=$f``;e.data.title&&(s=$f`
|
|
1996
1996
|
<c:title>
|
|
1997
|
-
${
|
|
1997
|
+
${jb(e.data.title,e.data.fontColor)}
|
|
1998
1998
|
<c:overlay val="0" />
|
|
1999
1999
|
</c:title>
|
|
2000
|
-
`);let r
|
|
2000
|
+
`);let r=$f``;switch(e.data.type){case"bar":r=function(e){const t=new xs,i=[];for(const[n,o]of Object.entries(e.dataSets)){const s=gs(t.next()),r=qb({backgroundColor:s,line:{color:s}});i.push($f`
|
|
2001
2001
|
<c:ser>
|
|
2002
2002
|
<c:idx val="${n}"/>
|
|
2003
2003
|
<c:order val="${n}"/>
|
|
2004
|
-
${o.label
|
|
2004
|
+
${o.label?$f`<c:tx>${Qb(o.label)}</c:tx>`:""}
|
|
2005
2005
|
${r}
|
|
2006
|
-
${e.labelRange
|
|
2006
|
+
${e.labelRange?$f`<c:cat>${Qb(e.labelRange)}</c:cat>`:""} <!-- x-coordinate values -->
|
|
2007
2007
|
<c:val> <!-- x-coordinate values -->
|
|
2008
|
-
${
|
|
2008
|
+
${Jb(o.range)}
|
|
2009
2009
|
</c:val>
|
|
2010
2010
|
</c:ser>
|
|
2011
|
-
`)}const n="left"===e.verticalAxisPosition?"l":"r",o=e.stacked?"stacked":"clustered",s=e.stacked?100:-20;return
|
|
2011
|
+
`)}const n="left"===e.verticalAxisPosition?"l":"r",o=e.stacked?"stacked":"clustered",s=e.stacked?100:-20;return $f`
|
|
2012
2012
|
<c:barChart>
|
|
2013
2013
|
<c:barDir val="col"/>
|
|
2014
2014
|
<c:grouping val="${o}"/>
|
|
@@ -2016,13 +2016,13 @@
|
|
|
2016
2016
|
<c:gapWidth val="70"/>
|
|
2017
2017
|
<!-- each data marker in the series does not have a different color -->
|
|
2018
2018
|
<c:varyColors val="0"/>
|
|
2019
|
-
${
|
|
2020
|
-
<c:axId val="${Bb}" />
|
|
2019
|
+
${kf(i)}
|
|
2021
2020
|
<c:axId val="${Hb}" />
|
|
2021
|
+
<c:axId val="${Wb}" />
|
|
2022
2022
|
</c:barChart>
|
|
2023
|
-
${
|
|
2024
|
-
${
|
|
2025
|
-
`}(e.data);break;case"line":r=function(e){const t=new xs,i=[];for(const[n,o]of Object.entries(e.dataSets)){const s=
|
|
2023
|
+
${Kb("b","c:catAx",Hb,Wb,{fontColor:e.fontColor})}
|
|
2024
|
+
${Kb(n,"c:valAx",Wb,Hb,{fontColor:e.fontColor})}
|
|
2025
|
+
`}(e.data);break;case"line":r=function(e){const t=new xs,i=[];for(const[n,o]of Object.entries(e.dataSets)){const s=qb({line:{width:2.5,style:"solid",color:gs(t.next())}});i.push($f`
|
|
2026
2026
|
<c:ser>
|
|
2027
2027
|
<c:idx val="${n}"/>
|
|
2028
2028
|
<c:order val="${n}"/>
|
|
@@ -2031,50 +2031,50 @@
|
|
|
2031
2031
|
<c:symbol val="circle" />
|
|
2032
2032
|
<c:size val="5"/>
|
|
2033
2033
|
</c:marker>
|
|
2034
|
-
${o.label
|
|
2034
|
+
${o.label?$f`<c:tx>${Qb(o.label)}</c:tx>`:""}
|
|
2035
2035
|
${s}
|
|
2036
|
-
${e.labelRange
|
|
2036
|
+
${e.labelRange?$f`<c:cat>${Qb(e.labelRange)}</c:cat>`:""} <!-- x-coordinate values -->
|
|
2037
2037
|
<c:val> <!-- x-coordinate values -->
|
|
2038
|
-
${
|
|
2038
|
+
${Jb(o.range)}
|
|
2039
2039
|
</c:val>
|
|
2040
2040
|
</c:ser>
|
|
2041
|
-
`)}const n="left"===e.verticalAxisPosition?"l":"r",o=e.stacked?"stacked":"standard";return
|
|
2041
|
+
`)}const n="left"===e.verticalAxisPosition?"l":"r",o=e.stacked?"stacked":"standard";return $f`
|
|
2042
2042
|
<c:lineChart>
|
|
2043
2043
|
<c:grouping val="${o}"/>
|
|
2044
2044
|
<!-- each data marker in the series does not have a different color -->
|
|
2045
2045
|
<c:varyColors val="0"/>
|
|
2046
|
-
${
|
|
2047
|
-
<c:axId val="${Bb}" />
|
|
2046
|
+
${kf(i)}
|
|
2048
2047
|
<c:axId val="${Hb}" />
|
|
2048
|
+
<c:axId val="${Wb}" />
|
|
2049
2049
|
</c:lineChart>
|
|
2050
|
-
${
|
|
2051
|
-
${
|
|
2052
|
-
`}(e.data);break;case"pie":r=function(e,t,i,{holeSize:n}={holeSize:50}){const o=new xs,s=lt(e.dataSets.map((e=>of(e.range,t,i)))),r=$e(0,s).map((()=>gs(o.next()))),a=[];for(const[n,o]of Object.entries(e.dataSets).reverse()){const s=of(o.range,t,i),l=[];for(const e of $e(0,s)){const t=
|
|
2050
|
+
${Kb("b","c:catAx",Hb,Wb,{fontColor:e.fontColor})}
|
|
2051
|
+
${Kb(n,"c:valAx",Wb,Hb,{fontColor:e.fontColor})}
|
|
2052
|
+
`}(e.data);break;case"pie":r=function(e,t,i,{holeSize:n}={holeSize:50}){const o=new xs,s=lt(e.dataSets.map((e=>of(e.range,t,i)))),r=$e(0,s).map((()=>gs(o.next()))),a=[];for(const[n,o]of Object.entries(e.dataSets).reverse()){const s=of(o.range,t,i),l=[];for(const e of $e(0,s)){const t=qb({backgroundColor:r[e],line:{color:"FFFFFF",width:1.5}});l.push($f`
|
|
2053
2053
|
<c:dPt>
|
|
2054
2054
|
<c:idx val="${e}"/>
|
|
2055
2055
|
${t}
|
|
2056
2056
|
</c:dPt>
|
|
2057
|
-
`)}a.push(
|
|
2057
|
+
`)}a.push($f`
|
|
2058
2058
|
<c:ser>
|
|
2059
2059
|
<c:idx val="${n}"/>
|
|
2060
2060
|
<c:order val="${n}"/>
|
|
2061
|
-
${o.label
|
|
2062
|
-
${
|
|
2063
|
-
${
|
|
2064
|
-
${e.labelRange
|
|
2061
|
+
${o.label?$f`<c:tx>${Qb(o.label)}</c:tx>`:""}
|
|
2062
|
+
${kf(l)}
|
|
2063
|
+
${Xb({showLeaderLines:!0})}
|
|
2064
|
+
${e.labelRange?$f`<c:cat>${Qb(e.labelRange)}</c:cat>`:""}
|
|
2065
2065
|
<c:val>
|
|
2066
|
-
${
|
|
2066
|
+
${Jb(o.range)}
|
|
2067
2067
|
</c:val>
|
|
2068
2068
|
</c:ser>
|
|
2069
|
-
`)}return
|
|
2069
|
+
`)}return $f`
|
|
2070
2070
|
<c:doughnutChart>
|
|
2071
2071
|
<c:varyColors val="1" />
|
|
2072
2072
|
<c:holeSize val="${n}" />
|
|
2073
|
-
${
|
|
2074
|
-
${
|
|
2073
|
+
${Xb()}
|
|
2074
|
+
${kf(a)}
|
|
2075
2075
|
</c:doughnutChart>
|
|
2076
|
-
`}(e.data,t,i,{holeSize:0})}let a="t";switch(e.data.legendPosition){case"bottom":a="b";break;case"left":a="l";break;case"right":a="r";break;case"top":a="t"}const l=e.data.fontColor,c
|
|
2077
|
-
<c:chartSpace ${
|
|
2076
|
+
`}(e.data,t,i,{holeSize:0})}let a="t";switch(e.data.legendPosition){case"bottom":a="b";break;case"left":a="l";break;case"right":a="r";break;case"top":a="t"}const l=e.data.fontColor,c=$f`
|
|
2077
|
+
<c:chartSpace ${Mf(n)}>
|
|
2078
2078
|
<c:roundedCorners val="0" />
|
|
2079
2079
|
<!-- <manualLayout/> to manually position the chart in the figure container -->
|
|
2080
2080
|
${o}
|
|
@@ -2085,32 +2085,32 @@
|
|
|
2085
2085
|
<!-- how the chart element is placed on the chart -->
|
|
2086
2086
|
<c:layout />
|
|
2087
2087
|
${r}
|
|
2088
|
-
${
|
|
2088
|
+
${qb({backgroundColor:e.data.backgroundColor})}
|
|
2089
2089
|
</c:plotArea>
|
|
2090
|
-
${function(e,t){return
|
|
2090
|
+
${function(e,t){return $f`
|
|
2091
2091
|
<c:legend>
|
|
2092
2092
|
<c:legendPos val="${e}"/>
|
|
2093
2093
|
<c:overlay val="0"/>
|
|
2094
|
-
${
|
|
2094
|
+
${Yb(10,t)}
|
|
2095
2095
|
</c:legend>
|
|
2096
2096
|
`}(a,l)}
|
|
2097
2097
|
</c:chart>
|
|
2098
2098
|
</c:chartSpace>
|
|
2099
|
-
`;return
|
|
2099
|
+
`;return _f(c)}function qb(e){return $f`
|
|
2100
2100
|
<c:spPr>
|
|
2101
|
-
${e.backgroundColor?
|
|
2102
|
-
${e.line?function(e){const t=[["cmpd","sng"]];e.width&&t.push(["w",nf(e.width)]);const i=e.style
|
|
2103
|
-
<a:ln ${
|
|
2104
|
-
${
|
|
2101
|
+
${e.backgroundColor?Zb(e.backgroundColor):""}
|
|
2102
|
+
${e.line?function(e){const t=[["cmpd","sng"]];e.width&&t.push(["w",nf(e.width)]);const i=e.style?$f`<a:prstDash val="${e.style}"/>`:"";return $f`
|
|
2103
|
+
<a:ln ${Mf(t)}>
|
|
2104
|
+
${Zb(e.color)}
|
|
2105
2105
|
${i}
|
|
2106
2106
|
</a:ln>
|
|
2107
2107
|
`}(e.line):""}
|
|
2108
2108
|
</c:spPr>
|
|
2109
|
-
`}function
|
|
2109
|
+
`}function Zb(e){return $f`
|
|
2110
2110
|
<a:solidFill>
|
|
2111
2111
|
<a:srgbClr val="${e}"/>
|
|
2112
2112
|
</a:solidFill>
|
|
2113
|
-
`}function
|
|
2113
|
+
`}function jb(e,t="000000",i=22){return $f`
|
|
2114
2114
|
<c:tx>
|
|
2115
2115
|
<c:rich>
|
|
2116
2116
|
<a:bodyPr />
|
|
@@ -2118,7 +2118,7 @@
|
|
|
2118
2118
|
<a:p>
|
|
2119
2119
|
<a:pPr lvl="0">
|
|
2120
2120
|
<a:defRPr b="0">
|
|
2121
|
-
${
|
|
2121
|
+
${Zb(t)}
|
|
2122
2122
|
<a:latin typeface="+mn-lt"/>
|
|
2123
2123
|
</a:defRPr>
|
|
2124
2124
|
</a:pPr>
|
|
@@ -2129,20 +2129,20 @@
|
|
|
2129
2129
|
</a:p>
|
|
2130
2130
|
</c:rich>
|
|
2131
2131
|
</c:tx>
|
|
2132
|
-
`}function
|
|
2132
|
+
`}function Yb(e=12,t="000000",i=!1,n=!1){return $f`
|
|
2133
2133
|
<c:txPr>
|
|
2134
2134
|
<a:bodyPr/>
|
|
2135
2135
|
<a:lstStyle/>
|
|
2136
2136
|
<a:p>
|
|
2137
2137
|
<a:pPr lvl="0">
|
|
2138
|
-
<a:defRPr ${
|
|
2139
|
-
${
|
|
2138
|
+
<a:defRPr ${Mf([["b",i?"1":"0"],["i",n?"1":"0"],["sz",100*e]])}>
|
|
2139
|
+
${Zb(t)}
|
|
2140
2140
|
<a:latin typeface="+mn-lt"/>
|
|
2141
2141
|
</a:defRPr>
|
|
2142
2142
|
</a:pPr>
|
|
2143
2143
|
</a:p>
|
|
2144
2144
|
</c:txPr>
|
|
2145
|
-
`}function
|
|
2145
|
+
`}function Xb({showLeaderLines:e}={showLeaderLines:!1}){return $f`
|
|
2146
2146
|
<dLbls>
|
|
2147
2147
|
<c:showLegendKey val="0"/>
|
|
2148
2148
|
<c:showVal val="0"/>
|
|
@@ -2152,7 +2152,7 @@
|
|
|
2152
2152
|
<c:showBubbleSize val="0"/>
|
|
2153
2153
|
<c:showLeaderLines val="${e?"1":"0"}"/>
|
|
2154
2154
|
</dLbls>
|
|
2155
|
-
`}function
|
|
2155
|
+
`}function Kb(e,t,i,n,{fontColor:o}){return $f`
|
|
2156
2156
|
<${t}>
|
|
2157
2157
|
<c:axId val="${i}"/>
|
|
2158
2158
|
<c:crossAx val="${n}"/> <!-- reference to the other axe of the chart -->
|
|
@@ -2161,58 +2161,58 @@
|
|
|
2161
2161
|
<c:orientation val="minMax" />
|
|
2162
2162
|
</c:scaling>
|
|
2163
2163
|
<c:axPos val="${e}" />
|
|
2164
|
-
${function(e="B7B7B7"){return
|
|
2164
|
+
${function(e="B7B7B7"){return $f`
|
|
2165
2165
|
<c:majorGridlines>
|
|
2166
|
-
${
|
|
2166
|
+
${qb({line:{color:e}})}
|
|
2167
2167
|
</c:majorGridlines>
|
|
2168
2168
|
`}()}
|
|
2169
2169
|
<c:majorTickMark val="out" />
|
|
2170
2170
|
<c:minorTickMark val="none" />
|
|
2171
2171
|
<c:numFmt formatCode="General" sourceLinked="1" />
|
|
2172
2172
|
<c:title>
|
|
2173
|
-
${
|
|
2173
|
+
${jb("")}
|
|
2174
2174
|
</c:title>
|
|
2175
|
-
${
|
|
2175
|
+
${Yb(10,o)}
|
|
2176
2176
|
</${t}>
|
|
2177
2177
|
<!-- <tickLblPos/> omitted -->
|
|
2178
|
-
`}function
|
|
2178
|
+
`}function Qb(e){return $f`
|
|
2179
2179
|
<c:strRef>
|
|
2180
2180
|
<c:f>${e}</c:f>
|
|
2181
2181
|
</c:strRef>
|
|
2182
|
-
`}function
|
|
2182
|
+
`}function Jb(e){return $f`
|
|
2183
2183
|
<c:numRef>
|
|
2184
2184
|
<c:f>${e}</c:f>
|
|
2185
2185
|
<c:numCache />
|
|
2186
2186
|
</c:numRef>
|
|
2187
|
-
`}function
|
|
2187
|
+
`}function eS(e){const t=e.content,i=Yu.content,n=[];let o=$f``;const s=Ju(t).filter((e=>"FUNCTION"===e.type)).every((e=>i[e.value.toUpperCase()].isExported)),r=function(e){switch(typeof e){case"boolean":return"b";case"string":return"str";case"number":return"n"}}(e.value),l=(c=e.value)===a.InvalidReference?"#REF!":c;var c;if(s){return o=$f`
|
|
2188
2188
|
<f>
|
|
2189
|
-
${
|
|
2189
|
+
${iS(t)}
|
|
2190
2190
|
</f>
|
|
2191
|
-
${
|
|
2192
|
-
`,n.push(["t",r]),{attrs:n,node:o}}if(""!==l)return n.push(["t",r]),o
|
|
2191
|
+
${$f`<v>${l}</v>`}
|
|
2192
|
+
`,n.push(["t",r]),{attrs:n,node:o}}if(""!==l)return n.push(["t",r]),o=$f`<v>${l}</v>`,{attrs:n,node:o}}function tS(e,t,i=!1){let n=e;const o=[];return!i&&["TRUE","FALSE"].includes(n.trim())?(n="TRUE"===n?"1":"0",o.push(["t","b"])):!i&&Ci(n)||(n=Jm(e,t),o.push(["t","s"])),{attrs:o,node:$f`<v>${n}</v>`}}function iS(e){let t;"="===e[0]&&(e=e.slice(1));try{t=Ag(e)}catch(t){return e}return t=Og(t,"STRING",nS),t=Og(t,"FUNCALL",(e=>(e=function(e){const t=e.value.toUpperCase(),i=e.args,n=am[t];if(n){const o=Yu.content[t].args.filter((e=>!e.optional)),s=o.length-e.args.length;if(s)for(let t=e.args.length;t<o.length;t++){const e=n[t-s];i.push({type:e.type,value:e.value})}}return{...e,args:i}}(e=function(e){const t=e.value.toUpperCase();return{...e,value:lm.includes(t)?`_xlfn.${t}`:t}}(e={...e,value:e.value.toUpperCase()})),e))),t=Og(t,"REFERENCE",(e=>e.value===a.InvalidReference?{...e,value:"#REF!"}:e)),t?Mg(t):e}function nS(e){const t=e.value.replace(new RegExp('"',"g"),""),i=ve(t);if(i){let n=[];return(t.match(ge)||t.match(pe))&&n.push("yyyy-mm-dd"),t.match(me)&&n.push("hh:mm:ss"),{...e,value:Qt(i.value,n.join(" "))}}return{...e,value:e.value.replace(/\\"/g,'""')}}function oS(e,t){const i=[];for(const n of t)switch(n.rule.type){case"CellIsRule":i.push(sS(n,n.rule,e));break;case"ColorScaleRule":i.push(rS(n,n.rule));break;case"IconSetRule":i.push(aS(n,n.rule));break;default:console.warn(`Conditional formatting ${n.rule.type} not implemented`)}return i}function sS(e,t,i){const n=lS(e),o=Zm(t.operator);n.push(...function(e){const t=Zm(e.operator);switch(e.operator){case"ContainsText":case"NotContains":case"BeginsWith":case"EndsWith":return[["type",t],["text",e.values[0]]];case"IsEmpty":case"IsNotEmpty":return[["type",t]];case"Equal":case"NotEqual":case"GreaterThan":case"GreaterThanOrEqual":case"LessThan":case"LessThanOrEqual":case"Between":case"NotBetween":return[["type","cellIs"]]}}(t),["operator",o]);const s=function(e,t){const i=e[0].split(":")[0],n=t.values;switch(t.operator){case"ContainsText":return[`NOT(ISERROR(SEARCH("${n[0]}",${i})))`];case"NotContains":return[`ISERROR(SEARCH("${n[0]}",${i}))`];case"BeginsWith":return[`LEFT(${i},LEN("${n[0]}"))="${n[0]}"`];case"EndsWith":return[`RIGHT(${i},LEN("${n[0]}"))="${n[0]}"`];case"IsEmpty":return[`LEN(TRIM(${i}))=0`];case"IsNotEmpty":return[`LEN(TRIM(${i}))>0`];case"Equal":case"NotEqual":case"GreaterThan":case"GreaterThanOrEqual":case"LessThan":case"LessThanOrEqual":return[n[0]];case"Between":case"NotBetween":return[n[0],n[1]]}}(e.ranges,t).map((e=>$f`<formula>${e}</formula>`)),r={font:{color:{rgb:t.style.textColor},bold:t.style.bold,italic:t.style.italic,strike:t.style.strikethrough,underline:t.style.underline}};return t.style.fillColor&&(r.fill={fgColor:{rgb:t.style.fillColor}}),n.push(["dxfId",Jm(r,i)]),$f`
|
|
2193
2193
|
<conditionalFormatting sqref="${e.ranges.join(" ")}">
|
|
2194
|
-
<cfRule ${
|
|
2195
|
-
${
|
|
2194
|
+
<cfRule ${Mf(n)}>
|
|
2195
|
+
${kf(s)}
|
|
2196
2196
|
</cfRule>
|
|
2197
2197
|
</conditionalFormatting>
|
|
2198
|
-
`}function
|
|
2198
|
+
`}function rS(e,t){const i=lS(e);i.push(["type","colorScale"]);const n=[];for(const o of e.ranges){const e=[],s=[];let r=!0;for(let i of["minimum","midpoint","maximum"]){const n=t[i];n&&("formula"!==n.type?(e.push(dS(n,i)),s.push([["rgb",gs(gt(n.color))]])):r=!1)}if(!r){console.warn("Conditional formats with formula rules are not supported at the moment. The rule is therefore skipped.");continue}const a=e.map((e=>$f`<cfvo ${Mf(e)}/>`)),l=s.map((e=>$f`<color ${Mf(e)}/>`));n.push($f`
|
|
2199
2199
|
<conditionalFormatting sqref="${o}">
|
|
2200
|
-
<cfRule ${
|
|
2200
|
+
<cfRule ${Mf(i)}>
|
|
2201
2201
|
<colorScale>
|
|
2202
|
-
${
|
|
2203
|
-
${
|
|
2202
|
+
${kf(a)}
|
|
2203
|
+
${kf(l)}
|
|
2204
2204
|
</colorScale>
|
|
2205
2205
|
</cfRule>
|
|
2206
2206
|
</conditionalFormatting>
|
|
2207
|
-
`)}return
|
|
2207
|
+
`)}return kf(n)}function aS(e,t){const i=lS(e);i.push(["type","iconSet"]);const n=[];for(const s of e.ranges){const e=[[["type","percent"],["val",0]]];let r=!0;for(let i of["lowerInflectionPoint","upperInflectionPoint"]){if("formula"===t[i].type){r=!1;continue}const n=t[i];e.push([...dS(n,i),["gte","ge"===n.operator?"1":"0"]])}if(!r){console.warn("Conditional formats with formula rules are not supported at the moment. The rule is therefore skipped.");continue}const a=e.map((e=>$f`<cfvo ${Mf(e)} />`)),l=[["iconSet",(o=t.icons,Zp[hS(o)])]];cS(t.icons)&&l.push(["reverse","1"]),n.push($f`
|
|
2208
2208
|
<conditionalFormatting sqref="${s}">
|
|
2209
|
-
<cfRule ${
|
|
2210
|
-
<iconSet ${
|
|
2211
|
-
${
|
|
2209
|
+
<cfRule ${Mf(i)}>
|
|
2210
|
+
<iconSet ${Mf(l)}>
|
|
2211
|
+
${kf(a)}
|
|
2212
2212
|
</iconSet>
|
|
2213
2213
|
</cfRule>
|
|
2214
2214
|
</conditionalFormatting>
|
|
2215
|
-
`)}var o;return
|
|
2215
|
+
`)}var o;return kf(n)}function lS(e){return[["priority",1],["stopIfTrue",e.stopIfTrue?1:0]]}function cS(e){const t=Cr[hS(e)];return e.upper===t.bad&&e.lower===t.good}function hS(e){return Object.keys(Cr).find((t=>Object.values(Cr[t]).includes(e.upper)))||"dots"}function dS(e,t){const i=function(e,t){switch(e){case"value":return"minimum"===t?"min":"max";case"number":return"num";case"percentage":return"percent";default:return e}}(e.type,t),n=[["type",i]];if("min"!==i&&"max"!==i){let t=e.value;if("formula"===i)try{t=iS(e.value)}catch(i){t=e.value}n.push(["val",t])}return n}function uS(e,t,i){const n=[["xmlns:xdr",jp.drawing],["xmlns:r",Jp],["xmlns:a",Yp],["xmlns:c",Xp]],o=[];for(const[n,s]of Object.entries(i)){const{from:i,to:r}=gS(s,t),a=tf(s.id),l=[["id",a],["name",`Chart ${a}`],["title","Chart"]];o.push($f`
|
|
2216
2216
|
<xdr:twoCellAnchor>
|
|
2217
2217
|
<xdr:from>
|
|
2218
2218
|
<xdr:col>${i.col}</xdr:col>
|
|
@@ -2228,7 +2228,7 @@
|
|
|
2228
2228
|
</xdr:to>
|
|
2229
2229
|
<xdr:graphicFrame>
|
|
2230
2230
|
<xdr:nvGraphicFramePr>
|
|
2231
|
-
<xdr:cNvPr ${
|
|
2231
|
+
<xdr:cNvPr ${Mf(l)} />
|
|
2232
2232
|
<xdr:cNvGraphicFramePr />
|
|
2233
2233
|
</xdr:nvGraphicFramePr>
|
|
2234
2234
|
<xdr:xfrm>
|
|
@@ -2243,71 +2243,71 @@
|
|
|
2243
2243
|
</xdr:graphicFrame>
|
|
2244
2244
|
<xdr:clientData fLocksWithSheet="0"/>
|
|
2245
2245
|
</xdr:twoCellAnchor>
|
|
2246
|
-
`)}return
|
|
2247
|
-
<xdr:wsDr ${
|
|
2248
|
-
${
|
|
2246
|
+
`)}return _f($f`
|
|
2247
|
+
<xdr:wsDr ${Mf(n)}>
|
|
2248
|
+
${kf(o)}
|
|
2249
2249
|
</xdr:wsDr>
|
|
2250
|
-
`)}function
|
|
2250
|
+
`)}function gS(e,t){const{x:i,y:n,height:o,width:s}=e,r=Object.values(t.cols),a=Object.values(t.rows),{index:l,offset:c}=pS(r,i),{index:h,offset:d}=pS(r,i+s),{index:u,offset:g}=pS(a,n),{index:p,offset:m}=pS(a,n+o);return{from:{col:l,colOff:c,row:u,rowOff:g},to:{col:h,colOff:d,row:p,rowOff:m}}}function pS(e,t){let i=0;for(const[n,o]of Object.entries(e)){if(i<=t&&t<i+o.size)return{index:parseInt(n),offset:nf(t-i+H)};i+=o.size}return{index:e.length-1,offset:nf(t-i+H)}}function mS(e){return Qe(e)?$f``:$f`
|
|
2251
2251
|
<font>
|
|
2252
|
-
${e.bold
|
|
2253
|
-
${e.italic
|
|
2254
|
-
${e.underline
|
|
2255
|
-
${e.strike
|
|
2256
|
-
${e.size
|
|
2257
|
-
${e.color&&e.color.rgb
|
|
2258
|
-
${e.name
|
|
2252
|
+
${e.bold?$f`<b />`:""}
|
|
2253
|
+
${e.italic?$f`<i />`:""}
|
|
2254
|
+
${e.underline?$f`<u />`:""}
|
|
2255
|
+
${e.strike?$f`<strike />`:""}
|
|
2256
|
+
${e.size?$f`<sz val="${e.size}" />`:""}
|
|
2257
|
+
${e.color&&e.color.rgb?$f`<color rgb="${gs(e.color.rgb)}" />`:""}
|
|
2258
|
+
${e.name?$f`<name val="${e.name}" />`:""}
|
|
2259
2259
|
</font>
|
|
2260
|
-
`}function
|
|
2261
|
-
<table ${
|
|
2262
|
-
${function(e){const t=[["ref",e.range]];return
|
|
2263
|
-
<autoFilter ${
|
|
2264
|
-
${
|
|
2265
|
-
<filterColumn ${
|
|
2266
|
-
${
|
|
2260
|
+
`}function fS(e){return e?Mf([["style",e.style],["color",gs(e.color.rgb)]]):$f``}const vS=$f`<tableStyleInfo name="TableStyleLight8" showFirstColumn="0" showLastColumn="0" showRowStripes="0" showColumnStripes="0"/>`;function bS(e,t,i){const n=$f`
|
|
2261
|
+
<table ${Mf([["id",t],["name",`Table${t}`],["displayName",`Table${t}`],["ref",e.range],["xmlns",jp.table],["xmlns:xr",jp.revision],["xmlns:xr3",jp.revision3],["xmlns:mc",jp.markupCompatibility]])}>
|
|
2262
|
+
${function(e){const t=[["ref",e.range]];return $f`
|
|
2263
|
+
<autoFilter ${Mf(t)}>
|
|
2264
|
+
${kf(function(e){const t=[];for(const i of e.filters){const e=$f`
|
|
2265
|
+
<filterColumn ${Mf([["colId",i.colId]])}>
|
|
2266
|
+
${SS(i)}
|
|
2267
2267
|
</filterColumn>
|
|
2268
2268
|
`;t.push(e)}return t}(e))}
|
|
2269
2269
|
</autoFilter>
|
|
2270
2270
|
`}(e)}
|
|
2271
|
-
${function(e,t){var i;const n=Fi(e.range),o=[];for(const e of $e(0,ji(n).width)){const s=Vt(n.left+e,n.top),r=[["id",e+1],["name",(null===(i=t.cells[s])||void 0===i?void 0:i.content)||`col${e}`]];o.push(
|
|
2272
|
-
<tableColumns ${
|
|
2273
|
-
${
|
|
2271
|
+
${function(e,t){var i;const n=Fi(e.range),o=[];for(const e of $e(0,ji(n).width)){const s=Vt(n.left+e,n.top),r=[["id",e+1],["name",(null===(i=t.cells[s])||void 0===i?void 0:i.content)||`col${e}`]];o.push($f`<tableColumn ${Mf(r)}/>`)}return $f`
|
|
2272
|
+
<tableColumns ${Mf([["count",o.length]])}>
|
|
2273
|
+
${kf(o)}
|
|
2274
2274
|
</tableColumns>
|
|
2275
2275
|
`}(e,i)}
|
|
2276
|
-
${
|
|
2276
|
+
${vS}
|
|
2277
2277
|
</table>
|
|
2278
|
-
`;return
|
|
2279
|
-
<filters ${
|
|
2280
|
-
${
|
|
2278
|
+
`;return _f(n)}function SS(e){const t=e.displayedValues.map((e=>$f`<filter ${Mf([["val",e]])}/>`));return $f`
|
|
2279
|
+
<filters ${Mf(e.displayBlanks?[["blank",1]]:[])}>
|
|
2280
|
+
${kf(t)}
|
|
2281
2281
|
</filters>
|
|
2282
|
-
`}function
|
|
2283
|
-
<col ${
|
|
2284
|
-
`)}return
|
|
2282
|
+
`}function CS(e){if(!Object.values(e).length)return $f``;const t=[];for(let[i,n]of Object.entries(e)){const e=[["min",parseInt(i)+1],["max",parseInt(i)+1],["width",Ym(n.size||_)],["customWidth",1],["hidden",n.isHidden?1:0]];t.push($f`
|
|
2283
|
+
<col ${Mf(e)}/>
|
|
2284
|
+
`)}return $f`
|
|
2285
2285
|
<cols>
|
|
2286
|
-
${
|
|
2286
|
+
${kf(t)}
|
|
2287
2287
|
</cols>
|
|
2288
|
-
`}function
|
|
2288
|
+
`}function ES(e,t,i){const n=[];for(let o=0;o<i.rowNumber;o++){const s=[["r",o+1]],r=i.rows[o]||{};s.push(["ht",jm(r.size||F)],["customHeight",1],["hidden",r.isHidden?1:0]);const a=[];for(let n=0;n<i.colNumber;n++){const s=Vt(n,o),r=i.cells[s];if(r){const l=[["r",s]],c=Km(e,Xm(r,t));l.push(["s",c]);let h=[],d=$f``;if(r.isFormula){const e=eS(r);if(!e)continue;({attrs:h,node:d}=e)}else if(r.content&&He(r.content)){const{label:t}=Ge(r.content);({attrs:h,node:d}=tS(t,e.sharedStrings))}else if(r.content&&""!==r.content){const t=wS(n,o,i);({attrs:h,node:d}=tS(r.content,e.sharedStrings,t))}l.push(...h),a.push($f`<c ${Mf(l)}>
|
|
2289
2289
|
${d}
|
|
2290
|
-
</c>`)}}(a.length||r.size!==F||r.isHidden)&&n.push(
|
|
2291
|
-
<row ${
|
|
2292
|
-
${
|
|
2290
|
+
</c>`)}}(a.length||r.size!==F||r.isHidden)&&n.push($f`
|
|
2291
|
+
<row ${Mf(s)}>
|
|
2292
|
+
${kf(a)}
|
|
2293
2293
|
</row>
|
|
2294
|
-
`)}return
|
|
2294
|
+
`)}return $f`
|
|
2295
2295
|
<sheetData>
|
|
2296
|
-
${
|
|
2296
|
+
${kf(n)}
|
|
2297
2297
|
</sheetData>
|
|
2298
|
-
`}function
|
|
2298
|
+
`}function wS(e,t,i){return i.filterTables.some((i=>{const n=Fi(i.range),o={...n,bottom:n.top};return Wi(e,t,o)}))}function yS(e,t,i){var n;const o=t.sheets[i].cells,s=[];for(const r in o){const a=null===(n=o[r])||void 0===n?void 0:n.content;if(a&&He(a)){const{label:n,url:o}=Ge(a);if(Ze(a)){const e=Ye(o),i=t.sheets.find((t=>t.id===e)),a=i?`${i.name}!A1`:X;s.push($f`
|
|
2299
2299
|
<hyperlink display="${n}" location="${a}" ref="${r}"/>
|
|
2300
|
-
`)}else{const t=Qm(e.relsFiles,`xl/worksheets/_rels/sheet${i}.xml.rels`,{target:o,type:Qp.hyperlink,targetMode:"External"});s.push(
|
|
2300
|
+
`)}else{const t=Qm(e.relsFiles,`xl/worksheets/_rels/sheet${i}.xml.rels`,{target:o,type:Qp.hyperlink,targetMode:"External"});s.push($f`
|
|
2301
2301
|
<hyperlink r:id="${t}" ref="${r}"/>
|
|
2302
|
-
`)}}}return s.length
|
|
2302
|
+
`)}}}return s.length?$f`
|
|
2303
2303
|
<hyperlinks>
|
|
2304
|
-
${
|
|
2304
|
+
${kf(s)}
|
|
2305
2305
|
</hyperlinks>
|
|
2306
|
-
|
|
2306
|
+
`:$f``}function xS(e){if(e.length){const t=e.map((e=>$f`<mergeCell ref="${e}" />`));return $f`
|
|
2307
2307
|
<mergeCells count="${e.length}">
|
|
2308
|
-
${
|
|
2308
|
+
${kf(t)}
|
|
2309
2309
|
</mergeCells>
|
|
2310
|
-
`}return
|
|
2310
|
+
`}return $f``}function RS(e){const t=e.panes;let i=$f``;if(t&&(t.xSplit||t.ySplit)){const e=Vt(t.xSplit,t.ySplit),n=t.xSplit?$f`xSplit="${t.xSplit}"`:"",o=t.ySplit?$f`ySplit="${t.ySplit}"`:"",s=t.xSplit?$f`<selection pane="topRight"/>`:"",r=t.ySplit?$f`<selection pane="bottomLeft"/>`:"",a=t.xSplit&&t.ySplit?$f`<selection pane="bottomRight"/>`:"";i=$f`
|
|
2311
2311
|
<pane
|
|
2312
2312
|
${n}
|
|
2313
2313
|
${o}
|
|
@@ -2317,123 +2317,123 @@
|
|
|
2317
2317
|
${s}
|
|
2318
2318
|
${r}
|
|
2319
2319
|
${a}
|
|
2320
|
-
`}return
|
|
2320
|
+
`}return $f`
|
|
2321
2321
|
<sheetViews>
|
|
2322
2322
|
<sheetView showGridLines="${e.areGridLinesVisible?1:0}" workbookViewId="0">
|
|
2323
2323
|
${i}
|
|
2324
2324
|
</sheetView>
|
|
2325
2325
|
</sheetViews>
|
|
2326
|
-
`}function
|
|
2327
|
-
<sheet ${
|
|
2328
|
-
`),Qm(t.relsFiles,"xl/_rels/workbook.xml.rels",{type:Qp.sheet,target:`worksheets/sheet${i}.xml`})}return
|
|
2329
|
-
<workbook ${
|
|
2326
|
+
`}function IS(e){const t=[],i=function(e){const t=[{},...Object.values(e.borders).map((e=>({left:Ff(e.left),right:Ff(e.right),bottom:Ff(e.bottom),top:Ff(e.top)})))];return{relsFiles:[],sharedStrings:[],styles:[{fontId:0,fillId:0,numFmtId:0,borderId:0,alignment:{vertical:"center"}}],fonts:[{size:G,family:2,color:{rgb:"000000"},name:"Calibri"}],fills:[{reservedAttribute:"none"},{reservedAttribute:"gray125"}],borders:t,numFmts:[],dxfs:[]}}(e);return t.push(function(e,t){const i=[["xmlns",jp.workbook],["xmlns:r",Jp]],n=[];for(const[i,o]of Object.entries(e.sheets)){const e=[["state",o.isVisible?"visible":"hidden"],["name",o.name],["sheetId",parseInt(i)+1],["r:id",`rId${parseInt(i)+1}`]];n.push($f`
|
|
2327
|
+
<sheet ${Mf(e)} />
|
|
2328
|
+
`),Qm(t.relsFiles,"xl/_rels/workbook.xml.rels",{type:Qp.sheet,target:`worksheets/sheet${i}.xml`})}return Nf(_f($f`
|
|
2329
|
+
<workbook ${Mf(i)}>
|
|
2330
2330
|
<sheets>
|
|
2331
|
-
${
|
|
2331
|
+
${kf(n)}
|
|
2332
2332
|
</sheets>
|
|
2333
2333
|
</workbook>
|
|
2334
|
-
`),"xl/workbook.xml","workbook")}(e,i)),t.push(...function(e,t){const i=[];let n=1;for(const[o,s]of Object.entries(e.sheets)){const r=[["xmlns",jp.worksheet],["xmlns:r",Jp]],a=[["defaultRowHeight",jm(F)],["defaultColWidth",Ym(_)]],l=
|
|
2335
|
-
<worksheet ${
|
|
2336
|
-
${
|
|
2337
|
-
<sheetFormatPr ${
|
|
2338
|
-
${
|
|
2339
|
-
${
|
|
2340
|
-
${
|
|
2341
|
-
${
|
|
2342
|
-
${
|
|
2334
|
+
`),"xl/workbook.xml","workbook")}(e,i)),t.push(...function(e,t){const i=[];let n=1;for(const[o,s]of Object.entries(e.sheets)){const r=[["xmlns",jp.worksheet],["xmlns:r",Jp]],a=[["defaultRowHeight",jm(F)],["defaultColWidth",Ym(_)]],l=TS(s,o,n,t,i);n+=s.filterTables.length;let c=$f``;const h=s.charts;if(h.length){const n=[];for(const s of h){const r=tf(s.id),a=Qm(t.relsFiles,`xl/drawings/_rels/drawing${o}.xml.rels`,{target:`../charts/chart${r}.xml`,type:Qp.chart});n.push(a),i.push(Nf(Gb(s,o,e),`xl/charts/chart${r}.xml`,"chart"))}const r=Qm(t.relsFiles,`xl/worksheets/_rels/sheet${o}.xml.rels`,{target:`../drawings/drawing${o}.xml`,type:Qp.drawing});i.push(Nf(uS(n,s,h),`xl/drawings/drawing${o}.xml`,"drawing")),c=$f`<drawing r:id="${r}" />`}const d=$f`
|
|
2335
|
+
<worksheet ${Mf(r)}>
|
|
2336
|
+
${RS(s)}
|
|
2337
|
+
<sheetFormatPr ${Mf(a)} />
|
|
2338
|
+
${CS(s.cols)}
|
|
2339
|
+
${ES(t,e,s)}
|
|
2340
|
+
${xS(s.merges)}
|
|
2341
|
+
${kf(oS(t.dxfs,s.conditionalFormats))}
|
|
2342
|
+
${yS(t,e,o)}
|
|
2343
2343
|
${c}
|
|
2344
2344
|
${l}
|
|
2345
2345
|
</worksheet>
|
|
2346
|
-
`;i.push(
|
|
2347
|
-
<styleSheet ${
|
|
2348
|
-
${function(e){const t=[];for(let[i,n]of Object.entries(e)){const e=[["numFmtId",parseInt(i)+rm],["formatCode",n.format]];t.push(
|
|
2349
|
-
<numFmt ${
|
|
2350
|
-
`)}return
|
|
2346
|
+
`;i.push(Nf(_f(d),`xl/worksheets/sheet${o}.xml`,"sheet"))}return Qm(t.relsFiles,"xl/_rels/workbook.xml.rels",{type:Qp.sharedStrings,target:"sharedStrings.xml"}),Qm(t.relsFiles,"xl/_rels/workbook.xml.rels",{type:Qp.styles,target:"styles.xml"}),i}(e,i)),t.push(function(e){const t=$f`
|
|
2347
|
+
<styleSheet ${Mf([["xmlns",jp.styleSheet],["xmlns:r",Jp]])}>
|
|
2348
|
+
${function(e){const t=[];for(let[i,n]of Object.entries(e)){const e=[["numFmtId",parseInt(i)+rm],["formatCode",n.format]];t.push($f`
|
|
2349
|
+
<numFmt ${Mf(e)}/>
|
|
2350
|
+
`)}return $f`
|
|
2351
2351
|
<numFmts count="${e.length}">
|
|
2352
|
-
${
|
|
2352
|
+
${kf(t)}
|
|
2353
2353
|
</numFmts>
|
|
2354
2354
|
`}(e.numFmts)}
|
|
2355
|
-
${i=e.fonts
|
|
2355
|
+
${i=e.fonts,$f`
|
|
2356
2356
|
<fonts count="${i.length}">
|
|
2357
|
-
${
|
|
2357
|
+
${kf(Object.values(i).map(mS))}
|
|
2358
2358
|
</fonts>
|
|
2359
2359
|
`}
|
|
2360
|
-
${function(e){const t=[];for(let i of Object.values(e))void 0!==i.reservedAttribute?t.push(
|
|
2360
|
+
${function(e){const t=[];for(let i of Object.values(e))void 0!==i.reservedAttribute?t.push($f`
|
|
2361
2361
|
<fill>
|
|
2362
2362
|
<patternFill patternType="${i.reservedAttribute}" />
|
|
2363
2363
|
</fill>
|
|
2364
|
-
`):t.push(
|
|
2364
|
+
`):t.push($f`
|
|
2365
2365
|
<fill>
|
|
2366
2366
|
<patternFill patternType="solid">
|
|
2367
2367
|
<fgColor rgb="${gs(i.fgColor.rgb)}" />
|
|
2368
2368
|
<bgColor indexed="64" />
|
|
2369
2369
|
</patternFill>
|
|
2370
2370
|
</fill>
|
|
2371
|
-
`);return
|
|
2371
|
+
`);return $f`
|
|
2372
2372
|
<fills count="${e.length}">
|
|
2373
|
-
${
|
|
2373
|
+
${kf(t)}
|
|
2374
2374
|
</fills>
|
|
2375
2375
|
`}(e.fills)}
|
|
2376
|
-
${function(e){const t=[];for(let i of Object.values(e))t.push(
|
|
2376
|
+
${function(e){const t=[];for(let i of Object.values(e))t.push($f`
|
|
2377
2377
|
<border>
|
|
2378
|
-
<left ${
|
|
2379
|
-
<right ${
|
|
2380
|
-
<top ${
|
|
2381
|
-
<bottom ${
|
|
2382
|
-
<diagonal ${
|
|
2378
|
+
<left ${fS(i.left)} />
|
|
2379
|
+
<right ${fS(i.right)} />
|
|
2380
|
+
<top ${fS(i.top)} />
|
|
2381
|
+
<bottom ${fS(i.bottom)} />
|
|
2382
|
+
<diagonal ${fS(i.diagonal)} />
|
|
2383
2383
|
</border>
|
|
2384
|
-
`);return
|
|
2384
|
+
`);return $f`
|
|
2385
2385
|
<borders count="${e.length}">
|
|
2386
|
-
${
|
|
2386
|
+
${kf(t)}
|
|
2387
2387
|
</borders>
|
|
2388
2388
|
`}(e.borders)}
|
|
2389
|
-
${function(e){const t=[];for(let i of e){const e=[["numFmtId",i.numFmtId],["fillId",i.fillId],["fontId",i.fontId],["borderId",i.borderId]],n=[];i.alignment&&i.alignment.vertical&&n.push(["vertical",i.alignment.vertical]),i.alignment&&i.alignment.horizontal&&n.push(["horizontal",i.alignment.horizontal]),t.push(
|
|
2390
|
-
<xf ${
|
|
2391
|
-
${n
|
|
2389
|
+
${function(e){const t=[];for(let i of e){const e=[["numFmtId",i.numFmtId],["fillId",i.fillId],["fontId",i.fontId],["borderId",i.borderId]],n=[];i.alignment&&i.alignment.vertical&&n.push(["vertical",i.alignment.vertical]),i.alignment&&i.alignment.horizontal&&n.push(["horizontal",i.alignment.horizontal]),t.push($f`
|
|
2390
|
+
<xf ${Mf(e)}>
|
|
2391
|
+
${n?$f`<alignment ${Mf(n)} />`:""}
|
|
2392
2392
|
</xf>
|
|
2393
|
-
`)}return
|
|
2393
|
+
`)}return $f`
|
|
2394
2394
|
<cellXfs count="${e.length}">
|
|
2395
|
-
${
|
|
2395
|
+
${kf(t)}
|
|
2396
2396
|
</cellXfs>
|
|
2397
2397
|
`}(e.styles)}
|
|
2398
|
-
${function(e){const t=[];for(const i of e){let e
|
|
2398
|
+
${function(e){const t=[];for(const i of e){let e=$f``;i.font&&(e=mS(i.font));let n=$f``;i.fill&&(n=$f`
|
|
2399
2399
|
<fill>
|
|
2400
2400
|
<patternFill>
|
|
2401
2401
|
<bgColor rgb="${gs(i.fill.fgColor.rgb)}" />
|
|
2402
2402
|
</patternFill>
|
|
2403
2403
|
</fill>
|
|
2404
|
-
`),t.push(
|
|
2404
|
+
`),t.push($f`
|
|
2405
2405
|
<dxf>
|
|
2406
2406
|
${e}
|
|
2407
2407
|
${n}
|
|
2408
2408
|
</dxf>
|
|
2409
|
-
`)}return
|
|
2409
|
+
`)}return $f`
|
|
2410
2410
|
<dxfs count="${e.length}">
|
|
2411
|
-
${
|
|
2411
|
+
${kf(t)}
|
|
2412
2412
|
</dxfs>
|
|
2413
2413
|
`}(e.dxfs)}
|
|
2414
2414
|
</styleSheet>
|
|
2415
|
-
`;var i;return
|
|
2416
|
-
<sst ${
|
|
2417
|
-
${
|
|
2415
|
+
`;var i;return Nf(_f(t),"xl/styles.xml","styles")}(i)),t.push(function(e){const t=[["xmlns",jp.sst],["count",e.length],["uniqueCount",e.length]],i=e.map((e=>$f`<si><t>${e}</t></si>`));return Nf(_f($f`
|
|
2416
|
+
<sst ${Mf(t)}>
|
|
2417
|
+
${kf(i)}
|
|
2418
2418
|
</sst>
|
|
2419
|
-
`),"xl/sharedStrings.xml","sharedStrings")}(i.sharedStrings)),t.push(...function(e){const t=[];for(const i of e){const e=[];for(const t of i.rels){const i=[["Id",t.id],["Target",t.target],["Type",t.type]];t.targetMode&&i.push(["TargetMode",t.targetMode]),e.push(
|
|
2420
|
-
<Relationship ${
|
|
2421
|
-
`)}const n
|
|
2419
|
+
`),"xl/sharedStrings.xml","sharedStrings")}(i.sharedStrings)),t.push(...function(e){const t=[];for(const i of e){const e=[];for(const t of i.rels){const i=[["Id",t.id],["Target",t.target],["Type",t.type]];t.targetMode&&i.push(["TargetMode",t.targetMode]),e.push($f`
|
|
2420
|
+
<Relationship ${Mf(i)} />
|
|
2421
|
+
`)}const n=$f`
|
|
2422
2422
|
<Relationships xmlns="${jp.Relationships}">
|
|
2423
|
-
${
|
|
2423
|
+
${kf(e)}
|
|
2424
2424
|
</Relationships>
|
|
2425
|
-
`;t.push(
|
|
2425
|
+
`;t.push(Nf(_f(n),i.path))}return t}(i.relsFiles)),t.push(function(e){const t=[];for(const i of e)i.contentType&&t.push(Df("/"+i.path,Kp[i.contentType]));return Nf(_f($f`
|
|
2426
2426
|
<Types xmlns="${jp.Types}">
|
|
2427
2427
|
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
|
|
2428
2428
|
<Default Extension="xml" ContentType="application/xml" />
|
|
2429
|
-
${
|
|
2429
|
+
${kf(t)}
|
|
2430
2430
|
</Types>
|
|
2431
|
-
`),"[Content_Types].xml")}(t)),t.push(function(){const e=[["Id","rId1"],["Type",Qp.document],["Target","xl/workbook.xml"]];return
|
|
2431
|
+
`),"[Content_Types].xml")}(t)),t.push(function(){const e=[["Id","rId1"],["Type",Qp.document],["Target","xl/workbook.xml"]];return Nf(_f($f`
|
|
2432
2432
|
<Relationships xmlns="${jp.Relationships}">
|
|
2433
|
-
<Relationship ${
|
|
2433
|
+
<Relationship ${Mf(e)} />
|
|
2434
2434
|
</Relationships>
|
|
2435
|
-
`),"_rels/.rels")}()),{name:"my_spreadsheet.xlsx",files:t}}function
|
|
2435
|
+
`),"_rels/.rels")}()),{name:"my_spreadsheet.xlsx",files:t}}function TS(e,t,i,n,o){let s=i;if(!e.filterTables.length)return new Wp("");const r=`xl/worksheets/_rels/sheet${t}.xml.rels`,a=[];for(const t of e.filterTables){const i=Qm(n.relsFiles,r,{target:`../tables/table${s}.xml`,type:Qp.table});o.push(Nf(bS(t,s,e),`xl/tables/table${s}.xml`,"table")),a.push($f`<tablePart r:id="${i}" />`),s++}return $f`
|
|
2436
2436
|
<tableParts count="${e.filterTables.length}">
|
|
2437
|
-
${
|
|
2437
|
+
${kf(a)}
|
|
2438
2438
|
</tableParts>
|
|
2439
|
-
`}var
|
|
2439
|
+
`}var AS;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.RunningCore=2]="RunningCore",e[e.Finalizing=3]="Finalizing"}(AS||(AS={}));const NS={},OS={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:O,HEADER_WIDTH:M,TOPBAR_HEIGHT:63,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:_,DEFAULT_CELL_HEIGHT:F,SCROLLBAR_WIDTH:D},MS={autofillModifiersRegistry:cn,autofillRulesRegistry:En,cellMenuRegistry:jo,colMenuRegistry:Yo,linkMenuRegistry:Qn,functionRegistry:Yu,uiPluginRegistry:fb,corePluginRegistry:mb,rowMenuRegistry:Xo,sidePanelRegistry:Rr,figureRegistry:oo,sheetMenuRegistry:Qo,chartSidePanelComponentRegistry:fr,chartComponentRegistry:an,chartRegistry:rn,topbarMenuRegistry:rs,topbarComponentRegistry:Ir,clickableCellRegistry:vb,otRegistry:as,inverseCommandRegistry:so,cellRegistry:io,cellPopoverRegistry:to},_S={LinkCell:Pp},FS={args:Ur,toBoolean:Kr,toJsDate:Qr,toNumber:Gr,toString:Zr,toXC:Vt,toZone:Fi,toCartesian:Ut,numberToLetters:Lt,createFullMenuItem:Yn,UuidGenerator:Mi,formatValue:Qt,computeTextWidth:_e,isMarkdownLink:He,parseMarkdownLink:Ge,markdownLink:We,createEmptyWorkbookData:av,createEmptySheet:rv,createEmptyExcelSheet:lv,getDefaultChartJsRuntime:Ds,chartFontColor:Rs,getMenuChildren:Fn,ChartColors:xs,EvaluationError:c,CellErrorLevel:l,getFillingMode:Ls,rgbaToHex:Ct,colorToRGBA:Et,positionToZone:en,deepEquals:ot},DS={ChartPanel:vr,ChartFigure:Mr,ChartJsComponent:ln,Grid:Mp,GridOverlay:mp,ScorecardChart:Ar,LineConfigPanel:ur,LineBarPieDesignPanel:lr,BarConfigPanel:ds,LineBarPieConfigPanel:hs,GaugeChartConfigPanel:hr,GaugeChartDesignPanel:dr,ScorecardChartConfigPanel:pr,ScorecardChartDesignPanel:mr};e.AbstractChart=us,e.CorePlugin=cv,e.DATETIME_FORMAT=Y,e.DispatchResult=fn,e.EvaluationError=c,e.Model=class extends Qv{constructor(e={},i={},n=[],o=new Mi,s=!0){super(),this.corePlugins=[],this.uiPlugins=[],this.isReplayingCommand=!1,this.renderers=[],this.status=0,this.handlers=[],this.coreHandlers=[],this.dispatch=(e,t)=>{const i={type:e,...t};let n=this.status;if(this.getters.isReadonly()&&(o=i,!gn.has(o.type)))return new fn(68);var o;if(!this.session.canApplyOptimisticUpdate())return new fn(65);switch(n){case 0:const t=this.checkDispatchAllowed(i);if(!t.isSuccessful)return t;this.status=1;const{changes:n,commands:o}=this.state.recordChanges((()=>{mn(i)&&this.state.addCommand(i),this.dispatchToHandlers(this.handlers,i),this.finalize()}));this.session.save(o,n),this.status=0,this.trigger("update");break;case 1:if(mn(i)){const e=this.checkDispatchAllowed(i);if(!e.isSuccessful)return e;this.state.addCommand(i),this.dispatchToHandlers(this.handlers,i)}else this.dispatchToHandlers(this.handlers,i);break;case 3:throw new Error("Cannot dispatch commands in the finalize state");case 2:if(mn(i))throw new Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,i)}return fn.Success},this.dispatchFromCorePlugin=(e,t)=>{const i={type:e,...t},n=this.status;this.status=2;const o=this.isReplayingCommand?this.coreHandlers:this.handlers;return this.dispatchToHandlers(o,i),this.status=n,fn.Success},n=ov(e,n);const r=iv(e,s);this.state=new Bb,this.uuidGenerator=o,this.config=this.setupConfig(i),this.session=this.setupSession(r.revisionId),this.config.moveClient=this.session.move.bind(this.session),this.history=new Pb(this.dispatchFromCorePlugin,this.session),this.coreGetters={},this.range=new Ub(this.coreGetters),this.coreGetters.getRangeString=this.range.getRangeString.bind(this.range),this.coreGetters.getRangeFromSheetXC=this.range.getRangeFromSheetXC.bind(this.range),this.coreGetters.createAdaptedRanges=this.range.createAdaptedRanges.bind(this.range),this.coreGetters.getRangeDataFromXc=this.range.getRangeDataFromXc.bind(this.range),this.coreGetters.getRangeDataFromZone=this.range.getRangeDataFromZone.bind(this.range),this.coreGetters.getRangeFromRangeData=this.range.getRangeFromRangeData.bind(this.range),this.coreGetters.getSelectionRangeString=this.range.getSelectionRangeString.bind(this.range),this.getters={isReadonly:()=>"readonly"===this.config.mode||"dashboard"===this.config.mode,isDashboard:()=>"dashboard"===this.config.mode,canUndo:this.history.canUndo.bind(this.history),canRedo:this.history.canRedo.bind(this.history),getClient:this.session.getClient.bind(this.session),getConnectedClients:this.session.getConnectedClients.bind(this.session),isFullySynchronized:this.session.isFullySynchronized.bind(this.session)},this.uuidGenerator.setIsFastStrategy(!0),this.selection=new zb(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range);for(let e of mb.getAll())this.setupCorePlugin(e,r);Object.assign(this.getters,this.coreGetters);for(let e of fb.getAll())this.setupUiPlugin(e);this.uuidGenerator.setIsFastStrategy(!1),this.handlers.push(this.history),this.dispatch("START"),this.selection.observe(this,{handleEvent:()=>this.trigger("update")}),this.isLoading=!0,this.setupSessionEvents(),this.session.loadInitialMessages(n),this.joinSession(),i.snapshotRequested&&this.session.snapshot(this.exportData()),t.markRaw(this),this.isLoading=!1,this.finalize()}joinSession(){this.session.join(this.config.client)}leaveSession(){this.session.leave()}setupUiPlugin(e){const t=new e(this.getters,this.state,this.dispatch,this.config,this.selection);for(let i of e.getters){if(!(i in t))throw new Error(`Invalid getter name: ${i} for plugin ${t.constructor}`);if(i in this.getters)throw new Error(`Getter "${i}" is already defined.`);this.getters[i]=t[i].bind(t)}this.uiPlugins.push(t),this.handlers.push(t);const i=e.layers.map((e=>[t,e]));this.renderers.push(...i),this.renderers.sort(((e,t)=>e[1]-t[1]))}setupCorePlugin(e,t){const i=new e(this.coreGetters,this.state,this.range,this.dispatchFromCorePlugin,this.config,this.uuidGenerator);for(let t of e.getters){if(!(t in i))throw new Error(`Invalid getter name: ${t} for plugin ${i.constructor}`);if(t in this.coreGetters)throw new Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=i[t].bind(i)}i.import(t),this.corePlugins.push(i),this.coreHandlers.push(i),this.handlers.push(i)}onRemoteRevisionReceived({commands:e}){for(let t of e){const e=this.status;this.status=2,this.dispatchToHandlers(this.uiPlugins,t),this.status=e}this.finalize()}setupSession(e){return new ab($b(e,this.state.recordChanges.bind(this.state),(e=>{this.checkDispatchAllowed(e).isSuccessful&&(this.isReplayingCommand=!0,this.dispatchToHandlers(this.coreHandlers,e),this.isReplayingCommand=!1)})),this.config.transportService,e)}setupSessionEvents(){this.session.on("remote-revision-received",this,this.onRemoteRevisionReceived),this.session.on("revision-redone",this,this.finalize),this.session.on("revision-undone",this,this.finalize),this.session.on("unexpected-revision-id",this,(()=>this.trigger("unexpected-revision-id"))),this.session.on("collaborative-event-received",this,(()=>{this.trigger("update")}))}setupConfig(e){const t=e.client||{id:this.uuidGenerator.smallUuid(),name:s("Anonymous").toString()},i=e.transportService||new Tb;return{...e,mode:e.mode||"normal",evalContext:e.evalContext||{},transportService:i,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger("notify-ui",e)}}checkDispatchAllowed(e){const t=this.handlers.map((t=>t.allowDispatch(e)));return t.some((e=>0!==e))?new fn(t.flat()):fn.Success}finalize(){if(!this.isLoading){this.status=3;for(const e of this.handlers)e.finalize();this.status=0}}dispatchToHandlers(e,t){t=Ae(t);for(const i of e)i.beforeHandle(t);for(const i of e)i.handle(t)}drawGrid(e){for(let[t,i]of this.renderers)e.ctx.save(),t.drawGrid(e,i),e.ctx.restore()}exportData(){let e=av();for(let t of this.handlers)t instanceof cv&&t.export(e);return e.revisionId=this.session.getRevisionId()||K,e=Ae(e),e}updateMode(e){"normal"!==e&&this.dispatch("STOP_EDITION",{cancel:!0}),this.config.mode=e,this.trigger("update")}exportXLSX(){this.dispatch("EVALUATE_CELLS");let e={...av(),sheets:[lv(tv,"Sheet1")]};for(let t of this.handlers)t instanceof Wg&&t.exportForExcel(e);return e=Ae(e),IS(e)}},e.Registry=sn,e.Revision=sb,e.SPREADSHEET_DIMENSIONS=OS,e.Spreadsheet=Ib,e.UIPlugin=Gg,e.__info__=NS,e.addFunction=function(e,t){Yu.add(e,t)},e.astToFormula=Mg,e.cellTypes=_S,e.compile=Ug,e.components=DS,e.convertAstNodes=Og,e.coreTypes=pn,e.findCellInNewZone=Qi,e.functionCache=Pg,e.helpers=FS,e.invalidateEvaluationCommands=dn,e.load=iv,e.parse=Ag,e.readonlyAllowedCommands=gn,e.registries=MS,e.setTranslationMethod=function(e){i=e},e.tokenize=Ju,Object.defineProperty(e,"__esModule",{value:!0}),NS.version="16.0.75",NS.date="2025-07-11T11:06:44.633Z",NS.hash="c6d8a41"}(this.o_spreadsheet=this.o_spreadsheet||{},owl);
|