@odoo/o-spreadsheet 17.0.104 → 17.0.106

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.
@@ -2,9 +2,9 @@
2
2
  /**
3
3
  * This file is generated by o-spreadsheet build tools. Do not edit it.
4
4
  * @see https://github.com/odoo/o-spreadsheet
5
- * @version 17.0.104
6
- * @date 2026-07-23T07:43:17.811Z
7
- * @hash ff598a7
5
+ * @version 17.0.106
6
+ * @date 2026-08-29T09:12:26.343Z
7
+ * @hash c877406
8
8
  */
9
9
 
10
10
  import { Component, markRaw, onMounted, onPatched, onWillPatch, onWillStart, onWillUnmount, onWillUpdateProps, useChildSubEnv, useComponent, useEffect, useExternalListener, useRef, useState, useSubEnv, xml } from "@odoo/owl";
@@ -41288,7 +41288,7 @@ var SheetUIPlugin = class extends UIPlugin {
41288
41288
  if (contentWidth === 0) return 0;
41289
41289
  contentWidth += 2 * 4;
41290
41290
  if (style.wrapping === "wrap") {
41291
- const colWidth = this.getters.getColSize(this.getters.getActiveSheetId(), position.col);
41291
+ const colWidth = this.getters.getColSize(position.sheetId, position.col);
41292
41292
  return Math.min(colWidth, contentWidth);
41293
41293
  }
41294
41294
  return contentWidth;
@@ -45684,6 +45684,9 @@ css`
45684
45684
  position: absolute;
45685
45685
  cursor: pointer;
45686
45686
  }
45687
+ .o-grid.o-dashboard-grid {
45688
+ background: #ffffff;
45689
+ }
45687
45690
  `;
45688
45691
  var SpreadsheetDashboard = class extends Component {
45689
45692
  static template = "o-spreadsheet-SpreadsheetDashboard";
@@ -50869,6 +50872,6 @@ const constants = { DEFAULT_LOCALE };
50869
50872
  //#endregion
50870
50873
  export { AbstractChart, CommandResult, CorePlugin, DispatchResult, EvaluationError, Model, Registry, Revision, SPREADSHEET_DIMENSIONS, Spreadsheet, UIPlugin, __info__, addFunction, astToFormula, compile, compileTokens, components, constants, convertAstNodes, coreTypes, findCellInNewZone, functionCache, helpers, hooks, invalidateCFEvaluationCommands, invalidateDependenciesCommands, invalidateEvaluationCommands, iterateAstNodes, links, load, parse, parseTokens, readonlyAllowedCommands, registries, setDefaultSheetViewSize, setTranslationMethod, tokenize };
50871
50874
 
50872
- __info__.version = "17.0.104";
50873
- __info__.date = "2026-07-23T07:43:17.811Z";
50874
- __info__.hash = "ff598a7";
50875
+ __info__.version = "17.0.106";
50876
+ __info__.date = "2026-08-29T09:12:26.343Z";
50877
+ __info__.hash = "c877406";
@@ -2,9 +2,9 @@
2
2
  /**
3
3
  * This file is generated by o-spreadsheet build tools. Do not edit it.
4
4
  * @see https://github.com/odoo/o-spreadsheet
5
- * @version 17.0.104
6
- * @date 2026-07-23T07:43:17.811Z
7
- * @hash ff598a7
5
+ * @version 17.0.106
6
+ * @date 2026-08-29T09:12:26.343Z
7
+ * @hash c877406
8
8
  */
9
9
 
10
10
  (function(exports, _odoo_owl) {
@@ -41290,7 +41290,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
41290
41290
  if (contentWidth === 0) return 0;
41291
41291
  contentWidth += 2 * 4;
41292
41292
  if (style.wrapping === "wrap") {
41293
- const colWidth = this.getters.getColSize(this.getters.getActiveSheetId(), position.col);
41293
+ const colWidth = this.getters.getColSize(position.sheetId, position.col);
41294
41294
  return Math.min(colWidth, contentWidth);
41295
41295
  }
41296
41296
  return contentWidth;
@@ -45686,6 +45686,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
45686
45686
  position: absolute;
45687
45687
  cursor: pointer;
45688
45688
  }
45689
+ .o-grid.o-dashboard-grid {
45690
+ background: #ffffff;
45691
+ }
45689
45692
  `;
45690
45693
  var SpreadsheetDashboard = class extends _odoo_owl.Component {
45691
45694
  static template = "o-spreadsheet-SpreadsheetDashboard";
@@ -50907,8 +50910,8 @@ exports.setDefaultSheetViewSize = setDefaultSheetViewSize;
50907
50910
  exports.setTranslationMethod = setTranslationMethod;
50908
50911
  exports.tokenize = tokenize;
50909
50912
 
50910
- __info__.version = "17.0.104";
50911
- __info__.date = "2026-07-23T07:43:17.811Z";
50912
- __info__.hash = "ff598a7";
50913
+ __info__.version = "17.0.106";
50914
+ __info__.date = "2026-08-29T09:12:26.343Z";
50915
+ __info__.hash = "c877406";
50913
50916
 
50914
50917
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);
@@ -1474,7 +1474,7 @@
1474
1474
  `))}extractAttr(e,t,n){let r=e.attributes[t];r||this.handleMissingValue(e,`attribute "${t}"`,n);let i=r?.value?r.value:n?.default;return i===void 0?void 0:new eO(i)}extractTextContent(e,t){if(t?.default!==void 0&&typeof t.default!=`string`)throw Error(`extractTextContent default value should be a string`);let n=e?.attributes[`xml:space`]?.value===`preserve`,r=e?.textContent;return(!e||r===null)&&this.handleMissingValue(e,`text content`,t),r&&=n?r:r.trim(),r?CE(r):t?.default}extractChildAttr(e,t,n,r){let i;i=typeof t==`number`?e.children[t]:this.querySelector(e,t),i||this.handleMissingValue(e,typeof t==`number`?`child at index ${t}`:`child <${t}>`,r);let a=i?this.extractAttr(i,n,r)?.asString():r?.default;return a===void 0?void 0:new eO(a)}extractChildTextContent(e,t,n){if(n?.default!==void 0&&typeof n.default!=`string`)throw Error(`extractTextContent default value should be a string`);let r=this.querySelector(e,t);return r||this.handleMissingValue(e,`child <${t}>`,n),r?this.extractTextContent(r,n):n?.default}handleMissingValue(e,t,n){if(n?.required)if(n?.default!==void 0)this.warningManager.addParsingWarning(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, replacing it by the default value ${n.default}`);else throw Error(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, and no default value was set`)}extractColor(e,t,n){if(!e)return n?{rgb:n}:void 0;let r=this.extractAttr(e,`theme`)?.asString(),i;if(r!==void 0){if(!t||!t.clrScheme)throw Error(`Color referencing a theme but no theme was provided`);i=this.getThemeColor(r,t.clrScheme)}else i=this.extractAttr(e,`rgb`)?.asString();return{rgb:i,auto:this.extractAttr(e,`auto`)?.asBool(),indexed:this.extractAttr(e,`indexed`)?.asNum(),tint:this.extractAttr(e,`tint`)?.asNum()}}getTargetXmlFile(e){if(!e)throw Error(`Undefined target file`);let t=this.processRelationshipTargetName(e.target),n=this.getListOfXMLFiles().find(e=>e.file.fileName.endsWith(t));if(!n||!n.file)throw Error(`Cannot find target file`);return n}getTargetImageFile(e){if(!e)throw Error(`Undefined target file`);let t=this.processRelationshipTargetName(e.target),n=this.xlsxFileStructure.images.find(e=>e.fileName.endsWith(t));if(!n)throw Error(`Cannot find target file`);return n}querySelector(e,t){let n=$D(t);return e.querySelector(n)}querySelectorAll(e,t){let n=$D(t);return e.querySelectorAll(n)}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}}processRelationshipTargetName(e){return e.replace(/\.+\//,``)}},nO=class extends tO{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:Bw}).asString(),lastClr:this.extractChildAttr(e,0,`lastClr`,{default:Bw}).asString()}))}}getSharedStrings(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`si`},e=>this.mapOnElements({parent:e,query:`t`},e=>this.extractTextContent(e)||``).join(``))}},rO=class extends tO{theme;constructor(e,t,n,r){super(e,t,n),this.theme=r}extractConditionalFormattings(){let e=this.mapOnElements({parent:this.rootFile.file.xml,query:`worksheet > conditionalFormatting`},e=>({sqref:this.extractAttr(e,`sqref`,{required:!0}).asString().split(` `),pivot:this.extractAttr(e,`pivot`)?.asBool(),cfRules:this.extractCFRules(e,this.theme)}));return e.push(...this.mapOnElements({parent:this.rootFile.file.xml,query:`extLst x14:conditionalFormatting`},e=>({sqref:this.extractChildTextContent(e,`xm:sqref`,{required:!0}).split(` `),pivot:this.extractAttr(e,`xm:pivot`)?.asBool(),cfRules:this.extractCFRules(e,this.theme)}))),e}extractCFRules(e,t){return this.mapOnElements({parent:e,query:`cfRule, x14:cfRule`},e=>{let n=this.extractAttr(e,`type`,{required:!0}).asString();if(n===`dataBar`)throw Error(`Databars conditional formats are not supported.`);return{type:n,priority:this.extractAttr(e,`priority`,{required:!0}).asNum(),colorScale:this.extractCfColorScale(e,t),formula:this.extractCfFormula(e),iconSet:this.extractCfIconSet(e),dxfId:this.extractAttr(e,`dxfId`)?.asNum(),stopIfTrue:this.extractAttr(e,`stopIfTrue`)?.asBool(),aboveAverage:this.extractAttr(e,`aboveAverage`)?.asBool(),percent:this.extractAttr(e,`percent`)?.asBool(),bottom:this.extractAttr(e,`bottom`)?.asBool(),operator:this.extractAttr(e,`operator`)?.asString(),text:this.extractAttr(e,`text`)?.asString(),timePeriod:this.extractAttr(e,`timePeriod`)?.asString(),rank:this.extractAttr(e,`rank`)?.asNum(),stdDev:this.extractAttr(e,`stdDev`)?.asNum(),equalAverage:this.extractAttr(e,`equalAverage`)?.asBool()}})}extractCfFormula(e){return this.mapOnElements({parent:e,query:`formula`},e=>this.extractTextContent(e,{required:!0}))}extractCfColorScale(e,t){let n=this.querySelector(e,`colorScale`);if(n)return{colors:this.mapOnElements({parent:n,query:`color`},e=>this.extractColor(e,t,`ffffff`)),cfvos:this.extractCFVos(n)}}extractCfIconSet(e){let t=this.querySelector(e,`iconSet, x14:iconSet`);if(t)return{iconSet:this.extractAttr(t,`iconSet`,{default:`3TrafficLights1`}).asString(),showValue:this.extractAttr(t,`showValue`,{default:!0}).asBool(),percent:this.extractAttr(t,`percent`,{default:!0}).asBool(),reverse:this.extractAttr(t,`reverse`)?.asBool(),custom:this.extractAttr(t,`custom`)?.asBool(),cfvos:this.extractCFVos(t),cfIcons:this.extractCfIcons(t)}}extractCfIcons(e){let 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 t.length===0?void 0:t}extractCFVos(e){return this.mapOnElements({parent:e,query:`cfvo, x14:cfvo`},e=>({type:this.extractAttr(e,`type`,{required:!0}).asString(),gte:this.extractAttr(e,`gte`,{default:!0})?.asBool(),value:e.attributes.val?this.extractAttr(e,`val`)?.asString():this.extractChildTextContent(e,`f, xm:f`)}))}},iO=class extends tO{extractChart(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`c:chartSpace`},e=>{let t=this.getChartType(e);if(!lE[t])throw Error(`Unsupported chart type ${t}`);let n=this.mapOnElements({parent:e,query:`c:title a:t`},e=>e.textContent||``).join(``),r=this.extractChildAttr(e,`c:grouping`,`val`,{default:`clustered`}).asString();return{title:n,type:lE[t],dataSets:this.extractChartDatasets(this.querySelector(e,`c:${t}`)),labelRange:this.extractChildTextContent(e,`c:ser c:cat c:f`),backgroundColor:this.extractChildAttr(e,`c:chartSpace > c:spPr a:srgbClr`,`val`,{default:`ffffff`}).asString(),verticalAxisPosition:this.extractChildAttr(e,`c:valAx > c:axPos`,`val`,{default:`l`}).asString()===`r`?`right`:`left`,legendPosition:cE[this.extractChildAttr(e,`c:legendPos`,`val`,{default:`none`}).asString()],stacked:r===`stacked`,fontColor:`000000`}})[0]}extractChartDatasets(e){return this.mapOnElements({parent:e,query:`c:ser`},e=>({label:this.extractChildTextContent(e,`c:tx c:f`),range:this.extractChildTextContent(e,`c:val c:f`,{required:!0})}))}getChartType(e){let t=this.querySelector(e,`c:plotArea`);if(!t)throw Error(`Missing plot area in the chart definition.`);for(let e of t.children){let t=ZD(e.tagName);if(zw.some(e=>e===t))return t}throw Error(`Unknown chart type`)}},aO=class extends tO{extractFigures(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`xdr:wsDr`,children:!0},e=>{if(ZD(e.tagName)!==`twoCellAnchor`)throw Error(`Only twoCellAnchor are supported for xlsx drawings.`);let t=this.querySelector(e,`c:chart`),n=this.querySelector(e,`a:blip`);if(!t&&!n)throw Error(`Only chart and image figures are currently supported.`);return{anchors:[this.extractFigureAnchor(`xdr:from`,e),this.extractFigureAnchor(`xdr:to`,e)],data:t?this.extractChart(t):this.extractImage(e)}})}extractFigureAnchor(e,t){let n=this.querySelector(t,e);if(!n)throw Error(`Missing anchor element ${e}`);return{col:Number(this.extractChildTextContent(n,`xdr:col`,{required:!0})),colOffset:Number(this.extractChildTextContent(n,`xdr:colOff`,{required:!0})),row:Number(this.extractChildTextContent(n,`xdr:row`,{required:!0})),rowOffset:Number(this.extractChildTextContent(n,`xdr:rowOff`,{required:!0}))}}extractChart(e){let t=this.extractAttr(e,`r:id`,{required:!0}).asString(),n=new iO(this.getTargetXmlFile(this.relationships[t]),this.xlsxFileStructure,this.warningManager).extractChart();if(!n)throw Error(`Unable to extract chart definition`);return n}extractImage(e){let t=this.querySelector(e,`a:blip`),n=this.extractAttr(t,`r:embed`,{required:!0}).asString(),r=this.getTargetImageFile(this.relationships[n]);if(!r)throw Error(`Unable to extract image`);let i=this.querySelector(e,`a:xfrm`),a=r.fileName.split(`.`).at(-1);return{imageSrc:r.imageSrc,mimetype:a?hE[a]:void 0,size:{cx:this.extractChildAttr(i,`a:ext`,`cx`,{required:!0}).asNum(),cy:this.extractChildAttr(i,`a:ext`,`cy`,{required:!0}).asNum()}}}},oO=class extends tO{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]}},sO=class extends tO{getTable(){return this.mapOnElements({query:`table`,parent:this.rootFile.file.xml},e=>({displayName:this.extractAttr(e,`displayName`,{required:!0}).asString(),name:this.extractAttr(e,`name`)?.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=>({name:this.extractAttr(e,`name`)?.asString(),showFirstColumn:this.extractAttr(e,`showFirstColumn`)?.asBool(),showLastColumn:this.extractAttr(e,`showLastColumn`)?.asBool(),showRowStripes:this.extractAttr(e,`showRowStripes`)?.asBool(),showColumnStripes:this.extractAttr(e,`showColumnStripes`)?.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()}))}},cO=class extends tO{theme;constructor(e,t,n,r){super(e,t,n),this.theme=r}getSheet(){return this.mapOnElements({query:`worksheet`,parent:this.rootFile.file.xml},e=>{let 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:t.state===`visible`}})[0]}extractSheetViews(e){return this.mapOnElements({parent:e,query:`sheetView`},e=>{let 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(){let e=bE(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 Error(`Missing sheet name`)}getSheetWorkbookInfo(){let e=bE(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find(t=>t.target===e).id,n=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(!n)throw Error(`Cannot find corresponding workbook sheet`);return n}extractConditionalFormats(){return new rO(this.rootFile,this.xlsxFileStructure,this.warningManager,this.theme).extractConditionalFormattings()}extractFigures(e){return this.mapOnElements({parent:e,query:`drawing`},e=>{let t=this.extractAttr(e,`r:id`,{required:!0})?.asString();return new aO(this.getTargetXmlFile(this.relationships[t]),this.xlsxFileStructure,this.warningManager).extractFigures()})[0]||[]}extractTables(e){return this.mapOnElements({query:`tablePart`,parent:e},e=>{let t=this.extractAttr(e,`r:id`,{required:!0})?.asString();return new sO(this.getTargetXmlFile(this.relationships[t]),this.xlsxFileStructure,this.warningManager).getTable()})}extractPivotTables(){try{return Object.values(this.relationships).filter(e=>e.type.endsWith(`pivotTable`)).map(e=>new oO(this.getTargetXmlFile(e),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){let t=this.querySelector(e,`sheetFormatPr`);if(t)return{defaultColWidth:this.extractAttr(t,`defaultColWidth`,{default:`8.43`}).asNum(),defaultRowHeight:this.extractAttr(t,`defaultRowHeight`,{default:`12.75`}).asNum()}}extractCols(e){return this.mapOnElements({parent:e,query:`cols col`},e=>({width:this.extractAttr(e,`width`)?.asNum(),customWidth:this.extractAttr(e,`customWidth`)?.asBool(),bestFit:this.extractAttr(e,`bestFit`)?.asBool(),hidden:this.extractAttr(e,`hidden`)?.asBool(),min:this.extractAttr(e,`min`,{required:!0})?.asNum(),max:this.extractAttr(e,`max`,{required:!0})?.asNum(),styleIndex:this.extractAttr(e,`style`)?.asNum()}))}extractRows(e){let t=new Set;return this.mapOnElements({parent:e,query:`sheetData row`},e=>({index:this.extractAttr(e,`r`,{required:!0})?.asNum(),cells:this.extractCells(e,t),height:this.extractAttr(e,`ht`)?.asNum(),customHeight:this.extractAttr(e,`customHeight`)?.asBool(),hidden:this.extractAttr(e,`hidden`)?.asBool(),styleIndex:this.extractAttr(e,`s`)?.asNum()}))}extractCells(e,t){return this.mapOnElements({parent:e,query:`c`},e=>{let n=this.extractAttr(e,`r`,{required:!0})?.asString(),r=this.extractCellFormula(e);if(r?.ref&&r.sharedIndex===void 0){let e=ea(r.ref);for(let{col:r,row:i}of ba(e)){let e=O(r,i);e!==n&&t.add(e)}}let i=t.has(n);return{xc:n,styleIndex:this.extractAttr(e,`s`)?.asNum(),type:$T[this.extractAttr(e,`t`,{default:`n`})?.asString()],value:i?void 0:this.extractChildTextContent(e,`v`)??void 0,formula:i?void 0:r}})}extractCellFormula(e){let t=this.querySelector(e,`f`);if(!t)return;let n=this.extractTextContent(t),r=this.extractAttr(t,`si`)?.asNum(),i=this.extractAttr(t,`ref`)?.asString();if(!((n===void 0||n.trim()===``)&&r===void 0))return{content:n,sharedIndex:r,ref:i}}extractHyperLinks(e){return this.mapOnElements({parent:e,query:`hyperlink`},e=>{let t=this.extractAttr(e,`r:id`)?.asString();return{xc:this.extractAttr(e,`ref`,{required:!0})?.asString(),location:this.extractAttr(e,`location`)?.asString(),display:this.extractAttr(e,`display`)?.asString(),relTarget:t?this.relationships[t].target:void 0}})}extractSharedFormulas(e){let t=this.querySelectorAll(e,`f[si][ref]`),n={};for(let e of t){let t=this.extractAttr(e,`si`,{required:!0}).asNum();n[t]=this.extractTextContent(e,{required:!0})}let r=[];for(let e=0;e<Object.keys(n).length;e++)n[e]?r.push(n[e]):(this.warningManager.addParsingWarning(`Missing shared formula ${e}, replacing it by empty formula`),r.push(``));return r}},lO=class extends tO{theme;constructor(e,t,n){super(e.styles,e,t),this.theme=n}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){let t=this.extractChildAttr(e,`name`,`val`,{default:`Arial`}).asString(),n=this.extractChildAttr(e,`sz`,`val`,{default:Me.toString()}).asNum(),r=this.extractColor(this.querySelector(e,`color`),this.theme),i=this.querySelector(e,`i`)||void 0,a=i&&i.attributes.val?.value!==`0`,o=this.querySelector(e,`b`)||void 0,s=o&&o.attributes.val?.value!==`0`,c=this.querySelector(e,`strike`)||void 0,l=c&&c.attributes.val?.value!==`0`,u=this.querySelector(e,`u`)||void 0;return{name:t,size:n,color:r,italic:a,bold:s,underline:u&&u.attributes.val?.value!==`none`,strike:l}}getFills(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`fill`},e=>this.extractFill(e))}extractFill(e){let t=e.children[0];return t.tagName===`patternFill`?{patternType:t.attributes.patternType?.value,bgColor:this.extractColor(this.querySelector(t,`bgColor`),this.theme),fgColor:this.extractColor(this.querySelector(t,`fgColor`),this.theme)}:{patternType:`solid`,fgColor:this.extractColor(this.querySelectorAll(t,`color`)[1],this.theme)}}getBorders(){return this.mapOnElements({parent:this.rootFile.file.xml,query:`border`},e=>this.extractBorder(e))}extractBorder(e){let t={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 t.diagonal&&(t.diagonalUp=this.extractAttr(e,`diagonalUp`)?.asBool(),t.diagonalDown=this.extractAttr(e,`diagonalDown`)?.asBool()),t}extractSingleBorder(e,t,n){let r=this.querySelector(e,t);if(!(!r||!r.attributes.style))return{style:this.extractAttr(r,`style`,{required:!0,default:`thin`}).asString(),color:this.extractColor(r.children[0],n,`000000`)}}extractAlignment(e){return{horizontal:this.extractAttr(e,`horizontal`,{default:`general`}).asString(),vertical:this.extractAttr(e,`vertical`,{default:`bottom`}).asString(),textRotation:this.extractAttr(e,`textRotation`)?.asNum(),wrapText:this.extractAttr(e,`wrapText`)?.asBool(),indent:this.extractAttr(e,`indent`)?.asNum(),relativeIndent:this.extractAttr(e,`relativeIndent`)?.asNum(),justifyLastLine:this.extractAttr(e,`justifyLastLine`)?.asBool(),shrinkToFit:this.extractAttr(e,`shrinkToFit`)?.asBool(),readingOrder:this.extractAttr(e,`readingOrder`)?.asNum()}}getDxfs(){return this.mapOnElements({query:`dxf`,parent:this.rootFile.file.xml},e=>{let t=this.querySelector(e,`font`),n=this.querySelector(e,`fill`),r=this.querySelector(e,`border`),i=this.querySelector(e,`numFmt`),a=this.querySelector(e,`alignment`);return{font:t?this.extractFont(t):void 0,fill:n?this.extractFill(n):void 0,numFmt:i?this.extractNumFormats(i):void 0,alignment:a?this.extractAlignment(a):void 0,border:r?this.extractBorder(r):void 0}})}getStyles(){return this.mapOnElements({query:`cellXfs xf`,parent:this.rootFile.file.xml},e=>{let 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}})}},uO=class extends tO{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=>{let t=this.mapOnElements({parent:e,query:`cell`},e=>({xc:this.extractAttr(e,`r`,{required:!0}).asString(),value:this.extractChildTextContent(e,`v`,{required:!0})})),n={};for(let e of t)n[e.xc]=e.value;return{sheetId:this.extractAttr(e,`sheetId`,{required:!0}).asNum(),data:n}})}};function dO(e,t){return fO(pO(e,t),t)}function fO(e,t){let n=[];for(let r of e){let e=mO(r,t);n.push({file:{fileName:r,xml:t[r]},rels:e?{fileName:e,xml:t[e]}:void 0})}return n}function pO(e,t){let n=t[`[Content_Types].xml`].querySelectorAll(`Override[ContentType="${e}"]`),r=[];for(let e of n){let t=e?.attributes.PartName.value;r.push(t.substring(1))}return r}function mO(e,t){if(e===`[Content_Types].xml`)return`_rels/.rels`;let n=``,r=e.split(`/`);for(let e=0;e<r.length-1;e++)n+=r[e]+`/`;return n+=`_rels/`,n+=r[r.length-1]+`.rels`,t[n]||(n=void 0),n}var hO=class{warningManager;xmls;images;constructor(e){this.warningManager=new KT,this.xmls={},this.images=[];for(let t of Object.keys(e))if(t.endsWith(`.xml`)||t.endsWith(`.rels`)){let n=QD(e[t]);this.xmls[t]=KD(new Rw(n))}else t.includes(`media/image`)&&this.images.push({fileName:t,imageSrc:e[t].imageSrc})}convertXlsx(){let e=this.getXlsxData();return this.convertImportedData(e)}getXlsxData(){let e=this.buildXlsxFileStructure(),t=e.theme?new nO(e.theme,e,this.warningManager).getTheme():void 0,n=e.sharedStrings?new nO(e.sharedStrings,e,this.warningManager).getSharedStrings():[],r=e.sheets.sort((e,t)=>e.file.fileName.localeCompare(t.file.fileName,void 0,{numeric:!0})).map(n=>new cO(n,e,this.warningManager,t).getSheet()),i=e.externalLinks.map(t=>new uO(t,e,this.warningManager).getExternalBook()),a=new lO(e,this.warningManager,t);return{fonts:a.getFonts(),fills:a.getFills(),borders:a.getBorders(),dxfs:a.getDxfs(),numFmts:a.getNumFormats(),styles:a.getStyles(),sheets:r,sharedStrings:n,externalBooks:i}}buildXlsxFileStructure(){let e={sheets:dO(Gw.sheet,this.xmls),workbook:dO(Gw.workbook,this.xmls)[0],styles:dO(Gw.styles,this.xmls)[0],sharedStrings:dO(Gw.sharedStrings,this.xmls)[0],theme:dO(Gw.themes,this.xmls)[0],charts:dO(Gw.chart,this.xmls),figures:dO(Gw.drawing,this.xmls),tables:dO(Gw.table,this.xmls),pivots:dO(Gw.pivot,this.xmls),externalLinks:dO(Gw.externalLink,this.xmls),images:this.images};if(!e.workbook.rels)throw Error(y(`Cannot find workbook relations file`));return e}convertImportedData(e){let t={version:12,sheets:TD(e,this.warningManager),styles:jE(e,this.warningManager),formats:NE(e,this.warningManager),borders:kE(e,this.warningManager),entities:{},revisionId:Le};return ID(t,e),Object.keys(e.styles).map(t=>{e.styles[t]=St(e.styles[t])}),t}};function gO(e){let t=lT(e),n=[];return{text:``.concat(...t.map(e=>{if(e.type===`REFERENCE`&&Ri.test(e.value)){let t=e.value.trim();return n.includes(t)||n.push(t),`|${n.indexOf(t)}|`}else return e.value})),dependencies:n}}let _O=14.5,vO=`Sheet1`;function yO(e,t){if(!e)return MO();if(e[`[Content_Types].xml`]){let n=new hO(e);if(e=n.convertXlsx(),t)for(let e of n.warningManager.warnings.sort())console.warn(e)}return`version`in e&&e.version<14.5&&(e=bO(e)),e=SO(e),e}function bO(e){let t=xO.findIndex(t=>t.from===e.version);for(let n=t;n<xO.length;n++)e=xO[n].applyMigration(e);return e}let xO=[{description:"add the `activeSheet` field on data",from:1,to:2,applyMigration(e){return 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){return e.sheets&&e.activeSheet&&(e.activeSheet=e.sheets.find(t=>t.name===e.activeSheet).id),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||[]){let n=t.cells[e];n.content&&n.content.startsWith(`=`)&&(n.formula=gO(n.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||[]){let{dataSets:n,...r}=t.figures[e].data,i=[];for(let e of n)if(e.labelCell){let t=ea(e.dataRange),n=e.labelCell+`:`+O(t.right,t.bottom);i.push(n)}else i.push(e.dataRange);r.dataSetsHaveTitle=!!n[0].labelCell,r.dataSets=i,t.figures[e].data=r}return e}},{description:`remove single quotes in sheet names`,from:7,to:8,applyMigration(e){let t=[],n=new RegExp(He,`g`);for(let r of e.sheets||[]){if(!r.name)continue;let e=r.name,i=e.replace(n,`_`),a=1,o=i;for(;t.includes(o);)o=`${i}${a}`,a++;r.name=o,t.push(o);let s=t=>{if(t===void 0)return t;let n=t.replace(e,o),r=t;for(;r!==n;)r=n,n=r.replace(e,o);return r};for(let e in r.cells){let t=r.cells[e];t.formula&&(t.formula.dependencies=t.formula.dependencies.map(s))}for(let e of r.figures||[])if(e.type===`chart`){let t=e.data.dataSets.map(s),n=s(e.data.labelRange);e.data={...e.data,dataSets:t,labelRange:n}}for(let e of r.conditionalFormats||[]){e.ranges=e.ranges.map(s);for(let t of[`minimum`,`maximum`,`midpoint`,`upperInflectionPoint`,`lowerInflectionPoint`])e.rule[t]?.type===`formula`&&(e.rule[t].value=s(e.rule[t].value))}}return e}},{description:`transform chart data structure with design attributes`,from:8,to:9,applyMigration(e){for(let t of e.sheets||[])for(let e of t.figures||[])e.data.background=me,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||[]){let n=t.cells[e];if(n.formula){let{text:e,dependencies:t}=n.formula;for(let[n,r]of Object.entries(t)){let t=`\\|${n}\\|`;e=e.replace(new RegExp(t,`g`),r)}n.content=e,delete n.formula}}return e}},{description:`normalize the formats of the cells`,from:10,to:11,applyMigration(e){let t={};for(let n of e.sheets||[])for(let e in n.cells||[]){let r=n.cells[e];r.format&&=ht(r.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){return kO(e)}},{description:`Change Border description structure`,from:12.5,to:13,applyMigration(e){for(let t in e.borders){let n=e.borders[t];for(let e in n)Array.isArray(n[e])&&(n[e]={style:n[e][0],color:n[e][1]})}return e}},{description:`Add locale to spreadsheet settings`,from:13,to:14,applyMigration(e){return e.settings||={},e.settings.locale||(e.settings.locale=A),e}},{description:`Fix datafilter duplication (post saas-16.4)`,from:14,to:14.5,applyMigration(e){return kO(e)}}];function SO(e){return e=CO(e),e=wO(e),e}function CO(e){if(e.uniqueFigureIds)return e;let t=new Set,n=new ko;for(let r of e.sheets||[])for(let e of r.figures||[])t.has(e.id)&&(e.id+=n.smallUuid()),t.add(e.id);return e.uniqueFigureIds=!0,e}function wO(e){let t=Object.assign(MO(),e,{version:_O});return t.sheets=t.sheets?t.sheets.map((e,t)=>Object.assign(jO(`Sheet${t+1}`,`Sheet${t+1}`),e)):[],t.sheets.length===0&&t.sheets.push(jO(vO,`Sheet1`)),Fc(t.settings.locale)||(t.settings.locale=A),t}function TO(e,t){return t=EO(e,t),t=DO(t,`SORT_CELLS`),t=DO(t,`SET_DECIMAL`),t=OO(e,t),t=AO(e,t),t}function EO(e,t){if(Object.keys(e).length!==0)return t;let n=[],r=[],i=e=>{if(e.type===`CREATE_SHEET`)n.push(e.sheetId);else if(`sheetId`in e&&!n.includes(e.sheetId))return{...e,sheetId:vO};return e};for(let e of t)e.type===`REMOTE_REVISION`?r.push({...e,commands:e.commands.map(i)}):r.push(e);return r}function DO(e,t){let n=[];for(let r of e)r.type===`REMOTE_REVISION`?n.push({...r,commands:r.commands.filter(e=>e.type!==t)}):n.push(r);return n}function OO(e,t){let n=[],r={};for(let t of e.sheets||[])t.figures?.forEach(e=>{e.tag===`chart`&&(r[e.id]=e.data)});for(let e of t)if(e.type===`REMOTE_REVISION`){let t=[];for(let n of e.commands){let e=n;switch(n.type){case`CREATE_CHART`:r[n.id]=n.definition;break;case`UPDATE_CHART`:if(!r[n.id]){console.log(`Fix chart definition: chart with id ${n.id} not found.`);continue}let t={...r[n.id],...n.definition};e={...n,definition:t},r[n.id]=t;break}t.push(e)}n.push({...e,commands:t})}else n.push(e);return n}function kO(e){for(let t of e.sheets||[]){let e=[];for(let n of t.filterTables||[]){let t=ea(n.range),r=e.findIndex(e=>ua(e,t));r===-1?e.push(t):e[r]=t}t.filterTables=e.map(e=>({range:B(e)}))}return e}function AO(e,t){let n={};for(let t of e.sheets||[])n[t.id]=t.name;let r=[];for(let e of t)if(e.type===`REMOTE_REVISION`){let t=[];for(let r of e.commands){switch(r.type){case`DUPLICATE_SHEET`:r.sheetNameTo=r.sheetNameTo??Wa(n[r.sheetId],Object.values(n));break;case`CREATE_SHEET`:case`RENAME_SHEET`:n[r.sheetId]=r.name||Ua(Object.values(n));break}t.push(r)}r.push({...e,commands:t})}else r.push(e);return t}function jO(e,t){return{id:e,name:t,colNumber:26,rowNumber:100,cells:{},cols:{},rows:{},merges:[],conditionalFormats:[],figures:[],filterTables:[],isVisible:!0}}function MO(e=`Sheet1`){return{version:_O,sheets:[jO(vO,e)],entities:{},styles:{},formats:{},borders:{},revisionId:Le,uniqueFigureIds:!0,settings:{locale:A}}}function NO(e,t){return{...jO(e,t),charts:[],images:[]}}function PO(){return{...MO(),sheets:[NO(vO,`Sheet1`)]}}var FO=class{static getters=[];history;dispatch;constructor(e,t){this.history=Object.assign(Object.create(e),{update:e.addChange.bind(e,this),selectCell:()=>{}}),this.dispatch=t}exportForExcel(e){}allowDispatch(e){return`Success`}beforeHandle(e){}handle(e){}finalize(){}batchValidations(...e){return t=>e.map(e=>e.call(this,t)).flat()}chainValidations(...e){return t=>{for(let n of e){let e=n.call(this,t);Array.isArray(e)||(e=[e]);let r=e.filter(e=>e!==`Success`);if(r.length)return r}return`Success`}}checkValidations(e,...t){return this.batchValidations(...t)(e)}},IO=class extends FO{getters;uuidGenerator;constructor({getters:e,stateObserver:t,range:n,dispatch:r,uuidGenerator:i}){super(t,r),n.addRangeProvider(this.adaptRanges.bind(this)),this.getters=e,this.uuidGenerator=i}import(e){}export(e){}adaptRanges(e,t){}garbageCollectExternalResources(){}},LO=class extends IO{static getters=[`getCellBorder`,`getBordersColors`];borders={};allowDispatch(e){switch(e.type){case`SET_BORDER`:return this.checkBordersUnchanged(e);default:return`Success`}}handle(e){switch(e.type){case`ADD_MERGE`:for(let t of e.target)this.addBordersToMerge(e.sheetId,t);break;case`DUPLICATE_SHEET`:let t=this.borders[e.sheetId];if(t){let n=t.slice().map(e=>e?.slice().map(e=>({...e})));this.history.update(`borders`,e.sheetIdTo,n)}break;case`DELETE_SHEET`:let n={...this.borders};delete n[e.sheetId],this.history.update(`borders`,n);break;case`SET_BORDER`:this.setBorder(e.sheetId,e.col,e.row,e.border);break;case`SET_BORDERS_ON_TARGET`:for(let t of e.target)for(let n=t.top;n<=t.bottom;n++)for(let r=t.left;r<=t.right;r++)this.setBorder(e.sheetId,r,n,e.border);break;case`SET_ZONE_BORDERS`:if(e.border){let t=e.target.map(t=>this.getters.expandZone(e.sheetId,t));this.setBorders(e.sheetId,t,e.border.position,e.border.color===``?void 0:{style:e.border.style||Pe.style,color:e.border.color||Pe.color})}break;case`CLEAR_FORMATTING`:this.clearBorders(e.sheetId,e.target);break;case`REMOVE_COLUMNS_ROWS`:let r=[...e.elements].sort((e,t)=>t-e);for(let t of et(r))if(e.dimension===`COL`){if(t[0]>=this.getters.getNumberCols(e.sheetId))for(let n=0;n<this.getters.getNumberRows(e.sheetId);n++)this.history.update(`borders`,e.sheetId,t[0]+1,n,`vertical`,void 0);if(t[t.length-1]===0)for(let t=0;t<this.getters.getNumberRows(e.sheetId);t++)this.history.update(`borders`,e.sheetId,0,t,`vertical`,void 0);let n=this.getters.getColsZone(e.sheetId,t[t.length-1]+1,t[0]);this.clearInsideBorders(e.sheetId,[n]),this.shiftBordersHorizontally(e.sheetId,t[0]+1,-t.length)}else{if(t[0]>=this.getters.getNumberRows(e.sheetId))for(let n=0;n<this.getters.getNumberCols(e.sheetId);n++)this.history.update(`borders`,e.sheetId,n,t[0]+1,`horizontal`,void 0);if(t[t.length-1]===0)for(let t=0;t<this.getters.getNumberCols(e.sheetId);t++)this.history.update(`borders`,e.sheetId,t,0,`horizontal`,void 0);let n=this.getters.getRowsZone(e.sheetId,t[t.length-1]+1,t[0]);this.clearInsideBorders(e.sheetId,[n]),this.shiftBordersVertically(e.sheetId,t[0]+1,-t.length)}break;case`ADD_COLUMNS_ROWS`:e.dimension===`COL`?this.handleAddColumns(e):this.handleAddRows(e);break}}handleAddColumns(e){let t,n;e.position===`before`?(this.shiftBordersHorizontally(e.sheetId,e.base,e.quantity,{moveFirstLeftBorder:!0}),t=e.base-1,n=e.base+e.quantity):(this.shiftBordersHorizontally(e.sheetId,e.base+1,e.quantity,{moveFirstLeftBorder:!1}),t=e.base,n=e.base+e.quantity+1),this.ensureColumnBorderContinuity(e.sheetId,t,n)}handleAddRows(e){let t,n;e.position===`before`?(this.shiftBordersVertically(e.sheetId,e.base,e.quantity,{moveFirstTopBorder:!0}),t=e.base-1,n=e.base+e.quantity):(this.shiftBordersVertically(e.sheetId,e.base+1,e.quantity,{moveFirstTopBorder:!1}),t=e.base,n=e.base+e.quantity+1),this.ensureRowBorderContinuity(e.sheetId,t,n)}getCellBorder({sheetId:e,col:t,row:n}){let r={top:this.borders[e]?.[t]?.[n]?.horizontal,bottom:this.borders[e]?.[t]?.[n+1]?.horizontal,left:this.borders[e]?.[t]?.[n]?.vertical,right:this.borders[e]?.[t+1]?.[n]?.vertical};return!r.bottom&&!r.left&&!r.right&&!r.top?null:r}getBordersColors(e){let t=[],n=this.borders[e];if(n)for(let e of n.filter(T))for(let n of e)n?.horizontal&&t.push(n.horizontal.color),n?.vertical&&t.push(n.vertical.color);return t}ensureColumnBorderContinuity(e,t,n){let r=w(t+1,n);for(let i=0;i<this.getters.getNumberRows(e);i++){let a=this.getCellBorder({sheetId:e,col:t,row:i}),o=this.getCellBorder({sheetId:e,col:n,row:i});if(a&&o){let t=this.getCommonSides(a,o);for(let n of r)this.addBorder(e,n,i,t)}}}ensureRowBorderContinuity(e,t,n){let r=w(t+1,n);for(let i=0;i<this.getters.getNumberCols(e);i++){let a=this.getCellBorder({sheetId:e,col:i,row:t}),o=this.getCellBorder({sheetId:e,col:i,row:n});if(a&&o){let t=this.getCommonSides(a,o);for(let n of r)this.addBorder(e,i,n,t)}}}getCommonSides(e,t){let n={};for(let r of[`top`,`bottom`,`left`,`right`])e[r]&&E(e[r],t[r])&&(n[r]=e[r]);return n}getColumnsWithBorders(e){let t=this.borders[e];return t?Object.keys(t).map(e=>parseInt(e,10)):[]}getRowsWithBorders(e){let t=this.borders[e]?.filter(T);if(!t)return[];let n=new Set;for(let e of t)for(let t in e)n.add(parseInt(t,10));return Array.from(n)}getRowsRange(e){return this.borders[e]?w(0,this.getters.getNumberRows(e)+1):[]}shiftBordersHorizontally(e,t,n,{moveFirstLeftBorder:r}={}){this.borders[e]&&(n<0&&this.moveBordersOfColumn(e,t,n,`vertical`,{destructive:!1}),this.getColumnsWithBorders(e).filter(e=>e>=t).sort((e,t)=>n<0?e-t:t-e).forEach(i=>{(i===t&&r||i!==t)&&this.moveBordersOfColumn(e,i,n,`vertical`),this.moveBordersOfColumn(e,i,n,`horizontal`)}))}shiftBordersVertically(e,t,n,{moveFirstTopBorder:r}={}){this.borders[e]&&(n<0&&this.moveBordersOfRow(e,t,n,`horizontal`,{destructive:!1}),this.getRowsWithBorders(e).filter(e=>e>=t).sort((e,t)=>n<0?e-t:t-e).forEach(i=>{(i===t&&r||i!==t)&&this.moveBordersOfRow(e,i,n,`horizontal`),this.moveBordersOfRow(e,i,n,`vertical`)}))}moveBordersOfRow(e,t,n,r,{destructive:i}={destructive:!0}){let a=this.borders[e];a&&this.getColumnsWithBorders(e).forEach(o=>{let s=a[o]?.[t+n]?.[r],c=a[o]?.[t]?.[r];this.history.update(`borders`,e,o,t+n,r,i?c:c||s),this.history.update(`borders`,e,o,t,r,void 0)})}moveBordersOfColumn(e,t,n,r,{destructive:i}={destructive:!0}){let a=this.borders[e];a&&this.getRowsRange(e).forEach(o=>{let s=a[t+n]?.[o]?.[r],c=a[t]?.[o]?.[r];this.history.update(`borders`,e,t+n,o,r,i?c:c||s),this.history.update(`borders`,e,t,o,r,void 0)})}setBorder(e,t,n,r,i=!0){(i||!this.borders?.[e]?.[t]?.[n]?.vertical)&&this.history.update(`borders`,e,t,n,`vertical`,r?.left),(i||!this.borders?.[e]?.[t]?.[n]?.horizontal)&&this.history.update(`borders`,e,t,n,`horizontal`,r?.top),(i||!this.borders?.[e]?.[t+1]?.[n]?.vertical)&&this.history.update(`borders`,e,t+1,n,`vertical`,r?.right),(i||!this.borders?.[e]?.[t]?.[n+1]?.horizontal)&&this.history.update(`borders`,e,t,n+1,`horizontal`,r?.bottom)}clearBorders(e,t){for(let n of t){for(let t=n.top;t<=n.bottom;t++){this.history.update(`borders`,e,n.right+1,t,`vertical`,void 0);for(let r=n.left;r<=n.right;r++)this.history.update(`borders`,e,r,t,void 0)}for(let t=n.left;t<=n.right;t++)this.history.update(`borders`,e,t,n.bottom+1,`horizontal`,void 0)}}clearInsideBorders(e,t){for(let n of t)for(let t=n.top;t<=n.bottom;t++)for(let r=n.left;r<=n.right;r++)this.history.update(`borders`,e,r,t,void 0)}addBorder(e,t,n,r){this.setBorder(e,t,n,{...this.getCellBorder({sheetId:e,col:t,row:n}),...r})}setBorders(e,t,n,r){if(n===`clear`)return this.clearBorders(e,t);for(let i of t){if(n===`h`||n===`hv`||n===`all`)for(let t=i.top+1;t<=i.bottom;t++)for(let n=i.left;n<=i.right;n++)this.addBorder(e,n,t,{top:r});if(n===`v`||n===`hv`||n===`all`)for(let t=i.top;t<=i.bottom;t++)for(let n=i.left+1;n<=i.right;n++)this.addBorder(e,n,t,{left:r});if(n===`left`||n===`all`||n===`external`)for(let t=i.top;t<=i.bottom;t++)this.addBorder(e,i.left,t,{left:r});if(n===`right`||n===`all`||n===`external`)for(let t=i.top;t<=i.bottom;t++)this.addBorder(e,i.right+1,t,{left:r});if(n===`top`||n===`all`||n===`external`)for(let t=i.left;t<=i.right;t++)this.addBorder(e,t,i.top,{top:r});if(n===`bottom`||n===`all`||n===`external`)for(let t=i.left;t<=i.right;t++)this.addBorder(e,t,i.bottom+1,{top:r})}}addBordersToMerge(e,t){let{left:n,right:r,top:i,bottom:a}=t,o=this.getCellBorder({sheetId:e,col:n,row:i}),s=this.getCellBorder({sheetId:e,col:r,row:a});this.clearBorders(e,[t]),o?.top&&this.setBorders(e,[{...t,bottom:i}],`top`,o.top),o?.left&&this.setBorders(e,[{...t,right:n}],`left`,o.left),s?.bottom?this.setBorders(e,[{...t,top:a}],`bottom`,s.bottom):o?.bottom&&this.setBorders(e,[{...t,top:a}],`bottom`,o.bottom),s?.right?this.setBorders(e,[{...t,left:r}],`right`,s.right):o?.right&&this.setBorders(e,[{...t,left:r}],`right`,o.right)}checkBordersUnchanged(e){let t=this.getCellBorder(e),n=!e.border?.bottom&&!e.border?.left&&!e.border?.right&&!e.border?.top;return!t&&n||E(t,e.border)?`NoChanges`:`Success`}import(e){if(Object.keys(e.borders||{}).length)for(let t of e.sheets)for(let n in t.cells){let r=t.cells[n];if(r?.border){let i=e.borders[r.border],{col:a,row:o}=rn(n);this.setBorder(t.id,a,o,i,!1)}}for(let t of e.sheets)if(t.merges)for(let e of t.merges)this.addBordersToMerge(t.id,ea(e))}export(e){let t={};for(let n of e.sheets)for(let e=0;e<n.colNumber;e++)for(let r=0;r<n.rowNumber;r++){let i=this.getCellBorder({sheetId:n.id,col:e,row:r});if(i){let a=O(e,r),o=n.cells[a],s=ht(i,t);o?o.border=s:n.cells[a]={border:s}}}e.borders=t}exportForExcel(e){this.export(e)}},RO=class extends IO{static getters=[`zoneToXC`,`getCells`,`getFormulaCellContent`,`getTranslatedCellFormula`,`getCellStyle`,`getCellById`];nextId=1;cells={};adaptRanges(e,t){for(let n of Object.keys(this.cells))for(let r of Object.values(this.cells[n]||{}))if(r.isFormula){for(let i of r.compiledFormula.dependencies)if(!t||i.sheetId===t){let t=e(i);t.changeType!==`NONE`&&this.history.update(`cells`,n,r.id,`compiledFormula`,`dependencies`,r.compiledFormula.dependencies.indexOf(i),t.range)}}}allowDispatch(e){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||this.cells[e.sheetId]?.[e.cellId]?`Success`:`InvalidCellId`;default:return`Success`}}handle(e){switch(e.type){case`SET_FORMATTING`:`style`in e&&this.setStyle(e.sheetId,e.target,e.style),`format`in e&&e.format!==void 0&&this.setFormatter(e.sheetId,e.target,e.format);break;case`CLEAR_FORMATTING`:this.clearFormatting(e.sheetId,e.target);break;case`ADD_COLUMNS_ROWS`:e.dimension===`COL`?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`CLEAR_CELLS`:this.clearCells(e.sheetId,e.target);break;case`DELETE_SHEET`:this.history.update(`cells`,e.sheetId,void 0)}}setFormatter(e,t,n){for(let r of t)for(let t=r.top;t<=r.bottom;t++)for(let i=r.left;i<=r.right;i++)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:i,row:t,format:n})}clearFormatting(e,t){for(let n of t)for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,style:null,format:``})}clearCells(e,t){for(let n of t)for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,content:``,style:null,format:``})}handleAddColumnsRows(e,t){let n,r;e.position===`before`?(n=w(e.base,e.base+e.quantity),r=e.base+e.quantity):(n=w(e.base+1,e.base+e.quantity+1),r=e.base),t(e.sheetId,r,n)}import(e){for(let t of e.sheets)for(let n in t.cells){let r=t.cells[n],{col:i,row:a}=rn(n);if(r?.content||r?.format||r?.style){let n=this.importCell(t.id,r,e.styles,e.formats);this.history.update(`cells`,t.id,n.id,n),this.dispatch(`UPDATE_CELL_POSITION`,{cellId:n.id,col:i,row:a,sheetId:t.id})}}}export(e){let t={},n={};for(let r of e.sheets){let e={},i=Object.keys(this.cells[r.id]||{}).map(e=>this.getters.getCellPosition(e)).sort((e,t)=>e.col===t.col?e.row-t.row:e.col-t.col);for(let r of i){let i=this.getters.getCell(r),a=O(r.col,r.row),o=this.extractCustomStyle(i);e[a]={style:Object.keys(o).length?ht(o,t):void 0,format:i.format?ht(i.format,n):void 0,content:i.content||void 0}}r.cells=e}e.styles=t,e.formats=n}importCell(e,t,n,r){let i=t.style&&n[t.style]||void 0,a=t.format&&r[t.format]||void 0,o=this.getNextUid();return this.createCell(o,t?.content||``,a,i,e)}exportForExcel(e){this.export(e)}extractCustomStyle(e){let t={...e.style},n=Yn(e.content,A)?ke:Oe;for(let r in t)(r!==`align`||!e.isFormula)&&t[r]===n[r]&&delete t[r];return t}getCells(e){return this.cells[e]||{}}getCellById(e){let t=this.getters.getCellPosition(e);return this.cells[t.sheetId][e]}getFormulaCellContent(e,t,n,r=!1){let i=n||t.dependencies,a=0;return _t(t.tokens.map(t=>{if(t.type===`REFERENCE`){let t=i[a++];return this.getters.getRangeString(t,e,{useFixedReference:r})}return t.value}))}getTranslatedCellFormula(e,t,n,r){let i=this.getters.createAdaptedRanges(r.dependencies,t,n,e);return this.getFormulaCellContent(e,r,i)}getCellStyle(e){return this.getters.getCell(e)?.style||{}}zoneToXC(e,t,n=[{colFixed:!1,rowFixed:!1}]){t=this.getters.expandZone(e,t);let r=O(t.left,t.top,n[0]),i=O(t.right,t.bottom,n.length>1?n[1]:n[0]),a=this.getters.getMainCellPosition({sheetId:e,col:t.left,row:t.top}),o=this.getters.getMainCellPosition({sheetId:e,col:t.right,row:t.bottom}),s=a.col===o.col&&a.row===o.row;return r!==i&&!s?r+`:`+i:r}setStyle(e,t,n){for(let r of t)for(let t=r.left;t<=r.right;t++)for(let i=r.top;i<=r.bottom;i++){let r=this.getters.getCell({sheetId:e,col:t,row:i});this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:i,style:n?{...r?.style,...n}:void 0})}}copyColumnStyle(e,t,n){for(let r=0;r<this.getters.getNumberRows(e);r++){let i=this.getFormat(e,t,r);if(i.style||i.format)for(let t of n)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,...i})}}copyRowStyle(e,t,n){for(let r=0;r<this.getters.getNumberCols(e);r++){let i=this.getFormat(e,r,t);if(i.style||i.format)for(let t of n)this.dispatch(`UPDATE_CELL`,{sheetId:e,col:r,row:t,...i})}}getFormat(e,t,n){let r={},i=this.getters.getMainCellPosition({sheetId:e,col:t,row:n}),a=this.getters.getCell(i);return a&&(a.style&&(r.style=a.style),a.format&&(r.format=a.format)),r}getNextUid(){let e=this.nextId.toString();return this.history.update(`nextId`,this.nextId+1),e}updateCell(e,t,n,r){let i=this.getters.getCell({sheetId:e,col:t,row:n}),a=r.content!==void 0||`formula`in r,o=a?Tt(r?.content||void 0):i?.content||``,s;s=r.style===void 0?i?i.style:void 0:r.style||void 0;let c=r.format===void 0?i&&i.format:r.format;if((a&&!o&&!r.formula||!a&&(!i||i.content===``))&&!s&&!c){i&&(this.history.update(`cells`,e,i.id,void 0),this.dispatch(`UPDATE_CELL_POSITION`,{cellId:void 0,col:t,row:n,sheetId:e}));return}let l=i?.id||this.getNextUid(),u=this.createCell(l,o,c,s,e);this.history.update(`cells`,e,u.id,u),this.dispatch(`UPDATE_CELL_POSITION`,{cellId:u.id,col:t,row:n,sheetId:e})}createCell(e,t,n,r,i){if(!t.startsWith(`=`))return this.createLiteralCell(e,t,n,r);try{return this.createFormulaCell(e,t,n,r,i)}catch(i){return this.createErrorFormula(e,t,n,r,i)}}createLiteralCell(e,t,n,r){let i=this.getters.getLocale();return{id:e,content:to(t,i).toString(),style:r,format:n||wi(t,i)||Ti(t),isFormula:!1}}createFormulaCell(e,t,n,r,i){let a=NT(t);return a.dependencies.length?this.createFormulaCellWithDependencies(e,a,n,r,i):{id:e,content:t,style:r,format:n,isFormula:!0,compiledFormula:{...a,dependencies:[]}}}createFormulaCellWithDependencies(e,t,n,r,i){let a=[];for(let e of t.dependencies)a.push(this.getters.getRangeFromSheetXC(i,e));return new zO(e,t,n,r,a,i,this.getters.getRangeString)}createErrorFormula(e,t,n,r,i){return{id:e,content:t,style:r,format:n,isFormula:!0,compiledFormula:{tokens:vc(t),dependencies:[],execute:function(){throw i}}}}checkCellOutOfSheet(e){let{sheetId:t,col:n,row:r}=e;return this.getters.tryGetSheet(t)?da(n,r,this.getters.getSheetZone(t))?`Success`:`TargetOutOfSheet`:`InvalidSheetId`}checkUselessClearCell(e){let t=this.getters.getCell(e);return!t||!t.content&&!t.style&&!t.format?`NoChanges`:`Success`}checkUselessUpdateCell(e){let t=this.getters.getCell(e),n=`content`in e||`formula`in e,r=`style`in e,i=`format`in e;return(!n||t?.content===e.content)&&(!r||E(t?.style,e.style))&&(!i||t?.format===e.format)?`NoChanges`:`Success`}},zO=class{id;format;style;sheetId;getRangeString;isFormula=!0;compiledFormula;constructor(e,t,n,r,i,a,o){this.id=e,this.format=n,this.style=r,this.sheetId=a,this.getRangeString=o;let s=0,c=t.tokens.map(e=>e.type===`REFERENCE`?new BO(i,s++,this.sheetId,this.getRangeString):e);this.compiledFormula={...t,dependencies:i,tokens:c}}get content(){return _t(this.compiledFormula.tokens.map(e=>e.value))}get contentWithFixedReferences(){let e=0;return _t(this.compiledFormula.tokens.map(t=>{if(t.type===`REFERENCE`){let t=e++;return this.getRangeString(this.compiledFormula.dependencies[t],this.sheetId,{useFixedReference:!0})}return t.value}))}},BO=class{ranges;rangeIndex;sheetId;getRangeString;type=`REFERENCE`;constructor(e,t,n,r){this.ranges=e,this.rangeIndex=t,this.sheetId=n,this.getRangeString=r}get value(){let e=this.ranges[this.rangeIndex];return this.getRangeString(e,this.sheetId)}},VO=class extends IO{static getters=[`isChartDefined`,`getChartDefinition`,`getChartType`,`getChartIds`,`getChart`,`getContextCreationChart`];charts={};createChart=Ku(this.getters);validateChartDefinition=e=>Ju(this,e.definition);adaptRanges(e){for(let[t,n]of Object.entries(this.charts))this.history.update(`charts`,t,n?.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`Success`}}handle(e){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`:{let t=this.getters.getFigures(e.sheetId);for(let n of t)if(n.tag===`chart`){let t=n.id.split(`??`).pop(),r=`${e.sheetIdTo}??${t}`,i=this.charts[n.id]?.copyForSheetId(e.sheetIdTo);i&&this.dispatch(`CREATE_CHART`,{id:r,position:{x:n.x,y:n.y},size:{width:n.width,height:n.height},definition:i.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);break}}getContextCreationChart(e){return this.charts[e]?.getContextCreation()}getChart(e){return this.charts[e]}getChartType(e){let t=this.charts[e]?.type;if(!t)throw Error(`Chart not defined.`);return t}isChartDefined(e){return e in this.charts&&this.charts!==void 0}getChartIds(e){return Object.entries(this.charts).filter(([,t])=>t?.sheetId===e).map(([e])=>e)}getChartDefinition(e){let t=this.charts[e]?.getDefinition();if(!t)throw Error(`There is no chart with the given figureId: ${e}`);return t}import(e){for(let t of e.sheets)if(t.figures)for(let e of t.figures)e.tag===`chart`&&(this.charts[e.id]=this.createChart(e.id,e.data,t.id))}export(e){if(e.sheets)for(let t of e.sheets){let e=this.getters.getFigures(t.id),n=[];for(let t of e){let e=t;if(e&&e.tag===`chart`){let t=this.charts[e.id]?.getDefinition();t&&(e.data=t,n.push(e))}else n.push(e)}t.figures=n}}addFigure(e,t,n={x:0,y:0},r={width:536,height:335}){if(this.getters.getFigure(t,e))return;let i={id:e,x:n.x,y:n.y,width:r.width,height:r.height,tag:`chart`};this.dispatch(`CREATE_FIGURE`,{sheetId:t,figure:i})}addChart(e,t){let n=this.getters.getFigureSheetId(e);n&&this.history.update(`charts`,e,this.createChart(e,t,n))}checkChartDuplicate(e){return this.getters.getFigureSheetId(e.id)?`DuplicatedChartId`:`Success`}checkChartExists(e){return this.isChartDefined(e.id)?`Success`:`ChartDoesNotExist`}};function HO(e,t=[]){let n=[0],r=new Map([[0,[]]]);return UO(n,r,e,!1),UO(n,r,t,!0),qO(n,r)}function UO(e,t,n,r=!1){for(let i of n){let n=i.left,a=i.right===void 0?void 0:i.right+1,o=WO(e,t,n,!0,0),s=WO(e,t,a,!1,o);for(let n=o;n<=s;n++)GO(t.get(e[n]),i,r);KO(e,t,o,s)}}function WO(e,t,n,r,i){if(n===void 0)return e.length-1;let a=JO(e,n,i);return n===e[a]?r?a:a-1:(e.splice(a+1,0,n),t.set(n,[...t.get(e[a])]),r?a+1:a)}function GO(e,t,n=!1){let r=t.top,i=t.bottom===void 0?void 0:t.bottom+1,a=[],o=JO(e,r,0,!1);if((o%2!=0&&!n||o%2==0&&n)&&a.push(r),i===void 0){e.splice(o+1),e.push(...a);return}let s=YO(e,i,0,!1);(s%2==0&&!n||s%2!=0&&n)&&a.push(i),e.splice(o+1,s-o-1,...a)}function KO(e,t,n,r){let i=n-1==-1?0:n-1,a=r===e.length-1?r:r+1;for(let n=a;n>i;n--)XO(t.get(e[n]),t.get(e[n-1]))&&(t.delete(e[n]),e.splice(n,1))}function qO(e,t){let n=[],r=[];for(let i=0;i<e.length;i++){let a=e[i],o=t.get(a);if(!o||o.length===0){n.push(...r),r=[];continue}let s=e[i+1];s!==void 0&&s--;let c=[];for(let e=0;e<o.length;e+=2){let t=o[e],n=o[e+1];n!==void 0&&n--;let i={top:t,left:a,bottom:n,right:s,hasHeader:n===void 0&&t!==0||s===void 0&&a!==0},l=!1;for(let e=r.length-1;e>=0;e--){let t=r[e];if(t.top===i.top&&t.bottom===i.bottom){t.right=i.right,r.splice(e,1),c.push(t),l=!0;break}}l||c.push(i)}n.push(...r),r=c}return n.push(...r),n}function JO(e,t,n=0,r=!0){let i=e.length-1,a=-1;for(;n<=i;){let o=Math.floor((n+i)/2);if(e[o]===t&&r)return o;e[o]<t?(a=o,n=o+1):i=o-1}return a}function YO(e,t,n=0,r=!0){let i=e.length-1,a=e.length;for(;n<=i;){let o=Math.floor((n+i)/2);if(e[o]===t&&r)return o;e[o]>t?(a=o,i=o-1):n=o+1}return a}function XO(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!E(e[n],t[n]))return!1;return!0}function ZO(e){return e===``?NaN:Number(e)}var QO=class extends IO{static getters=[`getConditionalFormats`,`getRulesSelection`,`getRulesByCell`,`getAdaptedCfRanges`];cfRules={};loopThroughRangesOfSheet(e,t){for(let n of this.cfRules[e])for(let r of n.ranges){let i=t(r);switch(i.changeType){case`REMOVE`:let t=n.ranges.slice();t.splice(n.ranges.indexOf(r),1),t.length>=1?this.history.update(`cfRules`,e,this.cfRules[e].indexOf(n),`ranges`,t):this.removeConditionalFormatting(n.id,e);break;case`RESIZE`:case`MOVE`:case`CHANGE`:this.history.update(`cfRules`,e,this.cfRules[e].indexOf(n),`ranges`,n.ranges.indexOf(r),i.range);break}}}adaptRanges(e,t){if(t)this.loopThroughRangesOfSheet(t,e);else for(let 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`CHANGE_CONDITIONAL_FORMAT_PRIORITY`:return this.checkValidPriorityChange(e.cfId,e.delta,e.sheetId)}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.cfRules[e.sheetId]=[];break;case`DUPLICATE_SHEET`:this.history.update(`cfRules`,e.sheetIdTo,[]);for(let t of this.getConditionalFormats(e.sheetId))this.addConditionalFormatting(t,e.sheetIdTo);break;case`DELETE_SHEET`:let t=Object.assign({},this.cfRules);delete t[e.sheetId],this.history.update(`cfRules`,t);break;case`ADD_CONDITIONAL_FORMAT`:let n={...e.cf,ranges:e.ranges.map(t=>this.getters.getRangeString(this.getters.getRangeFromRangeData(t),e.sheetId))};this.addConditionalFormatting(n,e.sheetId);break;case`REMOVE_CONDITIONAL_FORMAT`:this.removeConditionalFormatting(e.id,e.sheetId);break;case`CHANGE_CONDITIONAL_FORMAT_PRIORITY`:this.changeCFPriority(e.cfId,e.delta,e.sheetId);break}}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){return this.cfRules[e]?.map(t=>this.mapToConditionalFormat(e,t))||[]}getRulesSelection(e,t){let n=new Set;return t.forEach(t=>{this.getRulesByZone(e,t).forEach(e=>{n.add(e)})}),Array.from(n)}getRulesByZone(e,t){let n=new Set;for(let r=t.top;r<=t.bottom;r++)for(let i=t.left;i<=t.right;i++)this.getRulesByCell(e,i,r).forEach(e=>{n.add(e.id)});return n}getRulesByCell(e,t,n){let r=[];for(let i of this.cfRules[e])for(let e of i.ranges)da(t,n,e.zone)&&r.push(i);return new Set(r.map(t=>this.mapToConditionalFormat(e,t)))}getAdaptedCfRanges(e,t,n,r){if(n.length===0&&r.length===0)return;let i=this.getters.getConditionalFormats(e),a=i.findIndex(e=>e.id===t.id),o=[];a>-1&&(o=i[a].ranges.map(Qi)),o=o.concat(n);let s=HO(o,r);return HO([...n,...s],[])}mapToConditionalFormat(e,t,{useFixedReference:n}={useFixedReference:!1}){return{...t,ranges:t.ranges.map(t=>this.getters.getRangeString(t,e,{useFixedReference:n}))}}mapToConditionalFormatInternal(e,t){return{...t,ranges:t.ranges.map(t=>this.getters.getRangeFromSheetXC(e,t))}}addConditionalFormatting(e,t){let n=this.cfRules[t].slice(),r=n.findIndex(t=>t.id===e.id),i=this.mapToConditionalFormatInternal(t,e);r>-1?n.splice(r,1,i):n.push(i),this.history.update(`cfRules`,t,n)}checkValidPriorityChange(e,t,n){if(!this.cfRules[n])return`InvalidSheetId`;let r=this.cfRules[n].findIndex(t=>t.id===e);if(r===-1)return`InvalidConditionalFormatId`;let i=r-t;return i<0||i>=this.cfRules[n].length?`InvalidConditionalFormatId`:`Success`}checkEmptyRange(e){return e.ranges.length?`Success`:`EmptyRange`}checkCFRule(e){let t=e.cf.rule;switch(t.type){case`CellIsRule`:return _l[t.operator]?this.checkValidations(t,this.checkOperatorArgsNumber(2,[`Between`,`NotBetween`]),this.checkOperatorArgsNumber(1,[`BeginsWith`,`ContainsText`,`EndsWith`,`GreaterThan`,`GreaterThanOrEqual`,`LessThan`,`LessThanOrEqual`,`NotContains`]),this.checkOperatorArgsNumber(0,[`IsEmpty`,`IsNotEmpty`])):`InvalidConditionalFormatType`;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`InvalidConditionalFormatType`}checkOperatorArgsNumber(e,t){if(e>2)throw Error(`Checking more than 2 arguments is currently not supported. Add the appropriate CommandResult if you want to.`);return n=>{if(t.includes(n.operator)){let t=[],r=e=>e===void 0||e===``;return e>=1&&r(n.values[0])&&t.push(`FirstArgMissing`),e>=2&&r(n.values[1])&&t.push(`SecondArgMissing`),t.length?t:`Success`}return`Success`}}checkNaN(e,t){if([`number`,`percentage`,`percentile`].includes(e.type)&&(e.value===``||isNaN(e.value)))switch(t){case`min`:return`MinNaN`;case`max`:return`MaxNaN`;case`mid`:return`MidNaN`;case`upperInflectionPoint`:return`ValueUpperInflectionNaN`;case`lowerInflectionPoint`:return`ValueLowerInflectionNaN`}return`Success`}checkFormulaCompilation(e,t){if(e.type!==`formula`)return`Success`;try{NT(e.value||``)}catch{switch(t){case`min`:return`MinInvalidFormula`;case`max`:return`MaxInvalidFormula`;case`mid`:return`MidInvalidFormula`;case`upperInflectionPoint`:return`ValueUpperInvalidFormula`;case`lowerInflectionPoint`:return`ValueLowerInvalidFormula`}}return`Success`}checkThresholds(e){return this.batchValidations(t=>e(t.minimum,`min`),t=>e(t.maximum,`max`),t=>t.midpoint?e(t.midpoint,`mid`):`Success`)}checkInflectionPoints(e){return this.batchValidations(t=>e(t.lowerInflectionPoint,`lowerInflectionPoint`),t=>e(t.upperInflectionPoint,`upperInflectionPoint`))}checkLowerBiggerThanUpper(e){let t=e.lowerInflectionPoint.value,n=e.upperInflectionPoint.value;return[`number`,`percentage`,`percentile`].includes(e.lowerInflectionPoint.type)&&e.lowerInflectionPoint.type===e.upperInflectionPoint.type&&Number(t)>Number(n)?`LowerBiggerThanUpper`:`Success`}checkMinBiggerThanMax(e){let t=e.minimum.value,n=e.maximum.value;return[`number`,`percentage`,`percentile`].includes(e.minimum.type)&&e.minimum.type===e.maximum.type&&ZO(t)>=ZO(n)?`MinBiggerThanMax`:`Success`}checkMidBiggerThanMax(e){let t=e.midpoint?.value,n=e.maximum.value;return e.midpoint&&[`number`,`percentage`,`percentile`].includes(e.midpoint.type)&&e.midpoint.type===e.maximum.type&&ZO(t)>=ZO(n)?`MidBiggerThanMax`:`Success`}checkMinBiggerThanMid(e){let t=e.minimum.value,n=e.midpoint?.value;return e.midpoint&&[`number`,`percentage`,`percentile`].includes(e.midpoint.type)&&e.minimum.type===e.midpoint.type&&ZO(t)>=ZO(n)?`MinBiggerThanMid`:`Success`}removeConditionalFormatting(e,t){let n=this.cfRules[t].findIndex(t=>t.id===e);if(n!==-1){let e=this.cfRules[t].slice();e.splice(n,1),this.history.update(`cfRules`,t,e)}}changeCFPriority(e,t,n){let r=this.cfRules[n].findIndex(t=>t.id===e),i=this.cfRules[n][r],a=r-t,o=[...this.cfRules[n]];o.splice(r,1),o.splice(a,0,i),this.history.update(`cfRules`,n,o)}},$O=class extends IO{static getters=[`cellHasListDataValidationIcon`,`getDataValidationRule`,`getDataValidationRules`,`getValidationRuleForCell`];rules={};adaptRanges(e,t){let n=t?[t]:Object.keys(this.rules);for(let t of n)this.loopThroughRangesOfSheet(t,e)}loopThroughRangesOfSheet(e,t){let n=this.rules[e];for(let r=n.length-1;r>=0;r--){let n=this.rules[e][r];for(let i=n.ranges.length-1;i>=0;i--){let a=n.ranges[i],o=t(a);switch(o.changeType){case`REMOVE`:if(n.ranges.length===1)this.removeDataValidationRule(e,n.id);else{let t=n.ranges.slice();t.splice(i,1),this.history.update(`rules`,e,r,`ranges`,t)}break;case`RESIZE`:case`MOVE`:case`CHANGE`:this.history.update(`rules`,e,r,`ranges`,i,o.range);break}}}}allowDispatch(e){switch(e.type){case`ADD_DATA_VALIDATION_RULE`:return this.getters.tryGetSheet(e.sheetId)?this.checkValidations(e,this.chainValidations(this.checkCriterionTypeIsValid,this.checkCriterionHasValidNumberOfValues,this.checkCriterionValuesAreValid)):`InvalidSheetId`;case`REMOVE_DATA_VALIDATION_RULE`:if(!this.getters.tryGetSheet(e.sheetId))return`InvalidSheetId`;if(!this.rules[e.sheetId].find(t=>t.id===e.id))return`UnknownDataValidationRule`;break}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`rules`,e.sheetId,[]);break;case`DUPLICATE_SHEET`:{let t=S(this.rules[e.sheetId]).map(t=>({...t,ranges:t.ranges.map(t=>Pa(e.sheetId,e.sheetIdTo,t))}));this.history.update(`rules`,e.sheetIdTo,t);break}case`DELETE_SHEET`:{let t={...this.rules};delete t[e.sheetId],this.history.update(`rules`,t);break}case`REMOVE_DATA_VALIDATION_RULE`:this.removeDataValidationRule(e.sheetId,e.id);break;case`ADD_DATA_VALIDATION_RULE`:{let t=e.ranges.map(e=>this.getters.getRangeFromRangeData(e));this.addDataValidationRule(e.sheetId,{...e.rule,ranges:t});break}}}getDataValidationRules(e){return this.rules[e]}getDataValidationRule(e,t){return this.rules[e].find(e=>e.id===t)}getValidationRuleForCell({sheetId:e,col:t,row:n}){if(this.rules[e]){for(let r of this.rules[e])for(let e of r.ranges)if(da(t,n,e.zone))return r}}cellHasListDataValidationIcon(e){let t=this.getValidationRuleForCell(e);return t?(t.criterion.type===`isValueInList`||t.criterion.type===`isValueInRange`)&&t.criterion.displayStyle===`arrow`:!1}addDataValidationRule(e,t){let n=this.rules[e];t.criterion.type===`isBoolean`?this.setCenterStyleToBooleanCells(t):t.criterion.type===`isValueInList`&&(t.criterion.values=Array.from(new Set(t.criterion.values)));let r=this.removeRangesFromRules(e,t.ranges,n,t.id),i=r.findIndex(e=>e.id===t.id);i===-1?this.history.update(`rules`,e,[...r,t]):(r[i]=t,this.history.update(`rules`,e,r))}removeRangesFromRules(e,t,n,r){n=S(n);let i=t.map(t=>this.getters.getRangeString(t,e));for(let t of n)t.id!==r&&(t.ranges=pa(t.ranges.map(t=>this.getters.getRangeString(t,e)),i).map(t=>this.getters.getRangeFromSheetXC(e,t)));return n.filter(e=>e.ranges.length>0)}removeDataValidationRule(e,t){let n=this.rules[e].filter(e=>e.id!==t);this.history.update(`rules`,e,n)}setCenterStyleToBooleanCells(e){for(let t of La(e.ranges)){let e=this.getters.getCell(t),{sheetId:n,col:r,row:i}=t,a={...e?.style,align:e?.style?.align??`center`,verticalAlign:e?.style?.verticalAlign??`middle`};this.dispatch(`UPDATE_CELL`,{sheetId:n,col:r,row:i,style:a})}}import(e){for(let t of e.sheets)if(this.rules[t.id]=[],t.dataValidationRules)for(let e of t.dataValidationRules)this.rules[t.id].push({...e,ranges:e.ranges.map(e=>this.getters.getRangeFromSheetXC(t.id,e))})}export(e){if(e.sheets)for(let t of e.sheets){t.dataValidationRules=[];for(let e of this.rules[t.id])t.dataValidationRules.push({...e,ranges:e.ranges.map(e=>this.getters.getRangeString(e,t.id))})}}checkCriterionTypeIsValid(e){return q.contains(e.rule.criterion.type)?`Success`:`UnknownDataValidationCriterionType`}checkCriterionHasValidNumberOfValues(e){let t=e.rule.criterion,n=q.get(t.type).numberOfValues(t);return n!==void 0&&t.values.length!==n?`InvalidNumberOfCriterionValues`:`Success`}checkCriterionValuesAreValid(e){let t=e.rule.criterion,n=q.get(t.type);return t.values.some(e=>e.startsWith(`=`)?n.allowedValues===`onlyLiterals`:n.allowedValues===`onlyFormulas`?!0:!n.isCriterionValueValid(e))?`InvalidDataValidationCriterionValue`:`Success`}},ek=class extends IO{static getters=[`getFigures`,`getFigure`,`getFigureSheetId`];figures={};insertionOrders=[];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`Success`}}beforeHandle(e){switch(e.type){case`DELETE_SHEET`:this.getters.getFigures(e.sheetId).forEach(t=>{this.dispatch(`DELETE_FIGURE`,{id:t.id,sheetId:e.sheetId})});break}}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`:let{type:t,sheetId:n,...r}=e,i=r;this.updateFigure(n,i);break;case`DELETE_FIGURE`:this.removeFigure(e.id,e.sheetId);break;case`REMOVE_COLUMNS_ROWS`:this.onRowColDelete(e.sheetId,e.dimension)}}onRowColDelete(e,t){t===`ROW`?this.onRowDeletion(e):this.onColDeletion(e)}onRowDeletion(e){let t=this.getters.getNumberRows(e),n=0;for(let r=0;r<t;r++)n+=this.getters.getUserRowSize(e,r)||23;let r=this.getters.getFigures(e);for(let t of r){let r=Math.min(t.y,n-t.height);r!==t.y&&this.dispatch(`UPDATE_FIGURE`,{sheetId:e,id:t.id,y:r})}}onColDeletion(e){let t=this.getters.getNumberCols(e),n=0;for(let r=0;r<t;r++)n+=this.getters.getColSize(e,r);let r=this.getters.getFigures(e);for(let t of r){let r=Math.min(t.x,n-t.width);r!==t.x&&this.dispatch(`UPDATE_FIGURE`,{sheetId:e,id:t.id,x:r})}}updateFigure(e,t){if(`id`in t)for(let[n,r]of Object.entries(t))switch(n){case`x`:case`y`:r!==void 0&&this.history.update(`figures`,e,t.id,n,Math.max(r,0));break;case`width`:case`height`:r!==void 0&&this.history.update(`figures`,e,t.id,n,r);break}}addFigure(e,t){this.history.update(`figures`,t,e.id,e),this.history.update(`insertionOrders`,this.insertionOrders.length,e.id)}deleteSheet(e){this.history.update(`insertionOrders`,this.insertionOrders.filter(t=>!this.figures[e]?.[t])),this.history.update(`figures`,e,void 0)}removeFigure(e,t){this.history.update(`insertionOrders`,this.insertionOrders.filter(t=>t!==e)),this.history.update(`figures`,t,e,void 0)}checkFigureExists(e,t){return this.figures[e]?.[t]===void 0?`FigureDoesNotExist`:`Success`}checkFigureDuplicate(e){return Object.values(this.figures).find(t=>t?.[e])?`DuplicatedFigureId`:`Success`}getFigures(e){let t=[];for(let n of this.insertionOrders){let r=this.figures[e]?.[n];r&&t.push(r)}return t}getFigure(e,t){return this.figures[e]?.[t]}getFigureSheetId(e){return Object.keys(this.figures).find(t=>this.figures[t]?.[e]!==void 0)}import(e){for(let t of e.sheets)for(let e of t.figures)this.addFigure(e,t.id)}export(e){for(let t of e.sheets)for(let e of this.getFigures(t.id))t.figures.push({...e,data:void 0})}exportForExcel(e){this.export(e)}},tk=class e{id;zone;filters;constructor(e){this.filters=[],this.zone=e;let t=new ko;this.id=t.smallUuid();for(let n of w(e.left,e.right+1)){let e={...this.zone,left:n,right:n};this.filters.push(new nk(t.smallUuid(),e))}}get contentZone(){if(this.zone.bottom!==this.zone.top)return{...this.zone,top:this.zone.top+1}}getFilterId(e){return this.filters.find(t=>t.col===e)?.id}clone(){return new e(this.zone)}},nk=class{id;zoneWithHeaders;constructor(e,t){if(t.left!==t.right)throw Error(`Can only define a filter on a single column`);this.id=e,this.zoneWithHeaders=t}get col(){return this.zoneWithHeaders.left}get filteredZone(){let e=this.zoneWithHeaders;if(e.bottom!==e.top)return{...e,top:e.top+1}}},rk=class extends IO{static getters=[`doesZonesContainFilter`,`getFilter`,`getFilters`,`getFilterTable`,`getFilterTables`,`getFilterTablesInZone`,`getFilterId`,`getFilterHeaders`,`isFilterHeader`];tables={};allowDispatch(e){switch(e.type){case`CREATE_FILTER_TABLE`:if(!Aa(...e.target))return`NonContinuousTargets`;let t=sa(...e.target);return this.checkValidations(e,()=>this.getFilterTables(e.sheetId).some(e=>ua(e.zone,t))?`FilterOverlap`:`Success`,()=>{let n=this.getters.getMergesInZone(e.sheetId,t);for(let e of n)if(ua(t,e))return`MergeInFilter`;return`Success`});case`ADD_MERGE`:for(let t of e.target)for(let n of this.getFilterTables(e.sheetId))if(ua(n.zone,t))return`MergeInFilter`;break}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`tables`,e.sheetId,{});break;case`DELETE_SHEET`:let t={...this.tables};delete t[e.sheetId],this.history.update(`tables`,t);break;case`DUPLICATE_SHEET`:let n={};for(let t of Object.values(this.tables[e.sheetId]||{}))if(t){let e=S(t);n[e.id]=e}this.history.update(`tables`,e.sheetIdTo,n);break;case`ADD_COLUMNS_ROWS`:this.onAddColumnsRows(e);break;case`REMOVE_COLUMNS_ROWS`:this.onDeleteColumnsRows(e);break;case`CREATE_FILTER_TABLE`:{let t=sa(...e.target),n=this.createFilterTable(t);this.history.update(`tables`,e.sheetId,n.id,n);break}case`REMOVE_FILTER_TABLE`:{let t={};for(let n of this.getFilterTables(e.sheetId))e.target.every(e=>!ca(e,n.zone))&&(t[n.id]=n);this.history.update(`tables`,e.sheetId,t);break}case`UPDATE_CELL`:{let t=e.sheetId;for(let n of this.getFilterTables(t))this.canUpdateCellCmdExtendTable(e,n)&&this.extendTableDown(t,n);break}}}getFilters(e){return this.getFilterTables(e).map(e=>e.filters).flat()}getFilterTables(e){return this.tables[e]?Object.values(this.tables[e]).filter(T):[]}getFilter(e){return this.getFilterTable(e)?.filters.find(t=>t.col===e.col)}getFilterId(e){return this.getFilter(e)?.id}getFilterTable({sheetId:e,col:t,row:n}){return this.getFilterTables(e).find(e=>da(t,n,e.zone))}getFilterTablesInZone(e,t){return this.getFilterTables(e).filter(e=>fa(e.zone,t))}doesZonesContainFilter(e,t){for(let n of t)for(let t of this.getFilterTables(e))if(ca(n,t.zone))return!0;return!1}getFilterHeaders(e){let t=[];for(let n of this.getFilterTables(e)){let e=n.zone,r=e.top;for(let n=e.left;n<=e.right;n++)t.push({col:n,row:r})}return t}isFilterHeader({sheetId:e,col:t,row:n}){return this.getFilterHeaders(e).some(e=>e.col===t&&e.row===n)}onAddColumnsRows(e){for(let t of this.getFilterTables(e.sheetId)){let n=ra(t.zone,e.dimension===`COL`?`left`:`top`,e.base,e.position,e.quantity),r=[];for(let n of t.filters){let t=ra(n.zoneWithHeaders,e.dimension===`COL`?`left`:`top`,e.base,e.position,e.quantity);r.push(new nk(n.id,t))}if(r.length<va(n).numberOfCols){for(let e=n.left;e<=n.right;e++)r.find(t=>t.col===e)||r.push(new nk(this.uuidGenerator.smallUuid(),{...n,left:e,right:e}));r.sort((e,t)=>e.col-t.col)}this.history.update(`tables`,e.sheetId,t.id,`zone`,n),this.history.update(`tables`,e.sheetId,t.id,`filters`,r)}}onDeleteColumnsRows(e){for(let t of this.getFilterTables(e.sheetId)){if(e.dimension===`ROW`&&e.elements.includes(t.zone.top)){let n={...this.tables[e.sheetId]};delete n[t.id],this.history.update(`tables`,e.sheetId,n);continue}let n=oa(t.zone,e.dimension===`COL`?`left`:`top`,e.elements);if(!n){let n={...this.tables[e.sheetId]};delete n[t.id],this.history.update(`tables`,e.sheetId,n)}else if(B(n)!==B(t.zone)){let r=[];for(let n of t.filters){let t=oa(n.zoneWithHeaders,e.dimension===`COL`?`left`:`top`,e.elements);t&&r.push(new nk(n.id,t))}this.history.update(`tables`,e.sheetId,t.id,`zone`,n),this.history.update(`tables`,e.sheetId,t.id,`filters`,r)}}}createFilterTable(e){return new tk(e)}extendTableDown(e,t){let n={...t.zone,bottom:t.zone.bottom+1};this.history.update(`tables`,e,t.id,`zone`,n);for(let n=0;n<t.filters.length;n++){let r=t.filters[n],i={...r.zoneWithHeaders,bottom:r.zoneWithHeaders.bottom+1};this.history.update(`tables`,e,t.id,`filters`,n,`zoneWithHeaders`,i)}}canUpdateCellCmdExtendTable({content:e,sheetId:t,col:n,row:r},i){if(!e)return;let a=i.zone;if(!(a.bottom+1===r&&n>=a.left&&n<=a.right))return!1;for(let e of w(a.left,a.right+1)){let n={sheetId:t,col:e,row:r};if(this.getters.getCell(n)?.content||this.getters.getFilter(n)||this.getters.isInMerge(n))return!1}return!0}import(e){for(let t of e.sheets)for(let e of t.filterTables||[]){let n=this.createFilterTable(ea(e.range));this.history.update(`tables`,t.id,n.id,n)}}export(e){for(let t of e.sheets)for(let e of this.getFilterTables(t.id))t.filterTables.push({range:B(e.zone)})}exportForExcel(e){for(let t of e.sheets)for(let e of this.getFilterTables(t.id))va(e.zone).numberOfRows!==1&&t.filterTables.push({range:B(e.zone),filters:[]})}},ik=class extends IO{static getters=[`getUserRowSize`,`getColSize`];sizes={};handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`sizes`,e.sheetId,{COL:Array(this.getters.getNumberCols(e.sheetId)).fill(void 0),ROW:Array(this.getters.getNumberRows(e.sheetId)).fill(void 0)});break;case`DUPLICATE_SHEET`:this.history.update(`sizes`,e.sheetIdTo,S(this.sizes[e.sheetId]));break;case`DELETE_SHEET`:let t={...this.sizes};delete t[e.sheetId],this.history.update(`sizes`,t);break;case`REMOVE_COLUMNS_ROWS`:{let t=this.sizes[e.sheetId][e.dimension],n=kt(t,e.elements);this.history.update(`sizes`,e.sheetId,e.dimension,n);break}case`ADD_COLUMNS_ROWS`:{let t=[...this.sizes[e.sheetId][e.dimension]],n=bt(e.position,e.base),r=t[e.base];t=At(t,Array(e.quantity).fill(r),n),this.history.update(`sizes`,e.sheetId,e.dimension,t);break}case`RESIZE_COLUMNS_ROWS`:if(e.dimension===`ROW`)for(let t of e.elements)this.history.update(`sizes`,e.sheetId,e.dimension,t,e.size||void 0);else for(let t of e.elements)this.history.update(`sizes`,e.sheetId,e.dimension,t,e.size||void 0);break}}getColSize(e,t){return Math.round(this.sizes[e]?.COL[t]||96)}getUserRowSize(e,t){let n=this.sizes[e]?.ROW[t];return n?Math.round(n):void 0}import(e){for(let t of e.sheets){let e={COL:Array(t.colNumber).fill(void 0),ROW:Array(t.rowNumber).fill(void 0)};for(let[n,r]of Object.entries(t.rows))r.size&&(e.ROW[n]=r.size);for(let[n,r]of Object.entries(t.cols))r.size&&(e.COL[n]=r.size);this.sizes[t.id]=e}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){for(let n of e.sheets){n.rows===void 0&&(n.rows={});for(let e of w(0,this.getters.getNumberRows(n.id)))(t||this.sizes[n.id].ROW[e])&&(n.rows[e]={...n.rows[e],size:this.getUserRowSize(n.id,e)??23});n.cols===void 0&&(n.cols={});for(let e of w(0,this.getters.getNumberCols(n.id)))(t||this.sizes[n.id].COL[e])&&(n.cols[e]={...n.cols[e],size:this.getColSize(n.id,e)})}}},ak=class extends IO{static getters=[`checkElementsIncludeAllVisibleHeaders`,`getHiddenColsGroups`,`getHiddenRowsGroups`,`isHeaderHiddenByUser`,`isRowHiddenByUser`,`isColHiddenByUser`];hiddenHeaders={};allowDispatch(e){switch(e.type){case`HIDE_COLUMNS_ROWS`:{if(!this.getters.tryGetSheet(e.sheetId))return`InvalidSheetId`;let t=e.dimension===`COL`?this.getHiddenColsGroups(e.sheetId):this.getHiddenRowsGroups(e.sheetId),n=e.dimension===`COL`?this.getters.getNumberCols(e.sheetId):this.getters.getNumberRows(e.sheetId);return new Set((t||[]).flat().concat(e.elements)).size>=n?`TooManyHiddenElements`:Pt(e.elements)<0||Nt(e.elements)>n?`InvalidHeaderIndex`:`Success`}case`REMOVE_COLUMNS_ROWS`:return this.getters.tryGetSheet(e.sheetId)?this.checkElementsIncludeAllVisibleHeaders(e.sheetId,e.dimension,e.elements)?`NotEnoughElements`:`Success`:`InvalidSheetId`}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:let 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,S(this.hiddenHeaders[e.sheetId]));break;case`DELETE_SHEET`:this.history.update(`hiddenHeaders`,e.sheetId,void 0);break;case`REMOVE_COLUMNS_ROWS`:{let t=[...this.hiddenHeaders[e.sheetId][e.dimension]];for(let n of[...e.elements].sort((e,t)=>t-e))t.splice(n,1);this.history.update(`hiddenHeaders`,e.sheetId,e.dimension,t);break}case`ADD_COLUMNS_ROWS`:{let t=bt(e.position,e.base),n=At([...this.hiddenHeaders[e.sheetId][e.dimension]],Array(e.quantity).fill(!1),t);this.history.update(`hiddenHeaders`,e.sheetId,e.dimension,n);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);break}}checkElementsIncludeAllVisibleHeaders(e,t,n){return xt(n,this.getAllVisibleHeaders(e,t))}isHeaderHiddenByUser(e,t,n){return t===`COL`?this.isColHiddenByUser(e,n):this.isRowHiddenByUser(e,n)}isRowHiddenByUser(e,t){return this.hiddenHeaders[e].ROW[t]||this.getters.isRowFolded(e,t)}isColHiddenByUser(e,t){return this.hiddenHeaders[e].COL[t]||this.getters.isColFolded(e,t)}getHiddenColsGroups(e){let t=[[]],n=this.hiddenHeaders[e].COL;for(let e=0;e<n.length;e++)n[e]?t[t.length-1].push(e):t[t.length-1].length!==0&&t.push([]);return t[t.length-1].length===0&&t.pop(),t}getHiddenRowsGroups(e){let t=[[]],n=this.hiddenHeaders[e].ROW;for(let e=0;e<n.length;e++)n[e]?t[t.length-1].push(e):t[t.length-1].length!==0&&t.push([]);return t[t.length-1].length===0&&t.pop(),t}getAllVisibleHeaders(e,t){let n=w(0,this.getters.getNumberHeaders(e,t)),r=[];return this.getters.getHeaderGroups(e,t).forEach(e=>{e.isFolded&&r.push(...w(e.start,e.end+1))}),n.filter(n=>!this.hiddenHeaders[e][t][n]&&!r.includes(n))}import(e){for(let t of e.sheets){this.hiddenHeaders[t.id]={COL:[],ROW:[]};for(let e=0;e<t.rowNumber;e++)this.hiddenHeaders[t.id].ROW[e]=!!t.rows[e]?.isHidden;for(let e=0;e<t.colNumber;e++)this.hiddenHeaders[t.id].COL[e]=!!t.cols[e]?.isHidden}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){for(let n of e.sheets){n.rows===void 0&&(n.rows={});for(let e=0;e<this.getters.getNumberRows(n.id);e++)(t||this.hiddenHeaders[n.id].ROW[e])&&(n.rows[e]===void 0&&(n.rows[e]={}),n.rows[e].isHidden=this.hiddenHeaders[n.id].ROW[e]);n.cols===void 0&&(n.cols={});for(let e=0;e<this.getters.getNumberCols(n.id);e++)(t||this.hiddenHeaders[n.id].COL[e])&&(n.cols[e]===void 0&&(n.cols[e]={}),n.cols[e].isHidden=this.hiddenHeaders[n.id].COL[e])}}},ok=class extends IO{static getters=[`getImage`,`getImagePath`,`getImageSize`];fileStore;images={};syncedImages=new Set;constructor(e){super(e),this.fileStore=e.external.fileStore}allowDispatch(e){switch(e.type){case`CREATE_IMAGE`:return this.getters.getFigure(e.sheetId,e.figureId)?`InvalidFigureId`:`Success`;default:return`Success`}}handle(e){switch(e.type){case`CREATE_IMAGE`:this.addImage(e.figureId,e.sheetId,e.position,e.size),this.history.update(`images`,e.sheetId,e.figureId,e.definition),this.syncedImages.add(e.definition.path);break;case`DUPLICATE_SHEET`:{let t=this.getters.getFigures(e.sheetId);for(let n of t)if(n.tag===`image`){let t=n.id.split(`??`).pop(),r=`${e.sheetIdTo}??${t}`,i=this.getImage(n.id);if(i){let t={width:n.width,height:n.height};this.dispatch(`CREATE_IMAGE`,{sheetId:e.sheetIdTo,figureId:r,position:{x:n.x,y:n.y},size:t,definition:S(i)})}}break}case`DELETE_FIGURE`:this.history.update(`images`,e.sheetId,e.id,void 0);break;case`DELETE_SHEET`:this.history.update(`images`,e.sheetId,void 0);break}}garbageCollectExternalResources(){let e=new Set(this.getAllImages().map(e=>e.path));for(let t of this.syncedImages)e.has(t)||this.fileStore?.delete(t)}getImage(e){for(let t of Object.values(this.images))if(t&&t[e])return t[e];throw Error(`There is no image with the given figureId: ${e}`)}getImagePath(e){return this.getImage(e).path}getImageSize(e){return this.getImage(e).size}addImage(e,t,n,r){let i={id:e,x:n.x,y:n.y,width:r.width,height:r.height,tag:`image`};this.dispatch(`CREATE_FIGURE`,{sheetId:t,figure:i})}import(e){for(let t of e.sheets){let e=(t.figures||[]).filter(e=>e.tag===`image`);for(let n of e)this.history.update(`images`,t.id,n.id,n.data),this.syncedImages.add(n.data.path)}}export(e){for(let t of e.sheets){let e=t.figures.filter(e=>e.tag===`image`);for(let n of e)n.data=this.images[t.id]?.[n.id]}}exportForExcel(e){for(let t of e.sheets){t.images||=[];let e=this.getters.getFigures(t.id),n=[];for(let t of e)if(t?.tag===`image`){let e=this.getImage(t.id);e&&n.push({...t,data:S(e)})}t.images=[...t.images,...n]}}getAllImages(){let e=[];for(let t in this.images)e.push(...Object.values(this.images[t]||{}).filter(T));return e}},sk=class extends IO{static getters=[`isInMerge`,`isInSameMerge`,`isMergeHidden`,`getMainCellPosition`,`getBottomLeftCell`,`expandZone`,`doesIntersectMerge`,`doesColumnsHaveCommonMerges`,`doesRowsHaveCommonMerges`,`getMerges`,`getMerge`,`getMergesInZone`,`isSingleCellOrMerge`,`getSelectionRangeString`,`isMainCellPosition`];nextId=1;merges={};mergeCellMap={};allowDispatch(e){let t=`force`in e?!!e.force:!1;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`Success`}}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`merges`,e.sheetId,{}),this.history.update(`mergeCellMap`,e.sheetId,{});break;case`DELETE_SHEET`:this.history.update(`merges`,e.sheetId,{}),this.history.update(`mergeCellMap`,e.sheetId,{});break;case`DUPLICATE_SHEET`:let t=this.merges[e.sheetId];if(!t)break;for(let n of Object.values(t).filter(T))this.addMerge(e.sheetIdTo,n.zone);break;case`ADD_MERGE`:for(let t of e.target)this.addMerge(e.sheetId,t);break;case`REMOVE_MERGE`:for(let t of e.target)this.removeMerge(e.sheetId,t);break}}adaptRanges(e,t){let n=t?[t]:Object.keys(this.merges);for(let t of n)this.applyRangeChangeOnSheet(t,e)}getMerges(e){return Object.keys(this.merges[e]||{}).map(t=>this.getMergeById(e,parseInt(t,10))).filter(T)}getMerge({sheetId:e,col:t,row:n}){let r=this.mergeCellMap[e],i=r?t in r&&r[t]?.[n]:void 0;return i?this.getMergeById(e,i):void 0}getMergesInZone(e,t){let n=this.mergeCellMap[e];if(!n)return[];let r=new Set;for(let{col:e,row:i}of ba(t)){let t=n[e]?.[i];t&&r.add(t)}return Array.from(r).map(t=>this.getMergeById(e,t)).filter(T)}getSelectionRangeString(e,t){let n=Na.fromRange(e,this.getters),r=this.getters.expandZone(n.sheetId,n.zone),i=n.clone({zone:{...r,bottom:n.isFullCol?void 0:r.bottom,right:n.isFullRow?void 0:r.right}}),a=this.getters.getRangeString(i,t);if(this.isSingleCellOrMerge(n.sheetId,n.zone)){let{sheetName:e,xc:t}=Xi(a);return`${e===void 0?``:$e(e)+`!`}${t.split(`:`)[0]}`}return a}doesIntersectMerge(e,t){for(let n of this.getMerges(e))if(ua(t,n))return!0;return!1}doesColumnsHaveCommonMerges(e,t,n){let r=this.getters.getSheet(e);for(let i=0;i<this.getters.getNumberRows(e);i++)if(this.isInSameMerge(r.id,t,i,n,i))return!0;return!1}doesRowsHaveCommonMerges(e,t,n){let r=this.getters.getSheet(e);for(let i=0;i<=this.getters.getNumberCols(e);i++)if(this.isInSameMerge(r.id,i,t,i,n))return!0;return!1}expandZone(e,t){let{left:n,right:r,top:i,bottom:a}=t,o={left:n,right:r,top:i,bottom:a};for(let t in this.merges[e]){let n=this.getMergeById(e,parseInt(t));n&&ua(n,o)&&(o=sa(n,o))}return la(o,t)?o:this.expandZone(e,o)}isInSameMerge(e,t,n,r,i){let a=this.getMerge({sheetId:e,col:t,row:n}),o=this.getMerge({sheetId:e,col:r,row:i});return!a||!o?!1:la(a,o)}isInMerge({sheetId:e,col:t,row:n}){let r=this.mergeCellMap[e];return r?t in r&&!!r[t]?.[n]:!1}getMainCellPosition(e){if(!this.isInMerge(e))return e;let t=this.getMerge(e).topLeft;return{sheetId:e.sheetId,col:t.col,row:t.row}}getBottomLeftCell(e){if(!this.isInMerge(e))return e;let{bottom:t,left:n}=this.getMerge(e);return{sheetId:e.sheetId,col:n,row:t}}isMergeHidden(e,t){let n=this.getters.getHiddenColsGroups(e),r=this.getters.getHiddenRowsGroups(e);for(let e of n)if(t.left>=e[0]&&t.right<=e[e.length-1])return!0;for(let e of r)if(t.top>=e[0]&&t.bottom<=e[e.length-1])return!0;return!1}isSingleCellOrMerge(e,t){let n=this.getMerge({sheetId:e,col:t.left,row:t.top});if(n)return la(t,n);let{numberOfCols:r,numberOfRows:i}=va(t);return r===1&&i===1}isMainCellPosition(e){return E(this.getMainCellPosition(e),e)}isMergeDestructive(e,t){let{left:n,right:r,top:i,bottom:a}=t;r=C(r,0,this.getters.getNumberCols(e)-1),a=C(a,0,this.getters.getNumberRows(e)-1);for(let t=i;t<=a;t++)for(let a=n;a<=r;a++)if(a!==n||t!==i){let n=this.getters.getCell({sheetId:e,col:a,row:t});if(n&&n.content!==``)return!0}return!1}getMergeById(e,t){let n=this.merges[e]?.[t];return n===void 0?void 0:lk(t,n)}checkDestructiveMerge({sheetId:e,target:t}){return this.getters.tryGetSheet(e)&&t.some(t=>this.isMergeDestructive(e,t))?`MergeIsDestructive`:`Success`}checkOverlap({target:e}){for(let t of e)for(let n of e)if(t!==n&&ua(t,n))return`MergeOverlap`;return`Success`}checkFrozenPanes({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return`Success`;let{xSplit:n,ySplit:r}=this.getters.getPaneDivisions(e);for(let e of t)if(e.left<n&&e.right>=n||e.top<r&&e.bottom>=r)return`FrozenPaneOverlap`;return`Success`}checkMergedContentUpdate(e){let{col:t,row:n,content:r}=e;if(r===void 0)return`Success`;let{col:i,row:a}=this.getMainCellPosition(e);return i===t&&a===n?`Success`:`CellIsMerged`}checkMergeExists(e){let{sheetId:t,target:n}=e;for(let e of n){let{left:n,top:r}=e,i=this.getMerge({sheetId:t,col:n,row:r});if(i===void 0||!la(e,i))return`InvalidTarget`}return`Success`}addMerge(e,t){let{left:n,right:r,top:i,bottom:a}=t;if(r=C(r,0,this.getters.getNumberCols(e)-1),a=C(a,0,this.getters.getNumberRows(e)-1),O(n,i)===O(r,a))return;let o=this.getters.getCell({sheetId:e,col:n,row:i}),s=this.nextId++;this.history.update(`merges`,e,s,this.getters.getRangeFromSheetXC(e,B({left:n,top:i,right:r,bottom:a})));let c=new Set;for(let t=i;t<=a;t++)for(let a=n;a<=r;a++){(a!==n||t!==i)&&this.dispatch(`UPDATE_CELL`,{sheetId:e,col:a,row:t,style:o?o.style:null,content:``});let r=this.getMerge({sheetId:e,col:a,row:t});r&&c.add(r.id),this.history.update(`mergeCellMap`,e,a,t,s)}for(let t of c){let{top:n,bottom:r,left:i,right:a}=this.getMergeById(e,t);for(let t=n;t<=r;t++)for(let n=i;n<=a;n++){let r={sheetId:e,col:n,row:t},i=this.getMerge(r);(!i||i.id!==s)&&(this.history.update(`mergeCellMap`,e,n,t,void 0),this.dispatch(`CLEAR_CELL`,r))}this.history.update(`merges`,e,t,void 0)}}removeMerge(e,t){let{left:n,top:r,bottom:i,right:a}=t,o=this.getMerge({sheetId:e,col:n,row:r});if(!(o===void 0||!la(t,o))){this.history.update(`merges`,e,o.id,void 0);for(let t=r;t<=i;t++)for(let r=n;r<=a;r++)this.history.update(`mergeCellMap`,e,r,t,void 0)}}applyRangeChangeOnSheet(e,t){let n=Object.entries(this.merges[e]||{});for(let[r,i]of n)if(i){let n=i.zone,a=t(i);switch(a.changeType){case`NONE`:break;case`REMOVE`:this.removeMerge(e,n);break;default:let{numberOfCols:t,numberOfRows:i}=va(a.range.zone);t===1&&i===1?this.removeMerge(e,n):this.history.update(`merges`,e,parseInt(r,10),a.range);break}}this.history.update(`mergeCellMap`,e,{});for(let t of this.getMerges(e))for(let{col:n,row:r}of ba(t))this.history.update(`mergeCellMap`,e,n,r,t.id)}import(e){let 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 n of t)this.addMerge(e,ea(n))}export(e){for(let t of e.sheets){let e=this.merges[t.id];e&&t.merges.push(...ck(e))}}exportForExcel(e){this.export(e)}};function ck(e){return Object.entries(e).map(([e,t])=>t?lk(parseInt(e,10),t):void 0).filter(T).map(e=>O(e.left,e.top)+`:`+O(e.right,e.bottom))}function lk(e,t){return{...t.zone,topLeft:{col:t.zone.left,row:t.zone.top},id:e}}var uk=class{getters;providers=[];constructor(e){this.getters=e}static getters=[`getRangeString`,`getRangeFromSheetXC`,`createAdaptedRanges`,`getRangeDataFromXc`,`getRangeDataFromZone`,`getRangeFromRangeData`,`getRangeFromZone`];allowDispatch(e){return e.type===`MOVE_RANGES`?e.target.length===1?`Success`:`InvalidZones`:`Success`}beforeHandle(e){}handle(e){switch(e.type){case`REMOVE_COLUMNS_ROWS`:{let t=e.dimension===`COL`?`left`:`top`,n=e.dimension===`COL`?`right`:`bottom`,r=e.dimension===`COL`?`columns`:`rows`,i=[...e.elements];i.sort((e,t)=>t-e);let a=et(i);this.executeOnAllRanges(i=>{if(i.sheetId!==e.sheetId)return{changeType:`NONE`};let o=i,s=`NONE`;for(let e of a){let a=Pt(e),c=Nt(e);if(i.zone[t]<=a&&a<=i.zone[n]){let e=Math.min(i.zone[n],c)-a+1;s=`RESIZE`,o=this.createAdaptedRange(o,r,s,-e)}else if(i.zone[t]>=a&&i.zone[n]<=c)s=`REMOVE`,o=i.clone({...this.getInvalidRange()});else if(i.zone[t]<=c&&i.zone[n]>=c){let e=c-i.zone[t]+1;s=`RESIZE`,o=this.createAdaptedRange(o,r,s,-e),o=this.createAdaptedRange(o,r,`MOVE`,-(i.zone[t]-a))}else a<i.zone[t]&&(s=`MOVE`,o=this.createAdaptedRange(o,r,s,-(c-a+1)))}return s===`NONE`?{changeType:`NONE`}:{changeType:s,range:o}},e.sheetId);break}case`ADD_COLUMNS_ROWS`:{let t=e.dimension===`COL`?`left`:`top`,n=e.dimension===`COL`?`right`:`bottom`,r=e.dimension===`COL`?`columns`:`rows`;this.executeOnAllRanges(i=>{if(i.sheetId!==e.sheetId)return{changeType:`NONE`};if(e.position===`after`){if(i.zone[t]<=e.base&&e.base<i.zone[n])return{changeType:`RESIZE`,range:this.createAdaptedRange(i,r,`RESIZE`,e.quantity)};if(e.base<i.zone[t])return{changeType:`MOVE`,range:this.createAdaptedRange(i,r,`MOVE`,e.quantity)}}else{if(i.zone[t]<e.base&&e.base<=i.zone[n])return{changeType:`RESIZE`,range:this.createAdaptedRange(i,r,`RESIZE`,e.quantity)};if(e.base<=i.zone[t])return{changeType:`MOVE`,range:this.createAdaptedRange(i,r,`MOVE`,e.quantity)}}return{changeType:`NONE`}},e.sheetId);break}case`DELETE_SHEET`:this.executeOnAllRanges(t=>{if(t.sheetId!==e.sheetId)return{changeType:`NONE`};let n=this.getters.getSheetName(e.sheetId);return t=t.clone({...this.getInvalidRange(),invalidSheetName:n}),{changeType:`REMOVE`,range:t}},e.sheetId);break;case`RENAME_SHEET`:this.executeOnAllRanges(t=>{if(t.sheetId===e.sheetId)return{changeType:`CHANGE`,range:t};if(Ga(t.invalidSheetName,e.name)){let n=e.sheetId;return{changeType:`CHANGE`,range:t.clone({sheetId:n,invalidSheetName:void 0})}}return{changeType:`NONE`}});break;case`MOVE_RANGES`:{let t=e.target[0];this.executeOnAllRanges(n=>{if(n.sheetId!==e.sheetId||!fa(n.zone,t))return{changeType:`NONE`};let r=e.targetSheetId,i=e.col-t.left,a=e.row-t.top,o=this.createAdaptedRange(n,`both`,`MOVE`,[i,a]),s=e.sheetId===r?o.prefixSheet:!0;return{changeType:`MOVE`,range:o.clone({sheetId:r,prefixSheet:s})}});break}}}finalize(){}verifyRangeRemoved(e){return t=>{let n=e(t);return n.changeType!==`NONE`&&!ta(n.range.zone)?{range:n.range,changeType:`REMOVE`}:n}}createAdaptedRange(e,t,n,r){let i=Sa(e.unboundedZone,t,n,r);return e.clone({zone:i})}executeOnAllRanges(e,t){let n=this.verifyRangeRemoved(e);for(let e of this.providers)e(n,t)}addRangeProvider(e){this.providers.push(e)}createAdaptedRanges(e,t,n,r){return e.map(e=>Na.fromRange(e,this.getters)).map(e=>{if(!ta(e.zone))return e;let i=e.prefixSheet?e.sheetId:r,a={...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:n),bottom:e.isFullCol?e.unboundedZone.bottom:e.unboundedZone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:n)};return e.clone({sheetId:i,zone:a}).orderZone()})}getRangeFromSheetXC(e,t){if(!Wi.test(t)||!this.getters.tryGetSheet(e))return new Na({sheetId:``,zone:{left:-1,top:-1,right:-1,bottom:-1},parts:[],invalidXc:t,prefixSheet:!1},this.getters.getSheetSize);let n,r=t,i=!1;t.includes(`!`)&&({xc:r,sheetName:n}=Xi(t),n&&(i=!0));let a=Qi(r),o=Na.getRangeParts(r,a),s=n&&!this.getters.getSheetIdByName(n)?n:void 0,c=this.getters.getSheetIdByName(n)||e;return new Na({prefixSheet:i,zone:a,sheetId:c,invalidSheetName:s,parts:o},this.getters.getSheetSize).orderZone()}getRangeString(e,t,n={useFixedReference:!1}){if(!e)return Ie;if(e.invalidXc)return e.invalidXc;if(!this.getters.tryGetSheet(e.sheetId)||e.zone.bottom-e.zone.top<0||e.zone.right-e.zone.left<0||e.zone.left<0||e.zone.top<0)return Ie;let r=Na.fromRange(e,this.getters),i=r.sheetId!==t||r.invalidSheetName||r.prefixSheet,a=``;if(i&&(a=r.invalidSheetName?$e(r.invalidSheetName):$e(this.getters.getSheetName(r.sheetId))),i&&!a)return Ie;let o=this.getRangePartString(r,0,n);return r.parts&&r.parts.length===2&&(r.zone.top!==r.zone.bottom||r.zone.left!==r.zone.right||r.parts[0].rowFixed||r.parts[0].colFixed||r.parts[1].rowFixed||r.parts[1].colFixed)&&(o+=`:`,o+=this.getRangePartString(r,1,n)),`${i?a+`!`:``}${o}`}getRangeDataFromXc(e,t){return this.getters.getRangeFromSheetXC(e,t).rangeData}getRangeDataFromZone(e,t){return{_sheetId:e,_zone:t}}getRangeFromZone(e,t){return new Na({sheetId:e,zone:t,parts:[{colFixed:!1,rowFixed:!1},{colFixed:!1,rowFixed:!1}],prefixSheet:!1},this.getters.getSheetSize)}getRangeFromRangeData(e){return new Na({prefixSheet:!1,zone:e._zone,sheetId:e._sheetId,invalidSheetName:void 0,parts:[{colFixed:!1,rowFixed:!1},{colFixed:!1,rowFixed:!1}]},this.getters.getSheetSize)}getRangePartString(e,t,n={useFixedReference:!1}){let r=e.parts&&e.parts[t]?.colFixed?`$`:``,i=D(t===0?e.zone.left:e.zone.right),a=e.parts&&e.parts[t]?.rowFixed?`$`:``,o=String(t===0?e.zone.top+1:e.zone.bottom+1),s=``;return s=e.isFullCol&&!n.useFixedReference?t===0&&e.unboundedZone.hasHeader?r+i+a+o:r+i:e.isFullRow&&!n.useFixedReference?t===0&&e.unboundedZone.hasHeader?r+i+a+o:a+o:r+i+a+o,s}getInvalidRange(){return{parts:[],prefixSheet:!1,zone:{left:-1,top:-1,right:-1,bottom:-1},sheetId:``,invalidXc:Ie}}},dk=class extends IO{static getters=`getSheetName.tryGetSheetName.getSheet.tryGetSheet.getSheetIdByName.getSheetIds.getVisibleSheetIds.isSheetVisible.getEvaluationSheets.doesHeaderExist.doesHeadersExist.getCell.getCellPosition.getColsZone.getRowCells.getRowsZone.getNumberCols.getNumberRows.getNumberHeaders.getGridLinesVisibility.getNextSheetName.getSheetSize.getSheetZone.getPaneDivisions.checkZonesExistInSheet.getCommandZones.getUnboundedZone.checkElementsIncludeAllNonFrozenHeaders.getDuplicateSheetName`.split(`.`);sheetIdsMapName={};orderedSheetIds=[];sheets={};cellPosition={};allowDispatch(e){let t=this.chainValidations(this.checkSheetExists,this.checkZonesAreInSheet)(e);if(t!==`Success`)return t;switch(e.type){case`HIDE_SHEET`:return this.getVisibleSheetIds().length===1?`NotEnoughSheets`:`Success`;case`CREATE_SHEET`:return this.checkValidations(e,this.checkSheetName,this.checkSheetPosition);case`DUPLICATE_SHEET`:return this.sheets[e.sheetIdTo]?`DuplicatedSheetId`:this.orderedSheetIds.map(this.getSheetName.bind(this)).includes(e.sheetNameTo)?`DuplicatedSheetName`:`Success`;case`MOVE_SHEET`:try{let t=this.orderedSheetIds.findIndex(t=>t===e.sheetId);return this.findIndexOfTargetSheet(t,e.delta),`Success`}catch{return`WrongSheetMove`}case`RENAME_SHEET`:return this.isRenameAllowed(e);case`DELETE_SHEET`:return this.getVisibleSheetIds().length>1?`Success`:`NotEnoughSheets`;case`ADD_COLUMNS_ROWS`:return this.doesHeaderExist(e.sheetId,e.dimension,e.base)?e.quantity<=0?`InvalidQuantity`:`Success`:`InvalidHeaderIndex`;case`REMOVE_COLUMNS_ROWS`:{let t=Pt(e.elements),n=Nt(e.elements);return t<0||!this.doesHeaderExist(e.sheetId,e.dimension,n)?`InvalidHeaderIndex`:this.checkElementsIncludeAllNonFrozenHeaders(e.sheetId,e.dimension,e.elements)?`NotEnoughElements`:`Success`}case`FREEZE_ROWS`:return this.checkValidations(e,this.checkRowFreezeQuantity,this.checkRowFreezeOverlapMerge);case`FREEZE_COLUMNS`:return this.checkValidations(e,this.checkColFreezeQuantity,this.checkColFreezeOverlapMerge);default:return`Success`}}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`:let 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.delta);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`:e.dimension===`COL`?this.removeColumns(this.sheets[e.sheetId],[...e.elements]):this.removeRows(this.sheets[e.sheetId],[...e.elements]);break;case`ADD_COLUMNS_ROWS`:e.dimension===`COL`?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){for(let t of e.sheets)this.sheetIdsMapName[t.name]=t.id;for(let t of e.sheets){let e=t.name||y(`Sheet`)+(Object.keys(this.sheets).length+1),{colNumber:n,rowNumber:r}=this.getImportedSheetSize(t),i={id:t.id,name:e,numberOfCols:n,rows:Ba(r),areGridLinesVisible:t.areGridLinesVisible===void 0?!0:t.areGridLinesVisible,isVisible:t.isVisible,panes:{xSplit:t.panes?.xSplit||0,ySplit:t.panes?.ySplit||0}};this.orderedSheetIds.push(i.id),this.sheets[i.id]=i}}exportSheets(e){e.sheets=this.orderedSheetIds.filter(T).map(e=>{let t=this.sheets[e],n={id:t.id,name:t.name,colNumber:t.numberOfCols,rowNumber:this.getters.getNumberRows(t.id),rows:{},cols:{},merges:[],cells:{},conditionalFormats:[],figures:[],filterTables:[],areGridLinesVisible:t.areGridLinesVisible===void 0?!0:t.areGridLinesVisible,isVisible:t.isVisible};return(t.panes.xSplit||t.panes.ySplit)&&(n.panes=t.panes),n})}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){let t=this.sheets[e];if(!t)throw Error(`Sheet ${e} not found.`);return t}isSheetVisible(e){return this.getSheet(e).isVisible}getSheetName(e){return this.getSheet(e).name}tryGetSheetName(e){return this.tryGetSheet(e)?.name}getSheetIdByName(e){if(e){let t=Qe(e);for(let e in this.sheetIdsMapName)if(Ga(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,n){return t===`COL`?n>=0&&n<this.getNumberCols(e):n>=0&&n<this.getNumberRows(e)}doesHeadersExist(e,t,n){return n.every(n=>this.doesHeaderExist(e,t,n))}getRow(e,t){let n=this.getSheet(e).rows[t];if(!n)throw Error(`Row ${n} not found.`);return n}getCell({sheetId:e,col:t,row:n}){let r=this.tryGetSheet(e)?.rows[n]?.cells[t];if(r!==void 0)return this.getters.getCellById(r)}getColsZone(e,t,n){return{top:0,bottom:this.getNumberRows(e)-1,left:t,right:n}}getRowCells(e,t){return Object.values(this.getSheet(e).rows[t]?.cells).filter(T)}getRowsZone(e,t,n){return{top:t,bottom:n,left:0,right:this.getSheet(e).numberOfCols-1}}getCellPosition(e){let t=this.cellPosition[e];if(!t)throw 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 t===`COL`?this.getNumberCols(e):this.getNumberRows(e)}getNextSheetName(e=`Sheet`){return Ua(this.orderedSheetIds.map(this.getSheetName.bind(this)),e)}getSheetSize(e){return{numberOfRows:this.getNumberRows(e),numberOfCols:this.getNumberCols(e)}}getSheetZone(e){return{top:0,left:0,bottom:this.getNumberRows(e)-1,right:this.getNumberCols(e)-1}}getUnboundedZone(e,t){let n=t.left===0&&t.right===this.getNumberCols(e)-1,r=t.top===0&&t.bottom===this.getNumberRows(e)-1;return{...t,bottom:r?void 0:t.bottom,right:n&&!r?void 0:t.right}}getPaneDivisions(e){return this.getSheet(e).panes}setPaneDivisions(e,t,n){let r={...this.getPaneDivisions(e)};n===`COL`?r.xSplit=t:n===`ROW`&&(r.ySplit=t),this.history.update(`sheets`,e,`panes`,r)}checkElementsIncludeAllNonFrozenHeaders(e,t,n){let r=this.getters.getPaneDivisions(e),i=t===`ROW`?r.ySplit:r.xSplit,a=this.getters.getNumberHeaders(e,t);return i?xt(n,w(i,a)):!1}getCommandZones(e){let t=[];return`zone`in e&&t.push(e.zone),`target`in e&&t.push(...e.target),`ranges`in e&&t.push(...e.ranges.map(e=>this.getters.getRangeFromRangeData(e).zone)),`col`in e&&`row`in e&&t.push({top:e.row,left:e.col,bottom:e.row,right:e.col}),t}checkZonesExistInSheet(e,t){if(!t.every(ta))return`InvalidRange`;if(t.length){let n=this.getSheetZone(e);return t.every(e=>fa(e,n))?`Success`:`TargetOutOfSheet`}return`Success`}updateCellPosition(e){let{sheetId:t,cellId:n,col:r,row:i}=e;n?this.setNewPosition(n,t,r,i):this.clearPosition(t,r,i)}setNewPosition(e,t,n,r){let i=this.cellPosition[e];i&&this.clearPosition(t,i.col,i.row),this.history.update(`cellPosition`,e,{row:r,col:n,sheetId:t}),this.history.update(`sheets`,t,`rows`,r,`cells`,n,e)}clearPosition(e,t,n){let r=this.sheets[e]?.rows[n].cells[t];r&&(this.history.update(`cellPosition`,r,void 0),this.history.update(`sheets`,e,`rows`,n,`cells`,t,void 0))}setGridLinesVisibility(e,t){this.history.update(`sheets`,e,`areGridLinesVisible`,t)}clearZones(e,t){for(let n of t)for(let t=n.left;t<=n.right;t++)for(let r=n.top;r<=n.bottom;r++)this.sheets[e].rows[r].cells[t]&&this.dispatch(`UPDATE_CELL`,{sheetId:e,content:``,col:t,row:r})}createSheet(e,t,n,r,i){let a={id:e,name:t,numberOfCols:n,rows:Ba(r),areGridLinesVisible:!0,isVisible:!0,panes:{xSplit:0,ySplit:0}},o=this.orderedSheetIds.slice();o.splice(i,0,a.id);let s=this.sheets;return this.history.update(`orderedSheetIds`,o),this.history.update(`sheets`,Object.assign({},s,{[a.id]:a})),a}moveSheet(e,t){let n=this.orderedSheetIds.slice(),r=n.findIndex(t=>t===e),i=n.splice(r,1),a=this.findIndexOfTargetSheet(r,t);n.splice(a,0,i[0]),this.history.update(`orderedSheetIds`,n)}findIndexOfTargetSheet(e,t){for(;t!==0&&0<=e&&e<=this.orderedSheetIds.length;)t>0?(e++,this.isSheetVisible(this.orderedSheetIds[e])&&t--):t<0&&(e--,this.isSheetVisible(this.orderedSheetIds[e])&&t++);if(t===0)return e;throw Error(y(`There is not enough visible sheets`))}checkSheetName(e){let t=this.getters.tryGetSheetName(e.sheetId);if(t!==void 0&&e.name===t)return`UnchangedSheetName`;let{orderedSheetIds:n,sheets:r}=this,i=e.name&&e.name.trim().toLowerCase();return n.find(t=>Ga(r[t]?.name,i)&&t!==e.sheetId)?`DuplicatedSheetName`:He.test(i)?`ForbiddenCharactersInSheetName`:`Success`}checkSheetPosition(e){let{orderedSheetIds:t}=this;return e.position>t.length||e.position<0?`WrongSheetPosition`:`Success`}checkRowFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberRows(e.sheetId)?`Success`:`InvalidFreezeQuantity`}checkColFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberCols(e.sheetId)?`Success`:`InvalidFreezeQuantity`}checkRowFreezeOverlapMerge(e){let t=this.getters.getMerges(e.sheetId);for(let n of t)if(n.top<e.quantity&&e.quantity<=n.bottom)return`MergeOverlap`;return`Success`}checkColFreezeOverlapMerge(e){let t=this.getters.getMerges(e.sheetId);for(let n of t)if(n.left<e.quantity&&e.quantity<=n.right)return`MergeOverlap`;return`Success`}isRenameAllowed(e){return e.name&&e.name.trim().toLowerCase()?this.checkSheetName(e):`MissingSheetName`}renameSheet(e,t){let n=e.name;this.history.update(`sheets`,e.id,`name`,t.trim());let r=Object.assign({},this.sheetIdsMapName);delete r[n],r[t]=e.id,this.history.update(`sheetIdsMapName`,r)}hideSheet(e){this.history.update(`sheets`,e,`isVisible`,!1)}showSheet(e){this.history.update(`sheets`,e,`isVisible`,!0)}duplicateSheet(e,t,n){let r=S(this.getSheet(e));r.id=t,r.name=n;for(let e=0;e<=r.numberOfCols;e++)for(let t=0;t<=r.rows.length;t++)r.rows[t]&&(r.rows[t].cells[e]=void 0);let i=this.orderedSheetIds.slice(),a=i.indexOf(e);i.splice(a+1,0,r.id),this.history.update(`orderedSheetIds`,i),this.history.update(`sheets`,Object.assign({},this.sheets,{[r.id]:r}));for(let t of Object.values(this.getters.getCells(e))){let{col:e,row:n}=this.getCellPosition(t.id);this.dispatch(`UPDATE_CELL`,{sheetId:r.id,col:e,row:n,content:t.content,format:t.format,style:t.style})}let o=Object.assign({},this.sheetIdsMapName);o[r.name]=r.id,this.history.update(`sheetIdsMapName`,o)}getDuplicateSheetName(e){return Wa(e,this.orderedSheetIds.map(this.getSheetName.bind(this)))}deleteSheet(e){let t=e.name,n=Object.assign({},this.sheets);delete n[e.id],this.history.update(`sheets`,n);let r=this.orderedSheetIds.slice(),i=r.indexOf(e.id);r.splice(i,1),this.history.update(`orderedSheetIds`,r);let a=Object.assign({},this.sheetIdsMapName);delete a[t],this.history.update(`sheetIdsMapName`,a)}removeColumns(e,t){t.sort((e,t)=>t-e);for(let n of t)this.moveCellOnColumnsDeletion(e,n);let n=this.sheets[e.id].numberOfCols;this.history.update(`sheets`,e.id,`numberOfCols`,n-t.length);let r=t.filter(t=>t<e.panes.xSplit).length;r&&this.setPaneDivisions(e.id,e.panes.xSplit-r,`COL`)}removeRows(e,t){t.sort((e,t)=>t-e);for(let n of et(t)){let t=n[n.length-1],r=n[0];this.moveCellOnRowsDeletion(e,t,r),this.updateRowsStructureOnDeletion(e,t,r)}let n=t.filter(t=>t<e.panes.ySplit).length;n&&this.setPaneDivisions(e.id,e.panes.ySplit-n,`ROW`)}addColumns(e,t,n,r){let i=n===`before`?t:t+1;this.moveCellsOnAddition(e,i,r,`columns`);let a=this.sheets[e.id].numberOfCols;this.history.update(`sheets`,e.id,`numberOfCols`,a+r),i<e.panes.xSplit&&this.setPaneDivisions(e.id,e.panes.xSplit+r,`COL`)}addRows(e,t,n,r){let i=n===`before`?t:t+1;this.addEmptyRows(e,r),this.moveCellsOnAddition(e,i,r,`rows`),i<e.panes.ySplit&&this.setPaneDivisions(e.id,e.panes.ySplit+r,`ROW`)}moveCellOnColumnsDeletion(e,t){this.dispatch(`CLEAR_CELLS`,{sheetId:e.id,target:[{left:t,top:0,right:t,bottom:e.rows.length-1}]});for(let n=0;n<e.rows.length;n++){let r=e.rows[n];for(let i in r.cells){let a=Number(i),o=r.cells[i];o&&a>t&&this.setNewPosition(o,e.id,a-1,n)}}}moveCellsOnAddition(e,t,n,r){let i=[];for(let a=0;a<e.rows.length;a++){let o=e.rows[a];if(r!==`rows`||a>=t)for(let s in o.cells){let c=Number(s),l=o.cells[s];l&&(r===`rows`||c>=t)&&i.push({sheetId:e.id,cellId:l,col:c+(r===`columns`?n:0),row:a+(r===`rows`?n:0),type:`UPDATE_CELL_POSITION`})}}for(let e of i.reverse())this.updateCellPosition(e)}moveCellOnRowsDeletion(e,t,n){this.dispatch(`CLEAR_CELLS`,{sheetId:e.id,target:[{left:0,top:t,right:this.getters.getNumberCols(e.id),bottom:n}]});let r=n-t+1;for(let t=0;t<e.rows.length;t++){let i=e.rows[t];if(t>n)for(let n in i.cells){let a=Number(n),o=i.cells[n];o&&this.setNewPosition(o,e.id,a,t-r)}}}updateRowsStructureOnDeletion(e,t,n){let r=[],i=e.rows.map(e=>e.cells).reverse();for(let a in e.rows){let e=Number(a);e>=t&&e<=n||r.push({cells:i.pop()})}this.history.update(`sheets`,e.id,`rows`,r)}addEmptyRows(e,t){let n=e.rows.slice();for(let e=0;e<t;e++)n.push({cells:{}});this.history.update(`sheets`,e.id,`rows`,n)}getImportedSheetSize(e){let t=Object.keys(e.cells).map(rn),n=e.rowNumber,r=e.colNumber;for(let{col:e,row:i}of t)n=Math.max(n,i+1),r=Math.max(r,e+1);return{rowNumber:n,colNumber:r}}checkSheetExists(e){return e.type!==`CREATE_SHEET`&&`sheetId`in e&&this.sheets[e.sheetId]===void 0?`InvalidSheetId`:e.type===`CREATE_SHEET`&&this.sheets[e.sheetId]!==void 0?`DuplicatedSheetId`:`Success`}checkZonesAreInSheet(e){return`sheetId`in e?`ranges`in e&&e.ranges.some(e=>!this.getters.tryGetSheet(e._sheetId))?`InvalidSheetId`:this.checkZonesExistInSheet(e.sheetId,this.getCommandZones(e)):`Success`}},fk=class extends IO{static getters=[`getHeaderGroups`,`getGroupsLayers`,`getVisibleGroupLayers`,`getHeaderGroup`,`getHeaderGroupsInZone`,`isGroupFolded`,`isRowFolded`,`isColFolded`];groups={};allowDispatch(e){switch(e.type){case`GROUP_HEADERS`:{let{start:t,end:n,sheetId:r}=e;if(!this.getters.tryGetSheet(r))return`InvalidSheetId`;if(!this.getters.doesHeadersExist(e.sheetId,e.dimension,[t,n])||t>n)return`InvalidHeaderGroupStartEnd`;if(this.findGroupWithStartEnd(e.sheetId,e.dimension,t,n))return`HeaderGroupAlreadyExists`;break}case`UNGROUP_HEADERS`:{let{start:t,end:n,sheetId:r}=e;if(!this.getters.tryGetSheet(r))return`InvalidSheetId`;if(!this.getters.doesHeadersExist(e.sheetId,e.dimension,[t,n])||t>n)return`InvalidHeaderGroupStartEnd`;break}case`UNFOLD_HEADER_GROUP`:case`FOLD_HEADER_GROUP`:if(!this.getters.tryGetSheet(e.sheetId))return`InvalidSheetId`;let t=this.findGroupWithStartEnd(e.sheetId,e.dimension,e.start,e.end);if(!t)return`UnknownHeaderGroup`;if(w(0,this.getters.getNumberHeaders(e.sheetId,e.dimension)).every(n=>n>=t.start&&n<=t.end||this.getters.isHeaderHiddenByUser(e.sheetId,e.dimension,n)))return`NotEnoughElements`;break}return`Success`}handle(e){switch(e.type){case`CREATE_SHEET`:this.history.update(`groups`,e.sheetId,{ROW:[],COL:[]});break;case`GROUP_HEADERS`:this.groupHeaders(e.sheetId,e.dimension,e.start,e.end);break;case`UNGROUP_HEADERS`:this.unGroupHeaders(e.sheetId,e.dimension,e.start,e.end);break;case`DUPLICATE_SHEET`:{let t=S(this.groups[e.sheetId]);this.history.update(`groups`,e.sheetIdTo,t);break}case`DELETE_SHEET`:{let t={...this.groups};delete t[e.sheetId],this.history.update(`groups`,t);break}case`ADD_COLUMNS_ROWS`:let t=bt(e.position,e.base);this.moveGroupsOnHeaderInsertion(e.sheetId,e.dimension,t,e.quantity);break;case`REMOVE_COLUMNS_ROWS`:this.moveGroupsOnHeaderDeletion(e.sheetId,e.dimension,e.elements);break;case`UNFOLD_HEADER_GROUP`:{let t=this.findGroupWithStartEnd(e.sheetId,e.dimension,e.start,e.end);t&&this.unfoldHeaderGroup(e.sheetId,e.dimension,t);break}case`FOLD_HEADER_GROUP`:{let t=this.findGroupWithStartEnd(e.sheetId,e.dimension,e.start,e.end);t&&this.foldHeaderGroup(e.sheetId,e.dimension,t);break}case`UNFOLD_ALL_HEADER_GROUPS`:{let t=this.getters.getHeaderGroups(e.sheetId,e.dimension);for(let n of t)this.unfoldHeaderGroup(e.sheetId,e.dimension,n);break}case`FOLD_ALL_HEADER_GROUPS`:{let t=this.getters.getHeaderGroups(e.sheetId,e.dimension);for(let n of t)this.foldHeaderGroup(e.sheetId,e.dimension,n);break}case`FOLD_HEADER_GROUPS_IN_ZONE`:case`UNFOLD_HEADER_GROUPS_IN_ZONE`:{let t=e.type===`UNFOLD_HEADER_GROUPS_IN_ZONE`?`unfold`:`fold`,n=this.getGroupsLayers(e.sheetId,e.dimension);t===`fold`&&n.reverse();let r=n.flat(),i=e.dimension===`ROW`?e.zone.top:e.zone.left,a=e.dimension===`ROW`?e.zone.bottom:e.zone.right,o=new Set;for(let e=i;e<=a;e++){let n=r.filter(t=>t.start-1<=e&&e<=t.end);for(let e of n)if(!(t===`fold`&&e.isFolded||t===`unfold`&&!e.isFolded)){o.add(e);break}}for(let n of o)t===`unfold`?this.unfoldHeaderGroup(e.sheetId,e.dimension,n):this.foldHeaderGroup(e.sheetId,e.dimension,n);break}}}getHeaderGroups(e,t){return this.groups[e][t]}getHeaderGroup(e,t,n,r){return this.getHeaderGroups(e,t).find(e=>e.start===n&&e.end===r)}getHeaderGroupsInZone(e,t,n){return this.getHeaderGroups(e,t).filter(e=>{let r=t===`ROW`?n.top:n.left,i=t===`ROW`?n.bottom:n.right;return this.doGroupOverlap(e,r,i)})}getGroupsLayers(e,t){let n=this.getHeaderGroups(e,t);return this.bricksFallingAlgorithm(n,0,0)}getVisibleGroupLayers(e,t){let n=this.getGroupsLayers(e,t);for(let r of n)for(let n=r.length-1;n>=0;n--){let i=r[n];i.start!==0&&w(i.start-1,i.end+1).every(n=>this.getters.isHeaderHiddenByUser(e,t,n))&&r.splice(n,1)}return n.filter(e=>e.length>0)}isGroupFolded(e,t,n,r){return this.getHeaderGroup(e,t,n,r)?.isFolded||!1}isRowFolded(e,t){return this.getters.getHeaderGroups(e,`ROW`).some(e=>e.start<=t&&t<=e.end&&e.isFolded)}isColFolded(e,t){return this.getters.getHeaderGroups(e,`COL`).some(e=>e.start<=t&&t<=e.end&&e.isFolded)}getGroupId(e){return`${e.start}-${e.end}}`}bricksFallingAlgorithm(e,t,n,r=0){let i={};for(let t of e)i[this.getGroupId(t)]=t.isFolded;let a={};for(let t of e)for(let e=t.start;e<=t.end;e++)a[e]=a[e]?a[e]+1:1;for(let e=t;e<=n;e++)a[e]=a[e]?a[e]+r:r;let o=Math.max(...Object.values(a),0),s=Array.from({length:o},()=>[]),c=Math.max(n,...e.map(e=>e.end)),l=Math.min(t,...e.map(e=>e.start));for(let e=l;e<=c;e++){let t=a[e]||0;for(let n=0;n<t;n++){let t=s[n].at(-1);if(t&&Et([t.end,e]))t.end++;else{let t={start:e,end:e};s[n].push(t)}}}for(let e of s)for(let t of e)t.isFolded=i[this.getGroupId(t)];return s}groupHeaders(e,t,n,r){let i=this.getHeaderGroups(e,t),a=this.bricksFallingAlgorithm(i,n,r,1).flat();this.history.update(`groups`,e,t,this.removeDuplicateGroups(a))}unGroupHeaders(e,t,n,r){let i=this.getHeaderGroups(e,t),a=this.bricksFallingAlgorithm(i,n,r,-1).flat();this.history.update(`groups`,e,t,this.removeDuplicateGroups(a))}moveGroupsOnHeaderInsertion(e,t,n,r){let i=this.groups[e][t];for(let a=0;a<i.length;a++){let o=i[a],[s,c]=Va(n,r,[o.start,o.end]);(s!==o.start||c!==o.end)&&this.history.update(`groups`,e,t,a,{...o,start:s,end:c})}}moveGroupsOnHeaderDeletion(e,t,n){let r=this.getHeaderGroups(e,t),i=[];for(let e of r){let t=Ha(n,w(e.start,e.end+1));t.length!==0&&i.push({...e,start:Math.min(...t),end:Math.max(...t)})}this.history.update(`groups`,e,t,this.bricksFallingAlgorithm(i,0,0).flat())}doGroupOverlap(e,t,n){return e.start<=n&&e.end>=t}removeDuplicateGroups(e){let t={};for(let n of e)t[this.getGroupId(n)]=n;return Object.values(t)}findGroupWithStartEnd(e,t,n,r){return this.getHeaderGroups(e,t).find(e=>e.start===n&&e.end===r)}foldHeaderGroup(e,t,n){let r=this.getGroupIndex(e,t,n.start,n.end);if(r===void 0)return;this.history.update(`groups`,e,t,r,`isFolded`,!0);let i=this.getters.getHeaderGroups(e,t);for(let r=0;r<i.length;r++){let a=i[r];a.start===n.start&&a.end<=n.end&&this.history.update(`groups`,e,t,r,`isFolded`,!0)}}unfoldHeaderGroup(e,t,n){let r=this.getGroupIndex(e,t,n.start,n.end);if(r===void 0)return;this.history.update(`groups`,e,t,r,`isFolded`,!1);let i=this.getters.getHeaderGroups(e,t);for(let r=0;r<i.length;r++){let a=i[r];a.start===n.start&&a.end>=n.end&&this.history.update(`groups`,e,t,r,`isFolded`,!1)}}getGroupIndex(e,t,n,r){let i=this.groups[e][t].findIndex(e=>e.start===n&&e.end===r);return i===-1?void 0:i}import(e){for(let t of e.sheets)if(this.groups[t.id]={ROW:[],COL:[]},t.headerGroups)for(let e of[`ROW`,`COL`])for(let n of t.headerGroups[e]||[])this.groups[t.id][e].push({...n})}export(e){for(let t of e.sheets)t.headerGroups=this.groups[t.id]}},pk=class extends IO{static getters=[`getLocale`];locale=A;allowDispatch(e){switch(e.type){case`UPDATE_LOCALE`:return Fc(e.locale)?`Success`:`InvalidLocale`}return`Success`}handle(e){switch(e.type){case`UPDATE_LOCALE`:let t=this.locale,n=e.locale;this.history.update(`locale`,n),this.changeCellsDateFormatWithLocale(t,n);break}}getLocale(){return this.locale}changeCellsDateFormatWithLocale(e,t){for(let n of this.getters.getSheetIds())for(let[r,i]of Object.entries(this.getters.getCells(n))){let n;if(i.format===e.dateFormat&&(n=t.dateFormat),i.format===e.timeFormat&&(n=t.timeFormat),i.format===Qc(e)&&(n=Qc(t)),n){let{col:e,row:t,sheetId:i}=this.getters.getCellPosition(r);this.dispatch(`UPDATE_CELL`,{col:e,row:t,sheetId:i,format:n})}}}import(e){this.locale=e.settings?.locale??A}export(e){e.settings={locale:this.locale}}},Q=class extends FO{static layers=[];getters;ui;selection;constructor({getters:e,stateObserver:t,dispatch:n,uiActions:r,selection:i}){super(t,n),this.getters=e,this.ui=r,this.selection=i}drawGrid(e,t){}};let mk=Ny.mapping;function hk(e,t,n){return new gk(e,t,n).getParameters()}var gk=class{getters;computeCell;evalContext;rangeCache={};constructor(e,t,n){this.getters=t,this.computeCell=n,this.evalContext=Object.assign(Object.create(mk),e,{getters:this.getters,locale:this.getters.getLocale()})}getParameters(){return[this.refFn.bind(this),this.range.bind(this),this.evalContext]}refFn(e,t,n,r){if(this.assertRangeValid(e),t)return{value:B(e.zone)};if(e.zone.bottom!==e.zone.top||e.zone.left!==e.zone.right)throw Error(r?y(`Function %s expects the parameter %s to be a single value or a single cell reference, not a range.`,n.toString(),r.toString()):y(`Function %s expects its parameters to be single values or single cell references, not ranges.`,n.toString()));let i={sheetId:e.sheetId,col:e.zone.left,row:e.zone.top};return this.readCell(i)}readCell(e){if(!this.getters.tryGetSheet(e.sheetId))throw Error(y(`Invalid sheet name`));let t=this.getEvaluatedCellIfNotEmpty(e);if(t===void 0)return{value:null,format:this.getters.getCell(e)?.format};if(t.type===`error`)throw t.error;return t}getEvaluatedCellIfNotEmpty(e){let t=this.computeCell(e);if(t.type===`empty`){let t=this.getters.getCell(e);if(!t||!t.isFormula&&t.content===``)return}return t}range(e){this.assertRangeValid(e);let t=e.sheetId,n=e.zone,r=ca(n,this.getters.getSheetZone(t));if(!r)return[[]];let{top:i,left:a,bottom:o,right:s}=n,c=`${t}-${i}-${a}-${o}-${s}`;if(c in this.rangeCache){let e=this.rangeCache[c];if(e instanceof b)throw e;return e}let l=r.bottom-r.top+1,u=r.right-r.left+1,d=Array(u);for(let e=r.left;e<=r.right;e++){let n=e-r.left;d[n]=Array(l);for(let i=r.top;i<=r.bottom;i++){let a=this.getEvaluatedCellIfNotEmpty({sheetId:t,col:e,row:i});if(a?.type===`error`)throw this.rangeCache[c]=a.error,a.error;let o=i-r.top;d[n][o]=this.readCell({sheetId:t,col:e,row:i})}}return this.rangeCache[c]=d,d}assertRangeValid(e){if(!ta(e.zone))throw new re;if(e.invalidSheetName)throw Error(y(`Invalid sheet name: %s`,e.invalidSheetName))}},_k=d(c(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n||=self).RBush=r()})(e,function(){"use strict";function e(e,r,i,a,o){(function e(n,r,i,a,o){for(;a>i;){if(a-i>600){var s=a-i+1,c=r-i+1,l=Math.log(s),u=.5*Math.exp(2*l/3),d=.5*Math.sqrt(l*u*(s-u)/s)*(c-s/2<0?-1:1);e(n,r,Math.max(i,Math.floor(r-c*u/s+d)),Math.min(a,Math.floor(r+(s-c)*u/s+d)),o)}var f=n[r],p=i,m=a;for(t(n,i,r),o(n[a],f)>0&&t(n,i,a);p<m;){for(t(n,p,m),p++,m--;o(n[p],f)<0;)p++;for(;o(n[m],f)>0;)m--}o(n[i],f)===0?t(n,i,m):t(n,++m,a),m<=r&&(i=m+1),r<=m&&(a=m-1)}})(e,r,i||0,a||e.length-1,o||n)}function t(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function n(e,t){return e<t?-1:+(e>t)}var r=function(e){e===void 0&&(e=9),this._maxEntries=Math.max(4,e),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()};function i(e,t,n){if(!n)return t.indexOf(e);for(var r=0;r<t.length;r++)if(n(e,t[r]))return r;return-1}function a(e,t){o(e,0,e.children.length,t,e)}function o(e,t,n,r,i){i||=m(null),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(var a=t;a<n;a++){var o=e.children[a];s(i,e.leaf?r(o):o)}return i}function s(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function c(e,t){return e.minX-t.minX}function l(e,t){return e.minY-t.minY}function u(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function d(e){return e.maxX-e.minX+(e.maxY-e.minY)}function f(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function p(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function m(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function h(t,n,r,i,a){for(var o=[n,r];o.length;)if(!((r=o.pop())-(n=o.pop())<=i)){var s=n+Math.ceil((r-n)/i/2)*i;e(t,s,n,r,a),o.push(n,s,s,r)}}return r.prototype.all=function(){return this._all(this.data,[])},r.prototype.search=function(e){var t=this.data,n=[];if(!p(e,t))return n;for(var r=this.toBBox,i=[];t;){for(var a=0;a<t.children.length;a++){var o=t.children[a],s=t.leaf?r(o):o;p(e,s)&&(t.leaf?n.push(o):f(e,s)?this._all(o,n):i.push(o))}t=i.pop()}return n},r.prototype.collides=function(e){var t=this.data;if(!p(e,t))return!1;for(var n=[];t;){for(var r=0;r<t.children.length;r++){var i=t.children[r],a=t.leaf?this.toBBox(i):i;if(p(e,a)){if(t.leaf||f(e,a))return!0;n.push(i)}}t=n.pop()}return!1},r.prototype.load=function(e){if(!e||!e.length)return this;if(e.length<this._minEntries){for(var t=0;t<e.length;t++)this.insert(e[t]);return this}var n=this._build(e.slice(),0,e.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this},r.prototype.insert=function(e){return e&&this._insert(e,this.data.height-1),this},r.prototype.clear=function(){return this.data=m([]),this},r.prototype.remove=function(e,t){if(!e)return this;for(var n,r,a,o=this.data,s=this.toBBox(e),c=[],l=[];o||c.length;){if(o||(o=c.pop(),r=c[c.length-1],n=l.pop(),a=!0),o.leaf){var u=i(e,o.children,t);if(u!==-1)return o.children.splice(u,1),c.push(o),this._condense(c),this}a||o.leaf||!f(o,s)?r?(n++,o=r.children[n],a=!1):o=null:(c.push(o),l.push(n),n=0,r=o,o=o.children[0])}return this},r.prototype.toBBox=function(e){return e},r.prototype.compareMinX=function(e,t){return e.minX-t.minX},r.prototype.compareMinY=function(e,t){return e.minY-t.minY},r.prototype.toJSON=function(){return this.data},r.prototype.fromJSON=function(e){return this.data=e,this},r.prototype._all=function(e,t){for(var n=[];e;)e.leaf?t.push.apply(t,e.children):n.push.apply(n,e.children),e=n.pop();return t},r.prototype._build=function(e,t,n,r){var i,o=n-t+1,s=this._maxEntries;if(o<=s)return a(i=m(e.slice(t,n+1)),this.toBBox),i;r||(r=Math.ceil(Math.log(o)/Math.log(s)),s=Math.ceil(o/s**(r-1))),(i=m([])).leaf=!1,i.height=r;var c=Math.ceil(o/s),l=c*Math.ceil(Math.sqrt(s));h(e,t,n,l,this.compareMinX);for(var u=t;u<=n;u+=l){var d=Math.min(u+l-1,n);h(e,u,d,c,this.compareMinY);for(var f=u;f<=d;f+=c){var p=Math.min(f+c-1,d);i.children.push(this._build(e,f,p,r-1))}}return a(i,this.toBBox),i},r.prototype._chooseSubtree=function(e,t,n,r){for(;r.push(t),!t.leaf&&r.length-1!==n;){for(var i=1/0,a=1/0,o=void 0,s=0;s<t.children.length;s++){var c=t.children[s],l=u(c),d=(f=e,p=c,(Math.max(p.maxX,f.maxX)-Math.min(p.minX,f.minX))*(Math.max(p.maxY,f.maxY)-Math.min(p.minY,f.minY))-l);d<a?(a=d,i=l<i?l:i,o=c):d===a&&l<i&&(i=l,o=c)}t=o||t.children[0]}var f,p;return t},r.prototype._insert=function(e,t,n){var r=n?e:this.toBBox(e),i=[],a=this._chooseSubtree(r,this.data,t,i);for(a.children.push(e),s(a,r);t>=0&&i[t].children.length>this._maxEntries;)this._split(i,t),t--;this._adjustParentBBoxes(r,i,t)},r.prototype._split=function(e,t){var n=e[t],r=n.children.length,i=this._minEntries;this._chooseSplitAxis(n,i,r);var o=this._chooseSplitIndex(n,i,r),s=m(n.children.splice(o,n.children.length-o));s.height=n.height,s.leaf=n.leaf,a(n,this.toBBox),a(s,this.toBBox),t?e[t-1].children.push(s):this._splitRoot(n,s)},r.prototype._splitRoot=function(e,t){this.data=m([e,t]),this.data.height=e.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},r.prototype._chooseSplitIndex=function(e,t,n){for(var r,i,a,s,c,l,d,f=1/0,p=1/0,m=t;m<=n-t;m++){var h=o(e,0,m,this.toBBox),g=o(e,m,n,this.toBBox),_=(i=h,a=g,s=void 0,c=void 0,l=void 0,d=void 0,s=Math.max(i.minX,a.minX),c=Math.max(i.minY,a.minY),l=Math.min(i.maxX,a.maxX),d=Math.min(i.maxY,a.maxY),Math.max(0,l-s)*Math.max(0,d-c)),v=u(h)+u(g);_<f?(f=_,r=m,p=v<p?v:p):_===f&&v<p&&(p=v,r=m)}return r||n-t},r.prototype._chooseSplitAxis=function(e,t,n){var r=e.leaf?this.compareMinX:c,i=e.leaf?this.compareMinY:l;this._allDistMargin(e,t,n,r)<this._allDistMargin(e,t,n,i)&&e.children.sort(r)},r.prototype._allDistMargin=function(e,t,n,r){e.children.sort(r);for(var i=this.toBBox,a=o(e,0,t,i),c=o(e,n-t,n,i),l=d(a)+d(c),u=t;u<n-t;u++){var f=e.children[u];s(a,e.leaf?i(f):f),l+=d(a)}for(var p=n-t-1;p>=t;p--){var m=e.children[p];s(c,e.leaf?i(m):m),l+=d(c)}return l},r.prototype._adjustParentBBoxes=function(e,t,n){for(var r=n;r>=0;r--)s(t[r],e)},r.prototype._condense=function(e){for(var t=e.length-1,n=void 0;t>=0;t--)e[t].children.length===0?t>0?(n=e[t-1].children).splice(n.indexOf(e[t]),1):this.clear():a(e[t],this.toBBox)},r})}))(),1),vk=class{rTrees={};constructor(e=[]){let t={};for(let n of e){let e=n.boundingBox.sheetId;t[e]||(t[e]=[]),t[e].push(n)}for(let e in t)this.rTrees[e]=new yk,this.rTrees[e].load(t[e])}insert(e){let t=e.boundingBox.sheetId;this.rTrees[t]||(this.rTrees[t]=new yk),this.rTrees[t].insert(e)}search({zone:e,sheetId:t}){return this.rTrees[t]?this.rTrees[t].search({minX:e.left,minY:e.top,maxX:e.right,maxY:e.bottom}):[]}remove(e){let t=e.boundingBox.sheetId;this.rTrees[t]&&this.rTrees[t].remove(e,this.rtreeItemComparer)}rtreeItemComparer(e,t){return e.data===t.data&&e.boundingBox.sheetId===t.boundingBox.sheetId&&e.boundingBox?.zone.left===t.boundingBox.zone.left&&e.boundingBox?.zone.top===t.boundingBox.zone.top&&e.boundingBox?.zone.right===t.boundingBox.zone.right&&e.boundingBox?.zone.bottom===t.boundingBox.zone.bottom}},yk=class extends _k.default{toBBox({boundingBox:e}){let t=e.zone;return{minX:t.left,minY:t.top,maxX:t.right,maxY:t.bottom}}compareMinX(e,t){return e.boundingBox.zone.left-t.boundingBox.zone.left}compareMinY(e,t){return e.boundingBox.zone.top-t.boundingBox.zone.top}},bk=class{encoder;dependencies=new Map;rTree;constructor(e,t=[]){this.encoder=e,this.rTree=new vk(t)}removeAllDependencies(e){let t=this.dependencies.get(e);if(t){for(let e of t)this.rTree.remove(e);this.dependencies.delete(e)}}addDependencies(e,t){let n=t.map(({sheetId:t,zone:n})=>({data:e,boundingBox:{zone:n,sheetId:t}}));for(let e of n)this.rTree.insert(e);let r=this.dependencies.get(e);r?r.push(...n):this.dependencies.set(e,n)}getCellsDependingOn(e){let t=new Dt,n=Array.from(e).reverse();for(;n.length>0;){let e=n.pop();t.addMany(this.encoder.encodeBoundingBox(e));let r=this.rTree.search(e).map(e=>e.data),i={};for(let e of r)if(!t.has(e)){let{sheetId:t,zone:n}=this.encoder.decodeToBoundingBox(e);i[t]||(i[t]=[]),i[t].push(n)}for(let e in i){let t=HO(i[e]);n.push(...t.map(t=>({sheetId:e,zone:t})))}}return t.deleteMany(e.flatMap(e=>this.encoder.encodeBoundingBox(e))),t}},xk=class{resultsToArrayFormulas=new Map;arrayFormulasToResults=new Map;getFormulaPositionsSpreadingOn(e){return this.resultsToArrayFormulas.get(e)||Sk}getArrayResultPositionIds(e){return this.arrayFormulasToResults.get(e)||Sk}removeNode(e){this.resultsToArrayFormulas.delete(e),this.arrayFormulasToResults.delete(e)}addRelation({arrayFormulaPositionId:e,resultPositionId:t}){this.resultsToArrayFormulas.has(t)||this.resultsToArrayFormulas.set(t,new Set),this.resultsToArrayFormulas.get(t)?.add(e),this.arrayFormulasToResults.has(e)||this.arrayFormulasToResults.set(e,new Set),this.arrayFormulasToResults.get(e)?.add(t)}hasArrayFormulaResult(e){return this.resultsToArrayFormulas.has(e)}isArrayFormula(e){return this.arrayFormulasToResults.has(e)}};let Sk=[];var Ck=class{context;getters;compilationParams;encoder=new Tk;evaluatedCells=new Map;formulaDependencies=vt(new bk(this.encoder));blockedArrayFormulas=new Set;spreadingRelations=new xk;constructor(e,t){this.context=e,this.getters=t,this.compilationParams=hk(this.context,this.getters,this.computeAndSave.bind(this))}getEvaluatedCell(e){return this.evaluatedCells.get(this.encoder.encode(e))||no(``,{locale:this.getters.getLocale()})}getSpreadPositionsOf(e){let t=this.encoder.encode(e);return this.spreadingRelations.isArrayFormula(t)?Array.from(this.spreadingRelations.getArrayResultPositionIds(t)).map(e=>this.encoder.decode(e)):[]}getArrayFormulaSpreadingOn(e){let t=this.encoder.encode(e),n=this.getArrayFormulaSpreadingOnId(t);return n===void 0?void 0:this.encoder.decode(n)}getEvaluatedPositions(){return[...this.evaluatedCells.keys()].map(e=>this.encoder.decode(e))}getArrayFormulaSpreadingOnId(e){if(!this.spreadingRelations.hasArrayFormulaResult(e))return;let t=this.spreadingRelations.getFormulaPositionsSpreadingOn(e);return Array.from(t).find(e=>!this.blockedArrayFormulas.has(e))}updateDependencies(e){let t=this.encoder.encode(e);this.formulaDependencies().removeAllDependencies(t);let n=this.getDirectDependencies(t);this.formulaDependencies().addDependencies(t,n)}updateCompilationParameters(){this.compilationParams=hk(this.context,this.getters,this.computeAndSave.bind(this))}evaluateCells(e){let t=e.map(e=>this.encoder.encode(e)),n=new Dt(t),r=this.getArrayFormulasImpactedByChangesOf(t);n.addMany(this.getCellsDependingOn(t)),n.addMany(r),n.addMany(this.getCellsDependingOn(r)),this.evaluate(n)}getArrayFormulasImpactedByChangesOf(e){let t=new Dt;for(let n of e){let e=this.getCell(n)?.content,r=this.getArrayFormulaSpreadingOnId(n);r!==void 0&&t.add(r),e||t.addMany(this.getArrayFormulasBlockedBy(n))}return t}buildDependencyGraph(){this.blockedArrayFormulas=new Set,this.spreadingRelations=new xk,this.formulaDependencies=vt(()=>{let e=[...this.getAllCells()].flatMap(e=>this.getDirectDependencies(e).filter(e=>!e.invalidSheetName&&!e.invalidXc).map(t=>({data:e,boundingBox:{zone:t.zone,sheetId:t.sheetId}})));return new bk(this.encoder,e)})}evaluateAllCells(){this.evaluatedCells=new Map,this.evaluate(this.getAllCells())}evaluateFormulaResult(e,t){try{let n=NT(t),r=n.dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t));return this.updateCompilationParameters(),n.execute(r,...this.compilationParams)}catch(e){return this.handleError(e)}}getAllCells(){let e=new Dt;for(let t of this.getters.getSheetIds()){let n=this.getters.getCells(t);for(let t in n)e.add(this.encoder.encode(this.getters.getCellPosition(t)))}return e}getArrayFormulasBlockedBy(e){if(!this.spreadingRelations.hasArrayFormulaResult(e))return[];let t=new Dt(this.spreadingRelations.getFormulaPositionsSpreadingOn(e)),n=this.getArrayFormulaSpreadingOnId(e);return n!==void 0&&t.delete(n),t.addMany(this.getCellsDependingOn(t)),t}nextPositionsToUpdate=new Dt;cellsBeingComputed=new Set;evaluate(e){this.cellsBeingComputed=new Set,this.nextPositionsToUpdate=e;let t=0;for(;this.nextPositionsToUpdate.size&&t++<30;){this.updateCompilationParameters();let e=Array.from(this.nextPositionsToUpdate);this.nextPositionsToUpdate.clear();for(let t=0;t<e.length;++t){let n=e[t];this.evaluatedCells.delete(n)}for(let t=0;t<e.length;++t){let n=e[t];this.nextPositionsToUpdate.has(n)||this.setEvaluatedCell(n,this.computeCell(n))}}t>=30&&console.warn(`Maximum iteration reached while evaluating cells`)}setEvaluatedCell(e,t){this.evaluatedCells.set(e,t)}computeCell(e){let t=this.evaluatedCells.get(e);if(t)return t;this.blockedArrayFormulas.has(e)||this.invalidateSpreading(e);let n=this.getCell(e);if(n===void 0)return no(``,{locale:this.getters.getLocale()});let r=n.id;try{if(this.cellsBeingComputed.has(r))throw new ne;return this.cellsBeingComputed.add(r),n.isFormula?this.computeFormulaCell(n):eo(n.content,{format:n.format,locale:this.getters.getLocale()})}catch(e){return this.handleError(e)}finally{this.cellsBeingComputed.delete(r)}}computeAndSave(e){let t=this.encoder.encode(e),n=this.computeCell(t);return this.evaluatedCells.has(t)||this.setEvaluatedCell(t,n),n}handleError(e){e instanceof b||(e=new b(`#ERROR`,e.message));let t=this.compilationParams[2].__lastFnCalled||``;return e.message=e.message.replace(`[[FUNCTION_NAME]]`,t),uo(e)}computeFormulaCell(e){let t=e.id;this.compilationParams[2].__originCellXC=()=>{let e=this.compilationParams[2].getters.getCellPosition(t);return O(e.col,e.row)};let n=e.compiledFormula.execute(e.compiledFormula.dependencies,...this.compilationParams);if(!j(n))return no(n.value,{format:e.format||n.format,locale:this.getters.getLocale()});let r=this.getters.getCellPosition(t);this.assertSheetHasEnoughSpaceToSpreadFormulaResult(r,n);let i=n.length,a=n[0].length;return a===0?no(null,{format:e.format,locale:this.getters.getLocale()}):(wk(i,a,this.updateSpreadRelation(r)),wk(i,a,this.checkCollision(r)),wk(i,a,this.spreadValues(r,n)),this.invalidatePositionsDependingOnSpread(r,i,a),no(n[0][0].value,{format:e.format||n[0][0]?.format,locale:this.getters.getLocale()}))}invalidatePositionsDependingOnSpread(e,t,n){let r=e.row,i=e.col,a=r+n-1,o={top:r+1,bottom:a,left:i,right:i},s={top:r,bottom:a,left:i+1,right:i+t-1},c=e.sheetId,l=this.formulaDependencies().getCellsDependingOn([{sheetId:c,zone:s},{sheetId:c,zone:o}]);l.delete(this.encoder.encode(e)),this.nextPositionsToUpdate.addMany(l)}assertSheetHasEnoughSpaceToSpreadFormulaResult({sheetId:e,col:t,row:n},r){let i=this.getters.getNumberCols(e),a=this.getters.getNumberRows(e),o=t+r.length<=i,s=n+r[0].length<=a;if(!(o&&s))throw Error(y(o?`Result couldn't be automatically expanded. Please insert more rows.`:s?`Result couldn't be automatically expanded. Please insert more columns.`:`Result couldn't be automatically expanded. Please insert more columns and rows.`))}updateSpreadRelation({sheetId:e,col:t,row:n}){let r=this.encoder.encode({sheetId:e,col:t,row:n});return(i,a)=>{let o={sheetId:e,col:i+t,row:a+n},s=this.encoder.encode(o);this.spreadingRelations.addRelation({resultPositionId:s,arrayFormulaPositionId:r})}}checkCollision({sheetId:e,col:t,row:n}){let r=this.encoder.encode({sheetId:e,col:t,row:n});return(i,a)=>{let o={sheetId:e,col:i+t,row:a+n};if(this.getters.getCell(o)?.content||this.getters.getEvaluatedCell(o).type!==`empty`)throw this.blockedArrayFormulas.add(r),Error(y(`Array result was not expanded because it would overwrite data in %s.`,O(o.col,o.row)));this.blockedArrayFormulas.delete(r)}}spreadValues({sheetId:e,col:t,row:n},r){return(i,a)=>{let o={sheetId:e,col:i+t,row:a+n},s=this.getters.getCell(o)?.format,c=no(r[i][a].value,{format:s||r[i][a]?.format,locale:this.getters.getLocale()}),l=this.encoder.encode(o);this.setEvaluatedCell(l,c)}}invalidateSpreading(e){if(this.spreadingRelations.isArrayFormula(e)){for(let t of this.spreadingRelations.getArrayResultPositionIds(e))this.getCell(t)?.content||(this.evaluatedCells.delete(t),this.nextPositionsToUpdate.addMany(this.getCellsDependingOn([t])),this.nextPositionsToUpdate.addMany(this.getArrayFormulasBlockedBy(t)),this.spreadingRelations.removeNode(t));this.spreadingRelations.removeNode(e)}}getDirectDependencies(e){let t=this.getCell(e);return t?.isFormula?t.compiledFormula.dependencies:[]}getCellsDependingOn(e){let t=[];for(let n of e)t.push(this.encoder.decodeToBoundingBox(n));return this.formulaDependencies().getCellsDependingOn(t)}getCell(e){return this.getters.getCell(this.encoder.decode(e))}};function wk(e,t,n){for(let r=0;r<e;++r)for(let e=0;e<t;++e)r===0&&e===0||n(r,e)}var Tk=class{sheetMapping={};inverseSheetMapping=new Map;constructor(){try{o_spreadsheet.__DEBUG__=o_spreadsheet.__DEBUG__||{},o_spreadsheet.__DEBUG__.decodePosition=this.decode.bind(this),o_spreadsheet.__DEBUG__.encodePosition=this.encode.bind(this)}catch{}}encode({sheetId:e,col:t,row:n}){return this.encodeSheet(e)<<42n|BigInt(t)<<21n|BigInt(n)}encodeBoundingBox({sheetId:e,zone:t}){let n=[];return xa(t,(t,r)=>{n.push(this.encode({sheetId:e,col:t,row:r}))}),n}decode(e){let t=Number(e&2097151n),n=Number(e>>21n&2097151n);return{sheetId:this.decodeSheet(e>>42n),col:n,row:t}}decodeToBoundingBox(e){let{sheetId:t,col:n,row:r}=this.decode(e);return{sheetId:t,zone:{left:n,top:r,right:n,bottom:r}}}encodeSheet(e){let t=this.sheetMapping[e];if(t===void 0){let t=BigInt(Object.keys(this.sheetMapping).length);return this.sheetMapping[e]=t,this.inverseSheetMapping.set(t,e),t}return t}decodeSheet(e){let t=this.inverseSheetMapping.get(e);if(t===void 0)throw Error(`Sheet id not found`);return t}},Ek=class extends Q{static getters=[`evaluateFormula`,`evaluateFormulaResult`,`getCorrespondingFormulaCell`,`getRangeFormattedValues`,`getRangeValues`,`getRangeFormats`,`getEvaluatedCell`,`getEvaluatedCells`,`getEvaluatedCellsInZone`,`getSpreadPositionsOf`,`getArrayFormulaSpreadingOn`,`isEmpty`];shouldRebuildDependenciesGraph=!0;evaluator;positionsToUpdate=[];constructor(e){super(e),this.evaluator=new Ck(e.custom,this.getters)}beforeHandle(e){or.has(e.type)&&(this.shouldRebuildDependenciesGraph=!0)}handle(e){switch(e.type){case`UPDATE_CELL`:if(!(`content`in e||`format`in e)||this.shouldRebuildDependenciesGraph)return;this.positionsToUpdate.push(e),`content`in e&&this.evaluator.updateDependencies(e);break;case`EVALUATE_CELLS`:this.evaluator.evaluateAllCells();break}}finalize(){this.shouldRebuildDependenciesGraph?(this.evaluator.buildDependencyGraph(),this.evaluator.evaluateAllCells(),this.shouldRebuildDependenciesGraph=!1):this.positionsToUpdate.length&&this.evaluator.evaluateCells(this.positionsToUpdate),this.positionsToUpdate=[]}evaluateFormula(e,t){let n=this.evaluateFormulaResult(e,t);return j(n)?Rr(n,e=>e.value):n.value}evaluateFormulaResult(e,t){return this.evaluator.evaluateFormulaResult(e,t)}getRangeFormattedValues(e){let t=this.getters.tryGetSheet(e.sheetId);return t===void 0?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map(e=>e.formattedValue)}getRangeValues(e){let t=this.getters.tryGetSheet(e.sheetId);return t===void 0?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map(e=>e.value)}getRangeFormats(e){let t=this.getters.tryGetSheet(e.sheetId);return t===void 0?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map(e=>e.format)}getEvaluatedCell(e){return this.evaluator.getEvaluatedCell(e)}getEvaluatedCells(e){let t=this.getters.getCells(e)||{},n={};for(let e of Object.keys(t)){let t=this.getters.getCellPosition(e);n[e]=this.getEvaluatedCell(t)}return n}getEvaluatedCellsInZone(e,t){return ba(t).map(({col:t,row:n})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:n}))}getSpreadPositionsOf(e){return this.evaluator.getSpreadPositionsOf(e)}getArrayFormulaSpreadingOn(e){return this.evaluator.getArrayFormulaSpreadingOn(e)}isEmpty(e,t){return ba(t).map(({col:t,row:n})=>this.getEvaluatedCell({sheetId:e,col:t,row:n})).every(e=>e.type===`empty`)}exportForExcel(e){for(let t of e.sheets)t.formulaSpillRanges={};for(let t of this.evaluator.getEvaluatedPositions()){let n=this.evaluator.getEvaluatedCell(t),r=O(t.col,t.row),i=n.value,a=!1,o,s,c=!0,l=e.sheets.find(e=>e.id===t.sheetId),u=this.getCorrespondingFormulaCell(t);if(u){let e=this.getters.getCell(t);c=GT(u.compiledFormula.tokens),a=c&&e?.content===u.content,c||i!==``&&(o=i.toString(),s=n.format)}let d=l.cells[r]||{},f=s?ht(s,e.formats):d.format,p;p=c&&a&&u?.compiledFormula.dependencies.length?this.getters.getFormulaCellContent(l.id,u.compiledFormula,u.compiledFormula.dependencies,!0):c?d.content:o,l.cells[r]={...d,value:i,isFormula:a,content:p,format:f};let m=this.getSpreadPositionsOf(t);m.push(t);let h=sa(...m.map(e=>V(e))),g=this.getters.getRangeString(this.getters.getRangeFromZone(t.sheetId,h),t.sheetId);g&&g!==`#REF`&&(l.formulaSpillRanges[r]=g)}}getCorrespondingFormulaCell(e){let t=this.getters.getCell(e);if(t&&t.isFormula)return Dk(t.compiledFormula.tokens)?void 0:t;if(t&&t.content)return;let n=this.getArrayFormulaSpreadingOn(e);if(n===void 0)return;let r=this.getters.getCell(n);if(r?.isFormula)return r}};function Dk(e){try{return PT(e),!1}catch{return!0}}function Ok(e){let t=[{leadColor:Ut(255,0,0),colors:[]},{leadColor:Ut(255,128,0),colors:[]},{leadColor:Ut(128,128,0),colors:[]},{leadColor:Ut(128,255,0),colors:[]},{leadColor:Ut(0,255,0),colors:[]},{leadColor:Ut(0,255,128),colors:[]},{leadColor:Ut(0,255,255),colors:[]},{leadColor:Ut(0,127,255),colors:[]},{leadColor:Ut(0,0,255),colors:[]},{leadColor:Ut(127,0,255),colors:[]},{leadColor:Ut(128,0,128),colors:[]},{leadColor:Ut(255,0,128),colors:[]}];for(let n of e.map(qt)){let e=500,r=0;t.forEach((t,i)=>{let a=kk(n,t.leadColor);e>a&&(e=a,r=i)}),t[r].colors.push(n)}return t.map(e=>e.colors.sort((e,t)=>Yt(e).s-Yt(t).s)).flat().map(Kt)}function kk(e,t){return Math.sqrt((e.r-t.r)**2+(e.g-t.g)**2+(e.b-t.b)**2)}var Ak=class extends Q{customColors={};shouldUpdateColors=!1;static getters=[`getCustomColors`];handle(e){switch(e.type){case`UPDATE_CELL`:case`UPDATE_CHART`:case`CREATE_CHART`:case`ADD_CONDITIONAL_FORMAT`:case`SET_BORDER`:case`SET_ZONE_BORDERS`:case`SET_FORMATTING`:this.history.update(`shouldUpdateColors`,!0)}}finalize(){if(this.shouldUpdateColors){this.history.update(`shouldUpdateColors`,!1);for(let e of this.getCustomColors())this.tryToAddColor(e)}}getCustomColors(){let e=[];for(let t of this.getters.getSheetIds())e=e.concat(this.getColorsFromCells(t),this.getFormattingColors(t),this.getChartColors(t));return Ok([...new Set([...new Set([...e,...Object.keys(this.customColors)])].filter(Bt).map(zt))]).filter(e=>!De.includes(e))}getColorsFromCells(e){let t=Object.values(this.getters.getCells(e)),n=new Set;for(let e of t)e.style?.textColor&&n.add(e.style.textColor),e.style?.fillColor&&n.add(e.style.fillColor);for(let t of this.getters.getBordersColors(e))n.add(t);return[...n]}getFormattingColors(e){let t=this.getters.getConditionalFormats(e),n=[];for(let e of t){let t=e.rule;t.type===`CellIsRule`?(n.push(t.style.textColor),n.push(t.style.fillColor)):t.type===`ColorScaleRule`&&(n.push(Rt(t.minimum.color)),n.push(t.midpoint?Rt(t.midpoint.color):void 0),n.push(Rt(t.maximum.color)))}return n.filter(T)}getChartColors(e){let t=this.getters.getChartIds(e).map(e=>this.getters.getChart(e)),n=new Set;for(let e of t){if(e===void 0)continue;let t=e.getDefinition().background;switch(t!==void 0&&n.add(t),e.type){case`gauge`:let t=e.sectionRule.colors;n.add(t.lowerColor),n.add(t.middleColor),n.add(t.upperColor);break;case`scorecard`:let r=e;n.add(r.baselineColorDown),n.add(r.baselineColorUp);break}}return[...n]}tryToAddColor(e){let t=zt(e);e&&!De.includes(t)&&this.history.update(`customColors`,t,!0)}},jk=class extends Q{static getters=[`getChartRuntime`,`getStyleOfSingleCellChart`];charts={};createRuntimeChart=qu(this.getters);handle(e){if(ar.has(e.type)||sr.has(e.type)||e.type===`EVALUATE_CELLS`||e.type===`UPDATE_CELL`)for(let 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);break}}getChartRuntime(e){if(!this.charts[e]){let t=this.getters.getChart(e);if(!t)throw 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:Jo(e)};if(!t)return{background:me,fontColor:Jo(me)};let n=t.zone.left,r=t.zone.top,i=t.sheetId,a=this.getters.getCellComputedStyle({sheetId:i,col:n,row:r}),o=a.fillColor||`#FFFFFF`;return{background:o,fontColor:a.textColor||Jo(o)}}exportForExcel(e){for(let t of e.sheets){t.images||=[];let e=this.getters.getFigures(t.id),n=[];for(let r of e){if(!r||r.tag!==`chart`)continue;let e=r.id,i=this.getters.getChart(e)?.getDefinitionForExcel();if(i)n.push({...r,data:i});else{if(!this.getters.getChart(e))continue;let n=this.getters.getChartType(e),i=Nl(this.getters.getChartRuntime(e),r,n);t.images.push({...r,tag:`image`,data:{mimetype:`image/png`,path:i,size:{width:r.width,height:r.height}}})}}t.charts=n}}},Mk=class extends Q{static getters=[`getConditionalIcon`,`getCellComputedStyle`];isStale=!0;computedStyles={};computedIcons={};handle(e){(sr.has(e.type)||e.type===`UPDATE_CELL`&&`content`in e)&&(this.isStale=!0)}finalize(){if(this.isStale){for(let e of this.getters.getSheetIds())this.computedStyles[e]=vt(()=>this.getComputedStyles(e)),this.computedIcons[e]=vt(()=>this.getComputedIcons(e));this.isStale=!1}}getCellComputedStyle(e){let{sheetId:t,col:n,row:r}=e,i=this.getters.getCell(e),a=this.computedStyles[t](),o=a&&a[n]?.[r],s={...i?.style,...o};return this.getters.getEvaluatedCell(e).link&&!s.textColor&&(s.textColor=`#01666b`),this.getters.isFilterHeader(e)&&(s.bold=!0),s}getConditionalIcon({sheetId:e,col:t,row:n}){let r=this.computedIcons[e]();return r&&r[t]?.[n]}getComputedStyles(e){let t={};for(let n of this.getters.getConditionalFormats(e).reverse())try{switch(n.rule.type){case`ColorScaleRule`:for(let r of n.ranges)this.applyColorScale(e,r,n.rule,t);break;case`CellIsRule`:let r=n.rule.values.map(e=>e.startsWith(`=`)?NT(e):void 0);for(let i of n.ranges){let a=this.getters.getRangeFromSheetXC(e,i).zone;for(let i=a.top;i<=a.bottom;i++)for(let o=a.left;o<=a.right;o++){let s=this.rulePredicate[n.rule.type],c={sheetId:e,col:o,row:i},l=n.rule.values.map((t,n)=>{let s=r[n];return s?this.getters.getTranslatedCellFormula(e,o-a.left,i-a.top,{...s,dependencies:s.dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t))}):t});s&&s(c,{...n.rule,values:l})&&(t[o]||(t[o]=[]),t[o][i]=Object.assign(t[o]?.[i]||{},n.rule.style))}}break}}catch{}return t}getComputedIcons(e){let t={};for(let n of this.getters.getConditionalFormats(e).reverse())if(n.rule.type===`IconSetRule`)for(let r of n.ranges)this.applyIcon(e,r,n.rule,t);return t}parsePoint(e,t,n,r){let i=this.getters.getEvaluatedCellsInZone(e,this.getters.getRangeFromSheetXC(e,t).zone).filter(e=>e.type===`number`).map(e=>e.value);switch(n.type){case`value`:return r===`max`?Nt(i):Pt(i);case`number`:return Number(n.value);case`percentage`:let t=Pt(i);return t+(Nt(i)-t)*Number(n.value)/100;case`percentile`:return Qn(i,Number(n.value)/100,!0);case`formula`:let a=n.value&&this.getters.evaluateFormula(e,n.value);return typeof a==`number`?a:null;default:return null}}applyIcon(e,t,n,r){let i=this.parsePoint(e,t,n.lowerInflectionPoint),a=this.parsePoint(e,t,n.upperInflectionPoint);if(i===null||a===null||i>a)return;let o=this.getters.getRangeFromSheetXC(e,t).zone,s=[n.icons.upper,n.icons.middle,n.icons.lower];for(let t=o.top;t<=o.bottom;t++)for(let c=o.left;c<=o.right;c++){let o=this.getters.getEvaluatedCell({sheetId:e,col:c,row:t});if(o.type!==`number`)continue;let l=this.computeIcon(o.value,a,n.upperInflectionPoint.operator,i,n.lowerInflectionPoint.operator,s);r[c]||(r[c]=[]),r[c][t]=l}}computeIcon(e,t,n,r,i,a){return n===`ge`&&e>=t||n===`gt`&&e>t?a[0]:i===`ge`&&e>=r||i===`gt`&&e>r?a[1]:a[2]}applyColorScale(e,t,n,r){let i=this.parsePoint(e,t,n.minimum,`min`),a=n.midpoint?this.parsePoint(e,t,n.midpoint):null,o=this.parsePoint(e,t,n.maximum,`max`);if(i===null||o===null||i>=o||a!==null&&(i>=a||a>=o))return;let s=this.getters.getRangeFromSheetXC(e,t).zone,c=[];n.midpoint&&a!==null?(c.push({minValue:i,minColor:n.minimum.color,colorDiffUnit:this.computeColorDiffUnits(i,a,n.minimum.color,n.midpoint.color)}),c.push({minValue:a,minColor:n.midpoint.color,colorDiffUnit:this.computeColorDiffUnits(a,o,n.midpoint.color,n.maximum.color)})):c.push({minValue:i,minColor:n.minimum.color,colorDiffUnit:this.computeColorDiffUnits(i,o,n.minimum.color,n.maximum.color)});for(let t=s.top;t<=s.bottom;t++)for(let n=s.left;n<=s.right;n++){let s=this.getters.getEvaluatedCell({sheetId:e,col:n,row:t});if(s.type===`number`){let e=C(s.value,i,o),l;l=c.length===2&&a!==null?e<=a?this.colorCell(e,c[0].minValue,c[0].minColor,c[0].colorDiffUnit):this.colorCell(e,c[1].minValue,c[1].minColor,c[1].colorDiffUnit):this.colorCell(e,c[0].minValue,c[0].minColor,c[0].colorDiffUnit),r[n]||(r[n]=[]),r[n][t]=r[n]?.[t]||{},r[n][t].fillColor=Rt(l)}}}computeColorDiffUnits(e,t,n,r){let i=t-e,a=(n>>16)%256-(r>>16)%256,o=(n>>8)%256-(r>>8)%256,s=n%256-r%256;return[a/i,o/i,s/i]}colorCell(e,t,n,r){let[i,a,o]=r,s=Math.round((n>>16)%256-i*(e-t)),c=Math.round((n>>8)%256-a*(e-t)),l=Math.round(n%256-o*(e-t));return s<<16|c<<8|l}rulePredicate={CellIsRule:(e,t)=>{let n=this.getters.getEvaluatedCell(e);if(n.type===`error`)return!1;let[r,i]=t.values.map(t=>t.startsWith(`=`)?this.getters.evaluateFormula(e.sheetId,t)??``:to(t,A));if(j(r)||j(i))return!1;switch(t.operator){case`IsEmpty`:return n.value.toString().trim()===``;case`IsNotEmpty`:return n.value.toString().trim()!==``;case`BeginsWith`:return r===``?!1:n.value.toString().startsWith(r.toString());case`EndsWith`:return r===``?!1:n.value.toString().endsWith(r.toString());case`Between`:return n.value>=r&&n.value<=i;case`NotBetween`:return!(n.value>=r&&n.value<=i);case`ContainsText`:return n.value.toString().indexOf(r.toString())>-1;case`NotContains`:return!n.value||n.value.toString().indexOf(r.toString())===-1;case`GreaterThan`:return n.value>r;case`GreaterThanOrEqual`:return n.value>=r;case`LessThan`:return n.value<r;case`LessThanOrEqual`:return n.value<=r;case`NotEqual`:return r===``?!1:n.value!==r;case`Equal`:return r===``?!0:n.value===r;default:console.warn(y(`Not implemented operator %s for kind of conditional formatting: %s`,t.operator,t.type))}return!1}}};let Nk={isValid:!0};var Pk=class extends Q{static getters=[`getDataValidationInvalidCriterionValueMessage`,`getInvalidDataValidationMessage`,`getValidationResultForCellValue`,`isCellValidCheckbox`,`isDataValidationInvalid`];validationResults={};handle(e){if(ar.has(e.type)||e.type===`EVALUATE_CELLS`||e.type===`UPDATE_CELL`&&`content`in e){this.validationResults={};return}switch(e.type){case`ADD_DATA_VALIDATION_RULE`:case`REMOVE_DATA_VALIDATION_RULE`:delete this.validationResults[e.sheetId];break}}isDataValidationInvalid(e){return!this.getValidationResultForCell(e).isValid}getInvalidDataValidationMessage(e){let t=this.getValidationResultForCell(e);return t.isValid?void 0:t.error}getDataValidationInvalidCriterionValueMessage(e,t){let n=q.get(e);return t.startsWith(`=`)?n.allowedValues===`onlyLiterals`?y(`The value must not be a formula`):void 0:n.allowedValues===`onlyFormulas`?y(`The value must be a formula`):n.isCriterionValueValid(t)?void 0:n.criterionValueErrorString}isCellValidCheckbox(e){if(!this.getters.isMainCellPosition(e))return!1;let t=this.getters.getValidationRuleForCell(e);return!t||t.criterion.type!==`isBoolean`?!1:this.getValidationResultForCell(e).isValid}getValidationResultForCellValue(e,t){let n=this.getters.getValidationRuleForCell(t);if(!n)return Nk;let r=this.getRuleErrorForCellValue(e,t,n);return r?{error:r,rule:n,isValid:!1}:Nk}getValidationResultForCell(e){let{col:t,row:n,sheetId:r}=e;return this.validationResults[r]||(this.validationResults[r]=this.computeSheetValidationResults(r)),this.validationResults[r][t]?.[n]?.()||Nk}computeSheetValidationResults(e){let t={},n=this.getters.getDataValidationRules(e).map(e=>e.ranges);for(let e of La(n.flat())){let{col:n,row:r}=e;t[n]||(t[n]=[]),t[n][r]=vt(()=>{let t=this.getters.getEvaluatedCell(e);return t.type===`empty`?Nk:this.getValidationResultForCellValue(t.value,e)})}return t}getRuleErrorForCellValue(e,t,n){let{sheetId:r}=t,i=n.criterion,a=q.get(i.type),o=this.getCellOffsetInRule(t,n),s=this.getEvaluatedCriterionValues(r,o,i),c={...i,values:s};if(!a.isValueValid(e,c,this.getters,r))return a.getErrorString(c,this.getters,r)}getCellOffsetInRule(e,t){let n=t.ranges.find(t=>da(e.col,e.row,t.zone));if(!n)throw Error(`The cell is not in any range of the rule`);return{col:e.col-n.zone.left,row:e.row-n.zone.top}}getEvaluatedCriterionValues(e,t,n){return n.values.map(n=>{if(!n.startsWith(`=`))return n;try{let r=NT(n),i=this.getters.getTranslatedCellFormula(e,t.col,t.row,{...r,dependencies:r.dependencies.map(t=>this.getters.getRangeFromSheetXC(e,t))}),a=this.getters.evaluateFormula(e,i);return a&&!j(a)?a.toString():``}catch(e){return e instanceof b?e.errorType:`#ERROR`}})}},Fk=class extends Q{static getters=[`getRowSize`,`getHeaderSize`];tallestCellInRow={};ctx=document.createElement(`canvas`).getContext(`2d`);beforeHandle(e){switch(e.type){case`ADD_COLUMNS_ROWS`:if(e.dimension===`COL`)return;let t=bt(e.position,e.base),n=Array(e.quantity).fill(void 0),r=At(this.tallestCellInRow[e.sheetId],n,t);this.history.update(`tallestCellInRow`,e.sheetId,r);break}}handle(e){switch(e.type){case`START`:case`UPDATE_LOCALE`:for(let e of this.getters.getSheetIds())this.initializeSheet(e);break;case`CREATE_SHEET`:this.initializeSheet(e.sheetId);break;case`DUPLICATE_SHEET`:{let t=S(this.tallestCellInRow[e.sheetId]);this.history.update(`tallestCellInRow`,e.sheetIdTo,t);break}case`DELETE_SHEET`:let t={...this.tallestCellInRow};delete t[e.sheetId],this.history.update(`tallestCellInRow`,t);break;case`REMOVE_COLUMNS_ROWS`:{if(e.dimension===`COL`)return;let t=kt(this.tallestCellInRow[e.sheetId],e.elements);this.history.update(`tallestCellInRow`,e.sheetId,t);break}case`RESIZE_COLUMNS_ROWS`:{let t=e.sheetId;if(e.dimension===`ROW`)for(let n of e.elements){let e=this.getRowTallestCell(t,n);this.history.update(`tallestCellInRow`,t,n,e)}else for(let n of w(0,this.getters.getNumberRows(t)))for(let r of e.elements)this.updateRowSizeForCellChange(t,n,r)}break;case`UPDATE_CELL`:this.updateRowSizeForCellChange(e.sheetId,e.row,e.col);break;case`ADD_MERGE`:case`REMOVE_MERGE`:for(let t of e.target)for(let n of ba(t))this.updateRowSizeForCellChange(e.sheetId,n.row,n.col)}}getRowSize(e,t){return Math.round(this.getters.getUserRowSize(e,t)??this.tallestCellInRow[e][t]?.size??23)}getHeaderSize(e,t,n){return this.getters.isHeaderHidden(e,t,n)?0:t===`ROW`?this.getRowSize(e,n):this.getters.getColSize(e,n)}updateRowSizeForCellChange(e,t,n){let r=this.tallestCellInRow[e]?.[t];if(r?.cell.col===n){let n=this.getRowTallestCell(e,t);this.history.update(`tallestCellInRow`,e,t,n)}let i=this.getCellHeight({sheetId:e,col:n,row:t});if(!(i<=23)&&(!r&&i>23||r&&i>r.size)){let r={cell:{sheetId:e,col:n,row:t},size:i};this.history.update(`tallestCellInRow`,e,t,r)}}initializeSheet(e){let t=[];for(let n=0;n<this.getters.getNumberRows(e);n++){let r=this.getRowTallestCell(e,n);t.push(r)}this.history.update(`tallestCellInRow`,e,t)}getCellHeight(e){if(this.isInMultiRowMerge(e))return 23;let t=this.getters.getCell(e),n=this.getters.getColSize(e.sheetId,e.col);return mo(this.ctx,t,this.getters.getLocale(),n)}isInMultiRowMerge(e){let t=this.getters.getMerge(e);return!!t&&t.bottom!==t.top}getRowTallestCell(e,t){if(this.getters.getUserRowSize(e,t)!==void 0)return;let n=this.getters.getRowCells(e,t),r=0,i;for(let e=0;e<n.length;e++){let t=this.getters.getCellById(n[e]);if(!t)continue;let a=this.getters.getCellPosition(t.id),o=this.getCellHeight(a);o>r&&o>23&&(r=o,i={cell:a,size:o})}if(i&&i.size>23)return i}},Ik=class{cells;getters;index=0;direction;constructor(e,t,n){this.cells=e,this.getters=t,this.direction=n}next(){let e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:n,tooltip:r}=Ss.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:n,tooltip:r,origin:{col:e.data.col,row:e.data.row}}}},Lk=class extends Q{static layers=[5];static getters=[`getAutofillTooltip`];autofillZone;steps;lastCellSelected={};direction;tooltip;allowDispatch(e){switch(e.type){case`AUTOFILL_SELECT`:let t=this.getters.getActiveSheetId();return this.lastCellSelected.col=e.col===-1?this.lastCellSelected.col:C(e.col,0,this.getters.getNumberCols(t)),this.lastCellSelected.row=e.row===-1?this.lastCellSelected.row:C(e.row,0,this.getters.getNumberRows(t)),this.lastCellSelected.col!==void 0&&this.lastCellSelected.row!==void 0?`Success`:`InvalidAutofillSelection`;case`AUTOFILL_AUTO`:let n=this.getters.getSelectedZone();return n.top===n.bottom?`Success`:`CancelledForUnknownReason`}return`Success`}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}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||!this.steps||this.direction===void 0){this.tooltip=void 0;return}let t=this.getters.getSelectedZone(),n=this.autofillZone,r=[];switch(this.direction){case`down`:for(let e=t.left;e<=t.right;e++){let i=[];for(let n=t.top;n<=t.bottom;n++)i.push(O(e,n));let a=this.createGenerator(i);for(let t=n.top;t<=n.bottom;t++)r.push(this.computeNewCell(a,e,t))}break;case`up`:for(let e=t.left;e<=t.right;e++){let i=[];for(let n=t.bottom;n>=t.top;n--)i.push(O(e,n));let a=this.createGenerator(i);for(let t=n.bottom;t>=n.top;t--)r.push(this.computeNewCell(a,e,t))}break;case`left`:for(let e=t.top;e<=t.bottom;e++){let i=[];for(let n=t.right;n>=t.left;n--)i.push(O(n,e));let a=this.createGenerator(i);for(let t=n.right;t>=n.left;t--)r.push(this.computeNewCell(a,t,e))}break;case`right`:for(let e=t.top;e<=t.bottom;e++){let i=[];for(let n=t.left;n<=t.right;n++)i.push(O(n,e));let a=this.createGenerator(i);for(let t=n.left;t<=n.right;t++)r.push(this.computeNewCell(a,t,e))}break}if(e){let e={},t={},n={},i=this.getters.getActiveSheetId();for(let a of r)this.collectBordersData(a,e),this.autofillMerge(i,a),this.autofillCell(i,a),this.collectConditionalFormatsData(i,a,t),this.collectDataValidationsData(i,a,n);this.autofillBorders(i,e),this.autofillConditionalFormats(i,t),this.autofillDataValidations(i,n),this.autofillZone=void 0,this.selection.resizeAnchorZone(this.direction,this.steps),this.lastCellSelected={},this.direction=void 0,this.steps=0,this.tooltip=void 0}}collectBordersData(e,t){let n=JSON.stringify(e.border);n in t||(t[n]=[]),t[n].push(V({col:e.col,row:e.row}))}collectConditionalFormatsData(e,t,n){let{originCol:r,originRow:i,col:a,row:o}=t,s=this.getters.getRulesByCell(e,r,i),c=O(a,o);for(let e of s)e.id in n||(n[e.id]=[]),n[e.id].push(c)}collectDataValidationsData(e,t,n){let{originCol:r,originRow:i,col:a,row:o}=t,s={sheetId:e,col:r,row:i},c=this.getters.getValidationRuleForCell(s);c&&(c.id in n||(n[c.id]=[]),n[c.id].push(V({col:a,row:o})))}autofillCell(e,t){this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t.col,row:t.row,content:t.content||``,style:t.style||null,format:t.format||``}),this.dispatch(`AUTOFILL_CELL`,t)}autofillBorders(e,t){for(let n in t){let r=n===`undefined`?void 0:JSON.parse(n);this.dispatch(`SET_BORDERS_ON_TARGET`,{sheetId:e,border:r,target:HO(t[n])})}}autofillConditionalFormats(e,t){for(let n in t){let r=t[n],i=this.getters.getConditionalFormats(e).find(e=>e.id===n);if(!i)continue;let a=this.getters.getAdaptedCfRanges(e,i,r.map(ea),[]);a&&this.dispatch(`ADD_CONDITIONAL_FORMAT`,{cf:{id:i.id,rule:i.rule,stopIfTrue:i.stopIfTrue},ranges:a.map(t=>this.getters.getRangeDataFromZone(e,t)),sheetId:e})}}autofillDataValidations(e,t){for(let n in t){let r=t[n],i=this.getters.getDataValidationRule(e,n);if(!i)continue;let a=HO(i.ranges.map(e=>e.zone).concat(r),[]);this.dispatch(`ADD_DATA_VALIDATION_RULE`,{rule:i,ranges:a.map(t=>this.getters.getRangeDataFromZone(e,t)),sheetId:e})}}select(e,t){let n=this.getters.getSelectedZone();if(da(e,t,n)){this.autofillZone=void 0;return}switch(this.direction=this.getDirection(e,t),this.direction){case`up`:this.saveZone(t,n.top-1,n.left,n.right),this.steps=n.top-t;break;case`down`:this.saveZone(n.bottom+1,t,n.left,n.right),this.steps=t-n.bottom;break;case`left`:this.saveZone(n.top,n.bottom,e,n.left-1),this.steps=n.left-e;break;case`right`:this.saveZone(n.top,n.bottom,n.right+1,e),this.steps=e-n.right;break}this.autofill(!1)}autofillAuto(){let e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId(),n=e.left,r=e.bottom;if(n>0){let e={sheetId:t,col:n-1,row:r};for(;this.getters.getCorrespondingFormulaCell(e)||this.getters.getCell(e)?.content;)r+=1,e={sheetId:t,col:n-1,row:r}}if(r===e.bottom&&(n=e.right,n<=this.getters.getNumberCols(t))){let e={sheetId:t,col:n+1,row:r};for(;this.getters.getCorrespondingFormulaCell(e)||this.getters.getCell(e)?.content;)r+=1,e={sheetId:t,col:n+1,row:r}}r!==e.bottom&&(this.select(e.left,r-1),this.autofill(!0))}computeNewCell(e,t,n){let{cellData:r,tooltip:i,origin:a}=e.next(),{content:o,style:s,border:c,format:l}=r;return this.tooltip=i,{originCol:a.col,originRow:a.row,col:t,row:n,content:o,style:s,border:c,format:l}}getRule(e,t){let n=Cs.getAll().sort((e,t)=>e.sequence-t.sequence).find(n=>n.condition(e,t));return n&&this.direction&&n.generateRule(e,t,this.direction)}createGenerator(e){let t=[],n=[],r=this.getters.getActiveSheetId();for(let t of e){let{col:e,row:i}=rn(t),a=this.getters.getCell({sheetId:r,col:e,row:i});n.push({col:e,row:i,cell:a,sheetId:r})}let i=n.map(e=>e.cell);for(let e of n){let n={type:`COPY_MODIFIER`};e&&e.cell&&(n=this.getRule(e.cell,i)||n);let r=this.getters.getCellBorder(e)||void 0;t.push({data:{...e,border:r},rule:n})}return new Ik(t,this.getters,this.direction)}saveZone(e,t,n,r){this.autofillZone={top:e,bottom:t,left:n,right:r}}getDirection(e,t){let n=this.getters.getSelectedZone(),r={up:{number:n.top-t,value:`up`},down:{number:t-n.bottom,value:`down`},left:{number:n.left-e,value:`left`},right:{number:e-n.right,value:`right`}};if(Object.values(r).map(e=>+(e.number>0)).reduce((e,t)=>e+t)===1)return Object.values(r).find(e=>+(e.number>0)).value;let i=r.up.number>0?`up`:`down`,a=r.left.number>0?`left`:`right`;return Math.abs(r[i].number)>=Math.abs(r[a].number)?r[i].value:r[a].value}autofillMerge(e,t){let{originCol:n,originRow:r,col:i,row:a}=t,o={sheetId:e,col:i,row:a},s={sheetId:e,col:n,row:r};if(this.getters.isInMerge(o)&&!this.getters.isInMerge(s)){let t=this.getters.getMerge(o);t&&this.dispatch(`REMOVE_MERGE`,{sheetId:e,target:[t]})}let c=this.getters.getMerge(s);c?.topLeft.col===n&&c?.topLeft.row===r&&this.dispatch(`ADD_MERGE`,{sheetId:e,target:[{top:a,bottom:a+c.bottom-c.top,left:i,right:i+c.right-c.left}]})}drawGrid(e){if(!this.autofillZone)return;let{ctx:t,thinLineWidth:n}=e,{x:r,y:i,width:a,height:o}=this.getters.getVisibleRect(this.autofillZone);a>0&&o>0&&(t.strokeStyle=`black`,t.lineWidth=n,t.setLineDash([3]),t.strokeRect(r,i,a,o),t.setLineDash([]))}},Rk=class extends Q{static getters=[`getAutomaticSums`];handle(e){switch(e.type){case`SUM_SELECTION`:let e=this.getters.getActiveSheetId(),{zones:t,anchor:n}=this.getters.getSelection();for(let r of t){let t=this.getAutomaticSums(e,r,n.cell);this.dispatchCellUpdates(e,t)}break}}getAutomaticSums(e,t,n){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,n):this.sumData(e,t)}sumData(e,t){let n=this.dimensionsToSum(e,t),r=this.sumDimensions(e,t,n).filter(({zone:t})=>!this.getters.isEmpty(e,t));return n.has(`ROW`)&&n.has(`COL`)&&r.push(this.sumTotal(t)),r}sumAdjacentData(e,t,n){let{col:r,row:i}=da(n.col,n.row,t)?n:{col:t.left,row:t.top},a=this.findAdjacentData(e,r,i);return a?this.getters.isSingleCellOrMerge(e,t)||ya(sa(a,t))?[{position:{col:r,row:i},zone:a}]:this.sumDimensions(e,sa(a,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,n){let r=this.getters.getSheet(e),i=this.getters.getMainCellPosition({sheetId:e,col:t,row:n}),a=this.findSuitableZoneToSum(r,i.col,i.row);if(a)return this.getters.expandZone(e,a)}findSuitableZoneToSum(e,t,n){let r=this.getters.getEvaluatedCell({sheetId:e.id,col:t,row:n-1}),i=this.getters.getEvaluatedCell({sheetId:e.id,col:t-1,row:n});if(this.isNumber(i)&&!this.isNumber(r))return this.findHorizontalZone(e,t,n);let a=this.findVerticalZone(e,t,n);if(this.isZoneValid(a))return a;let o=this.findHorizontalZone(e,t,n);if(this.isZoneValid(o))return o}findVerticalZone(e,t,n){let r={top:0,bottom:n-1,left:t,right:t},i=this.reduceZoneStart(e,r,r.bottom);return{...r,top:i}}findHorizontalZone(e,t,n){let r={top:n,bottom:n,left:0,right:t-1},i=this.reduceZoneStart(e,r,r.right);return{...r,left:i}}reduceZoneStart(e,t,n){let r=this.getters.getEvaluatedCellsInZone(e.id,t),i=w(n,-1,-1),a=Nt(i.filter(e=>r[e]&&!r[e].isAutoSummable)),o=et(i.filter(e=>this.isNumber(r[e])))[0]||[];return Nt(o)<a?1/0:Pt(o)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){return e.type===`number`&&!(e.format&&_i(e.format))}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){let n=new Set;return ya(t)?(n.add(va(t).numberOfCols===1?`COL`:`ROW`),n):(this.lastColIsEmpty(e,t)&&n.add(`ROW`),this.lastRowIsEmpty(e,t)&&n.add(`COL`),n.size===0&&n.add(`COL`),n)}sumDimensions(e,t,n){return[...n.has(`COL`)?this.sumColumns(t,e):[],...n.has(`ROW`)?this.sumRows(t,e):[]]}sumTotal(e){let{bottom:t,right:n}=e;return{position:{col:n,row:t},zone:{...e,top:t,right:n-1}}}sumColumns(e,t){let n=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,n.bottom-1)},ba(n).map(t=>({position:t,zone:{...e,right:t.col,left:t.col}}))}sumRows(e,t){let n=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,n.right-1)},ba(n).map(t=>({position:t,zone:{...e,top:t.row,bottom:t.row}}))}dispatchCellUpdates(e,t){for(let n of t){let{col:t,row:r}=n.position;this.dispatch(`UPDATE_CELL`,{sheetId:e,col:t,row:r,content:`=SUM(${this.getters.zoneToXC(e,n.zone)})`})}}nextEmptyRow(e,t){let n=t.bottom+1,{left:r,right:i}=t;for(;!this.getters.isEmpty(e,{bottom:n,top:n,left:r,right:i});)n++;return{...t,top:n,bottom:n}}nextEmptyCol(e,t){let n=t.right+1,{top:r,bottom:i}=t;for(;!this.getters.isEmpty(e,{left:n,right:n,top:r,bottom:i});)n++;return{...t,left:n,right:n}}transpose(e){return new Set([...e.values()].map(e=>e===`COL`?`ROW`:`COL`))}},zk=class extends Q{static getters=[`getCellPopover`,`getPersistentPopoverTypeAtPosition`,`hasOpenedPopover`];persistentPopover;allowDispatch(e){switch(e.type){case`OPEN_CELL_POPOVER`:try{ul.get(e.popoverType)}catch{return`InvalidCellPopover`}return`Success`;default:return`Success`}}handle(e){switch(e.type){case`ACTIVATE_SHEET`:this.persistentPopover=void 0;break;case`OPEN_CELL_POPOVER`:this.persistentPopover={col:e.col,row:e.row,sheetId:this.getters.getActiveSheetId(),type:e.popoverType};break;case`CLOSE_CELL_POPOVER`:this.persistentPopover=void 0;break}}getCellPopover({col:e,row:t}){let n=this.getters.getActiveSheetId();if(this.persistentPopover&&this.getters.isVisibleInViewport(this.persistentPopover)){let e=this.getters.getMainCellPosition(this.persistentPopover),t=ul.get(this.persistentPopover.type).onOpen?.(e,this.getters);return t?.isOpen?{...t,anchorRect:this.computePopoverAnchorRect(this.persistentPopover)}:{isOpen:!1}}if(e===void 0||t===void 0||!this.getters.isVisibleInViewport({sheetId:n,col:e,row:t}))return{isOpen:!1};let r=this.getters.getMainCellPosition({sheetId:n,col:e,row:t}),i=ul.getAll().map(e=>e.onHover?.(r,this.getters)).find(e=>e?.isOpen);return i?.isOpen?{...i,anchorRect:this.computePopoverAnchorRect(r)}:{isOpen:!1}}hasOpenedPopover(){return this.persistentPopover!==void 0}getPersistentPopoverTypeAtPosition({col:e,row:t}){if(this.persistentPopover&&this.persistentPopover.col===e&&this.persistentPopover.row===t)return this.persistentPopover.type}computePopoverAnchorRect({col:e,row:t}){let n=this.getters.getActiveSheetId(),r=this.getters.getMerge({sheetId:n,col:e,row:t});return r?this.getters.getVisibleRect(r):this.getters.getVisibleRect(V({col:e,row:t}))}},Bk=class{subscriptions={};on(e,t,n){if(!n)throw Error(`Missing callback`);this.subscriptions[e]||(this.subscriptions[e]=[]),this.subscriptions[e].push({owner:t,callback:n})}trigger(e,t){let n=this.subscriptions[e]||[];for(let e=0,r=n.length;e<r;e++){let r=n[e];r.callback.call(r.owner,t)}}off(e,t){let n=this.subscriptions[e];n&&(this.subscriptions[e]=n.filter(e=>e.owner!==t))}clear(){this.subscriptions={}}};lS.addTransformation(`ADD_COLUMNS_ROWS`,[`ADD_COLUMNS_ROWS`],Jk),lS.addTransformation(`REMOVE_COLUMNS_ROWS`,[`ADD_COLUMNS_ROWS`],Jk),lS.addTransformation(`ADD_COLUMNS_ROWS`,[`CREATE_CHART`,`UPDATE_CHART`],Uk),lS.addTransformation(`REMOVE_COLUMNS_ROWS`,[`CREATE_CHART`,`UPDATE_CHART`],Uk),lS.addTransformation(`DELETE_SHEET`,[`MOVE_RANGES`],Vk),lS.addTransformation(`DELETE_FIGURE`,[`UPDATE_FIGURE`,`UPDATE_CHART`],Hk),lS.addTransformation(`CREATE_SHEET`,[`CREATE_SHEET`],Wk),lS.addTransformation(`ADD_MERGE`,[`ADD_MERGE`,`REMOVE_MERGE`,`CREATE_FILTER_TABLE`],Gk),lS.addTransformation(`ADD_COLUMNS_ROWS`,[`FREEZE_COLUMNS`,`FREEZE_ROWS`],Kk),lS.addTransformation(`REMOVE_COLUMNS_ROWS`,[`FREEZE_COLUMNS`,`FREEZE_ROWS`],Kk),lS.addTransformation(`CREATE_FILTER_TABLE`,[`CREATE_FILTER_TABLE`,`ADD_MERGE`],qk),lS.addTransformation(`ADD_COLUMNS_ROWS`,[`GROUP_HEADERS`,`UNGROUP_HEADERS`,`FOLD_HEADER_GROUP`,`UNFOLD_HEADER_GROUP`],Yk),lS.addTransformation(`REMOVE_COLUMNS_ROWS`,[`GROUP_HEADERS`,`UNGROUP_HEADERS`,`FOLD_HEADER_GROUP`,`UNFOLD_HEADER_GROUP`],Yk);function Vk(e,t){let n=t.sheetId;if(!(e.targetSheetId===n||e.sheetId===n))return e}function Hk(e,t){if(e.id!==t.id)return e}function Uk(e,t){return{...e,definition:Yu(e.definition,t)}}function Wk(e,t){return e.sheetId===t.sheetId&&(e={...e,sheetId:`${e.sheetId}~`}),e.name===t.name?{...e,name:e.name?.match(/\d+/)?e.name.replace(/\d+/,e=>(parseInt(e)+1).toString()):`${e.name}~`,position:e.position+1}:e}function Gk(e,t){if(e.sheetId!==t.sheetId)return e;let n=[];for(let r of e.target)t.target.every(e=>!ua(r,e))&&n.push(r);if(n.length)return{...e,target:n}}function Kk(e,t){if(e.sheetId!==t.sheetId||(e.type===`FREEZE_COLUMNS`?`COL`:`ROW`)!==t.dimension)return e;let n=e.quantity;if(t.type===`REMOVE_COLUMNS_ROWS`){let e=[...t.elements].sort((e,t)=>t-e);for(let t of e)n>t&&n--}if(t.type===`ADD_COLUMNS_ROWS`){let e=t.position===`before`?t.base-1:t.base;n=n>e?n+t.quantity:n}return n>0?{...e,quantity:n}:void 0}function qk(e,t){if(e.sheetId!==t.sheetId)return e;for(let n of e.target)for(let e of t.target)if(ua(e,n))return;return e}function Jk(e,t){if(e.sheetId!==t.sheetId||e.dimension!==t.dimension)return e;let n;if(t.type===`REMOVE_COLUMNS_ROWS`?n=Ha(t.elements,[e.base])[0]:t.type===`ADD_COLUMNS_ROWS`&&(n=Va(bt(t.position,t.base),t.quantity,[e.base])[0]),n!==void 0)return{...e,base:n}}function Yk(e,t){if(e.sheetId!==t.sheetId||e.dimension!==t.dimension)return e;let n=w(e.start,e.end+1),r=[];if(t.type===`REMOVE_COLUMNS_ROWS`?r=Ha(t.elements,n):t.type===`ADD_COLUMNS_ROWS`&&(r=Va(bt(t.position,t.base),t.quantity,n)),r.length!==0)return{...e,start:Math.min(...r),end:Math.max(...r)}}let Xk=[{match:$n,fn:eA},{match:tr,fn:tA},{match:ir,fn:nA},{match:rr,fn:aA},{match:er,fn:iA},{match:nr,fn:rA}];function Zk(e,t){let n=lS.getTransformation(e.type,t.type);return n?n(e,t):$k(e,t)}function Qk(e,t){let n=[...e],r=new Set(lS.getKeys());for(let e of t)r.has(e.type)&&(n=n.reduce((t,n)=>{let r=Zk(n,e);return r&&t.push(r),t},[]));return n}function $k(e,t){for(let{match:n,fn:r}of Xk)if(n(e)){let n=r(e,t);if(n===`SKIP_TRANSFORMATION`)continue;if(n===`IGNORE_COMMAND`)return;e=n}return e}function eA(e,t){if(!(`sheetId`in t))return e;let n=t.type===`DELETE_SHEET`&&t.sheetId;return e.sheetId===n?`IGNORE_COMMAND`:e.type===`CREATE_SHEET`||t.type===`CREATE_SHEET`||e.sheetId!==t.sheetId?e:`SKIP_TRANSFORMATION`}function tA(e,t){let n=eA(e,t);if(n!==`SKIP_TRANSFORMATION`)return n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e;let r=[];for(let n of e.target){let e=No(n,t);e&&r.push(e)}return r.length?{...e,target:r}:`IGNORE_COMMAND`}function nA(e,t){let n=eA(e,t);if(n!==`SKIP_TRANSFORMATION`)return n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e;let r=No(e.zone,t);return r?{...e,zone:r}:`IGNORE_COMMAND`}function rA(e,t){if(!(`sheetId`in t))return e;let n=e.ranges.map(e=>Po(e,t)).filter(T);return n.length?{...e,ranges:n}:`IGNORE_COMMAND`}function iA(e,t){let n=eA(e,t);if(n!==`SKIP_TRANSFORMATION`)return n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e;if(t.type!==`ADD_COLUMNS_ROWS`&&t.type!==`REMOVE_COLUMNS_ROWS`)return`SKIP_TRANSFORMATION`;if(t.dimension!==e.dimension)return e;let r=[];return t.type===`REMOVE_COLUMNS_ROWS`?r=Ha(t.elements,e.elements):t.type===`ADD_COLUMNS_ROWS`&&(r=Va(bt(t.position,t.base),t.quantity,e.elements)),r.length===0?`IGNORE_COMMAND`:{...e,elements:r}}function aA(e,t){let n=eA(e,t);return n===`SKIP_TRANSFORMATION`?t.type===`ADD_COLUMNS_ROWS`||t.type===`REMOVE_COLUMNS_ROWS`?oA(e,t):t.type===`ADD_MERGE`?sA(e,t):`SKIP_TRANSFORMATION`:n===`IGNORE_COMMAND`?`IGNORE_COMMAND`:e}function oA(e,t){let n=t.dimension===`COL`?`col`:`row`,r=e[n];if(t.type===`REMOVE_COLUMNS_ROWS`){let e=[...t.elements].sort((e,t)=>t-e);if(e.includes(r))return`IGNORE_COMMAND`;for(let t of e)r>=t&&r--}return t.type===`ADD_COLUMNS_ROWS`&&(r>t.base||r===t.base&&t.position===`before`)&&(r+=t.quantity),{...e,[n]:r}}function sA(e,t){for(let n of t.target)if(!(e.col===n.left&&e.row===n.top)&&da(e.col,e.row,n))return`IGNORE_COMMAND`;return e}var cA=class{rootCommand;timestamp;id;clientId;_commands=[];_changes=[];constructor(e,t,n,r,i,a){this.rootCommand=r,this.timestamp=a,this.id=e,this.clientId=t,this._commands=[...n],this._changes=i?[...i]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}},lA=class extends Error{},uA=class extends Bk{revisions;transportService;serverRevisionId;clients={};clientId=`local`;debouncedMove;pendingMessages=[];waitingAck=!1;waitingUndoRedoAck=!1;isReplayingInitialRevisions=!1;processedRevisions=new Set;uuidGenerator=new ko;lastLocalOperation;constructor(e,t,n=Le){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=n,this.debouncedMove=gt(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t,n){if(!t.length||!n.length||!this.canApplyOptimisticUpdate())return;let r=new cA(this.uuidGenerator.uuidv4(),this.clientId,t,e,n,Date.now());this.revisions.append(r.id,r),e.type!==`REQUEST_REDO`&&(this.lastLocalOperation=r),this.trigger(`new-local-state-update`,{id:r.id}),this.sendUpdateMessage({type:`REMOTE_REVISION`,version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:r.id,clientId:r.clientId,commands:r.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(let t of e)this.onMessageReceived(t);this.isReplayingInitialRevisions=!1}async leave(e){e&&Object.keys(this.clients).length===1&&this.processedRevisions.size&&await this.snapshot(e()),delete this.clients[this.clientId],this.transportService.leave(this.clientId),this.transportService.sendMessage({type:`CLIENT_LEFT`,clientId:this.clientId,version:1})}async snapshot(e){if(this.pendingMessages.length!==0)return;let t=this.uuidGenerator.uuidv4();await this.transportService.sendMessage({type:`SNAPSHOT`,nextRevisionId:t,serverRevisionId:this.serverRevisionId,data:{...e,revisionId:t},version:1})}getClient(){let e=this.clients[this.clientId];if(!e)throw new lA(`The client left the session`);return e}getConnectedClients(){return new Set(Object.values(this.clients).filter(T))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return this.pendingMessages.length===0}getLastLocalNonEmptyRevision(){return this.lastLocalOperation}_move(e){if(!this.clients[this.clientId])return;let t=this.clients[this.clientId]?.position;if(t?.col===e.col&&t.row===e.row&&t.sheetId===e.sheetId)return;let n=t?`CLIENT_MOVED`:`CLIENT_JOINED`,r=this.getClient();this.clients[this.clientId]={...r,position:e},this.transportService.sendMessage({type:n,version:1,client:{...r,position:e}})}onMessageReceived(e){if(!this.isAlreadyProcessed(e)){if(this.isWrongServerRevisionId(e)){this.trigger(`unexpected-revision-id`);return}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`:let{clientId:t,commands:n,timestamp:r}=e,i=new cA(e.nextRevisionId,t,n,void 0,void 0,r);if(i.clientId!==this.clientId){this.revisions.insert(i.id,i,e.serverRevisionId);let t=this.pendingMessages.filter(e=>e.type===`REMOTE_REVISION`).map(e=>e.commands).flat();this.trigger(`remote-revision-received`,{commands:Qk(n,t)})}break;case`SNAPSHOT_CREATED`:{let t=new cA(e.nextRevisionId,`server`,[],void 0,void 0,Date.now());this.revisions.insert(t.id,t,e.serverRevisionId),this.dropPendingHistoryMessages(),this.trigger(`snapshot`),this.lastLocalOperation=void 0;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;let t=this.clients[this.clientId];if(t){let{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(e.type===`REMOTE_REVISION`){let t=this.revisions.get(e.nextRevisionId);t.commands.length===0&&(this.revisions.rebase(t.id),t=this.revisions.get(e.nextRevisionId)),e={...e,clientId:t.clientId,commands:t.commands}}if(this.isReplayingInitialRevisions)throw Error(`Trying to send a new revision while replaying initial revision. This can lead to endless dispatches every time the spreadsheet is open.
1475
1475
  ${JSON.stringify(e)}`);this.waitingAck=!0,this.transportService.sendMessage({...e,serverRevisionId:this.serverRevisionId})}}acknowledge(e){switch((e.type===`REVISION_UNDONE`||e.type===`REVISION_REDONE`)&&(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);let t=this.pendingMessages.findIndex(e=>e.type===`REMOTE_REVISION`);t!==-1&&this.revisions.rebase(this.pendingMessages[t].nextRevisionId),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.sendPendingMessage();break}}}isAlreadyProcessed(e){if(e.type===`CLIENT_MOVED`&&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})=>e!==`REVISION_REDONE`&&e!==`REVISION_UNDONE`)}};function dA(e){return e[Math.floor(Math.random()*e.length)]}let fA=[`#ff851b`,`#0074d9`,`#7fdbff`,`#b10dc9`,`#39cccc`,`#f012be`,`#3d9970`,`#111111`,`#ff4136`,`#aaaaaa`,`#85144b`,`#001f3f`];var pA=class extends Q{static getters=[`getClientsToDisplay`,`getClient`,`getConnectedClients`,`isFullySynchronized`];static layers=[6];availableColors=new Set(fA);colors={};session;constructor(e){super(e),this.session=e.session}isPositionValid(e){return e.row<this.getters.getNumberRows(e.sheetId)&&e.col<this.getters.getNumberCols(e.sheetId)}chooseNewColor(){this.availableColors.size===0&&(this.availableColors=new Set(fA));let e=dA([...this.availableColors.values()]);return this.availableColors.delete(e),e}getClient(){return this.session.getClient()}getConnectedClients(){return this.session.getConnectedClients()}isFullySynchronized(){return this.session.isFullySynchronized()}getClientsToDisplay(){try{this.getters.getClient()}catch(e){if(e instanceof lA)return[];throw e}let e=this.getters.getActiveSheetId(),t=[];for(let n of this.getters.getConnectedClients())if(n.id!==this.getters.getClient().id&&n.position&&n.position.sheetId===e&&this.isPositionValid(n.position)){let e=n.position;this.colors[n.id]||(this.colors[n.id]=this.chooseNewColor());let r=this.colors[n.id];t.push({...n,position:e,color:r})}return t}drawGrid(e){if(this.getters.isDashboard())return;let{ctx:t,thinLineWidth:n}=e,r=this.getters.getActiveSheetId();for(let e of this.getClientsToDisplay()){let{row:i,col:a}=e.position,o=this.getters.expandZone(r,{top:i,bottom:i,left:a,right:a}),{x:s,y:c,width:l,height:u}=this.getters.getVisibleRect(o);if(l<=0||u<=0)continue;let d=e.color;t.fillStyle=`${d}10`,t.lineWidth=4*n,t.strokeStyle=d,t.globalCompositeOperation=`multiply`,t.fillRect(s,c,l,u),t.globalCompositeOperation=`source-over`,t.strokeRect(s,c,l,u),t.font=`bold ${Me+1}px ${Ne}`}}},mA=class{getters;dispatch;selection;operation;sheetId;constructor(e,t,n,r){this.getters=t,this.dispatch=n,this.selection=r,this.operation=e,this.sheetId=t.getActiveSheetId()}isCutAllowed(e){return`Success`}isPasteAllowed(e,t){return`Success`}addMissingDimensions(e,t,n,r){let i=this.getters.getActiveSheetId(),a=t+r-this.getters.getNumberRows(i);a>0&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`ROW`,base:this.getters.getNumberRows(i)-1,sheetId:i,quantity:a,position:`after`});let o=e+n-this.getters.getNumberCols(i);o>0&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`COL`,base:this.getters.getNumberCols(i)-1,sheetId:i,quantity:o,position:`after`})}isColRowDirtyingClipboard(e,t){return!1}drawClipboard(e){}},hA=class extends mA{cells;copiedTables;zones;uuidGenerator=new ko;queuedBordersToAdd={};queuedCFChanges={};queuedDVChanges={};constructor(e,t,n,r,i,a=`copyPaste`){if(super(t,n,r,i),!e.length){this.cells=[[]],this.zones=[],this.copiedTables=[];return}let o=new Set(e.map(e=>e.left)),s=new Set(e.map(e=>e.right)),c=new Set(e.map(e=>e.top)),l=new Set(e.map(e=>e.bottom)),u=c.size===1&&l.size===1||o.size===1&&s.size===1?wa(e):[e[e.length-1]],d=u.map(e=>ba(e)).flat(),f=[...new Set(d.map(e=>e.col))].sort((e,t)=>e-t),p=[...new Set(d.map(e=>e.row))].sort((e,t)=>e-t),m=[],h=n.getActiveSheetId();for(let e of p){let t=[];for(let r of f){let i={col:r,row:e,sheetId:h},o=n.getArrayFormulaSpreadingOn(i),s=n.getCell(i),c=n.getEvaluatedCell(i);if(a!==`shiftCells`&&o){let e=p.includes(o.row)&&f.includes(o.col)?``:z(c.value,{locale:n.getLocale()});s={id:s?.id||``,style:s?.style,format:c.format,content:e,isFormula:!1}}t.push({cell:s,border:n.getCellBorder(i)||void 0,evaluatedCell:c,position:i})}m.push(t)}let g=[];for(let t of e)for(let e of this.getters.getFilterTablesInZone(h,t)){let t=[];for(let n of w(e.zone.left,e.zone.right+1))t.push(this.getters.getFilterValues({sheetId:h,col:n,row:e.zone.top}));g.push({filtersValues:t,zone:e.zone})}this.cells=m,this.zones=u,this.copiedTables=g}isCutAllowed(e){return e.length===1?`Success`:`WrongCutSelection`}isPasteAllowed(e,t){let n=this.getters.getActiveSheetId();if(this.operation===`CUT`&&t?.pasteOption!==void 0)return`WrongPasteOption`;if(e.length>1&&(this.cells.length>1||this.cells[0].length>1))return`WrongPasteSelection`;let r=this.cells.length,i=this.cells[0].length;for(let t of this.getPasteZones(e))if(this.getters.doesIntersectMerge(n,t)&&(e.length>1||!this.getters.isSingleCellOrMerge(n,e[0])||r*i!==1))return`WillRemoveExistingMerge`;let{xSplit:a,ySplit:o}=this.getters.getPaneDivisions(n);for(let t of this.getPasteZones(e))if(t.left<a&&t.right>=a||t.top<o&&t.bottom>=o)return`FrozenPaneOverlap`;return`Success`}paste(e,t){this.queuedCFChanges={},this.queuedDVChanges={},this.operation===`COPY`?this.pasteFromCopy(e,t):this.pasteFromCut(e,t);let n=this.cells.length,r=this.cells[0].length,i=this.operation===`CUT`;t?.selectTarget&&this.selectPastedZone(r,n,i,e),this.executeQueuedChanges(this.getters.getActiveSheetId())}pasteFromCopy(e,t){if(e.length===1){let n=this.cells.length,r=this.cells[0].length,i=this.pastedZones(e,r,n);for(let e of i)this.pasteZone(e.left,e.top,t)}else for(let n of e)for(let e=n.left;e<=n.right;e++)for(let r=n.top;r<=n.bottom;r++)this.pasteZone(e,r,t);t?.pasteOption===void 0&&this.pasteCopiedTables(e)}pasteFromCut(e,t){this.clearClippedZones();let n=e[0];this.pasteZone(n.left,n.top,t),this.dispatch(`MOVE_RANGES`,{target:this.zones,sheetId:this.sheetId,targetSheetId:this.getters.getActiveSheetId(),col:n.left,row:n.top});for(let e of this.copiedTables)this.dispatch(`REMOVE_FILTER_TABLE`,{sheetId:this.sheetId,target:[e.zone]});this.pasteCopiedTables(e)}pastedZones(e,t,n){let r=e[0],i=Math.max(1,Math.floor((r.right+1-r.left)/t)),a=Math.max(1,Math.floor((r.bottom+1-r.top)/n)),o=[];for(let e=0;e<i;e++)for(let i=0;i<a;i++){let a=r.top+i*n,s=r.left+e*t;o.push({left:s,top:a,bottom:a+n-1,right:s+t-1})}return o}getPasteZones(e){let t=this.cells;if(!t.length||!t[0].length)return e;let n=[],r=t.length,i=t[0].length,a=e[e.length-1],o=a.left,s=a.top,c=Math.max(1,Math.floor((a.right+1-o)/i)),l=Math.max(1,Math.floor((a.bottom+1-s)/r));for(let e=1;e<=c;e++)for(let t=1;t<=l;t++)n.push({left:o,top:s,right:o-1+e*i,bottom:s-1+t*r});return n}selectPastedZone(e,t,n,r){let i=r[0],a=i.left,o=i.top;if(t>1||e>1||n){let i=this.pastedZones(r,e,t),s=n?i[0]:sa(...i);this.selection.selectZone({cell:{col:a,row:o},zone:s},{scrollIntoView:!1})}}clearClippedZones(){this.dispatch(`CLEAR_CELLS`,{sheetId:this.sheetId,target:this.zones}),this.dispatch(`CLEAR_FORMATTING`,{sheetId:this.sheetId,target:this.zones})}pasteZone(e,t,n){let r=this.cells.length,i=this.cells[0].length,a=n?.pasteOption!==`onlyValue`&&n?.shouldPasteCF,o=!n?.pasteOption,s=this.getters.getActiveSheetId();this.addMissingDimensions(i,r,e,t);for(let c=0;c<r;c++){let r=this.cells[c];for(let l=0;l<i;l++){let i=r[l];if(!i)continue;let u={col:e+l,row:t+c,sheetId:s};this.pasteMergeIfExist(i.position,u,this.operation),this.pasteCell(i,u,this.operation,n),a&&this.pasteCf(i.position,u),o&&this.pasteDataValidation(i.position,u)}}}pasteCell(e,t,n,r){let{sheetId:i,col:a,row:o}=t,s=this.getters.getEvaluatedCell(t);if(r?.pasteOption===`onlyValue`){this.dispatch(`UPDATE_CELL`,{...t,content:e.evaluatedCell.value.toString()});return}let c=this.getters.getCellBorder(t),l=e.border,u={top:c?.top||l?.top,bottom:c?.bottom||l?.bottom,left:c?.left||l?.left,right:c?.right||l?.right},d=JSON.stringify(u);if(this.queuedBordersToAdd[d]||(this.queuedBordersToAdd[d]=[]),this.queuedBordersToAdd[d].push(V(t)),r?.pasteOption===`onlyFormat`){this.dispatch(`UPDATE_CELL`,{...t,style:e.cell?.style??null,format:e.cell?.format??e.evaluatedCell.format??s.format});return}let f=e.cell&&e.cell.isFormula&&n===`COPY`?this.getters.getTranslatedCellFormula(i,a-e.position.col,o-e.position.row,e.cell.compiledFormula):e.cell?.content;f!==``||e.cell?.format||e.cell?.style?this.dispatch(`UPDATE_CELL`,{...t,content:f??``,style:e.cell?.style||null,format:e.cell?.format}):s&&this.dispatch(`CLEAR_CELL`,t)}pasteMergeIfExist(e,t,n){let{sheetId:r,col:i,row:a}=e,{col:o,row:s}=this.getters.getMainCellPosition(e);if(o===i&&s===a){let o=this.getters.getMerge(e);if(!o)return;n===`CUT`&&this.dispatch(`REMOVE_MERGE`,{sheetId:r,target:[o]}),{sheetId:r,col:i,row:a}=t,this.dispatch(`ADD_MERGE`,{sheetId:r,force:!0,target:[{left:i,top:a,right:i+o.right-o.left,bottom:a+o.bottom-o.top}]})}}pasteCopiedTables(e){let t=this.getters.getActiveSheetId(),n=e[0],r=this.zones[0],i=[n.left-r.left,n.top-r.top];for(let e of this.copiedTables){let n=Sa(e.zone,`both`,`MOVE`,i);this.dispatch(`CREATE_FILTER_TABLE`,{sheetId:t,target:[n]});for(let r of w(0,e.filtersValues.length))this.dispatch(`UPDATE_FILTER`,{sheetId:t,col:n.left+r,row:n.top,hiddenValues:e.filtersValues[r]})}}getClipboardContent(){return{"text/plain":this.getPlainTextContent(),"text/html":this.getHTMLContent()}}getPlainTextContent(){return this.cells.map(e=>e.map(e=>this.getters.shouldShowFormulas()&&e?.cell?.isFormula?e.cell?.content||``:e?.evaluatedCell?.formattedValue||``).join(` `)).join(`
1476
1476
  `)||` `}getHTMLContent(){if(this.cells.length===1&&this.cells[0].length===1)return this.cells[0][0]?this.getters.getCellText(this.cells[0][0].position):``;let e=`<table border="1" style="border-collapse:collapse">`;for(let t of this.cells){e+=`<tr>`;for(let n of t){if(!n)continue;let t=W(Is(this.getters.getCellComputedStyle(n.position))),r=this.getters.getCellText(n.position);e+=`<td style="${t}">`+GD(r)+`</td>`}e+=`</tr>`}return e+=`</table>`,e}isColRowDirtyingClipboard(e,t){if(!this.zones)return!1;for(let n of this.zones)if(t===`COL`&&e<=n.right||t===`ROW`&&e<=n.bottom)return!0;return!1}drawClipboard(e){let{ctx:t,thinLineWidth:n}=e;if(!(this.sheetId!==this.getters.getActiveSheetId()||!this.zones||!this.zones.length)){t.setLineDash([8,5]),t.strokeStyle=pe,t.lineWidth=3.3*n;for(let e of this.zones){let{x:n,y:r,width:i,height:a}=this.getters.getVisibleRect(e);i>0&&a>0&&t.strokeRect(n,r,i,a)}}}pasteCf(e,t){let n=V(t),r=V(e);for(let i of this.getters.getConditionalFormats(e.sheetId))for(let a of i.ranges)if(da(e.col,e.row,this.getters.getRangeFromSheetXC(e.sheetId,a).zone)){let a=i,o=[];if(this.operation===`CUT`&&o.push(r),e.sheetId===t.sheetId)this.adaptCFRules(e.sheetId,a,[n],o);else{this.adaptCFRules(e.sheetId,a,[],o);let r=this.getCFToCopyTo(t.sheetId,a);this.adaptCFRules(t.sheetId,r,[n],[])}}}adaptCFRules(e,t,n,r){this.queuedCFChanges[e]||(this.queuedCFChanges[e]=[]);let i=this.queuedCFChanges[e].find(e=>e.cf.id===t.id);i?(i.toAdd.push(...n),i.toRemove.push(...r)):this.queuedCFChanges[e].push({toAdd:n,toRemove:r,cf:t})}getCFToCopyTo(e,t){let n=this.getters.getConditionalFormats(e).find(e=>e.stopIfTrue===t.stopIfTrue&&E(e.rule,t.rule)),r=this.queuedCFChanges[e];return!n&&r&&(n=r.find(e=>e.cf.stopIfTrue===t.stopIfTrue&&E(e.cf.rule,t.rule))?.cf),n||{...t,id:this.uuidGenerator.smallUuid(),ranges:[]}}pasteDataValidation(e,t){let n=this.getters.getValidationRuleForCell(e),r=V(e);if(!n)return;let i=V(t);for(let a of n.ranges)if(da(e.col,e.row,a.zone)){let a=[];if(this.operation===`CUT`&&a.push(r),e.sheetId===t.sheetId){let r=this.getDataValidationRuleToCopyTo(t.sheetId,n);this.adaptDataValidationRule(e.sheetId,r,[i],a)}else{let r=this.getters.getValidationRuleForCell(e);r&&this.adaptDataValidationRule(e.sheetId,r,[],a);let o=this.getDataValidationRuleToCopyTo(t.sheetId,n);this.adaptDataValidationRule(t.sheetId,o,[i],[])}}}getDataValidationRuleToCopyTo(e,t){let n=this.getters.getDataValidationRules(e).find(e=>E(t.criterion,e.criterion)&&t.isBlocking===e.isBlocking),r=this.queuedDVChanges[e];return!n&&r&&(n=r.find(e=>E(t.criterion,e.rule.criterion)&&t.isBlocking===e.rule.isBlocking)?.rule),n||{...t,id:this.uuidGenerator.smallUuid(),ranges:[]}}adaptDataValidationRule(e,t,n,r){this.queuedDVChanges[e]||(this.queuedDVChanges[e]=[]);let i=this.queuedDVChanges[e].find(e=>e.rule.id===t.id);i?(i.toAdd.push(...n),i.toRemove.push(...r)):this.queuedDVChanges[e].push({toAdd:n,toRemove:r,rule:S(t)})}executeQueuedChanges(e){for(let e in this.queuedCFChanges)for(let{toAdd:t,toRemove:n,cf:r}of this.queuedCFChanges[e]){let i=this.getters.getAdaptedCfRanges(e,r,t,n);if(i){if(i.length===0){this.dispatch(`REMOVE_CONDITIONAL_FORMAT`,{id:r.id,sheetId:e});continue}this.dispatch(`ADD_CONDITIONAL_FORMAT`,{cf:{id:r.id,rule:r.rule,stopIfTrue:r.stopIfTrue},ranges:i.map(t=>this.getters.getRangeDataFromZone(e,t)),sheetId:e})}}for(let e in this.queuedDVChanges)for(let{toAdd:t,toRemove:n,rule:r}of this.queuedDVChanges[e]){let i=HO([...HO(r.ranges.map(e=>e.zone),n),...t],[]);if(i.length===0){this.dispatch(`REMOVE_DATA_VALIDATION_RULE`,{sheetId:e,id:r.id});continue}this.dispatch(`ADD_DATA_VALIDATION_RULE`,{rule:{id:r.id,criterion:r.criterion,isBlocking:r.isBlocking},ranges:i.map(t=>this.getters.getRangeDataFromZone(e,t)),sheetId:e})}for(let t in this.queuedBordersToAdd){let n=this.queuedBordersToAdd[t],r=JSON.parse(t),i=HO(n,[]);this.dispatch(`SET_BORDERS_ON_TARGET`,{sheetId:e,target:i,border:r})}this.queuedBordersToAdd={}}},gA=class extends Q{allowDispatch(e){switch(e.type){case`REMOVE_DUPLICATES`:return this.checkValidations(e,this.chainValidations(this.checkSingleRangeSelected,this.checkNoMergeInZone,this.checkRangeContainsValues,this.checkColumnsIncludedInZone),this.chainValidations(this.checkNoColumnProvided,this.checkColumnsAreUnique))}return`Success`}handle(e){switch(e.type){case`REMOVE_DUPLICATES`:this.removeDuplicates(e.columns,e.hasHeader);break;case`TRIM_WHITESPACE`:this.trimWhitespace();break}}removeDuplicates(e,t){let n=this.getters.getActiveSheetId(),r=this.getters.getSelectedZone();t&&(r.top+=1);let i=this.getUniqueRowsIndexes(n,r.top,r.bottom,e),a=i.length;if(a===va(r).numberOfRows){this.notifyRowsRemovedAndRemaining(0,a);return}let o=new hA(i.map(e=>({left:r.left,top:e,right:r.right,bottom:e})),`COPY`,this.getters,this.dispatch,this.selection);this.dispatch(`CLEAR_CELLS`,{target:[r],sheetId:n});let s={left:r.left,top:r.top,right:r.left,bottom:r.top};o.paste([s]);let c={left:r.left,top:r.top-+!!t,right:r.right,bottom:r.top+a-1};this.selection.selectZone({cell:{col:c.left,row:c.top},zone:c});let l=r.bottom-r.top+1-a;this.notifyRowsRemovedAndRemaining(l,a)}getUniqueRowsIndexes(e,t,n,r){let i=new Map;for(let a of w(t,n+1)){let t=r.map(t=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:a}).value);Object.values(i).some(e=>E(e,t))||(i[a]=t)}return Object.keys(i).map(e=>parseInt(e))}notifyRowsRemovedAndRemaining(e,t){this.ui.notifyUI({type:`info`,text:y(`%s duplicate rows found and removed.
1477
- %s unique rows remain.`,e.toString(),t.toString()),sticky:!1})}checkSingleRangeSelected(){return this.getters.getSelectedZones().length===1?`Success`:`MoreThanOneRangeSelected`}checkNoMergeInZone(){let e=this.getters.getActiveSheetId(),t=this.getters.getSelectedZone();return this.getters.getMergesInZone(e,t).length>0?`WillRemoveExistingMerge`:`Success`}checkRangeContainsValues(e){let t=this.getters.getActiveSheetId(),n=this.getters.getSelectedZone();return e.hasHeader&&(n.top+=1),this.getters.getEvaluatedCellsInZone(t,n).every(e=>e.type===`empty`)?`EmptyTarget`:`Success`}checkNoColumnProvided(e){return e.columns.length===0?`NoColumnsProvided`:`Success`}checkColumnsIncludedInZone(e){let t=this.getters.getSelectedZone();return e.columns.some(e=>e<t.left||e>t.right)?`ColumnsNotIncludedInZone`:`Success`}checkColumnsAreUnique(e){return e.columns.length===new Set(e.columns).size?`Success`:`DuplicatesColumnsSelected`}trimWhitespace(){let e=this.getters.getSelectedZones(),t=this.getters.getActiveSheetId(),n=0;for(let{col:r,row:i}of e.map(ba).flat()){let e=this.getters.getCell({col:r,row:i,sheetId:t});if(!e)continue;let a=jt(e.content);a!==e.content&&(n+=1,this.dispatch(`UPDATE_CELL`,{sheetId:t,col:r,row:i,content:a}))}let r=n?y(`Trimmed whitespace from %s cells.`,n):y(`No selected cells had whitespace trimmed.`);this.ui.notifyUI({type:`info`,text:r,sticky:!1})}},_A=class extends Q{static layers=[3];static getters=[`getSearchMatches`,`getCurrentSelectedMatchIndex`];searchMatches=[];selectedMatchIndex=null;currentSearchRegex=null;searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1};toSearch=``;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(-1);break;case`SELECT_SEARCH_NEXT_MATCH`:this.selectNextCell(1);break;case`REPLACE_SEARCH`:this.replace(e.replaceWith);break;case`REPLACE_ALL_SEARCH`:this.replaceAll(e.replaceWith);break;case`UNDO`:case`REDO`:case`REMOVE_FILTER_TABLE`:case`UPDATE_FILTER`:case`REMOVE_COLUMNS_ROWS`:case`HIDE_COLUMNS_ROWS`:case`UNHIDE_COLUMNS_ROWS`:case`ADD_COLUMNS_ROWS`:case`EVALUATE_CELLS`:case`UPDATE_CELL`:this.isSearchDirty=!0;break;case`ACTIVATE_SHEET`:this.refreshSearch();break}}finalize(){this.isSearchDirty&&=(this.refreshSearch(),!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(){let e=this.findMatches();this.searchMatches=e,this.selectNextCell(0)}updateRegex(){let e=Xe(this.toSearch),t=this.searchOptions.matchCase?``:`i`;this.searchOptions.exactMatch&&(e=`^${e}$`),this.currentSearchRegex=RegExp(e,t)}findMatches(){let e=this.getters.getActiveSheetId(),t=this.getters.getCells(e),n=[];if(this.toSearch&&this.currentSearchRegex)for(let r of Object.values(t)){let{col:t,row:i}=this.getters.getCellPosition(r.id),a={sheetId:e,col:t,row:i},o=this.getters.isColHidden(e,t),s=this.getters.isRowHidden(e,i);if(!(o||s)){if(this.currentSearchRegex.test(this.getSearchableString(a))){let e={col:t,row:i,selected:!1};n.push(e)}for(let e of this.getters.getSpreadPositionsOf(a))if(this.currentSearchRegex.test(this.getSearchableString(e))){let t={col:e.col,row:e.row,selected:!1};n.push(t)}}}return n.sort(this.sortByRowThenColumn)}sortByRowThenColumn(e,t){return e.row===t.row?e.col-t.col:e.row>t.row?1:-1}selectNextCell(e){let t=this.searchMatches;if(!t.length){this.selectedMatchIndex=null;return}let n;n=this.selectedMatchIndex===null?0:this.selectedMatchIndex+e,n=(n%t.length+t.length)%t.length,this.selectedMatchIndex=n,this.selection.selectCell(t[n].col,t[n].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}}replaceMatch(e,t){if(!this.currentSearchRegex)return;let n={sheetId:this.getters.getActiveSheetId(),...e},r=this.getters.getCell(n);if(!r?.content||r?.isFormula&&!this.searchOptions.searchFormulas)return;let i=new RegExp(this.currentSearchRegex.source,this.currentSearchRegex.flags+`g`),a=Ic(this.getSearchableString(n).replace(i,t),this.getters.getLocale());this.dispatch(`UPDATE_CELL`,{...n,content:a})}replace(e){if(this.selectedMatchIndex===null)return;let t=this.searchMatches[this.selectedMatchIndex];this.replaceMatch(t,e)}replaceAll(e){let t=this.searchMatches.length;for(let n=0;n<t;n++)this.replaceMatch(this.searchMatches[n],e)}getSearchableString(e){return this.getters.getCellText(e,this.searchOptions.searchFormulas)}drawGrid(e){let{ctx:t}=e,n=this.getters.getActiveSheetId();for(let e of this.searchMatches){let r=this.getters.getMerge({sheetId:n,col:e.col,row:e.row}),i=r?r.left:e.col,a=r?r.right:e.col,o=r?r.top:e.row,s=r?r.bottom:e.row,{x:c,y:l,width:u,height:d}=this.getters.getVisibleRect({top:o,left:i,right:a,bottom:s});u>0&&d>0&&(t.fillStyle=`#8B008B33`,t.fillRect(c,l,u,d),e.selected&&(t.strokeStyle=`#8B008B`,t.strokeRect(c,l,u,d)))}}},vA=class extends Q{handle(e){switch(e.type){case`SET_DECIMAL`:this.setDecimal(e.sheetId,e.target,e.step);break}}setDecimal(e,t,n){let r={};for(let i of t)for(let t of ba(i)){let i=this.getCellNumberFormat({sheetId:e,...t});if(i!==void 0){let e=Ai(i,n,this.getters.getLocale());r[e]=r[e]||[],r[e].push(t)}}for(let t in r){let n=HO(r[t].map(e=>V(e)));this.dispatch(`SET_FORMATTING`,{sheetId:e,format:t,target:n})}}getCellNumberFormat(e){for(let t of[e]){let e=this.getters.getEvaluatedCell(t);if(e.type===`number`&&!(e.format&&_i(e.format)))return e.format||Ci(e.value)}}},yA=class extends Q{static getters=[`getNextVisibleCellPosition`,`findVisibleHeader`,`findLastVisibleColRowIndex`,`findFirstVisibleColRowIndex`,`isRowHidden`,`isColHidden`,`isHeaderHidden`];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,n){return t===`COL`?this.isColHidden(e,n):this.isRowHidden(e,n)}getNextVisibleCellPosition({sheetId:e,col:t,row:n}){return{sheetId:e,col:this.findVisibleHeader(e,`COL`,t,this.getters.getNumberCols(e)-1)||this.findVisibleHeader(e,`COL`,t,0)||0,row:this.findVisibleHeader(e,`ROW`,n,this.getters.getNumberRows(e)-1)||this.findVisibleHeader(e,`ROW`,n,0)||0}}findVisibleHeader(e,t,n,r){if(n<=r){for(let i=n;i<=r;i++)if(this.getters.doesHeaderExist(e,t,i)&&!this.isHeaderHidden(e,t,i))return i}if(n>r){for(let i=n;i>=r;i--)if(this.getters.doesHeaderExist(e,t,i)&&!this.isHeaderHidden(e,t,i))return i}}findLastVisibleColRowIndex(e,t,{last:n,first:r}){return w(n,r,-1).find(n=>!this.isHeaderHidden(e,t,n))||r}findFirstVisibleColRowIndex(e,t){let n=this.getters.getNumberHeaders(e,t);for(let r=0;r<n;r++)if(t===`COL`&&!this.isColHidden(e,r)||t===`ROW`&&!this.isRowHidden(e,r))return r}exportForExcel(e){for(let t of e.sheets)for(let[e,n]of Object.entries(t.rows))n.isHidden=this.isRowHidden(t.id,Number(e))}},bA=class extends Q{static layers=[1];static getters=[`getHighlights`];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=>{let{numberOfRows:t,numberOfCols:n}=va(e.zone),r=t*n===1?this.getters.expandZone(e.sheetId,e.zone):e.zone;return{...e,zone:r}})}drawGrid(e){let{ctx:t,thinLineWidth:n}=e,r=this.getters.getActiveSheetId(),i=3*n;t.lineWidth=i;let a=this.getHighlights();for(let e of a.filter((e,t)=>a.findIndex(t=>la(t.zone,e.zone)&&t.sheetId===r)===t)){let{x:n,y:r,width:a,height:o}=this.getters.getVisibleRect(e.zone);a>0&&o>0&&(t.strokeStyle=e.color,t.strokeRect(n+i/2,r+i/2,a-i,o-i),t.globalCompositeOperation=`source-over`,t.fillStyle=e.color+`20`,t.fillRect(n+i,r+i,a-2*i,o-2*i))}}},xA=class extends Q{static layers=[0,7];static getters=[`getColDimensionsInViewport`,`getRowDimensionsInViewport`];boxes=[];getColDimensionsInViewport(e,t){let n=Pt(this.getters.getSheetViewVisibleCols()),r=this.getters.getColRowOffsetInViewport(`COL`,n,t),i=this.getters.getColSize(e,t);return{start:r,size:i,end:r+(this.getters.isColHidden(e,t)?0:i)}}getRowDimensionsInViewport(e,t){let n=Pt(this.getters.getSheetViewVisibleRows()),r=this.getters.getColRowOffsetInViewport(`ROW`,n,t),i=this.getters.getRowSize(e,t);return{start:r,size:i,end:r+(this.getters.isRowHidden(e,t)?0:i)}}getHeaderOffset(e,t,n){let r=this.getters.getColRowOffsetInViewport(e,t,n);return this.getters.isDashboard()||(r+=e===`ROW`?26:48),r}drawGrid(e,t){switch(t){case 0:this.drawGlobalBackground(e);for(let{zone:t,rect:n}of this.getters.getAllActiveViewportsZonesAndRect()){let{ctx:r}=e;r.save(),r.beginPath(),r.rect(n.x,n.y,n.width,n.height),r.clip(),this.boxes=this.getGridBoxes(t),this.drawBackground(e),this.drawOverflowingCellBackground(e),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e),this.drawIcon(e),r.restore()}this.drawFrozenPanes(e);break;case 7:this.getters.isDashboard()||(this.drawHeaders(e),this.drawFrozenPanesHeaders(e));break}}drawGlobalBackground(e){let{ctx:t}=e,{width:n,height:r}=this.getters.getSheetViewDimensionWithHeaders();t.fillStyle=`#ffffff`,t.fillRect(0,0,n+oe,r+oe)}drawBackground(e){let{ctx:t,thinLineWidth:n}=e,r=!this.getters.isDashboard()&&this.getters.getGridLinesVisibility(this.getters.getActiveSheetId()),i=r?.1*n:0;if(r)for(let e of this.boxes)t.strokeStyle=`#E2E3E3`,t.lineWidth=n,t.strokeRect(e.x+i,e.y+i,e.width-2*i,e.height-2*i)}drawCellBackground(e){let{ctx:t}=e;for(let e of this.boxes){let n=e.style;n.fillColor&&n.fillColor!==`#ffffff`&&(t.fillStyle=n.fillColor||`#ffffff`,t.fillRect(e.x,e.y,e.width,e.height)),e.isError&&(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())}}drawOverflowingCellBackground(e){let{ctx:t,thinLineWidth:n}=e;for(let e of this.boxes)if(e.content&&e.isOverflow){let r=e.content.align||`left`,i,a,o=e.y+n/2,s=e.height-n,c=Math.min(e.clipRect?.width||1/0,e.content.width);r===`left`?(i=e.x+n/2,a=c-2*n):r===`right`?(i=e.x+e.width-n/2,a=-c+2*n):(i=(e.clipRect?.x||e.x+e.width/2-e.content.width/2)+n/2,a=c-2*n),t.fillStyle=`#ffffff`,t.fillRect(i,o,a,s)}}drawBorders(e){let{ctx:t}=e;for(let e of this.boxes){let t=e.border;if(t){let{x:r,y:i,width:a,height:o}=e;t.left&&n(t.left,r,i,r,i+o),t.top&&n(t.top,r,i,r+a,i),t.right&&n(t.right,r+a,i,r+a,i+o),t.bottom&&n(t.bottom,r,i+o,r+a,i+o)}}function n({style:e,color:n},r,i,a,o){switch(t.strokeStyle=n,e){case`medium`:t.lineWidth=2,r+=i===o?-.5:.5,a+=i===o?1.5:.5,i+=r===a?-.5:.5,o+=r===a?1.5:.5;break;case`thick`:t.lineWidth=3,i===o&&(r--,a++),r===a&&(i--,o++);break;case`dashed`:t.lineWidth=1,t.setLineDash([1,3]);break;case`dotted`:t.lineWidth=1,i===o&&(r+=.5,a+=.5),r===a&&(i+=.5,o+=.5),t.setLineDash([1,1]);break;default:t.lineWidth=1;break}t.beginPath(),t.moveTo(r,i),t.lineTo(a,o),t.stroke(),t.lineWidth=1,t.setLineDash([])}}drawTexts(e){let{ctx:t}=e;t.textBaseline=`top`;let n;for(let e of this.boxes)if(e.content){let r=e.style||{},i=e.content.align||`left`,a=yo(r);a!==n&&(n=a,t.font=a),t.fillStyle=r.textColor||`#000`;let o=e.x;if(i===`left`?o+=4+(e.image?e.image.size+4:0):i===`right`?o+=e.width-4-(e.hasIcon?19:0):o+=e.width/2,t.textAlign=i,e.clipRect){t.save(),t.beginPath();let{x:n,y:r,width:i,height:a}=e.clipRect;t.rect(n,r,i,a),t.clip()}let s=bo(r),c=e.content.textLines.length,l=this.computeTextYCoordinate(e,s,c);for(let n of e.content.textLines)Oo(t,n,{x:Math.round(o),y:Math.round(l)},r.underline,r.strikethrough),l+=4+s;e.clipRect&&t.restore()}}drawIcon(e){let{ctx:t}=e;for(let e of this.boxes)if(e.image){let n=e.image.image;if(e.image.clipIcon){t.save(),t.beginPath();let{x:n,y:r,width:i,height:a}=e.image.clipIcon;t.rect(n,r,i,a),t.clip()}let r=e.image.size,i=this.computeTextYCoordinate(e,r);t.drawImage(n,e.x+4,i,r,r),e.image.clipIcon&&t.restore()}}computeTextYCoordinate(e,t,n=1){let r=e.y+1,i=po(t,n),a=e.height>i+8,o=e.verticalAlign||Ae;if(a){if(o===`middle`)return r+(e.height-i)/2;if(o===`bottom`)return r+e.height-i-4}return r+4}drawHeaders(e){let{ctx:t,thinLineWidth:n}=e,r=this.getters.getSheetViewVisibleCols(),i=r[0],a=this.getters.getSheetViewVisibleRows(),o=a[0],{width:s,height:c}=this.getters.getSheetViewDimensionWithHeaders(),l=this.getters.getSelectedZones(),u=ja(l),d=Ma(l),f=this.getters.getActiveSheetId(),p=this.getters.getNumberCols(f),m=this.getters.getNumberRows(f),h=this.getters.getActiveCols(),g=this.getters.getActiveRows();t.font=`400 11px ${Ne}`,t.textAlign=`center`,t.textBaseline=`middle`,t.lineWidth=n,t.strokeStyle=`#333`;for(let e of r){let n={left:e,right:e,top:0,bottom:m-1},{x:r,width:i}=this.getters.getVisibleRect(n),a=this.getters.doesZonesContainFilter(f,[n]),o=h.has(e),s=u.has(e);o?t.fillStyle=a?ve:ue:s?t.fillStyle=a?be:le:t.fillStyle=a?ye:ce,t.fillRect(r,0,i,26)}for(let e of a){let n={top:e,bottom:e,left:0,right:p-1},{y:r,height:i}=this.getters.getVisibleRect(n),a=this.getters.doesZonesContainFilter(f,[n]),o=g.has(e),s=d.has(e);o?t.fillStyle=a?ve:ue:s?t.fillStyle=a?be:le:t.fillStyle=a?ye:ce,t.fillRect(0,r,48,i)}t.beginPath(),t.moveTo(48,0),t.lineTo(48,c),t.moveTo(0,26),t.lineTo(s,26),t.strokeStyle=`#C0C0C0`,t.stroke(),t.beginPath();for(let e of r){let n=this.getters.getColSize(f,e),r=D(e);t.fillStyle=h.has(e)?`#fff`:de;let a=this.getHeaderOffset(`COL`,i,e);t.fillText(r,a+n/2,26/2),t.moveTo(a+n,0),t.lineTo(a+n,26)}for(let e of a){let n=this.getters.getRowSize(f,e);t.fillStyle=g.has(e)?`#fff`:de;let r=this.getHeaderOffset(`ROW`,o,e);t.fillText(String(e+1),48/2,r+n/2),t.moveTo(0,r+n),t.lineTo(48,r+n)}t.stroke()}drawFrozenPanesHeaders(e){let{ctx:t,thinLineWidth:n}=e,{x:r,y:i}=this.getters.getMainViewportCoordinates(),a=this.getters.isDashboard()?0:48,o=this.getters.isDashboard()?0:26;t.lineWidth=6*n,t.strokeStyle=Te,t.beginPath(),r&&(t.moveTo(a+r,0),t.lineTo(a+r,o)),i&&(t.moveTo(0,o+i),t.lineTo(a,o+i)),t.stroke()}drawFrozenPanes(e){let{ctx:t,thinLineWidth:n}=e,{x:r,y:i}=this.getters.getMainViewportCoordinates(),a=this.getters.getSheetViewVisibleCols(),o=a[0],s=a[a.length-1],c=this.getters.getSheetViewVisibleRows(),l={left:o,right:s,top:c[0],bottom:c[c.length-1]},u=this.getters.getVisibleRect(l),d=this.getters.isDashboard()?0:48,f=this.getters.isDashboard()?0:26;t.lineWidth=6*n,t.strokeStyle=`#DADFE8`,t.beginPath(),r&&(t.moveTo(d+r,f),t.lineTo(d+r,u.height+f)),i&&(t.moveTo(d,f+i),t.lineTo(u.width+d,f+i)),t.stroke()}findNextEmptyCol(e,t,n){let r=this.getters.getActiveSheetId(),i=e;for(;i<t;){let e={sheetId:r,col:i+1,row:n},t=this.getters.getEvaluatedCell(e),a=this.getters.getCellBorderWithFilterBorder(e),o=this.getters.doesCellHaveGridIcon(e),s=this.getters.isCellValidCheckbox(e);if(t.type!==`empty`||this.getters.isInMerge(e)||a?.left||o||s)return i;i++}return i}findPreviousEmptyCol(e,t,n){let r=this.getters.getActiveSheetId(),i=e;for(;i>t;){let e={sheetId:r,col:i-1,row:n},t=this.getters.getEvaluatedCell(e),a=this.getters.getCellBorderWithFilterBorder(e),o=this.getters.doesCellHaveGridIcon(e),s=this.getters.isCellValidCheckbox(e);if(t.type!==`empty`||this.getters.isInMerge(e)||a?.right||o||s)return i;i--}return i}computeCellAlignment(e,t){if(this.getters.getCell(e)?.isFormula&&this.getters.shouldShowFormulas())return`left`;let{align:n}=this.getters.getCellStyle(e),r=this.getters.getEvaluatedCell(e);return t&&r.type===`number`?n===`center`?n:`left`:n||r.defaultAlign}createZoneBox(e,t,n){let{left:r,right:i}=n,a=t.left,o=t.top,s={sheetId:e,col:a,row:o},c=this.getters.getEvaluatedCell(s),l=this.getters.shouldShowFormulas(),{x:u,y:d,width:f,height:p}=this.getters.getRect(t),{verticalAlign:m}=this.getters.getCellStyle(s),h={x:u,y:d,width:f,height:p,border:this.getters.getCellBorderWithFilterBorder(s)||void 0,style:this.getters.getCellComputedStyle(s),verticalAlign:m,isError:c.type===`error`&&c.error.isVerbose||this.getters.isDataValidationInvalid(s)};if(c.type===`empty`||this.getters.isCellValidCheckbox(s))return h;let g=this.getters.getConditionalIcon(s),_=bo(h.style),v=g?4+_:0;g&&(h.image={type:`icon`,size:_,clipIcon:{x:h.x,y:h.y,width:Math.min(v,f),height:p},image:MS[g].img}),h.hasIcon=this.getters.doesCellHaveGridIcon(s);let y=h.hasIcon?19:0,ee=this.getters.getCellComputedStyle(s),te=ee.wrapping||`overflow`,b=te===`wrap`&&!l?f-8:void 0,x=this.getters.getCellMultiLineText(s,b),ne=Math.max(...x.map(e=>this.getters.getTextWidth(e,ee)+4)),re=v+ne+y,ie=this.computeCellAlignment(s,re>f);h.content={textLines:x,width:te===`overflow`?ne:f,align:ie};let ae=re>f||_>p;if(g||h.hasIcon)h.clipRect={x:h.x+v,y:h.y,width:Math.max(0,f-v-y),height:p};else if(ae&&te===`overflow`){let e,n;switch(this.getters.isInMerge(s)?(e=this.getters.getMerge(s).right,n=a):(e=this.findNextEmptyCol(a,i,o),n=this.findPreviousEmptyCol(a,r,o),h.isOverflow=!0),ie){case`left`:{let n=V({col:e,row:o}),{x:r,y:i,width:a,height:s}=this.getters.getVisibleRect(sa(t,n));(a<re||_>s||x.length>1)&&(h.clipRect={x:r,y:i,width:a,height:s});break}case`right`:{let e=V({col:n,row:o}),{x:r,y:i,width:a,height:s}=this.getters.getVisibleRect(sa(t,e));(a<re||_>s||x.length>1)&&(h.clipRect={x:r,y:i,width:a,height:s});break}case`center`:{let r={...t,left:n,right:e},{x:i,y:a,height:o,width:s}=this.getters.getVisibleRect(r),c=re/2,l=h.x+h.width/2;if(i+s<l+c||i>l-c||_>o||x.length>1){let e=i>l-c?i:l-c;h.clipRect={x:e,y:a,width:i+s-e,height:o}}break}}}else(te===`clip`||te===`wrap`||x.length>1)&&(h.clipRect={x:h.x,y:h.y,width:f,height:p});return h}getGridBoxes(e){let t=[],n=this.getters.getSheetViewVisibleCols().filter(t=>t>=e.left&&t<=e.right),r=n[0],i=n[n.length-1],a=this.getters.getSheetViewVisibleRows().filter(t=>t>=e.top&&t<=e.bottom),o={left:r,right:i,top:a[0],bottom:a[a.length-1]},s=this.getters.getActiveSheetId();for(let e of a)for(let r of n){let n={sheetId:s,col:r,row:e};this.getters.isInMerge(n)||t.push(this.createZoneBox(s,V(n),o))}for(let e of this.getters.getMerges(s))if(!this.getters.isMergeHidden(s,e)&&ua(e,o)){let n=this.createZoneBox(s,e,o),r=this.getters.getCellBorder({sheetId:s,col:e.right,row:e.bottom});n.border={...n.border,bottom:r?r.bottom:void 0,right:r?r.right:void 0},n.isMerge=!0,t.push(n)}return t}},SA=class extends Q{inputHasSingleRange;static layers=[1];static getters=[];ranges=[];focusedRangeIndex=null;inputSheetId;constructor(e,t,n){if(n&&t.length>1)throw Error(`Input with a single range cannot be instantiated with several range references.`);super(e),this.inputHasSingleRange=n,this.insertNewRange(0,t),this.inputSheetId=this.getters.getActiveSheetId(),this.ranges.length===0&&(this.insertNewRange(this.ranges.length,[``]),this.focusLast())}handleEvent(e){if(this.focusedRangeIndex===null)return;let t=this.inputSheetId,n=this.getters.getActiveSheetId(),r=e.options.unbounded?this.getters.getUnboundedZone(n,e.anchor.zone):e.anchor.zone,i=this.getters.getRangeFromZone(n,r);if(e.mode===`newAnchor`&&!this.inputHasSingleRange&&this.ranges[this.focusedRangeIndex].xc.trim()!==``){let e=this.getters.getSelectionRangeString(i,t);this.insertNewRange(this.ranges.length,[e]),this.focusLast()}else{let e=i.parts,n=this.ranges[this.focusedRangeIndex].xc.trim();n&&(e=this.getters.getRangeFromSheetXC(t,n).parts);let r=i.clone({parts:e}),a=this.getters.getSelectionRangeString(r,t);this.setRange(this.focusedRangeIndex,[a])}}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`:{let t=this.getIndex(e.rangeId);if(t!==null&&this.focusedRangeIndex!==t&&this.focus(t),t!==null){let n=e.value.replace(/^,+/,``).split(`,`).map(e=>e.trim());this.setRange(t,n)}break}case`ADD_EMPTY_RANGE`:this.insertNewRange(this.ranges.length,[``]),this.focusLast();break;case`ADD_RANGE`:this.insertNewRange(this.ranges.length,[e.value]),this.focusLast();break;case`REMOVE_RANGE`:let t=this.getIndex(e.rangeId);t!==null&&this.removeRange(t);break;case`ACTIVATE_SHEET`:if(e.sheetIdFrom!==e.sheetIdTo){let{col:t,row:n}=this.getters.getNextVisibleCellPosition({sheetId:e.sheetIdTo,col:0,row:0}),r=this.getters.expandZone(e.sheetIdTo,V({col:t,row:n}));this.selection.resetAnchor(this,{cell:{col:t,row:n},zone:r})}break;case`START_CHANGE_HIGHLIGHT`:let n=this.getters.getActiveSheetId(),r=this.getters.expandZone(n,e.zone),i=this.ranges.findIndex(e=>{let{xc:t,sheetName:i}=Xi(e.xc),a=i||this.getters.getSheetName(this.inputSheetId);if(this.getters.getSheetName(n)!==a)return!1;let o=this.getters.getRangeFromSheetXC(n,t);return la(this.getters.expandZone(n,o.zone),r)});if(i!==-1){this.focus(i);let{left:e,top:t}=r;this.selection.resetAnchor(this,{cell:{col:e,row:t},zone:r})}break}}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}setContent(e,t){this.ranges[e]={...this.ranges[e],xc:t}}insertNewRange(e,t){let n=Math.max(0,...this.ranges.map(e=>Number(e.id)));this.ranges.splice(e,0,...t.map((e,t)=>({xc:e,id:n+t+1,color:Lt[(n+t)%Lt.length]})))}setRange(e,t){let[,...n]=t;this.setContent(e,t[0]),this.insertNewRange(e+1,n),n.length&&this.focus(e+n.length)}removeRange(e){this.ranges.splice(e,1),this.focusedRangeIndex!==null&&this.focusLast()}inputToHighlights({xc:e,color:t}){return this.cleanInputs([e]).filter(e=>this.getters.isRangeValid(e)).filter(e=>this.shouldBeHighlighted(this.inputSheetId,e)).map(e=>{let{sheetName:n}=Xi(e);return{zone:this.getters.getRangeFromSheetXC(this.inputSheetId,e).zone,sheetId:n&&this.getters.getSheetIdByName(n)||this.inputSheetId,color:t}})}cleanInputs(e){return e.map(e=>e.split(`,`)).flat().map(e=>e.trim()).filter(e=>e!==``)}shouldBeHighlighted(e,t){let{sheetName:n}=Xi(t),r=this.getters.getSheetIdByName(n),i=this.getters.getActiveSheet().id;return this.getters.isRangeValid(t)&&(r===i||r===void 0&&i===e)}getIndex(e){let t=this.ranges.findIndex(t=>t.id===e);return t>=0?t:null}},CA=class extends Q{config;static layers=[1];static getters=[`getSelectionInput`,`getSelectionInputValue`,`isRangeValid`,`getSelectionInputHighlights`];inputs={};focusedInputId=null;get currentInput(){return this.focusedInputId?this.inputs[this.focusedInputId]:null}constructor(e){super(e),this.config=e}allowDispatch(e){switch(e.type){case`FOCUS_RANGE`:case`CHANGE_RANGE`:case`ADD_EMPTY_RANGE`:case`REMOVE_RANGE`:if(!this.inputs[e.id])return`InvalidInputId`}switch(e.type){case`FOCUS_RANGE`:let t=this.currentInput?.getIndex(e.rangeId);if(this.focusedInputId===e.id&&this.currentInput?.focusedRangeIndex===t)return`InputAlreadyFocused`;break;case`ADD_RANGE`:case`ADD_EMPTY_RANGE`:let n=this.inputs[e.id];if(n.inputHasSingleRange&&n.ranges.length===1)return`MaximumRangesReached`;break;case`REMOVE_RANGE`:if(this.inputs[e.id].ranges.length===1)return`MinimumRangesReached`;break;case`CHANGE_RANGE`:if(this.inputs[e.id].inputHasSingleRange&&e.value.split(`,`).length>1)return`MaximumRangesReached`;break}return`Success`}handle(e){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_RANGE`:case`ADD_EMPTY_RANGE`:case`REMOVE_RANGE`:if(e.id!==this.focusedInputId){let t=this.inputs[e.id];this.selection.capture(t,{cell:{col:0,row:0},zone:V({col:0,row:0})},{handleEvent:t.handleEvent.bind(t),release:()=>this.focusedInputId=null}),this.focusedInputId=e.id}break;case`FOCUS_RANGE`:case`CHANGE_RANGE`:let t=this.inputs[e.id],n=t.ranges.find(t=>t.id===e.rangeId);if(n){let e=this.getters.getActiveSheetId(),r=this.getters.getRangeFromSheetXC(e,n?.xc||`A1`).zone;this.selection.capture(t,{cell:{col:r.left,row:r.top},zone:r},{handleEvent:t.handleEvent.bind(t),release:()=>this.focusedInputId=null})}this.focusedInputId=e.id;break}this.currentInput?.handle(e)}getSelectionInput(e){return this.inputs[e]?this.inputs[e].ranges.map((t,n)=>Object.assign({},t,{color:this.focusedInputId===e&&this.inputs[e].focusedRangeIndex!==null&&this.isRangeValid(t.xc)?t.color:null,isFocused:this.focusedInputId===e&&this.inputs[e].focusedRangeIndex===n})):[]}isRangeValid(e){if(!e)return!1;let{xc:t,sheetName:n}=Xi(e);return t.match(Wi)!==null&&(!n||this.getters.getSheetIdByName(n)!==void 0)}getSelectionInputValue(e){return this.inputs[e].getSelectionInputValue()}getSelectionInputHighlights(){return this.focusedInputId?this.inputs[this.focusedInputId].getSelectionInputHighlights():[]}initInput(e,t,n=!1){if(this.inputs[e]&&this.unfocus(),this.inputs[e]=new SA(this.config,t,n),t.length===0){let t=this.inputs[e],n={zone:V({col:0,row:0}),cell:{col:0,row:0}};this.selection.capture(t,n,{handleEvent:t.handleEvent.bind(t),release:()=>this.focusedInputId=null}),this.focusedInputId=e}}unfocus(){this.selection.release(this.currentInput),this.focusedInputId=null}},wA=class extends Q{static getters=[`getContiguousZone`];allowDispatch(e){switch(e.type){case`SORT_CELLS`:if(!da(e.col,e.row,e.zone))throw Error(y(`The anchor must be part of the provided zone`));return this.checkValidations(e,this.checkMerge,this.checkMergeSizes)}return`Success`}handle(e){switch(e.type){case`SORT_CELLS`:this.sortZone(e.sheetId,e,e.zone,e.sortDirection,e.sortOptions||{});break}}checkMerge({sheetId:e,zone:t}){return this.getters.doesIntersectMerge(e,t)&&ba(t).some(({col:t,row:n})=>!this.getters.isInMerge({sheetId:e,col:t,row:n}))?`InvalidSortZone`:`Success`}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return`Success`;let n=this.getters.getMerges(e).filter(e=>ua(e,t)),r=va(n[0]),[i,a]=[r.numberOfCols,r.numberOfRows];return n.every(e=>{let[t,n]=[e.right-e.left+1,e.bottom-e.top+1];return t===i&&n===a})?`Success`:`InvalidSortZone`}expand(e,t){let{left:n,right:r,top:i,bottom:a}=this.getters.expandZone(e,t);return{left:Math.max(0,n),right:Math.min(this.getters.getNumberCols(e)-1,r),top:Math.max(0,i),bottom:Math.min(this.getters.getNumberRows(e)-1,a)}}checkExpandedValues(e,t){let n=this.expand(e,t),r;if(this.getters.doesIntersectMerge(e,n)){let{left:t,right:i,top:a,bottom:o}=n;for(let n=t;n<=i;n++)for(let t=a;t<=o;t++){let{col:i,row:a}=this.getters.getMainCellPosition({sheetId:e,col:n,row:t});if(r=this.getters.getEvaluatedCell({sheetId:e,col:i,row:a}),r.formattedValue)return!0}}else for(let t of this.getters.getEvaluatedCellsInZone(e,n))if(t.formattedValue)return!0;return!1}getContiguousZone(e,t){let{top:n,bottom:r,left:i,right:a}=t,o,s=!1;for(;!s;)s=!0,n>0&&(o=this.checkExpandedValues(e,{left:i-1,right:a+1,top:n-1,bottom:n-1}),o&&(s=!1,n--)),i>0&&(o=this.checkExpandedValues(e,{left:i-1,right:i-1,top:n-1,bottom:r+1}),o&&(s=!1,i--)),a<this.getters.getNumberCols(e)-1&&(o=this.checkExpandedValues(e,{left:a+1,right:a+1,top:n-1,bottom:r+1}),o&&(s=!1,a++)),r<this.getters.getNumberRows(e)-1&&(o=this.checkExpandedValues(e,{left:i-1,right:a+1,top:r+1,bottom:r+1}),o&&(s=!1,r++));return{left:i,right:a,top:n,bottom:r}}hasHeader(e,t){if(t[0].length===1)return!1;let n=t.map(t=>t.map(({col:t,row:n})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:n}).type));return n[0][0]===`empty`&&(n=n.slice(1)),n.some(e=>e[0]===`empty`)?!1:!!n.some(e=>e[1]!==`empty`&&e[0]!==e[1])}sortZone(e,t,n,r,i){let[a,o]=this.mainCellsSteps(e,n),s=this.getters.getMainCellPosition({sheetId:e,col:t.col,row:t.row}).col,c=Object.assign({},n),l=this.mainCells(e,n);!i.sortHeaders&&this.hasHeader(e,l)&&(c.top+=o),l=this.mainCells(e,c);let u=l[s-c.left],d=_g(u.map(e=>this.getters.getEvaluatedCell(e)),r,!!i.emptyCellAsZero).map(e=>e.index),[f,p]=[l.length,l[0].length],m=[];for(let e=0;e<f;e++)for(let t=0;t<p;t++){let{col:n,row:r,sheetId:i}=l[e][d[t]],s=this.getters.getCell({sheetId:i,col:n,row:r}),u=c.left+e*a,f=c.top+t*o,p={sheetId:i,col:u,row:f,content:``};if(s){let e=s.content;if(s.isFormula){let t=this.getters.getCellPosition(s.id);e=this.getters.getTranslatedCellFormula(i,0,f-t.row,s.compiledFormula)}p.style=s.style,p.content=e,p.format=s.format}m.push(p)}m.forEach(e=>this.dispatch(`UPDATE_CELL`,e))}mainCellsSteps(e,t){let n=this.getters.getMerge({sheetId:e,col:t.left,row:t.top});return[n?n.right-n.left+1:1,n?n.bottom-n.top+1:1]}mainCells(e,t){let[n,r]=this.mainCellsSteps(e,t),i=[],a=w(t.left,t.right+1,n),o=w(t.top,t.bottom+1,r);for(let t of a){let n=[];i.push(n);for(let r of o)n.push({sheetId:e,col:t,row:r})}return i}},TA=class extends Q{static getters=[`shouldShowFormulas`];showFormulas=!1;handle(e){switch(e.type){case`SET_FORMULA_VISIBILITY`:this.showFormulas=e.show;break}}shouldShowFormulas(){return this.showFormulas}},EA=class extends Q{static getters=[`doesCellHaveGridIcon`,`getCellWidth`,`getTextWidth`,`getCellText`,`getCellMultiLineText`];ctx=document.createElement(`canvas`).getContext(`2d`);allowDispatch(e){return this.chainValidations(this.checkSheetExists,this.checkZonesAreInSheet)(e)}handle(e){switch(e.type){case`AUTORESIZE_COLUMNS`:for(let t of e.cols){let n=this.getColMaxWidth(e.sheetId,t);n!==0&&this.dispatch(`RESIZE_COLUMNS_ROWS`,{elements:[t],dimension:`COL`,size:n,sheetId:e.sheetId})}break;case`AUTORESIZE_ROWS`:this.autoResizeRows(e.sheetId,e.rows);break}}getCellWidth(e){let t=this.getters.getCellComputedStyle(e),n=0,r=this.getters.getEvaluatedCell(e).formattedValue;if(r){let e=So(this.ctx,r,t,void 0);n+=Math.max(...e.map(e=>_o(this.ctx,e,t)))}if(this.getters.getConditionalIcon(e)&&(n+=wo(t)),this.getters.doesCellHaveGridIcon(e)&&(n+=20),n===0)return 0;if(n+=8,t.wrapping===`wrap`){let t=this.getters.getColSize(this.getters.getActiveSheetId(),e.col);return Math.min(t,n)}return n}getTextWidth(e,t){return _o(this.ctx,e,t)}getCellText(e,t=!1){let n=this.getters.getCell(e);return t&&n?.isFormula?Vc(n.content,this.getters.getLocale()):t&&!n?.content?``:this.getters.getEvaluatedCell(e).formattedValue}getCellMultiLineText(e,t){let n=this.getters.getCellStyle(e),r=this.getters.getCellText(e,this.getters.shouldShowFormulas());return So(this.ctx,r,n,t)}doesCellHaveGridIcon(e){let t=this.getters.isFilterHeader(e),n=!this.getters.isReadonly()&&this.getters.cellHasListDataValidationIcon(e);return t||n}getColMaxWidth(e,t){let n=ba(this.getters.getColsZone(e,t,t)).map(t=>this.getCellWidth({sheetId:e,...t}));return Math.max(0,Nt(n))}checkSheetExists(e){return`sheetId`in e&&this.getters.tryGetSheet(e.sheetId)===void 0?`InvalidSheetId`:`Success`}checkZonesAreInSheet(e){let t=`sheetId`in e?e.sheetId:this.getters.tryGetActiveSheetId();if(`ranges`in e&&e.ranges.some(e=>!this.getters.tryGetSheet(e._sheetId)))return`InvalidSheetId`;let n=this.getters.getCommandZones(e);return!t&&n.length>0?`NoActiveSheet`:t&&n.length>0?this.getters.checkZonesExistInSheet(t,n):`Success`}autoResizeRows(e,t){let n=[];for(let r of t){let t=0;for(let n of this.getters.getRowCells(e,r)){let r=this.getters.getCellById(n);if(!r)continue;let i=this.getters.getCellPosition(r.id),a=this.getters.getColSize(e,i.col);if(r.isFormula||this.getters.getArrayFormulaSpreadingOn(i)){let e=this.getters.getEvaluatedCell(i).formattedValue,n=ho(this.ctx,e,r?.style,a);n>t&&n>23&&(t=n)}else{let e=r.content,n=ho(this.ctx,e,r?.style,a);n>=t&&n>23&&(t=0)}}n.push(t||null)}let r=new Map(n.map(e=>[e,[]]));for(let e=0;e<n.length;e++)r.get(n[e])?.push(t[e]);for(let[t,n]of r)this.dispatch(`RESIZE_COLUMNS_ROWS`,{elements:n,dimension:`ROW`,size:t,sheetId:e})}};let DA=[OA,kA,jA];function OA(e,t){return`sheetId`in t?{...S(t),sheetId:e.getActiveSheetId()}:t}function kA(e,t){return!(`target`in t)||!Array.isArray(t.target)?t:{...S(t),target:e.getSelectedZones()}}function AA(e,t){return`zone`in t?{...S(t),zone:e.getSelectedZone()}:t}function jA(e,t){if(!(`row`in t)||!(`col`in t))return t;let{col:n,row:r}=e.getActivePosition();return{...S(t),col:n,row:r}}let MA=new ko;function NA(e,t){return{...OA(e,t),id:MA.smallUuid()}}function PA(e,t){return{...OA(e,t),figureId:MA.smallUuid()}}function FA(e,t){let n=OA(e,t);return n.figure.id=MA.smallUuid(),n}function IA(e,t){let n=S(t);n.sheetId=MA.smallUuid();let r=t.name||e.getSheet(e.getActiveSheetId()).name,i=r.match(/(.+?)\d*$/)?.[1]||r;return n.name=e.getNextSheetName(i),n}function LA(e,t){let n=e.getActivePosition();return{...OA(e,t),base:t.dimension===`COL`?n.col:n.row}}function RA(e,t){let n=e.getSelectedZone();return{...OA(e,t),elements:t.dimension===`COL`?w(n.left,n.right+1):w(n.top,n.bottom+1)}}function zA(e,t){let n=e.getSelectedZone();return{...S(t),zone:n}}function BA(e,t){let n=S(t),{top:r,bottom:i,left:a,right:o}=e.getSelectedZone();return`cols`in n?n.cols=w(a,o+1):`rows`in n&&(n.rows=w(r,i+1)),n}function VA(e,t){let n=e.getSelectedZone();return{...OA(e,t),col:n.left,row:n.top,zone:n}}function HA(e,t){return{type:`REPEAT_PASTE`,pasteOption:S(t.pasteOption),target:e.getSelectedZones()}}function UA(e,t){let n=e.getSelectedZone();return{...OA(e,t),start:t.dimension===`COL`?n.left:n.top,end:t.dimension===`COL`?n.right:n.bottom}}let $=new H;$.add(`UPDATE_CELL`,GA),$.add(`CLEAR_CELL`,GA),$.add(`CLEAR_CELLS`,GA),$.add(`DELETE_CONTENT`,GA),$.add(`ADD_MERGE`,GA),$.add(`REMOVE_MERGE`,GA),$.add(`SET_FORMATTING`,GA),$.add(`CLEAR_FORMATTING`,GA),$.add(`SET_BORDER`,GA),$.add(`CREATE_FILTER_TABLE`,GA),$.add(`REMOVE_FILTER_TABLE`,GA),$.add(`HIDE_SHEET`,GA),$.add(`ADD_COLUMNS_ROWS`,LA),$.add(`REMOVE_COLUMNS_ROWS`,RA),$.add(`HIDE_COLUMNS_ROWS`,RA),$.add(`RESIZE_COLUMNS_ROWS`,RA),$.add(`CREATE_SHEET`,IA),$.add(`CREATE_FIGURE`,FA),$.add(`CREATE_CHART`,NA),$.add(`CREATE_IMAGE`,PA),$.add(`GROUP_HEADERS`,UA),$.add(`UNGROUP_HEADERS`,UA),$.add(`UNGROUP_HEADERS`,UA),$.add(`UNFOLD_HEADER_GROUPS_IN_ZONE`,AA),$.add(`FOLD_HEADER_GROUPS_IN_ZONE`,AA);let WA=new H;WA.add(`STOP_EDITION`,JA),WA.add(`PASTE`,HA),WA.add(`INSERT_CELL`,zA),WA.add(`DELETE_CELL`,zA),WA.add(`AUTORESIZE_COLUMNS`,BA),WA.add(`AUTORESIZE_ROWS`,BA),WA.add(`SORT_CELLS`,VA),WA.add(`SUM_SELECTION`,GA),WA.add(`SET_DECIMAL`,GA);function GA(e,t){let n=S(t);for(let t of DA)n=t(e,n);return n}function KA(e,t){if(t&&$.contains(t.type))return $.get(t.type)(e,t)}function qA(e,t,n){if(WA.contains(t.type))return WA.get(t.type)(e,t,n)}function JA(e,t,n){return n.map(t=>KA(e,t)).filter(T)}function YA(e){return!e||!e.rootCommand||typeof e.rootCommand!=`object`?!1:ur(e.rootCommand)?$.contains(e.rootCommand.type):WA.contains(e.rootCommand.type)}function XA(e,t){if(!(!e.rootCommand||typeof e.rootCommand!=`object`))return ur(e.rootCommand)?KA(t,e.rootCommand):qA(t,e.rootCommand,e.commands)}var ZA=class extends Q{static getters=[`canUndo`,`canRedo`];undoStack=[];redoStack=[];session;constructor(e){super(e),this.session=e.session,this.session.on(`new-local-state-update`,this,this.onNewLocalStateUpdate),this.session.on(`snapshot`,this,()=>{this.undoStack=[],this.redoStack=[]})}allowDispatch(e){switch(e.type){case`REQUEST_UNDO`:if(!this.canUndo())return`EmptyUndoStack`;break;case`REQUEST_REDO`:if(!this.canRedo())return`EmptyRedoStack`;break}return`Success`}handle(e){switch(e.type){case`REQUEST_UNDO`:case`REQUEST_REDO`:this.requestHistoryChange(e.type===`REQUEST_UNDO`?`UNDO`:`REDO`)}}finalize(){}requestHistoryChange(e){let t=e===`UNDO`?this.undoStack.pop():this.redoStack.pop();if(!t){let e=this.getPossibleRevisionToRepeat();if(!e)return;let t=XA(e,this.getters);if(!t)return;if(!Array.isArray(t)){this.dispatch(t.type,t);return}for(let e of t)this.dispatch(e.type,e);return}e===`UNDO`?(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?!0:YA(this.getPossibleRevisionToRepeat())}onNewLocalStateUpdate({id:e}){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>99&&this.undoStack.shift()}getPossibleRevisionToRepeat(){return this.session.getLastLocalNonEmptyRevision()}},QA=class extends Q{static getters=[`getAutomaticSeparator`];allowDispatch(e){switch(e.type){case`SPLIT_TEXT_INTO_COLUMNS`:return this.chainValidations(this.batchValidations(this.checkSingleColSelected,this.checkNonEmptySelector),this.batchValidations(this.checkNotOverwritingContent,this.checkSeparatorInSelection))(e)}return`Success`}handle(e){switch(e.type){case`SPLIT_TEXT_INTO_COLUMNS`:this.splitIntoColumns(e);break}}getAutomaticSeparator(){let e=this.getters.getSelectedCells();for(let t of e)if(t.value&&t.type===`text`){let e=this.getAutoSeparatorForString(t.value);if(e)return e}return` `}getAutoSeparatorForString(e){for(let t of[`
1477
+ %s unique rows remain.`,e.toString(),t.toString()),sticky:!1})}checkSingleRangeSelected(){return this.getters.getSelectedZones().length===1?`Success`:`MoreThanOneRangeSelected`}checkNoMergeInZone(){let e=this.getters.getActiveSheetId(),t=this.getters.getSelectedZone();return this.getters.getMergesInZone(e,t).length>0?`WillRemoveExistingMerge`:`Success`}checkRangeContainsValues(e){let t=this.getters.getActiveSheetId(),n=this.getters.getSelectedZone();return e.hasHeader&&(n.top+=1),this.getters.getEvaluatedCellsInZone(t,n).every(e=>e.type===`empty`)?`EmptyTarget`:`Success`}checkNoColumnProvided(e){return e.columns.length===0?`NoColumnsProvided`:`Success`}checkColumnsIncludedInZone(e){let t=this.getters.getSelectedZone();return e.columns.some(e=>e<t.left||e>t.right)?`ColumnsNotIncludedInZone`:`Success`}checkColumnsAreUnique(e){return e.columns.length===new Set(e.columns).size?`Success`:`DuplicatesColumnsSelected`}trimWhitespace(){let e=this.getters.getSelectedZones(),t=this.getters.getActiveSheetId(),n=0;for(let{col:r,row:i}of e.map(ba).flat()){let e=this.getters.getCell({col:r,row:i,sheetId:t});if(!e)continue;let a=jt(e.content);a!==e.content&&(n+=1,this.dispatch(`UPDATE_CELL`,{sheetId:t,col:r,row:i,content:a}))}let r=n?y(`Trimmed whitespace from %s cells.`,n):y(`No selected cells had whitespace trimmed.`);this.ui.notifyUI({type:`info`,text:r,sticky:!1})}},_A=class extends Q{static layers=[3];static getters=[`getSearchMatches`,`getCurrentSelectedMatchIndex`];searchMatches=[];selectedMatchIndex=null;currentSearchRegex=null;searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1};toSearch=``;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(-1);break;case`SELECT_SEARCH_NEXT_MATCH`:this.selectNextCell(1);break;case`REPLACE_SEARCH`:this.replace(e.replaceWith);break;case`REPLACE_ALL_SEARCH`:this.replaceAll(e.replaceWith);break;case`UNDO`:case`REDO`:case`REMOVE_FILTER_TABLE`:case`UPDATE_FILTER`:case`REMOVE_COLUMNS_ROWS`:case`HIDE_COLUMNS_ROWS`:case`UNHIDE_COLUMNS_ROWS`:case`ADD_COLUMNS_ROWS`:case`EVALUATE_CELLS`:case`UPDATE_CELL`:this.isSearchDirty=!0;break;case`ACTIVATE_SHEET`:this.refreshSearch();break}}finalize(){this.isSearchDirty&&=(this.refreshSearch(),!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(){let e=this.findMatches();this.searchMatches=e,this.selectNextCell(0)}updateRegex(){let e=Xe(this.toSearch),t=this.searchOptions.matchCase?``:`i`;this.searchOptions.exactMatch&&(e=`^${e}$`),this.currentSearchRegex=RegExp(e,t)}findMatches(){let e=this.getters.getActiveSheetId(),t=this.getters.getCells(e),n=[];if(this.toSearch&&this.currentSearchRegex)for(let r of Object.values(t)){let{col:t,row:i}=this.getters.getCellPosition(r.id),a={sheetId:e,col:t,row:i},o=this.getters.isColHidden(e,t),s=this.getters.isRowHidden(e,i);if(!(o||s)){if(this.currentSearchRegex.test(this.getSearchableString(a))){let e={col:t,row:i,selected:!1};n.push(e)}for(let e of this.getters.getSpreadPositionsOf(a))if(this.currentSearchRegex.test(this.getSearchableString(e))){let t={col:e.col,row:e.row,selected:!1};n.push(t)}}}return n.sort(this.sortByRowThenColumn)}sortByRowThenColumn(e,t){return e.row===t.row?e.col-t.col:e.row>t.row?1:-1}selectNextCell(e){let t=this.searchMatches;if(!t.length){this.selectedMatchIndex=null;return}let n;n=this.selectedMatchIndex===null?0:this.selectedMatchIndex+e,n=(n%t.length+t.length)%t.length,this.selectedMatchIndex=n,this.selection.selectCell(t[n].col,t[n].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}}replaceMatch(e,t){if(!this.currentSearchRegex)return;let n={sheetId:this.getters.getActiveSheetId(),...e},r=this.getters.getCell(n);if(!r?.content||r?.isFormula&&!this.searchOptions.searchFormulas)return;let i=new RegExp(this.currentSearchRegex.source,this.currentSearchRegex.flags+`g`),a=Ic(this.getSearchableString(n).replace(i,t),this.getters.getLocale());this.dispatch(`UPDATE_CELL`,{...n,content:a})}replace(e){if(this.selectedMatchIndex===null)return;let t=this.searchMatches[this.selectedMatchIndex];this.replaceMatch(t,e)}replaceAll(e){let t=this.searchMatches.length;for(let n=0;n<t;n++)this.replaceMatch(this.searchMatches[n],e)}getSearchableString(e){return this.getters.getCellText(e,this.searchOptions.searchFormulas)}drawGrid(e){let{ctx:t}=e,n=this.getters.getActiveSheetId();for(let e of this.searchMatches){let r=this.getters.getMerge({sheetId:n,col:e.col,row:e.row}),i=r?r.left:e.col,a=r?r.right:e.col,o=r?r.top:e.row,s=r?r.bottom:e.row,{x:c,y:l,width:u,height:d}=this.getters.getVisibleRect({top:o,left:i,right:a,bottom:s});u>0&&d>0&&(t.fillStyle=`#8B008B33`,t.fillRect(c,l,u,d),e.selected&&(t.strokeStyle=`#8B008B`,t.strokeRect(c,l,u,d)))}}},vA=class extends Q{handle(e){switch(e.type){case`SET_DECIMAL`:this.setDecimal(e.sheetId,e.target,e.step);break}}setDecimal(e,t,n){let r={};for(let i of t)for(let t of ba(i)){let i=this.getCellNumberFormat({sheetId:e,...t});if(i!==void 0){let e=Ai(i,n,this.getters.getLocale());r[e]=r[e]||[],r[e].push(t)}}for(let t in r){let n=HO(r[t].map(e=>V(e)));this.dispatch(`SET_FORMATTING`,{sheetId:e,format:t,target:n})}}getCellNumberFormat(e){for(let t of[e]){let e=this.getters.getEvaluatedCell(t);if(e.type===`number`&&!(e.format&&_i(e.format)))return e.format||Ci(e.value)}}},yA=class extends Q{static getters=[`getNextVisibleCellPosition`,`findVisibleHeader`,`findLastVisibleColRowIndex`,`findFirstVisibleColRowIndex`,`isRowHidden`,`isColHidden`,`isHeaderHidden`];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,n){return t===`COL`?this.isColHidden(e,n):this.isRowHidden(e,n)}getNextVisibleCellPosition({sheetId:e,col:t,row:n}){return{sheetId:e,col:this.findVisibleHeader(e,`COL`,t,this.getters.getNumberCols(e)-1)||this.findVisibleHeader(e,`COL`,t,0)||0,row:this.findVisibleHeader(e,`ROW`,n,this.getters.getNumberRows(e)-1)||this.findVisibleHeader(e,`ROW`,n,0)||0}}findVisibleHeader(e,t,n,r){if(n<=r){for(let i=n;i<=r;i++)if(this.getters.doesHeaderExist(e,t,i)&&!this.isHeaderHidden(e,t,i))return i}if(n>r){for(let i=n;i>=r;i--)if(this.getters.doesHeaderExist(e,t,i)&&!this.isHeaderHidden(e,t,i))return i}}findLastVisibleColRowIndex(e,t,{last:n,first:r}){return w(n,r,-1).find(n=>!this.isHeaderHidden(e,t,n))||r}findFirstVisibleColRowIndex(e,t){let n=this.getters.getNumberHeaders(e,t);for(let r=0;r<n;r++)if(t===`COL`&&!this.isColHidden(e,r)||t===`ROW`&&!this.isRowHidden(e,r))return r}exportForExcel(e){for(let t of e.sheets)for(let[e,n]of Object.entries(t.rows))n.isHidden=this.isRowHidden(t.id,Number(e))}},bA=class extends Q{static layers=[1];static getters=[`getHighlights`];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=>{let{numberOfRows:t,numberOfCols:n}=va(e.zone),r=t*n===1?this.getters.expandZone(e.sheetId,e.zone):e.zone;return{...e,zone:r}})}drawGrid(e){let{ctx:t,thinLineWidth:n}=e,r=this.getters.getActiveSheetId(),i=3*n;t.lineWidth=i;let a=this.getHighlights();for(let e of a.filter((e,t)=>a.findIndex(t=>la(t.zone,e.zone)&&t.sheetId===r)===t)){let{x:n,y:r,width:a,height:o}=this.getters.getVisibleRect(e.zone);a>0&&o>0&&(t.strokeStyle=e.color,t.strokeRect(n+i/2,r+i/2,a-i,o-i),t.globalCompositeOperation=`source-over`,t.fillStyle=e.color+`20`,t.fillRect(n+i,r+i,a-2*i,o-2*i))}}},xA=class extends Q{static layers=[0,7];static getters=[`getColDimensionsInViewport`,`getRowDimensionsInViewport`];boxes=[];getColDimensionsInViewport(e,t){let n=Pt(this.getters.getSheetViewVisibleCols()),r=this.getters.getColRowOffsetInViewport(`COL`,n,t),i=this.getters.getColSize(e,t);return{start:r,size:i,end:r+(this.getters.isColHidden(e,t)?0:i)}}getRowDimensionsInViewport(e,t){let n=Pt(this.getters.getSheetViewVisibleRows()),r=this.getters.getColRowOffsetInViewport(`ROW`,n,t),i=this.getters.getRowSize(e,t);return{start:r,size:i,end:r+(this.getters.isRowHidden(e,t)?0:i)}}getHeaderOffset(e,t,n){let r=this.getters.getColRowOffsetInViewport(e,t,n);return this.getters.isDashboard()||(r+=e===`ROW`?26:48),r}drawGrid(e,t){switch(t){case 0:this.drawGlobalBackground(e);for(let{zone:t,rect:n}of this.getters.getAllActiveViewportsZonesAndRect()){let{ctx:r}=e;r.save(),r.beginPath(),r.rect(n.x,n.y,n.width,n.height),r.clip(),this.boxes=this.getGridBoxes(t),this.drawBackground(e),this.drawOverflowingCellBackground(e),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e),this.drawIcon(e),r.restore()}this.drawFrozenPanes(e);break;case 7:this.getters.isDashboard()||(this.drawHeaders(e),this.drawFrozenPanesHeaders(e));break}}drawGlobalBackground(e){let{ctx:t}=e,{width:n,height:r}=this.getters.getSheetViewDimensionWithHeaders();t.fillStyle=`#ffffff`,t.fillRect(0,0,n+oe,r+oe)}drawBackground(e){let{ctx:t,thinLineWidth:n}=e,r=!this.getters.isDashboard()&&this.getters.getGridLinesVisibility(this.getters.getActiveSheetId()),i=r?.1*n:0;if(r)for(let e of this.boxes)t.strokeStyle=`#E2E3E3`,t.lineWidth=n,t.strokeRect(e.x+i,e.y+i,e.width-2*i,e.height-2*i)}drawCellBackground(e){let{ctx:t}=e;for(let e of this.boxes){let n=e.style;n.fillColor&&n.fillColor!==`#ffffff`&&(t.fillStyle=n.fillColor||`#ffffff`,t.fillRect(e.x,e.y,e.width,e.height)),e.isError&&(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())}}drawOverflowingCellBackground(e){let{ctx:t,thinLineWidth:n}=e;for(let e of this.boxes)if(e.content&&e.isOverflow){let r=e.content.align||`left`,i,a,o=e.y+n/2,s=e.height-n,c=Math.min(e.clipRect?.width||1/0,e.content.width);r===`left`?(i=e.x+n/2,a=c-2*n):r===`right`?(i=e.x+e.width-n/2,a=-c+2*n):(i=(e.clipRect?.x||e.x+e.width/2-e.content.width/2)+n/2,a=c-2*n),t.fillStyle=`#ffffff`,t.fillRect(i,o,a,s)}}drawBorders(e){let{ctx:t}=e;for(let e of this.boxes){let t=e.border;if(t){let{x:r,y:i,width:a,height:o}=e;t.left&&n(t.left,r,i,r,i+o),t.top&&n(t.top,r,i,r+a,i),t.right&&n(t.right,r+a,i,r+a,i+o),t.bottom&&n(t.bottom,r,i+o,r+a,i+o)}}function n({style:e,color:n},r,i,a,o){switch(t.strokeStyle=n,e){case`medium`:t.lineWidth=2,r+=i===o?-.5:.5,a+=i===o?1.5:.5,i+=r===a?-.5:.5,o+=r===a?1.5:.5;break;case`thick`:t.lineWidth=3,i===o&&(r--,a++),r===a&&(i--,o++);break;case`dashed`:t.lineWidth=1,t.setLineDash([1,3]);break;case`dotted`:t.lineWidth=1,i===o&&(r+=.5,a+=.5),r===a&&(i+=.5,o+=.5),t.setLineDash([1,1]);break;default:t.lineWidth=1;break}t.beginPath(),t.moveTo(r,i),t.lineTo(a,o),t.stroke(),t.lineWidth=1,t.setLineDash([])}}drawTexts(e){let{ctx:t}=e;t.textBaseline=`top`;let n;for(let e of this.boxes)if(e.content){let r=e.style||{},i=e.content.align||`left`,a=yo(r);a!==n&&(n=a,t.font=a),t.fillStyle=r.textColor||`#000`;let o=e.x;if(i===`left`?o+=4+(e.image?e.image.size+4:0):i===`right`?o+=e.width-4-(e.hasIcon?19:0):o+=e.width/2,t.textAlign=i,e.clipRect){t.save(),t.beginPath();let{x:n,y:r,width:i,height:a}=e.clipRect;t.rect(n,r,i,a),t.clip()}let s=bo(r),c=e.content.textLines.length,l=this.computeTextYCoordinate(e,s,c);for(let n of e.content.textLines)Oo(t,n,{x:Math.round(o),y:Math.round(l)},r.underline,r.strikethrough),l+=4+s;e.clipRect&&t.restore()}}drawIcon(e){let{ctx:t}=e;for(let e of this.boxes)if(e.image){let n=e.image.image;if(e.image.clipIcon){t.save(),t.beginPath();let{x:n,y:r,width:i,height:a}=e.image.clipIcon;t.rect(n,r,i,a),t.clip()}let r=e.image.size,i=this.computeTextYCoordinate(e,r);t.drawImage(n,e.x+4,i,r,r),e.image.clipIcon&&t.restore()}}computeTextYCoordinate(e,t,n=1){let r=e.y+1,i=po(t,n),a=e.height>i+8,o=e.verticalAlign||Ae;if(a){if(o===`middle`)return r+(e.height-i)/2;if(o===`bottom`)return r+e.height-i-4}return r+4}drawHeaders(e){let{ctx:t,thinLineWidth:n}=e,r=this.getters.getSheetViewVisibleCols(),i=r[0],a=this.getters.getSheetViewVisibleRows(),o=a[0],{width:s,height:c}=this.getters.getSheetViewDimensionWithHeaders(),l=this.getters.getSelectedZones(),u=ja(l),d=Ma(l),f=this.getters.getActiveSheetId(),p=this.getters.getNumberCols(f),m=this.getters.getNumberRows(f),h=this.getters.getActiveCols(),g=this.getters.getActiveRows();t.font=`400 11px ${Ne}`,t.textAlign=`center`,t.textBaseline=`middle`,t.lineWidth=n,t.strokeStyle=`#333`;for(let e of r){let n={left:e,right:e,top:0,bottom:m-1},{x:r,width:i}=this.getters.getVisibleRect(n),a=this.getters.doesZonesContainFilter(f,[n]),o=h.has(e),s=u.has(e);o?t.fillStyle=a?ve:ue:s?t.fillStyle=a?be:le:t.fillStyle=a?ye:ce,t.fillRect(r,0,i,26)}for(let e of a){let n={top:e,bottom:e,left:0,right:p-1},{y:r,height:i}=this.getters.getVisibleRect(n),a=this.getters.doesZonesContainFilter(f,[n]),o=g.has(e),s=d.has(e);o?t.fillStyle=a?ve:ue:s?t.fillStyle=a?be:le:t.fillStyle=a?ye:ce,t.fillRect(0,r,48,i)}t.beginPath(),t.moveTo(48,0),t.lineTo(48,c),t.moveTo(0,26),t.lineTo(s,26),t.strokeStyle=`#C0C0C0`,t.stroke(),t.beginPath();for(let e of r){let n=this.getters.getColSize(f,e),r=D(e);t.fillStyle=h.has(e)?`#fff`:de;let a=this.getHeaderOffset(`COL`,i,e);t.fillText(r,a+n/2,26/2),t.moveTo(a+n,0),t.lineTo(a+n,26)}for(let e of a){let n=this.getters.getRowSize(f,e);t.fillStyle=g.has(e)?`#fff`:de;let r=this.getHeaderOffset(`ROW`,o,e);t.fillText(String(e+1),48/2,r+n/2),t.moveTo(0,r+n),t.lineTo(48,r+n)}t.stroke()}drawFrozenPanesHeaders(e){let{ctx:t,thinLineWidth:n}=e,{x:r,y:i}=this.getters.getMainViewportCoordinates(),a=this.getters.isDashboard()?0:48,o=this.getters.isDashboard()?0:26;t.lineWidth=6*n,t.strokeStyle=Te,t.beginPath(),r&&(t.moveTo(a+r,0),t.lineTo(a+r,o)),i&&(t.moveTo(0,o+i),t.lineTo(a,o+i)),t.stroke()}drawFrozenPanes(e){let{ctx:t,thinLineWidth:n}=e,{x:r,y:i}=this.getters.getMainViewportCoordinates(),a=this.getters.getSheetViewVisibleCols(),o=a[0],s=a[a.length-1],c=this.getters.getSheetViewVisibleRows(),l={left:o,right:s,top:c[0],bottom:c[c.length-1]},u=this.getters.getVisibleRect(l),d=this.getters.isDashboard()?0:48,f=this.getters.isDashboard()?0:26;t.lineWidth=6*n,t.strokeStyle=`#DADFE8`,t.beginPath(),r&&(t.moveTo(d+r,f),t.lineTo(d+r,u.height+f)),i&&(t.moveTo(d,f+i),t.lineTo(u.width+d,f+i)),t.stroke()}findNextEmptyCol(e,t,n){let r=this.getters.getActiveSheetId(),i=e;for(;i<t;){let e={sheetId:r,col:i+1,row:n},t=this.getters.getEvaluatedCell(e),a=this.getters.getCellBorderWithFilterBorder(e),o=this.getters.doesCellHaveGridIcon(e),s=this.getters.isCellValidCheckbox(e);if(t.type!==`empty`||this.getters.isInMerge(e)||a?.left||o||s)return i;i++}return i}findPreviousEmptyCol(e,t,n){let r=this.getters.getActiveSheetId(),i=e;for(;i>t;){let e={sheetId:r,col:i-1,row:n},t=this.getters.getEvaluatedCell(e),a=this.getters.getCellBorderWithFilterBorder(e),o=this.getters.doesCellHaveGridIcon(e),s=this.getters.isCellValidCheckbox(e);if(t.type!==`empty`||this.getters.isInMerge(e)||a?.right||o||s)return i;i--}return i}computeCellAlignment(e,t){if(this.getters.getCell(e)?.isFormula&&this.getters.shouldShowFormulas())return`left`;let{align:n}=this.getters.getCellStyle(e),r=this.getters.getEvaluatedCell(e);return t&&r.type===`number`?n===`center`?n:`left`:n||r.defaultAlign}createZoneBox(e,t,n){let{left:r,right:i}=n,a=t.left,o=t.top,s={sheetId:e,col:a,row:o},c=this.getters.getEvaluatedCell(s),l=this.getters.shouldShowFormulas(),{x:u,y:d,width:f,height:p}=this.getters.getRect(t),{verticalAlign:m}=this.getters.getCellStyle(s),h={x:u,y:d,width:f,height:p,border:this.getters.getCellBorderWithFilterBorder(s)||void 0,style:this.getters.getCellComputedStyle(s),verticalAlign:m,isError:c.type===`error`&&c.error.isVerbose||this.getters.isDataValidationInvalid(s)};if(c.type===`empty`||this.getters.isCellValidCheckbox(s))return h;let g=this.getters.getConditionalIcon(s),_=bo(h.style),v=g?4+_:0;g&&(h.image={type:`icon`,size:_,clipIcon:{x:h.x,y:h.y,width:Math.min(v,f),height:p},image:MS[g].img}),h.hasIcon=this.getters.doesCellHaveGridIcon(s);let y=h.hasIcon?19:0,ee=this.getters.getCellComputedStyle(s),te=ee.wrapping||`overflow`,b=te===`wrap`&&!l?f-8:void 0,x=this.getters.getCellMultiLineText(s,b),ne=Math.max(...x.map(e=>this.getters.getTextWidth(e,ee)+4)),re=v+ne+y,ie=this.computeCellAlignment(s,re>f);h.content={textLines:x,width:te===`overflow`?ne:f,align:ie};let ae=re>f||_>p;if(g||h.hasIcon)h.clipRect={x:h.x+v,y:h.y,width:Math.max(0,f-v-y),height:p};else if(ae&&te===`overflow`){let e,n;switch(this.getters.isInMerge(s)?(e=this.getters.getMerge(s).right,n=a):(e=this.findNextEmptyCol(a,i,o),n=this.findPreviousEmptyCol(a,r,o),h.isOverflow=!0),ie){case`left`:{let n=V({col:e,row:o}),{x:r,y:i,width:a,height:s}=this.getters.getVisibleRect(sa(t,n));(a<re||_>s||x.length>1)&&(h.clipRect={x:r,y:i,width:a,height:s});break}case`right`:{let e=V({col:n,row:o}),{x:r,y:i,width:a,height:s}=this.getters.getVisibleRect(sa(t,e));(a<re||_>s||x.length>1)&&(h.clipRect={x:r,y:i,width:a,height:s});break}case`center`:{let r={...t,left:n,right:e},{x:i,y:a,height:o,width:s}=this.getters.getVisibleRect(r),c=re/2,l=h.x+h.width/2;if(i+s<l+c||i>l-c||_>o||x.length>1){let e=i>l-c?i:l-c;h.clipRect={x:e,y:a,width:i+s-e,height:o}}break}}}else(te===`clip`||te===`wrap`||x.length>1)&&(h.clipRect={x:h.x,y:h.y,width:f,height:p});return h}getGridBoxes(e){let t=[],n=this.getters.getSheetViewVisibleCols().filter(t=>t>=e.left&&t<=e.right),r=n[0],i=n[n.length-1],a=this.getters.getSheetViewVisibleRows().filter(t=>t>=e.top&&t<=e.bottom),o={left:r,right:i,top:a[0],bottom:a[a.length-1]},s=this.getters.getActiveSheetId();for(let e of a)for(let r of n){let n={sheetId:s,col:r,row:e};this.getters.isInMerge(n)||t.push(this.createZoneBox(s,V(n),o))}for(let e of this.getters.getMerges(s))if(!this.getters.isMergeHidden(s,e)&&ua(e,o)){let n=this.createZoneBox(s,e,o),r=this.getters.getCellBorder({sheetId:s,col:e.right,row:e.bottom});n.border={...n.border,bottom:r?r.bottom:void 0,right:r?r.right:void 0},n.isMerge=!0,t.push(n)}return t}},SA=class extends Q{inputHasSingleRange;static layers=[1];static getters=[];ranges=[];focusedRangeIndex=null;inputSheetId;constructor(e,t,n){if(n&&t.length>1)throw Error(`Input with a single range cannot be instantiated with several range references.`);super(e),this.inputHasSingleRange=n,this.insertNewRange(0,t),this.inputSheetId=this.getters.getActiveSheetId(),this.ranges.length===0&&(this.insertNewRange(this.ranges.length,[``]),this.focusLast())}handleEvent(e){if(this.focusedRangeIndex===null)return;let t=this.inputSheetId,n=this.getters.getActiveSheetId(),r=e.options.unbounded?this.getters.getUnboundedZone(n,e.anchor.zone):e.anchor.zone,i=this.getters.getRangeFromZone(n,r);if(e.mode===`newAnchor`&&!this.inputHasSingleRange&&this.ranges[this.focusedRangeIndex].xc.trim()!==``){let e=this.getters.getSelectionRangeString(i,t);this.insertNewRange(this.ranges.length,[e]),this.focusLast()}else{let e=i.parts,n=this.ranges[this.focusedRangeIndex].xc.trim();n&&(e=this.getters.getRangeFromSheetXC(t,n).parts);let r=i.clone({parts:e}),a=this.getters.getSelectionRangeString(r,t);this.setRange(this.focusedRangeIndex,[a])}}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`:{let t=this.getIndex(e.rangeId);if(t!==null&&this.focusedRangeIndex!==t&&this.focus(t),t!==null){let n=e.value.replace(/^,+/,``).split(`,`).map(e=>e.trim());this.setRange(t,n)}break}case`ADD_EMPTY_RANGE`:this.insertNewRange(this.ranges.length,[``]),this.focusLast();break;case`ADD_RANGE`:this.insertNewRange(this.ranges.length,[e.value]),this.focusLast();break;case`REMOVE_RANGE`:let t=this.getIndex(e.rangeId);t!==null&&this.removeRange(t);break;case`ACTIVATE_SHEET`:if(e.sheetIdFrom!==e.sheetIdTo){let{col:t,row:n}=this.getters.getNextVisibleCellPosition({sheetId:e.sheetIdTo,col:0,row:0}),r=this.getters.expandZone(e.sheetIdTo,V({col:t,row:n}));this.selection.resetAnchor(this,{cell:{col:t,row:n},zone:r})}break;case`START_CHANGE_HIGHLIGHT`:let n=this.getters.getActiveSheetId(),r=this.getters.expandZone(n,e.zone),i=this.ranges.findIndex(e=>{let{xc:t,sheetName:i}=Xi(e.xc),a=i||this.getters.getSheetName(this.inputSheetId);if(this.getters.getSheetName(n)!==a)return!1;let o=this.getters.getRangeFromSheetXC(n,t);return la(this.getters.expandZone(n,o.zone),r)});if(i!==-1){this.focus(i);let{left:e,top:t}=r;this.selection.resetAnchor(this,{cell:{col:e,row:t},zone:r})}break}}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}setContent(e,t){this.ranges[e]={...this.ranges[e],xc:t}}insertNewRange(e,t){let n=Math.max(0,...this.ranges.map(e=>Number(e.id)));this.ranges.splice(e,0,...t.map((e,t)=>({xc:e,id:n+t+1,color:Lt[(n+t)%Lt.length]})))}setRange(e,t){let[,...n]=t;this.setContent(e,t[0]),this.insertNewRange(e+1,n),n.length&&this.focus(e+n.length)}removeRange(e){this.ranges.splice(e,1),this.focusedRangeIndex!==null&&this.focusLast()}inputToHighlights({xc:e,color:t}){return this.cleanInputs([e]).filter(e=>this.getters.isRangeValid(e)).filter(e=>this.shouldBeHighlighted(this.inputSheetId,e)).map(e=>{let{sheetName:n}=Xi(e);return{zone:this.getters.getRangeFromSheetXC(this.inputSheetId,e).zone,sheetId:n&&this.getters.getSheetIdByName(n)||this.inputSheetId,color:t}})}cleanInputs(e){return e.map(e=>e.split(`,`)).flat().map(e=>e.trim()).filter(e=>e!==``)}shouldBeHighlighted(e,t){let{sheetName:n}=Xi(t),r=this.getters.getSheetIdByName(n),i=this.getters.getActiveSheet().id;return this.getters.isRangeValid(t)&&(r===i||r===void 0&&i===e)}getIndex(e){let t=this.ranges.findIndex(t=>t.id===e);return t>=0?t:null}},CA=class extends Q{config;static layers=[1];static getters=[`getSelectionInput`,`getSelectionInputValue`,`isRangeValid`,`getSelectionInputHighlights`];inputs={};focusedInputId=null;get currentInput(){return this.focusedInputId?this.inputs[this.focusedInputId]:null}constructor(e){super(e),this.config=e}allowDispatch(e){switch(e.type){case`FOCUS_RANGE`:case`CHANGE_RANGE`:case`ADD_EMPTY_RANGE`:case`REMOVE_RANGE`:if(!this.inputs[e.id])return`InvalidInputId`}switch(e.type){case`FOCUS_RANGE`:let t=this.currentInput?.getIndex(e.rangeId);if(this.focusedInputId===e.id&&this.currentInput?.focusedRangeIndex===t)return`InputAlreadyFocused`;break;case`ADD_RANGE`:case`ADD_EMPTY_RANGE`:let n=this.inputs[e.id];if(n.inputHasSingleRange&&n.ranges.length===1)return`MaximumRangesReached`;break;case`REMOVE_RANGE`:if(this.inputs[e.id].ranges.length===1)return`MinimumRangesReached`;break;case`CHANGE_RANGE`:if(this.inputs[e.id].inputHasSingleRange&&e.value.split(`,`).length>1)return`MaximumRangesReached`;break}return`Success`}handle(e){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_RANGE`:case`ADD_EMPTY_RANGE`:case`REMOVE_RANGE`:if(e.id!==this.focusedInputId){let t=this.inputs[e.id];this.selection.capture(t,{cell:{col:0,row:0},zone:V({col:0,row:0})},{handleEvent:t.handleEvent.bind(t),release:()=>this.focusedInputId=null}),this.focusedInputId=e.id}break;case`FOCUS_RANGE`:case`CHANGE_RANGE`:let t=this.inputs[e.id],n=t.ranges.find(t=>t.id===e.rangeId);if(n){let e=this.getters.getActiveSheetId(),r=this.getters.getRangeFromSheetXC(e,n?.xc||`A1`).zone;this.selection.capture(t,{cell:{col:r.left,row:r.top},zone:r},{handleEvent:t.handleEvent.bind(t),release:()=>this.focusedInputId=null})}this.focusedInputId=e.id;break}this.currentInput?.handle(e)}getSelectionInput(e){return this.inputs[e]?this.inputs[e].ranges.map((t,n)=>Object.assign({},t,{color:this.focusedInputId===e&&this.inputs[e].focusedRangeIndex!==null&&this.isRangeValid(t.xc)?t.color:null,isFocused:this.focusedInputId===e&&this.inputs[e].focusedRangeIndex===n})):[]}isRangeValid(e){if(!e)return!1;let{xc:t,sheetName:n}=Xi(e);return t.match(Wi)!==null&&(!n||this.getters.getSheetIdByName(n)!==void 0)}getSelectionInputValue(e){return this.inputs[e].getSelectionInputValue()}getSelectionInputHighlights(){return this.focusedInputId?this.inputs[this.focusedInputId].getSelectionInputHighlights():[]}initInput(e,t,n=!1){if(this.inputs[e]&&this.unfocus(),this.inputs[e]=new SA(this.config,t,n),t.length===0){let t=this.inputs[e],n={zone:V({col:0,row:0}),cell:{col:0,row:0}};this.selection.capture(t,n,{handleEvent:t.handleEvent.bind(t),release:()=>this.focusedInputId=null}),this.focusedInputId=e}}unfocus(){this.selection.release(this.currentInput),this.focusedInputId=null}},wA=class extends Q{static getters=[`getContiguousZone`];allowDispatch(e){switch(e.type){case`SORT_CELLS`:if(!da(e.col,e.row,e.zone))throw Error(y(`The anchor must be part of the provided zone`));return this.checkValidations(e,this.checkMerge,this.checkMergeSizes)}return`Success`}handle(e){switch(e.type){case`SORT_CELLS`:this.sortZone(e.sheetId,e,e.zone,e.sortDirection,e.sortOptions||{});break}}checkMerge({sheetId:e,zone:t}){return this.getters.doesIntersectMerge(e,t)&&ba(t).some(({col:t,row:n})=>!this.getters.isInMerge({sheetId:e,col:t,row:n}))?`InvalidSortZone`:`Success`}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return`Success`;let n=this.getters.getMerges(e).filter(e=>ua(e,t)),r=va(n[0]),[i,a]=[r.numberOfCols,r.numberOfRows];return n.every(e=>{let[t,n]=[e.right-e.left+1,e.bottom-e.top+1];return t===i&&n===a})?`Success`:`InvalidSortZone`}expand(e,t){let{left:n,right:r,top:i,bottom:a}=this.getters.expandZone(e,t);return{left:Math.max(0,n),right:Math.min(this.getters.getNumberCols(e)-1,r),top:Math.max(0,i),bottom:Math.min(this.getters.getNumberRows(e)-1,a)}}checkExpandedValues(e,t){let n=this.expand(e,t),r;if(this.getters.doesIntersectMerge(e,n)){let{left:t,right:i,top:a,bottom:o}=n;for(let n=t;n<=i;n++)for(let t=a;t<=o;t++){let{col:i,row:a}=this.getters.getMainCellPosition({sheetId:e,col:n,row:t});if(r=this.getters.getEvaluatedCell({sheetId:e,col:i,row:a}),r.formattedValue)return!0}}else for(let t of this.getters.getEvaluatedCellsInZone(e,n))if(t.formattedValue)return!0;return!1}getContiguousZone(e,t){let{top:n,bottom:r,left:i,right:a}=t,o,s=!1;for(;!s;)s=!0,n>0&&(o=this.checkExpandedValues(e,{left:i-1,right:a+1,top:n-1,bottom:n-1}),o&&(s=!1,n--)),i>0&&(o=this.checkExpandedValues(e,{left:i-1,right:i-1,top:n-1,bottom:r+1}),o&&(s=!1,i--)),a<this.getters.getNumberCols(e)-1&&(o=this.checkExpandedValues(e,{left:a+1,right:a+1,top:n-1,bottom:r+1}),o&&(s=!1,a++)),r<this.getters.getNumberRows(e)-1&&(o=this.checkExpandedValues(e,{left:i-1,right:a+1,top:r+1,bottom:r+1}),o&&(s=!1,r++));return{left:i,right:a,top:n,bottom:r}}hasHeader(e,t){if(t[0].length===1)return!1;let n=t.map(t=>t.map(({col:t,row:n})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:n}).type));return n[0][0]===`empty`&&(n=n.slice(1)),n.some(e=>e[0]===`empty`)?!1:!!n.some(e=>e[1]!==`empty`&&e[0]!==e[1])}sortZone(e,t,n,r,i){let[a,o]=this.mainCellsSteps(e,n),s=this.getters.getMainCellPosition({sheetId:e,col:t.col,row:t.row}).col,c=Object.assign({},n),l=this.mainCells(e,n);!i.sortHeaders&&this.hasHeader(e,l)&&(c.top+=o),l=this.mainCells(e,c);let u=l[s-c.left],d=_g(u.map(e=>this.getters.getEvaluatedCell(e)),r,!!i.emptyCellAsZero).map(e=>e.index),[f,p]=[l.length,l[0].length],m=[];for(let e=0;e<f;e++)for(let t=0;t<p;t++){let{col:n,row:r,sheetId:i}=l[e][d[t]],s=this.getters.getCell({sheetId:i,col:n,row:r}),u=c.left+e*a,f=c.top+t*o,p={sheetId:i,col:u,row:f,content:``};if(s){let e=s.content;if(s.isFormula){let t=this.getters.getCellPosition(s.id);e=this.getters.getTranslatedCellFormula(i,0,f-t.row,s.compiledFormula)}p.style=s.style,p.content=e,p.format=s.format}m.push(p)}m.forEach(e=>this.dispatch(`UPDATE_CELL`,e))}mainCellsSteps(e,t){let n=this.getters.getMerge({sheetId:e,col:t.left,row:t.top});return[n?n.right-n.left+1:1,n?n.bottom-n.top+1:1]}mainCells(e,t){let[n,r]=this.mainCellsSteps(e,t),i=[],a=w(t.left,t.right+1,n),o=w(t.top,t.bottom+1,r);for(let t of a){let n=[];i.push(n);for(let r of o)n.push({sheetId:e,col:t,row:r})}return i}},TA=class extends Q{static getters=[`shouldShowFormulas`];showFormulas=!1;handle(e){switch(e.type){case`SET_FORMULA_VISIBILITY`:this.showFormulas=e.show;break}}shouldShowFormulas(){return this.showFormulas}},EA=class extends Q{static getters=[`doesCellHaveGridIcon`,`getCellWidth`,`getTextWidth`,`getCellText`,`getCellMultiLineText`];ctx=document.createElement(`canvas`).getContext(`2d`);allowDispatch(e){return this.chainValidations(this.checkSheetExists,this.checkZonesAreInSheet)(e)}handle(e){switch(e.type){case`AUTORESIZE_COLUMNS`:for(let t of e.cols){let n=this.getColMaxWidth(e.sheetId,t);n!==0&&this.dispatch(`RESIZE_COLUMNS_ROWS`,{elements:[t],dimension:`COL`,size:n,sheetId:e.sheetId})}break;case`AUTORESIZE_ROWS`:this.autoResizeRows(e.sheetId,e.rows);break}}getCellWidth(e){let t=this.getters.getCellComputedStyle(e),n=0,r=this.getters.getEvaluatedCell(e).formattedValue;if(r){let e=So(this.ctx,r,t,void 0);n+=Math.max(...e.map(e=>_o(this.ctx,e,t)))}if(this.getters.getConditionalIcon(e)&&(n+=wo(t)),this.getters.doesCellHaveGridIcon(e)&&(n+=20),n===0)return 0;if(n+=8,t.wrapping===`wrap`){let t=this.getters.getColSize(e.sheetId,e.col);return Math.min(t,n)}return n}getTextWidth(e,t){return _o(this.ctx,e,t)}getCellText(e,t=!1){let n=this.getters.getCell(e);return t&&n?.isFormula?Vc(n.content,this.getters.getLocale()):t&&!n?.content?``:this.getters.getEvaluatedCell(e).formattedValue}getCellMultiLineText(e,t){let n=this.getters.getCellStyle(e),r=this.getters.getCellText(e,this.getters.shouldShowFormulas());return So(this.ctx,r,n,t)}doesCellHaveGridIcon(e){let t=this.getters.isFilterHeader(e),n=!this.getters.isReadonly()&&this.getters.cellHasListDataValidationIcon(e);return t||n}getColMaxWidth(e,t){let n=ba(this.getters.getColsZone(e,t,t)).map(t=>this.getCellWidth({sheetId:e,...t}));return Math.max(0,Nt(n))}checkSheetExists(e){return`sheetId`in e&&this.getters.tryGetSheet(e.sheetId)===void 0?`InvalidSheetId`:`Success`}checkZonesAreInSheet(e){let t=`sheetId`in e?e.sheetId:this.getters.tryGetActiveSheetId();if(`ranges`in e&&e.ranges.some(e=>!this.getters.tryGetSheet(e._sheetId)))return`InvalidSheetId`;let n=this.getters.getCommandZones(e);return!t&&n.length>0?`NoActiveSheet`:t&&n.length>0?this.getters.checkZonesExistInSheet(t,n):`Success`}autoResizeRows(e,t){let n=[];for(let r of t){let t=0;for(let n of this.getters.getRowCells(e,r)){let r=this.getters.getCellById(n);if(!r)continue;let i=this.getters.getCellPosition(r.id),a=this.getters.getColSize(e,i.col);if(r.isFormula||this.getters.getArrayFormulaSpreadingOn(i)){let e=this.getters.getEvaluatedCell(i).formattedValue,n=ho(this.ctx,e,r?.style,a);n>t&&n>23&&(t=n)}else{let e=r.content,n=ho(this.ctx,e,r?.style,a);n>=t&&n>23&&(t=0)}}n.push(t||null)}let r=new Map(n.map(e=>[e,[]]));for(let e=0;e<n.length;e++)r.get(n[e])?.push(t[e]);for(let[t,n]of r)this.dispatch(`RESIZE_COLUMNS_ROWS`,{elements:n,dimension:`ROW`,size:t,sheetId:e})}};let DA=[OA,kA,jA];function OA(e,t){return`sheetId`in t?{...S(t),sheetId:e.getActiveSheetId()}:t}function kA(e,t){return!(`target`in t)||!Array.isArray(t.target)?t:{...S(t),target:e.getSelectedZones()}}function AA(e,t){return`zone`in t?{...S(t),zone:e.getSelectedZone()}:t}function jA(e,t){if(!(`row`in t)||!(`col`in t))return t;let{col:n,row:r}=e.getActivePosition();return{...S(t),col:n,row:r}}let MA=new ko;function NA(e,t){return{...OA(e,t),id:MA.smallUuid()}}function PA(e,t){return{...OA(e,t),figureId:MA.smallUuid()}}function FA(e,t){let n=OA(e,t);return n.figure.id=MA.smallUuid(),n}function IA(e,t){let n=S(t);n.sheetId=MA.smallUuid();let r=t.name||e.getSheet(e.getActiveSheetId()).name,i=r.match(/(.+?)\d*$/)?.[1]||r;return n.name=e.getNextSheetName(i),n}function LA(e,t){let n=e.getActivePosition();return{...OA(e,t),base:t.dimension===`COL`?n.col:n.row}}function RA(e,t){let n=e.getSelectedZone();return{...OA(e,t),elements:t.dimension===`COL`?w(n.left,n.right+1):w(n.top,n.bottom+1)}}function zA(e,t){let n=e.getSelectedZone();return{...S(t),zone:n}}function BA(e,t){let n=S(t),{top:r,bottom:i,left:a,right:o}=e.getSelectedZone();return`cols`in n?n.cols=w(a,o+1):`rows`in n&&(n.rows=w(r,i+1)),n}function VA(e,t){let n=e.getSelectedZone();return{...OA(e,t),col:n.left,row:n.top,zone:n}}function HA(e,t){return{type:`REPEAT_PASTE`,pasteOption:S(t.pasteOption),target:e.getSelectedZones()}}function UA(e,t){let n=e.getSelectedZone();return{...OA(e,t),start:t.dimension===`COL`?n.left:n.top,end:t.dimension===`COL`?n.right:n.bottom}}let $=new H;$.add(`UPDATE_CELL`,GA),$.add(`CLEAR_CELL`,GA),$.add(`CLEAR_CELLS`,GA),$.add(`DELETE_CONTENT`,GA),$.add(`ADD_MERGE`,GA),$.add(`REMOVE_MERGE`,GA),$.add(`SET_FORMATTING`,GA),$.add(`CLEAR_FORMATTING`,GA),$.add(`SET_BORDER`,GA),$.add(`CREATE_FILTER_TABLE`,GA),$.add(`REMOVE_FILTER_TABLE`,GA),$.add(`HIDE_SHEET`,GA),$.add(`ADD_COLUMNS_ROWS`,LA),$.add(`REMOVE_COLUMNS_ROWS`,RA),$.add(`HIDE_COLUMNS_ROWS`,RA),$.add(`RESIZE_COLUMNS_ROWS`,RA),$.add(`CREATE_SHEET`,IA),$.add(`CREATE_FIGURE`,FA),$.add(`CREATE_CHART`,NA),$.add(`CREATE_IMAGE`,PA),$.add(`GROUP_HEADERS`,UA),$.add(`UNGROUP_HEADERS`,UA),$.add(`UNGROUP_HEADERS`,UA),$.add(`UNFOLD_HEADER_GROUPS_IN_ZONE`,AA),$.add(`FOLD_HEADER_GROUPS_IN_ZONE`,AA);let WA=new H;WA.add(`STOP_EDITION`,JA),WA.add(`PASTE`,HA),WA.add(`INSERT_CELL`,zA),WA.add(`DELETE_CELL`,zA),WA.add(`AUTORESIZE_COLUMNS`,BA),WA.add(`AUTORESIZE_ROWS`,BA),WA.add(`SORT_CELLS`,VA),WA.add(`SUM_SELECTION`,GA),WA.add(`SET_DECIMAL`,GA);function GA(e,t){let n=S(t);for(let t of DA)n=t(e,n);return n}function KA(e,t){if(t&&$.contains(t.type))return $.get(t.type)(e,t)}function qA(e,t,n){if(WA.contains(t.type))return WA.get(t.type)(e,t,n)}function JA(e,t,n){return n.map(t=>KA(e,t)).filter(T)}function YA(e){return!e||!e.rootCommand||typeof e.rootCommand!=`object`?!1:ur(e.rootCommand)?$.contains(e.rootCommand.type):WA.contains(e.rootCommand.type)}function XA(e,t){if(!(!e.rootCommand||typeof e.rootCommand!=`object`))return ur(e.rootCommand)?KA(t,e.rootCommand):qA(t,e.rootCommand,e.commands)}var ZA=class extends Q{static getters=[`canUndo`,`canRedo`];undoStack=[];redoStack=[];session;constructor(e){super(e),this.session=e.session,this.session.on(`new-local-state-update`,this,this.onNewLocalStateUpdate),this.session.on(`snapshot`,this,()=>{this.undoStack=[],this.redoStack=[]})}allowDispatch(e){switch(e.type){case`REQUEST_UNDO`:if(!this.canUndo())return`EmptyUndoStack`;break;case`REQUEST_REDO`:if(!this.canRedo())return`EmptyRedoStack`;break}return`Success`}handle(e){switch(e.type){case`REQUEST_UNDO`:case`REQUEST_REDO`:this.requestHistoryChange(e.type===`REQUEST_UNDO`?`UNDO`:`REDO`)}}finalize(){}requestHistoryChange(e){let t=e===`UNDO`?this.undoStack.pop():this.redoStack.pop();if(!t){let e=this.getPossibleRevisionToRepeat();if(!e)return;let t=XA(e,this.getters);if(!t)return;if(!Array.isArray(t)){this.dispatch(t.type,t);return}for(let e of t)this.dispatch(e.type,e);return}e===`UNDO`?(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?!0:YA(this.getPossibleRevisionToRepeat())}onNewLocalStateUpdate({id:e}){this.undoStack.push(e),this.redoStack=[],this.undoStack.length>99&&this.undoStack.shift()}getPossibleRevisionToRepeat(){return this.session.getLastLocalNonEmptyRevision()}},QA=class extends Q{static getters=[`getAutomaticSeparator`];allowDispatch(e){switch(e.type){case`SPLIT_TEXT_INTO_COLUMNS`:return this.chainValidations(this.batchValidations(this.checkSingleColSelected,this.checkNonEmptySelector),this.batchValidations(this.checkNotOverwritingContent,this.checkSeparatorInSelection))(e)}return`Success`}handle(e){switch(e.type){case`SPLIT_TEXT_INTO_COLUMNS`:this.splitIntoColumns(e);break}}getAutomaticSeparator(){let e=this.getters.getSelectedCells();for(let t of e)if(t.value&&t.type===`text`){let e=this.getAutoSeparatorForString(t.value);if(e)return e}return` `}getAutoSeparatorForString(e){for(let t of[`
1478
1478
  `,`;`,`,`,` `,`.`])if(e.includes(t))return t}splitIntoColumns({separator:e,addNewColumns:t}){let n=this.getters.getSelectedZone(),r=this.getters.getActiveSheetId(),i=this.getSplittedCols(n,e);t&&this.addColsToAvoidCollisions(n,i),this.removeMergesInSplitZone(n,i),this.addColumnsToNotOverflowSheet(n,i);for(let e=0;e<i.length;e++){let t=n.top+e,a=i[e],o=n.left,s=this.getters.getCell({sheetId:r,col:o,row:t});if(!(a.length===1&&a[0]===s?.content))for(let[e,n]of a.entries())this.dispatch(`UPDATE_CELL`,{sheetId:r,col:o+e,row:t,content:Ic(n,this.getters.getLocale()),format:``,style:s?.style||null})}}getSplittedCols(e,t){if(!t)throw Error(`Separator cannot be empty`);let n=this.getters.getActiveSheetId(),r=[];for(let i of w(e.top,e.bottom+1)){let a=this.getters.getEvaluatedCell({sheetId:n,col:e.left,row:i}).formattedValue;r.push(this.splitAndRemoveTrailingEmpty(a,t))}return r}splitAndRemoveTrailingEmpty(e,t){let n=e.split(t);for(;n.length>1&&n[n.length-1]===``;)n.pop();return n}willSplittedColsOverwriteContent(e,t){let n=this.getters.getActiveSheetId();for(let r of w(e.top,e.bottom+1)){let i=t[r-e.top];for(let t=1;t<i.length;t++){let i=this.getters.getCell({sheetId:n,col:e.left+t,row:r});if(i&&i.content)return!0}}return!1}removeMergesInSplitZone(e,t){let n=this.getters.getActiveSheetId(),r=Math.max(...t.map(e=>e.length)),i={...e,right:e.left+r-1},a=this.getters.getMergesInZone(n,i);this.dispatch(`REMOVE_MERGE`,{sheetId:n,target:a})}addColsToAvoidCollisions(e,t){let n=this.getters.getActiveSheetId(),r=0;for(let i of w(e.top,e.bottom+1)){let a={sheetId:n,col:e.left,row:i},o=t[i-e.top],s=this.getColsToAddToAvoidCollision(a,o);r=Math.max(r,s)}r&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`COL`,base:e.left,sheetId:n,quantity:r,position:`after`})}getColsToAddToAvoidCollision(e,t){let n=t.length;for(let t=1;t<n;t++){let r=e.col+t,i=this.getters.getCell({...e,col:r});if(i&&i.content)return n-t}return 0}addColumnsToNotOverflowSheet(e,t){let n=this.getters.getActiveSheetId(),r=Math.max(...t.map(e=>e.length-1)),i=this.getters.getNumberCols(n)-1;e.left+r>i&&this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:`COL`,base:i,sheetId:n,quantity:e.left+r-i,position:`after`})}checkSingleColSelected(){return this.getters.isSingleColSelected()?`Success`:`MoreThanOneColumnSelected`}checkNonEmptySelector(e){return e.separator===``?`EmptySplitSeparator`:`Success`}checkNotOverwritingContent(e){if(e.addNewColumns||e.force)return`Success`;let t=this.getters.getSelectedZones()[0],n=this.getSplittedCols(t,e.separator);return this.willSplittedColsOverwriteContent(t,n)?`SplitWillOverwriteContent`:`Success`}checkSeparatorInSelection({separator:e}){let t=this.getters.getSelectedCells();for(let n of t)if(n.formattedValue.includes(e))return`Success`;return`NoSplitSeparatorInSelection`}},$A=class{operation;getters;dispatch;sheetId;copiedFigure;copiedFigureContent;constructor(e,t,n){this.operation=e,this.getters=t,this.dispatch=n,this.sheetId=t.getActiveSheetId();let r=t.getSelectedFigureId();if(!r)throw Error(`No figure selected`);let i=t.getFigure(this.sheetId,r);if(!i)throw Error(`No figure for the given id: ${r}`);switch(this.copiedFigure={...i},i.tag){case`chart`:this.copiedFigureContent=new ej(n,t,this.sheetId,r);break;case`image`:this.copiedFigureContent=new tj(n,t,this.sheetId,r);break;default:throw Error(`Unknow tag '${i.tag}' for the given figure id: ${r}`)}}isCutAllowed(e){return`Success`}isPasteAllowed(e,t){return e.length===0?`EmptyTarget`:t?.pasteOption===void 0?`Success`:`WrongFigurePasteOption`}paste(e){let t=this.getters.getActiveSheetId(),{width:n,height:r}=this.copiedFigure,i=this.getters.getNumberCols(t),a=this.getters.getNumberRows(t),o=this.getters.getColDimensions(t,e[0].left).start,s=this.getters.getRowDimensions(t,e[0].top).start,c=this.getters.getColDimensions(t,i-1).end,l=this.getters.getRowDimensions(t,a-1).end,u={x:c<n?0:Math.min(o,c-n),y:l<r?0:Math.min(s,l-r)},d=new ko().smallUuid();this.copiedFigureContent.paste(t,d,u,{height:r,width:n}),this.operation===`CUT`&&this.dispatch(`DELETE_FIGURE`,{sheetId:this.copiedFigureContent.sheetId,id:this.copiedFigure.id}),this.dispatch(`SELECT_FIGURE`,{id:d})}getClipboardContent(){return{"text/plain":` `}}isColRowDirtyingClipboard(e,t){return!1}drawClipboard(e){}},ej=class{dispatch;sheetId;copiedChart;constructor(e,t,n,r){this.dispatch=e,this.sheetId=n;let i=t.getChart(r);if(!i)throw Error(`No chart for the given id: ${r}`);this.copiedChart=i.copyInSheetId(n)}paste(e,t,n,r){let i=this.copiedChart.copyInSheetId(e);this.dispatch(`CREATE_CHART`,{id:t,sheetId:e,position:n,size:r,definition:i.getDefinition()})}},tj=class{dispatch;sheetId;copiedImage;constructor(e,t,n,r){this.dispatch=e,this.sheetId=n;let i=t.getImage(r);this.copiedImage=S(i)}paste(e,t,n,r){let i=S(this.copiedImage);this.dispatch(`CREATE_IMAGE`,{figureId:t,sheetId:e,position:n,size:r,definition:i})}},nj=class extends mA{values;constructor(e,t,n,r){super(`COPY`,t,n,r),this.values=e.replace(/\r/g,``).split(`
1479
1479
  `).map(e=>e.split(` `))}isPasteAllowed(e,t){let n=this.getters.getActiveSheetId(),r=this.getPasteZone(e);return this.getters.doesIntersectMerge(n,r)?`WillRemoveExistingMerge`:`Success`}paste(e,t){if(t?.pasteOption===`onlyFormat`)return;let n=this.values,r=this.getPasteZone(e),{left:i,top:a}=r,{numberOfCols:o,numberOfRows:s}=va(r),c=this.getters.getActiveSheetId(),l=this.getters.getLocale();this.addMissingDimensions(o,s,i,a);for(let e=0;e<n.length;e++)for(let t=0;t<n[e].length;t++)this.dispatch(`UPDATE_CELL`,{row:a+e,col:i+t,content:zc(n[e][t],l),sheetId:c});let u={left:i,top:a,right:i+o-1,bottom:a+s-1};this.selection.selectZone({cell:{col:i,row:a},zone:u},{scrollIntoView:!1})}getClipboardContent(){return{"text/plain":this.values.map(e=>e.join(` `)).join(`
1480
1480
  `)}}getPasteZone(e){let t=this.values.length,n=Nt(this.values.map(e=>e.length)),{left:r,top:i}=e[0];return{top:i,left:r,bottom:i+t-1,right:r+n-1}}},rj=class extends Q{static layers=[2];static getters=[`getClipboardContent`,`getClipboardTextContent`,`isCutOperation`,`isPaintingFormat`];status=`invisible`;state;lastPasteState;paintFormatStatus=`inactive`;originSheetId;allowDispatch(e){switch(e.type){case`CUT`:let t=this.getters.getSelectedZones();return this.getClipboardState(t,e.type).isCutAllowed(t);case`PASTE`:if(!this.state)return`EmptyClipboard`;let n=e.pasteOption||(this.paintFormatStatus===`inactive`?void 0:`onlyFormat`);return this.state.isPasteAllowed(e.target,{pasteOption:n});case`PASTE_FROM_OS_CLIPBOARD`:return new nj(e.text,this.getters,this.dispatch,this.selection).isPasteAllowed(e.target,{pasteOption:e.pasteOption});case`COPY_PASTE_CELLS_ABOVE`:{let e=this.getters.getSelectedZones();if(e.length>1||e[0].top===0&&e[0].bottom===0)return`InvalidCopyPasteSelection`;break}case`COPY_PASTE_CELLS_ON_LEFT`:{let e=this.getters.getSelectedZones();if(e.length>1||e[0].left===0&&e[0].right===0)return`InvalidCopyPasteSelection`;break}case`INSERT_CELL`:{let{cut:t,paste:n}=this.getInsertCellsTargets(e.zone,e.shiftDimension);return this.getClipboardStateForCopyCells(t,`CUT`,`shiftCells`).isPasteAllowed(n)}case`DELETE_CELL`:{let{cut:t,paste:n}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);return this.getClipboardStateForCopyCells(t,`CUT`,`shiftCells`).isPasteAllowed(n)}case`ACTIVATE_PAINT_FORMAT`:if(this.paintFormatStatus!==`inactive`)return`AlreadyInPaintingFormatMode`}return`Success`}handle(e){switch(e.type){case`COPY`:case`CUT`:let t=this.getters.getSelectedZones();this.state=this.getClipboardState(t,e.type),this.status=`visible`,this.originSheetId=this.getters.getActiveSheetId();break;case`PASTE`:if(!this.state)break;let n=e.pasteOption||(this.paintFormatStatus===`inactive`?void 0:`onlyFormat`);this.state.paste(e.target,{pasteOption:n,shouldPasteCF:!0,selectTarget:!0}),this.state.operation===`CUT`&&(this.state=void 0),this.lastPasteState=this.state,this.paintFormatStatus===`oneOff`&&(this.paintFormatStatus=`inactive`),this.status=`invisible`;break;case`COPY_PASTE_CELLS_ABOVE`:{let e=this.getters.getSelectedZone(),t=e.top!==e.bottom,n={...e,bottom:t?e.top:e.top-1,top:t?e.top:e.top-1};this.getClipboardStateForCopyCells([n],`COPY`).paste([e],{pasteOption:void 0,shouldPasteCF:!0,selectTarget:!0})}break;case`COPY_PASTE_CELLS_ON_LEFT`:{let e=this.getters.getSelectedZone(),t=e.left!==e.right,n={...e,right:t?e.left:e.left-1,left:t?e.left:e.left-1};this.getClipboardStateForCopyCells([n],`COPY`).paste([e],{pasteOption:void 0,shouldPasteCF:!0,selectTarget:!0})}break;case`CLEAN_CLIPBOARD_HIGHLIGHT`:this.status=`invisible`;break;case`DELETE_CELL`:{let{cut:t,paste:n}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);if(!ta(t[0])){this.dispatch(`CLEAR_CELLS`,{target:[e.zone],sheetId:this.getters.getActiveSheetId()});break}this.getClipboardStateForCopyCells(t,`CUT`,`shiftCells`).paste(n);break}case`INSERT_CELL`:{let{cut:t,paste:n}=this.getInsertCellsTargets(e.zone,e.shiftDimension);this.getClipboardStateForCopyCells(t,`CUT`,`shiftCells`).paste(n);break}case`ADD_COLUMNS_ROWS`:if(this.status=`invisible`,this.state?.operation!==`CUT`||e.sheetId!==this.state?.sheetId)return;this.state.isColRowDirtyingClipboard(e.position===`before`?e.base:e.base+1,e.dimension)&&(this.state=void 0);break;case`REMOVE_COLUMNS_ROWS`:if(this.status=`invisible`,this.state?.operation!==`CUT`||e.sheetId!==this.state?.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`:this.state=new nj(e.text,this.getters,this.dispatch,this.selection),this.state.paste(e.target,{pasteOption:e.pasteOption}),this.lastPasteState=this.state,this.status=`invisible`;break;case`REPEAT_PASTE`:this.lastPasteState?.paste(e.target,{pasteOption:e.pasteOption,shouldPasteCF:!0,selectTarget:!0});break;case`ACTIVATE_PAINT_FORMAT`:{let t=this.getters.getSelectedZones();this.state=this.getClipboardStateForCopyCells(t,`COPY`),this.status=`visible`,e.persistent?this.paintFormatStatus=`persistent`:this.paintFormatStatus=`oneOff`;break}case`DELETE_SHEET`:if(this.state?.operation!==`CUT`)return;this.originSheetId===e.sheetId&&(this.state=void 0,this.status=`invisible`);break;case`CANCEL_PAINT_FORMAT`:this.paintFormatStatus=`inactive`,this.status=`invisible`;break;default:ur(e)&&(this.status=`invisible`)}}getClipboardContent(){return this.state?.getClipboardContent()||{"text/plain":` `}}getClipboardTextContent(){return this.state?.getClipboardContent()[`text/plain`]||` `}isCutOperation(){return this.state?this.state.operation===`CUT`:!1}isPaintingFormat(){return this.paintFormatStatus!==`inactive`}getDeleteCellsTargets(e,t){let n=this.getters.getActiveSheetId(),r;return r=t===`COL`?{...e,left:e.right+1,right:this.getters.getNumberCols(n)-1}:{...e,top:e.bottom+1,bottom:this.getters.getNumberRows(n)-1},{cut:[r],paste:[e]}}getInsertCellsTargets(e,t){let n=this.getters.getActiveSheetId(),r,i;return t===`COL`?(r={...e,right:this.getters.getNumberCols(n)-1},i={...e,left:e.right+1,right:e.right+1}):(r={...e,bottom:this.getters.getNumberRows(n)-1},i={...e,top:e.bottom+1,bottom:this.getters.getNumberRows(n)-1}),{cut:[r],paste:[i]}}getClipboardStateForCopyCells(e,t,n=`copyPaste`){return new hA(e,t,this.getters,this.dispatch,this.selection,n)}getClipboardState(e,t){return this.getters.getSelectedFigureId()?new $A(t,this.getters,this.dispatch):new hA(e,t,this.getters,this.dispatch,this.selection)}drawGrid(e){this.status!==`visible`||!this.state||this.state.drawClipboard(e)}};function ij(e){if(e.type!==`REFERENCE`)return e;let{xc:t,sheetName:n}=Xi(e.value),[r,i]=t.split(`:`),a=n?`${$e(n)}!`:``,o=aj(r),s=i?`:${aj(i)}`:``;return{...e,value:a+o+s}}function aj(e){switch(sj(e)){case`none`:e=oj(e,`colrow`);break;case`colrow`:e=oj(e,`row`);break;case`row`:e=oj(e,`col`);break;case`col`:e=oj(e,`none`);break}return e}function oj(e,t){e=e.replace(/\$/g,``);let n;switch(t){case`col`:return`$`+e;case`row`:return n=e.search(/[0-9]/),e.slice(0,n)+`$`+e.slice(n);case`colrow`:return n=e.search(/[0-9]/),n===-1||n===0||(e=e.slice(0,n)+`$`+e.slice(n)),`$`+e;case`none`:return e}}function sj(e){return uj(e)?`colrow`:cj(e)?`col`:lj(e)?`row`:`none`}function cj(e){return e.startsWith(`$`)}function lj(e){return e.includes(`$`,1)}function uj(e){return e.startsWith(`$`)&&e.length>1&&e.slice(1).includes(`$`)}let dj=y(`The cell you are trying to edit has been deleted.`);var fj=class extends Q{static getters=[`getEditionMode`,`isSelectingForComposer`,`showSelectionIndicator`,`getCurrentContent`,`getComposerSelection`,`getCurrentTokens`,`getTokenAtCursor`,`getComposerHighlights`,`getCurrentEditedCell`,`getCycledReference`,`getAutoCompleteDataValidationValues`];col=0;row=0;mode=`inactive`;sheetId=``;currentContent=``;currentTokens=[];selectionStart=0;selectionEnd=0;initialContent=``;colorIndexByRange={};allowDispatch(e){switch(e.type){case`CHANGE_COMPOSER_CURSOR_SELECTION`:return this.validateSelection(this.currentContent.length,e.start,e.end);case`SET_CURRENT_CONTENT`:if(e.selection)return this.validateSelection(e.content.length,e.selection.start,e.selection.end);break;case`START_EDITION`:if(e.selection){let t=e.text||this.getComposerContent(this.getters.getActivePosition());return this.validateSelection(t.length,e.selection.start,e.selection.end)}break;case`STOP_EDITION`:return this.mode===`inactive`?`Success`:this.checkDataValidation(e)}return`Success`}handleEvent(e){let t=this.getters.getActiveSheetId(),n;switch(n=e.options.unbounded?this.getters.getUnboundedZone(t,e.anchor.zone):e.anchor.zone,e.mode){case`newAnchor`:this.mode===`selecting`&&this.insertSelectedRange(n);break;default:this.mode===`selecting`?this.replaceSelectedRange(n):this.updateComposerRange(e.previousAnchor.zone,n);break}}handle(e){switch(e.type){case`CHANGE_COMPOSER_CURSOR_SELECTION`:this.selectionStart=e.start,this.selectionEnd=e.end,this.isSelectingForComposer()&&(this.mode=`editing`);break;case`STOP_COMPOSER_RANGE_SELECTION`:this.isSelectingForComposer()&&(this.mode=`editing`);break;case`START_EDITION`:this.mode!==`inactive`&&e.text?this.setContent(e.text,e.selection):this.startEdition(e.text,e.selection),this.updateRangeColor();break;case`STOP_EDITION`:this.stopEdition(),this.colorIndexByRange={};break;case`CANCEL_EDITION`:this.resetContent(),this.cancelEditionAndActivateSheet(),this.colorIndexByRange={};break;case`SET_CURRENT_CONTENT`:this.setContent(e.content,e.selection,!0),this.updateRangeColor();break;case`REPLACE_COMPOSER_CURSOR_SELECTION`:this.replaceSelection(e.text);break;case`SELECT_FIGURE`:this.resetContent(),this.cancelEditionAndActivateSheet();break;case`ADD_COLUMNS_ROWS`:this.onAddElements(e);break;case`REMOVE_COLUMNS_ROWS`:e.dimension===`COL`?this.onColumnsRemoved(e):this.onRowsRemoved(e);break;case`START_CHANGE_HIGHLIGHT`:let{left:t,top:n}=e.zone;this.isSelectingForComposer()&&(this.mode=`editing`),this.selection.resetAnchor(this,{cell:{col:t,row:n},zone:e.zone});break;case`ACTIVATE_SHEET`:if(this.currentContent.startsWith(`=`)||(this.cancelEdition(),this.resetContent()),this.selection.isListening(this)&&e.sheetIdFrom!==e.sheetIdTo){let t=this.getters.getActivePosition(),{col:n,row:r}=this.getters.getNextVisibleCellPosition({sheetId:e.sheetIdTo,col:t.col,row:t.row}),i=this.getters.expandZone(e.sheetIdTo,V({col:n,row:r}));this.selection.resetAnchor(this,{cell:{col:n,row:r},zone:i})}break;case`DELETE_SHEET`:case`UNDO`:case`REDO`:!this.getters.tryGetSheet(this.sheetId)&&this.mode!==`inactive`&&(this.sheetId=this.getters.getActiveSheetId(),this.resetContent(),this.cancelEditionAndActivateSheet(),this.ui.raiseBlockingErrorUI(dj));break;case`CYCLE_EDITION_REFERENCES`:this.cycleReferences();break}}getEditionMode(){return this.mode}getCurrentContent(){return this.mode===`inactive`?this.getComposerContent(this.getters.getActivePosition()):this.currentContent}getComposerSelection(){return{start:this.selectionStart,end:this.selectionEnd}}getCurrentEditedCell(){return{sheetId:this.sheetId,col:this.col,row:this.row}}isSelectingForComposer(){return this.mode===`selecting`}showSelectionIndicator(){return this.isSelectingForComposer()&&this.canStartComposerRangeSelection()}getCurrentTokens(){return this.currentTokens}getTokenAtCursor(){let e=Math.min(this.selectionStart,this.selectionEnd),t=Math.max(this.selectionStart,this.selectionEnd);if(!(e===t&&t===0))return this.currentTokens.find(n=>n.start<=e&&n.end>=t)}getCycledReference(e,t){let n=this.getters.getLocale(),r=(t.startsWith(`=`)?UT(t,n):[]).filter(t=>t.start<=e.start&&t.end>=e.start||t.start>=e.start&&t.start<e.end),i=r.filter(e=>e.type===`REFERENCE`);if(i.length===0)return;let a=r.map(ij).map(e=>e.value).join(``),o=r[0].start,s=r[r.length-1].end,c=t.slice(0,o)+a+t.slice(s),l=c.length-t.length,u={start:i[0].start,end:i[i.length-1].end+l};return i.length===1&&e.start===e.end&&(u.start=u.end),{content:c,selection:u}}getInitialComposerContent(){return this.initialContent}cycleReferences(){let e=this.getCycledReference(this.getComposerSelection(),this.currentContent);e!==void 0&&this.dispatch(`SET_CURRENT_CONTENT`,{content:e.content,selection:e.selection})}validateSelection(e,t,n){return t>=0&&t<=e&&n>=0&&n<=e?`Success`:`WrongComposerSelection`}onColumnsRemoved(e){if(e.elements.includes(this.col)&&this.mode!==`inactive`){this.dispatch(`CANCEL_EDITION`),this.ui.raiseBlockingErrorUI(dj);return}let{top:t,left:n}=aa({left:this.col,right:this.col,top:this.row,bottom:this.row},`left`,[...e.elements]);this.col=n,this.row=t}onRowsRemoved(e){if(e.elements.includes(this.row)&&this.mode!==`inactive`){this.dispatch(`CANCEL_EDITION`),this.ui.raiseBlockingErrorUI(dj);return}let{top:t,left:n}=aa({left:this.col,right:this.col,top:this.row,bottom:this.row},`top`,[...e.elements]);this.col=n,this.row=t}onAddElements(e){let{top:t,left:n}=ia({left:this.col,right:this.col,top:this.row,bottom:this.row},e.dimension===`COL`?`left`:`top`,e.base,e.position,e.quantity);this.col=n,this.row=t}startComposerRangeSelection(){if(this.sheetId===this.getters.getActiveSheetId()){let e=V({col:this.col,row:this.row});this.selection.resetAnchor(this,{cell:{col:this.col,row:this.row},zone:e})}this.mode=`selecting`}startEdition(e,t){let n=this.getters.getActiveCell(),r=this.getters.getLocale();e&&n.format?.includes(`%`)&&Yn(e,r)&&(t||={start:e.length,end:e.length},e=`${e}%`);let{col:i,row:a,sheetId:o}=this.getters.getActivePosition();this.col=i,this.sheetId=o,this.row=a,this.initialContent=this.getComposerContent({sheetId:o,col:i,row:a}),this.mode=`editing`,this.setContent(e||this.initialContent,t),this.colorIndexByRange={};let s=V({col:this.col,row:this.row});this.selection.capture(this,{cell:{col:this.col,row:this.row},zone:s},{handleEvent:this.handleEvent.bind(this),release:()=>{this.stopEdition()}})}stopEdition(){if(this.mode!==`inactive`){this.cancelEditionAndActivateSheet();let e=this.col,t=this.row,n=this.getCurrentCanonicalContent();if(this.initialContent===n)return;if(n){let r=this.getters.getActiveSheetId(),i=this.getters.getEvaluatedCell({sheetId:r,col:this.col,row:this.row});if(n.startsWith(`=`)){let e=this.currentTokens.filter(e=>e.type===`LEFT_PAREN`).length-this.currentTokens.filter(e=>e.type===`RIGHT_PAREN`).length;e>0&&(n+=_t(Array(e).fill(`)`)))}else i.link&&(n=st(n,i.link.url));this.dispatch(`UPDATE_CELL`,{sheetId:this.sheetId,col:e,row:t,content:n})}else this.dispatch(`UPDATE_CELL`,{sheetId:this.sheetId,content:``,col:e,row:t});this.setContent(``)}}getCurrentCanonicalContent(){return Ic(this.currentContent,this.getters.getLocale())}cancelEditionAndActivateSheet(){this.mode!==`inactive`&&(this.cancelEdition(),this.getters.getActiveSheetId()!==this.sheetId&&this.dispatch(`ACTIVATE_SHEET`,{sheetIdFrom:this.getters.getActiveSheetId(),sheetIdTo:this.sheetId}))}getComposerContent(e){let t=this.getters.getLocale(),n=this.getters.getCell(e);if(n?.isFormula)return Vc(n.content,t);let{format:r,value:i,type:a,formattedValue:o}=this.getters.getEvaluatedCell(e);switch(a){case`text`:case`empty`:return i;case`boolean`:return o;case`error`:return n?.content||``;case`number`:return r&&_i(r)?yn(o,t)===null?z(i,{locale:t,format:Number.isInteger(i)?t.dateFormat:Qc(t)}):o:this.numberComposerContent(i,r,t)}}numberComposerContent(e,t,n){return t?.includes(`%`)?`${gi(e*100,n.decimalSeparator)}%`:gi(e,n.decimalSeparator)}cancelEdition(){this.mode!==`inactive`&&(this.mode=`inactive`,this.selection.release(this))}resetContent(){this.setContent(this.initialContent||``)}setContent(e,t,n){let r=this.currentContent!==e;if(this.currentContent=e,t?(this.selectionStart=t.start,this.selectionEnd=t.end):this.selectionStart=this.selectionEnd=e.length,r||this.mode!==`inactive`){let t=this.getters.getLocale();this.currentTokens=e.startsWith(`=`)?UT(e,t):[],this.currentTokens.length>100&&n&&this.ui.raiseBlockingErrorUI(y(`This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells`))}this.canStartComposerRangeSelection()&&this.startComposerRangeSelection()}insertSelectedRange(e){let t=Math.min(this.selectionStart,this.selectionEnd),n=this.getZoneReference(e);this.canStartComposerRangeSelection()?this.insertText(n,t):this.insertText(`,`+n,t)}replaceSelectedRange(e){let t=this.getZoneReference(e),n=this.getTokenAtCursor(),r=n?.type===`REFERENCE`?n.start:this.selectionStart;this.replaceText(t,r,this.selectionEnd)}updateComposerRange(e,t){let n=this.getters.getActiveSheetId(),r=this.getTokenAtCursor(),i=(r?[r,...this.currentTokens]:this.currentTokens).filter(e=>e.type===`REFERENCE`).find(t=>{let{xc:r,sheetName:i}=Xi(t.value),a=i||this.getters.getSheetName(this.sheetId);if(!Ga(this.getters.getSheetName(n),a))return!1;let o=this.getters.getRangeFromSheetXC(n,r);return la(this.getters.expandZone(n,o.zone),e)});if(!i)return;let a=this.getters.getRangeFromSheetXC(n,i.value);this.selectionStart=i.start,this.selectionEnd=this.selectionStart+i.value.length;let o=this.getters.getRangeFromZone(n,t),s=this.getRangeReference(o,a.parts);this.replaceSelection(s)}getZoneReference(e){let t=this.getters.getCurrentEditedCell().sheetId,n=this.getters.getActiveSheetId(),r=this.getters.getRangeFromZone(n,e);return this.getters.getSelectionRangeString(r,t)}getRangeReference(e,t){let n=[...t],r=e.clone({parts:n});return this.getters.getSelectionRangeString(r,this.getters.getCurrentEditedCell().sheetId)}replaceSelection(e){let t=Math.min(this.selectionStart,this.selectionEnd),n=Math.max(this.selectionStart,this.selectionEnd);this.replaceText(e,t,n)}replaceText(e,t,n){this.currentContent=this.currentContent.slice(0,t)+this.currentContent.slice(n,this.currentContent.length),this.insertText(e,t)}insertText(e,t){let n=this.currentContent.slice(0,t)+e+this.currentContent.slice(t),r=t+e.length;this.dispatch(`SET_CURRENT_CONTENT`,{content:n,selection:{start:r,end:r}})}updateRangeColor(){if(!this.currentContent.startsWith(`=`)||this.mode===`inactive`)return;let e=this.getters.getCurrentEditedCell().sheetId,t=this.getReferencedRanges().map(t=>this.getters.getRangeString(t,e)),n={};for(let e of t)this.colorIndexByRange[e]!==void 0&&(n[e]=this.colorIndexByRange[e]);let r=new Set(Object.values(n)),i=0,a=()=>{for(;r.has(i);)i++;return r.add(i),i};for(let e of t)n[e]=e in n?n[e]:a();this.colorIndexByRange=n}getComposerHighlights(){if(!this.currentContent.startsWith(`=`)||this.mode===`inactive`)return[];let e=this.getters.getCurrentEditedCell().sheetId,t=e=>Lt[this.colorIndexByRange[e]%Lt.length];return this.getReferencedRanges().map(n=>{let r=this.getters.getRangeString(n,e);return{zone:n.zone,color:t(r),sheetId:n.sheetId}})}getReferencedRanges(){let e=this.getters.getCurrentEditedCell().sheetId;return this.currentTokens.filter(e=>e.type===`REFERENCE`).map(t=>this.getters.getRangeFromSheetXC(e,t.value)).filter(e=>!e.invalidSheetName&&!e.invalidXc)}getAutoCompleteDataValidationValues(){if(this.mode===`inactive`)return[];let e=this.getters.getValidationRuleForCell(this.getCurrentEditedCell());if(!e||e.criterion.type!==`isValueInList`&&e.criterion.type!==`isValueInRange`)return[];let t;if(e.criterion.type===`isValueInList`)t=e.criterion.values;else{let n=this.getters.getRangeFromSheetXC(this.sheetId,e.criterion.values[0]);t=Array.from(new Set(this.getters.getRangeValues(n).filter(pt).map(e=>e.toString()).filter(e=>e!==``)))}let n=this.getCurrentContent();if(n&&n!==this.getInitialComposerContent()){let e=za(n,t,e=>e);t=e.length?e:t}return t}canStartComposerRangeSelection(){if(this.currentContent.startsWith(`=`)){let e=this.getTokenAtCursor();if(!e)return!1;let t=this.currentTokens.map(e=>e.start).indexOf(e.start),n=t,r=e;for(;![`ARG_SEPARATOR`,`LEFT_PAREN`,`OPERATOR`].includes(r.type)||gc.includes(r.value);){if(r.type!==`SPACE`||n<1)return!1;n--,r=this.currentTokens[n]}for(n=t+1,r=this.currentTokens[n];r&&![`ARG_SEPARATOR`,`RIGHT_PAREN`,`OPERATOR`].includes(r.type);){if(r.type!==`SPACE`)return!1;n++,r=this.currentTokens[n]}return!0}return!1}checkDataValidation(e){let t={sheetId:this.sheetId,col:this.col,row:this.row};try{let e=this.getCurrentCanonicalContent(),n=e.startsWith(`=`)?this.getters.evaluateFormula(this.sheetId,e):to(e,this.getters.getLocale());if(j(n))return`Success`;let r=this.getters.getValidationResultForCellValue(n,t);return!r.isValid&&r.rule.isBlocking?`BlockingValidationRule`:`Success`}catch{return this.getters.getValidationRuleForCell(t)?.isBlocking?`BlockingValidationRule`:`Success`}}},pj=class extends Q{static getters=[`getCellBorderWithFilterBorder`,`getFilterValues`,`isRowFiltered`,`isFilterActive`];filterValues={};hiddenRows={};isEvaluationDirty=!1;allowDispatch(e){switch(e.type){case`UPDATE_FILTER`:if(!this.getters.getFilterId(e))return`FilterNotFound`;break}return`Success`}handle(e){switch(e.type){case`UNDO`:case`REDO`:case`UPDATE_CELL`:case`EVALUATE_CELLS`:case`ACTIVATE_SHEET`:case`REMOVE_FILTER_TABLE`:case`ADD_COLUMNS_ROWS`:case`REMOVE_COLUMNS_ROWS`:this.isEvaluationDirty=!0;break;case`START`:for(let e of this.getters.getSheetIds()){this.filterValues[e]={};for(let 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`GROUP_HEADERS`:case`UNGROUP_HEADERS`:case`FOLD_HEADER_GROUP`:case`UNFOLD_HEADER_GROUP`:case`FOLD_ALL_HEADER_GROUPS`:case`UNFOLD_ALL_HEADER_GROUPS`:this.updateHiddenRows(e.sheetId);break;case`UPDATE_FILTER`:this.updateFilter(e),this.updateHiddenRows(e.sheetId);break;case`DUPLICATE_SHEET`:let t={};for(let n of this.getters.getFilters(e.sheetIdTo)){let r=n.zoneWithHeaders;t[n.id]=this.getFilterValues({sheetId:e.sheetId,col:r.left,row:r.top})}this.filterValues[e.sheetIdTo]=t;break}}finalize(){if(this.isEvaluationDirty){for(let e of this.getters.getSheetIds())this.updateHiddenRows(e);this.isEvaluationDirty=!1}}isRowFiltered(e,t){return!!this.hiddenRows[e]?.has(t)}getCellBorderWithFilterBorder(e){let{sheetId:t,col:n,row:r}=e,i;for(let e of this.getters.getFilterTables(t)){let a=e.zone;if(da(n,r,a)){let e=this.intersectZoneWithViewport(t,a);i={top:r===e.top?Fe:void 0,bottom:r===e.bottom?Fe:void 0,left:n===e.left?Fe:void 0,right:n===e.right?Fe:void 0}}}let a=this.getters.getCellBorder(e),o={...i,...St(a||{})};return mt(o)?null:o}getFilterValues(e){let t=this.getters.getFilterId(e),n=e.sheetId;return!t||!this.filterValues[n]?[]:this.filterValues[n][t]||[]}isFilterActive(e){let t=this.getters.getFilterId(e),n=e.sheetId;return!!(t&&this.filterValues[n]?.[t]?.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,hiddenValues:n,sheetId:r}){let i=this.getters.getFilterId({sheetId:r,col:e,row:t});i&&(this.filterValues[r]||(this.filterValues[r]={}),this.filterValues[r][i]=n)}updateHiddenRows(e){let t=this.getters.getFilters(e).sort((e,t)=>e.zoneWithHeaders.top-t.zoneWithHeaders.top),n=new Set;for(let r of t){if(n.has(r.zoneWithHeaders.top)||this.getters.isRowHiddenByUser(e,r.zoneWithHeaders.top))continue;let t=this.filterValues[e]?.[r.id]?.map(To);if(!t||!r.filteredZone)continue;let i=new Set(t);for(let t=r.filteredZone.top;t<=r.filteredZone.bottom;t++){let a=this.getCellValueAsString(e,r.col,t);i.has(a)&&n.add(t)}}this.hiddenRows[e]=n}getCellValueAsString(e,t,n){return this.getters.getEvaluatedCell({sheetId:e,col:t,row:n}).formattedValue.toLowerCase()}exportForExcel(e){for(let t of e.sheets){let e=t.id;for(let n of t.filterTables){let r=ea(n.range),i=[],a=[];for(let n of w(0,va(r).numberOfCols)){let o={sheetId:t.id,col:r.left+n,row:r.top},s=this.getFilterValues(o),c=this.getters.getFilter(o);if(!c)continue;let l=c.filteredZone?ba(c.filteredZone).map(t=>this.getters.getEvaluatedCell({sheetId:e,...t}).formattedValue):[];if(s.length){let e=l.filter(e=>e).filter(e=>!s.includes(e));i.push({colId:n,displayedValues:[...new Set(e)],displayBlanks:!s.includes(``)&&l.some(e=>!e)})}let u={col:c.col,row:c.zoneWithHeaders.top,sheetId:e},d=this.getters.getEvaluatedCell(u).formattedValue,f=this.getUniqueColNameForExcel(n,d,a);a.push(f),t.cells[O(u.col,u.row)]={...t.cells[O(u.col,u.row)],content:f,value:f,isFormula:!1}}n.filters=i}}}getUniqueColNameForExcel(e,t,n){t||=`Column${e}`;let r=t,i=2;for(;n.includes(r);)r=t+String(i),i++;return r}};let mj=[{name:y(`Sum`),types:[`number`],compute:(e,t)=>Kp.compute.bind({locale:t})([e])},{name:y(`Avg`),types:[`number`],compute:(e,t)=>gm.compute.bind({locale:t})([e])},{name:y(`Min`),types:[`number`],compute:(e,t)=>zm.compute.bind({locale:t})([e])},{name:y(`Max`),types:[`number`],compute:(e,t)=>Fm.compute.bind({locale:t})([e])},{name:y(`Count`),types:[`number`,`text`,`boolean`,`error`],compute:(e,t)=>wm.compute.bind({locale:t})([e])},{name:y(`Count Numbers`),types:[`number`,`text`,`boolean`,`error`],compute:(e,t)=>Cm.compute.bind({locale:t})([e])}];var hj=class extends Q{static layers=[6];static getters=[`getActiveSheet`,`getActiveSheetId`,`getActiveCell`,`getActiveCols`,`getActiveRows`,`getCurrentStyle`,`getSelectedZones`,`getSelectedZone`,`getSelectedCells`,`getStatisticFnResults`,`getAggregate`,`getSelectedFigureId`,`getSelection`,`getActivePosition`,`getSheetPosition`,`isSelected`,`isSingleColSelected`,`getElementsFromSelection`,`tryGetActiveSheetId`,`isGridSelectionActive`];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}]};selectedFigureId=null;sheetsData={};moveClient;activeSheet=null;constructor(e){super(e),this.moveClient=e.moveClient}allowDispatch(e){switch(e.type){case`ACTIVATE_SHEET`:try{this.getters.getSheet(e.sheetIdTo);break}catch{return`InvalidSheetId`}case`MOVE_COLUMNS_ROWS`:return this.isMoveElementAllowed(e)}return`Success`}handleEvent(e){let t=e.anchor,n=[];switch(e.mode){case`overrideSelection`:n=[t.zone];break;case`updateAnchor`:n=[...this.gridSelection.zones];let r=n.findIndex(t=>la(t,e.previousAnchor.zone));r>=0&&(n[r]=t.zone);break;case`newAnchor`:n=[...this.gridSelection.zones,t.zone];break}this.setSelectionMixin(e.anchor,n),this.selection.resetDefaultAnchor(this,S(this.gridSelection.anchor));let{col:r,row:i}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.getters.getActiveSheetId(),col:r,row:i}),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);break}switch(e.type){case`START`:let t=this.getters.getVisibleSheetIds()[0];this.activateSheet(t,t);let{col:n,row:r}=this.getters.getNextVisibleCellPosition({sheetId:t,col:0,row:0});this.selectCell(n,r),this.selection.registerAsDefault(this,this.gridSelection.anchor,{handleEvent:this.handleEvent.bind(this)}),this.moveClient({sheetId:t,col:0,row:0});break;case`ACTIVATE_SHEET`:this.activateSheet(e.sheetIdFrom,e.sheetIdTo);break;case`REMOVE_COLUMNS_ROWS`:{let t=this.getters.getActiveSheetId();if(e.sheetId===t){e.dimension===`COL`?this.onColumnsRemoved(e):this.onRowsRemoved(e);let{col:n,row:r}=this.gridSelection.anchor.cell;this.moveClient({sheetId:t,col:n,row:r})}break}case`ADD_COLUMNS_ROWS`:{let t=this.getters.getActiveSheetId();if(e.sheetId===t){this.onAddElements(e);let{col:n,row:r}=this.gridSelection.anchor.cell;this.moveClient({sheetId:t,col:n,row:r})}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`:let i=Object.keys(this.sheetsData).filter(e=>!this.getters.tryGetSheet(e));for(let e of i)delete this.sheetsData[e];for(let e in this.sheetsData){let t=this.clipSelection(e,this.sheetsData[e].gridSelection);this.sheetsData[e]={gridSelection:S(t)}}this.fallbackToVisibleSheet();let a=this.getters.getActiveSheetId();this.gridSelection.zones=this.gridSelection.zones.map(e=>this.getters.expandZone(a,e)),this.gridSelection.anchor.zone=this.getters.expandZone(a,this.gridSelection.anchor.zone),this.setSelectionMixin(this.gridSelection.anchor,this.gridSelection.zones),this.selectedFigureId=null;break}}finalize(){this.fallbackToVisibleSheet(),this.selection.resetDefaultAnchor(this,S(this.gridSelection.anchor))}isGridSelectionActive(){return this.selection.isListening(this)}getActiveSheet(){return this.activeSheet}getActiveSheetId(){return this.activeSheet.id}tryGetActiveSheetId(){return this.activeSheet?.id}getActiveCell(){return this.getters.getEvaluatedCell(this.getActivePosition())}getActiveCols(){let e=new Set;for(let t of this.gridSelection.zones)if(t.top===0&&t.bottom===this.getters.getNumberRows(this.getters.getActiveSheetId())-1)for(let n=t.left;n<=t.right;n++)e.add(n);return e}getActiveRows(){let e=new Set,t=this.getters.getActiveSheetId();for(let n of this.gridSelection.zones)if(n.left===0&&n.right===this.getters.getNumberCols(t)-1)for(let t=n.top;t<=n.bottom;t++)e.add(t);return e}getCurrentStyle(){let e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();return this.getters.getCellStyle({sheetId:t,col:e.left,row:e.top})}getSelectedZones(){return S(this.gridSelection.zones)}getSelectedZone(){return S(this.gridSelection.anchor.zone)}getSelection(){return S(this.gridSelection)}getSelectedCells(){let e=this.getters.getActiveSheetId(),t=[];for(let n of this.gridSelection.zones)t.push(...this.getters.getEvaluatedCellsInZone(e,n));return t}getSelectedFigureId(){return this.selectedFigureId}getActivePosition(){return this.getters.getMainCellPosition({sheetId:this.getActiveSheetId(),col:this.gridSelection.anchor.cell.col,row:this.gridSelection.anchor.cell.row})}getSheetPosition(e){if(e===this.getters.getActiveSheetId())return this.getActivePosition();{let t=this.sheetsData[e];return t?{sheetId:e,col:t.gridSelection.anchor.cell.col,row:t.gridSelection.anchor.cell.row}:this.getters.getNextVisibleCellPosition({sheetId:e,col:0,row:0})}}getStatisticFnResults(){let e=this.getters.getActiveSheetId(),t=new Set;for(let n of this.gridSelection.zones)for(let{col:r,row:i}of ba(n)){if(this.getters.isRowHidden(e,i)||this.getters.isColHidden(e,r))continue;let n=this.getters.getEvaluatedCell({sheetId:e,col:r,row:i});n.type!==`empty`&&t.add(n)}let n=new Set,r=[];for(let e of t)n.add(e.type),r.push(e.value);let i=this.getters.getLocale(),a={};for(let e of mj){let t;e.types.some(e=>n.has(e))&&(t=e.compute(r,i)),a[e.name]=t}return a}getAggregate(){let e=0,t=0,n=this.getters.getActiveSheetId(),r=this.gridSelection.zones.map(ba).flat();for(let{col:i,row:a}of r){let r=this.getters.getEvaluatedCell({sheetId:n,col:i,row:a});r.type===`number`&&(t++,e+=r.value)}let i=this.getters.getLocale();return t<2?null:z(e,{locale:i})}isSelected(e){return!!this.getters.getSelectedZones().find(t=>la(t,e))}isSingleColSelected(){let e=this.getters.getSelectedZones();return!(e.length!==1||e[0].left!==e[0].right)}getElementsFromSelection(e){if(e===`COL`&&this.getters.getActiveCols().size===0||e===`ROW`&&this.getters.getActiveRows().size===0)return[];let t=this.getters.getSelectedZones(),n=[],r=e===`COL`?`left`:`top`,i=e===`COL`?`right`:`bottom`;for(let e of t){let t=Array.from({length:e[i]-e[r]+1},(t,n)=>e[r]+n);n=n.concat(t)}return[...new Set(n)].sort()}activateSheet(e,t){if(this.getters.isSheetVisible(t)||this.dispatch(`SHOW_SHEET`,{sheetId:t}),this.setActiveSheet(t),this.sheetsData[e]={gridSelection:S(this.gridSelection)},t in this.sheetsData)Object.assign(this,this.sheetsData[t]),this.selection.resetDefaultAnchor(this,S(this.gridSelection.anchor));else{let{col:e,row:n}=this.getters.getNextVisibleCellPosition({sheetId:t,col:0,row:0});this.selectCell(e,n)}let{col:n,row:r}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.activeSheet.id,col:n,row:r})}setSelectionMixin(e,t){let{anchor:n,zones:r}=this.clipSelection(this.getters.getActiveSheetId(),{anchor:e,zones:t});this.gridSelection.anchor=n,this.gridSelection.zones=Ca(r)}selectCell(e,t){let n=this.getters.getActiveSheetId(),r=this.getters.expandZone(n,{left:e,right:e,top:t,bottom:t});this.setSelectionMixin({zone:r,cell:{col:e,row:t}},[r])}setActiveSheet(e){let t=this.getters.getSheet(e);this.activeSheet=t}activateNextSheet(e){let t=this.getters.getSheetIds(),n=(t.findIndex(e=>e===this.activeSheet.id)+(e===`left`?t.length-1:1))%t.length;this.dispatch(`ACTIVATE_SHEET`,{sheetIdFrom:this.getActiveSheetId(),sheetIdTo:t[n]})}onColumnsRemoved(e){let{cell:t,zone:n}=this.gridSelection.anchor,r=aa(n,`left`,[...e.elements]),i={left:t.col,right:t.col,top:t.row,bottom:t.row};i=aa(i,`left`,[...e.elements]);let a={cell:{col:i.left,row:i.top},zone:r},o=this.gridSelection.zones.map(t=>aa(t,`left`,[...e.elements]));this.setSelectionMixin(a,o)}onRowsRemoved(e){let{cell:t,zone:n}=this.gridSelection.anchor,r=aa(n,`top`,[...e.elements]),i={left:t.col,right:t.col,top:t.row,bottom:t.row};i=aa(i,`top`,[...e.elements]);let a={cell:{col:i.left,row:i.top},zone:r},o=this.gridSelection.zones.map(t=>aa(t,`top`,[...e.elements]));this.setSelectionMixin(a,o)}onAddElements(e){let t=e.dimension===`COL`?`left`:`top`,n=ia(this.gridSelection.anchor.zone,t,e.base,e.position,e.quantity),r=this.gridSelection.zones.map(n=>ia(n,t,e.base,e.position,e.quantity)),i={cell:{col:n.left,row:n.top},zone:n};this.setSelectionMixin(i,r)}onMoveElements(e){let t=e.elements.length;this.dispatch(`ADD_COLUMNS_ROWS`,{dimension:e.dimension,sheetId:e.sheetId,base:e.base,quantity:t,position:e.position});let n=e.dimension===`COL`,r=e.elements[0],i=e.elements[t-1],a=e.base<r,o=a&&n?t:0,s=a&&!n?t:0,c=a?e.elements.map(e=>e+t):e.elements,l=Object.fromEntries(c.map(t=>{let r=n?this.getters.getColSize(e.sheetId,t):this.getters.getUserRowSize(e.sheetId,t);return[t,n&&r===96||r===void 0?null:r]})),u=new hA([{left:n?r+o:0,right:n?i+o:this.getters.getNumberCols(e.sheetId)-1,top:n?0:r+s,bottom:n?this.getters.getNumberRows(e.sheetId)-1:i+s}],`CUT`,this.getters,this.dispatch,this.selection,`shiftCells`),d=a?e.base:e.base+1,f=[{left:n?d:0,right:n?d+t-1:this.getters.getNumberCols(e.sheetId)-1,top:n?0:d,bottom:n?this.getters.getNumberRows(e.sheetId)-1:d+t-1}];u.paste(f,{selectTarget:!0});let p=a?e.base:e.base+1;for(let t of c)this.dispatch(`RESIZE_COLUMNS_ROWS`,{dimension:e.dimension,sheetId:e.sheetId,size:l[t],elements:[p]}),p+=1;this.dispatch(`REMOVE_COLUMNS_ROWS`,{dimension:e.dimension,sheetId:e.sheetId,elements:c})}isMoveElementAllowed(e){let t=e.dimension===`COL`,n=e.elements[0],r=e.elements[e.elements.length-1],i=e.sheetId,a=t?this.getters.doesColumnsHaveCommonMerges:this.getters.doesRowsHaveCommonMerges;if(a(i,n-1,n)||a(i,r,r+1)||a(i,e.base-1,e.base))return`WillRemoveExistingMerge`;let o=[e.base,...e.elements],s=t?this.getters.getNumberCols(i):this.getters.getNumberRows(i);return o.some(e=>e<0||e>=s)?`InvalidHeaderIndex`:`Success`}fallbackToVisibleSheet(){if(!this.getters.tryGetSheet(this.getters.getActiveSheetId())){let e=this.getters.getVisibleSheetIds();if(this.activeSheet=this.getters.getSheet(e[0]),this.activeSheet.id in this.sheetsData){let{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);let{col:t,row:n}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.getters.getActiveSheetId(),col:t,row:n})}}clipSelection(e,t){let n=this.getters.getNumberCols(e)-1,r=this.getters.getNumberRows(e)-1,i=t.zones.map(e=>({left:C(e.left,0,n),right:C(e.right,0,n),top:C(e.top,0,r),bottom:C(e.bottom,0,r)})),a=C(t.anchor.cell.col,0,n),o=C(t.anchor.cell.row,0,r),s={left:C(t.anchor.zone.left,0,n),right:C(t.anchor.zone.right,0,n),top:C(t.anchor.zone.top,0,r),bottom:C(t.anchor.zone.bottom,0,r)};return{zones:i,anchor:{cell:{col:a,row:o},zone:s}}}drawGrid(e){if(this.getters.isDashboard())return;let{ctx:t,thinLineWidth:n}=e,r=this.getSelectedZones();t.fillStyle=`#f3f7fe`,t.fillStyle=r.length===1&&r[0].left===r[0].right&&r[0].top===r[0].bottom?`#f3f7fe`:`#e9f0ff`,t.strokeStyle=pe,t.lineWidth=1.5*n;for(let e of r){let{x:n,y:r,width:i,height:a}=this.getters.getVisibleRect(e);t.globalCompositeOperation=`multiply`,t.fillRect(n,r,i,a),t.globalCompositeOperation=`source-over`,t.strokeRect(n,r,i,a)}t.globalCompositeOperation=`source-over`;let i=this.getActivePosition();t.strokeStyle=pe,t.lineWidth=3*n;let a;a=this.getters.isInMerge(i)?this.getters.getMerge(i):V(i);let{x:o,y:s,width:c,height:l}=this.getters.getVisibleRect(a);c>0&&l>0&&t.strokeRect(o,s,c,l)}},gj=class{getters;sheetId;boundaries;top;bottom;left;right;offsetX;offsetY;offsetScrollbarX;offsetScrollbarY;canScrollVertically;canScrollHorizontally;viewportWidth;viewportHeight;offsetCorrectionX;offsetCorrectionY;constructor(e,t,n,r,i,a){if(this.getters=e,this.sheetId=t,this.boundaries=n,r.width<0||r.height<0)throw Error(`Viewport size cannot be negative`);this.viewportWidth=r.height&&r.width,this.viewportHeight=r.width&&r.height,this.top=n.top,this.bottom=n.bottom,this.left=n.left,this.right=n.right,this.offsetX=a.x,this.offsetY=a.y,this.offsetScrollbarX=a.x,this.offsetScrollbarY=a.y,this.canScrollVertically=i.canScrollVertically,this.canScrollHorizontally=i.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(){let 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:n,size:r}=this.getters.getColDimensions(this.sheetId,e),{end:i,size:a}=this.getters.getRowDimensions(this.sheetId,t),o=this.searchHeaderIndex(`COL`,n-this.viewportWidth,0),s=this.getters.getColSize(this.sheetId,o),c=this.searchHeaderIndex(`ROW`,i-this.viewportHeight,0),l=this.getters.getRowSize(this.sheetId,c),u=n-this.offsetCorrectionX;this.canScrollHorizontally&&(u+=Math.max(96,Math.min(s,this.viewportWidth-r)),u=Math.max(u,this.viewportWidth));let d=i-this.offsetCorrectionY;return this.canScrollVertically&&(d+=Math.max(28,Math.min(l,this.viewportHeight-a)),d=Math.max(d,this.viewportHeight),i+46>d&&!this.getters.isReadonly()&&(d+=46)),{width:u,height:d}}getColIndex(e){return e<this.offsetCorrectionX||e>this.offsetCorrectionX+this.viewportWidth?-1:this.searchHeaderIndex(`COL`,e-this.offsetCorrectionX,this.left)}getRowIndex(e){return e<this.offsetCorrectionY||e>this.offsetCorrectionY+this.viewportHeight?-1:this.searchHeaderIndex(`ROW`,e-this.offsetCorrectionY,this.top)}adjustPosition(e){let t=this.sheetId;e||=this.getters.getSheetPosition(t);let n=this.getters.getMainCellPosition({sheetId:t,...e}),{col:r,row:i}=this.getters.getNextVisibleCellPosition(n);da(r,this.boundaries.top,this.boundaries)&&this.adjustPositionX(r),da(this.boundaries.left,i,this.boundaries)&&this.adjustPositionY(i)}adjustPositionX(e){let t=this.sheetId,{end:n}=this.getters.getColDimensions(t,e),r=this.getters.getNumberCols(t);if(this.offsetX+this.offsetCorrectionX+this.viewportWidth<n){let n=e;for(;this.getters.isColHidden(t,n)&&e<r;)n++;let i=this.getters.getColDimensions(t,n).end,a=this.searchHeaderIndex(`COL`,i-this.viewportWidth-this.offsetCorrectionX,this.boundaries.left);this.offsetX=this.getters.getColDimensions(t,a).end-this.offsetCorrectionX,this.offsetScrollbarX=this.offsetX,this.adjustViewportZoneX()}else if(this.left>e){let n=e;for(;this.getters.isColHidden(t,n)&&e>0;)n--;this.offsetX=this.getters.getColDimensions(t,n).start-this.offsetCorrectionX,this.offsetScrollbarX=this.offsetX,this.adjustViewportZoneX()}}adjustPositionY(e){let t=this.sheetId,{end:n}=this.getters.getRowDimensions(t,e),r=this.getters.getNumberRows(t);if(this.offsetY+this.viewportHeight+this.offsetCorrectionY<n){let n=e;for(;this.getters.isRowHidden(t,n)&&e<r;)n++;let i=this.getters.getRowDimensions(t,n).end,a=this.searchHeaderIndex(`ROW`,i-this.viewportHeight-this.offsetCorrectionY,this.boundaries.top);this.offsetY=this.getters.getRowDimensions(t,a).end-this.offsetCorrectionY,this.offsetScrollbarY=this.offsetY,this.adjustViewportZoneY()}else if(this.top>e){let n=e;for(;this.getters.isRowHidden(t,n)&&e>0;)n--;this.offsetY=this.getters.getRowDimensions(t,n).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){let t=ca(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(ca(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,n=0){if(this.viewportWidth<=0||this.viewportHeight<=0)return-1;let r=this.sheetId,i=this.getters.getNumberHeaders(r,e),a=n,o=i;for(;a<=o&&a!==i&&o!==-1;){let i=Math.floor((a+o)/2),s=this.getters.getColRowOffset(e,n,i),c=this.getters.getHeaderSize(r,e,i);if(t>=s&&t<s+c)return i;t>=s+c?a=i+1:o=i-1}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){let{width:e}=this.getMaxSize();this.viewportWidth+this.offsetScrollbarX>e&&(this.offsetScrollbarX=Math.max(0,e-this.viewportWidth))}this.left=this.getColIndex(this.offsetScrollbarX),this.right=this.getColIndex(this.offsetScrollbarX+this.viewportWidth),this.right===-1&&(this.right=this.boundaries.right),this.adjustViewportZoneX()}adjustViewportOffsetY(){if(this.canScrollVertically){let{height:e}=this.getMaxSize();this.viewportHeight+this.offsetScrollbarY>e&&(this.offsetScrollbarY=Math.max(0,e-this.viewportHeight))}this.top=this.getRowIndex(this.offsetScrollbarY),this.bottom=this.getRowIndex(this.offsetScrollbarY+this.viewportHeight),this.bottom===-1&&(this.bottom=this.boundaries.bottom),this.adjustViewportZoneY()}adjustViewportZoneX(){let 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&&(this.left===-1&&(this.left=this.boundaries.left),this.right===-1&&(this.right=this.boundaries.right),this.offsetX=this.getters.getColDimensions(e,this.left).start-this.getters.getColDimensions(e,this.boundaries.left).start)}adjustViewportZoneY(){let 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&&(this.top===-1&&(this.top=this.boundaries.top),this.bottom===-1&&(this.bottom=this.boundaries.bottom),this.offsetY=this.getters.getRowDimensions(e,this.top).start-this.getters.getRowDimensions(e,this.boundaries.top).start)}},_j=class extends Q{static getters=[`getColIndex`,`getRowIndex`,`getActiveMainViewport`,`getSheetViewDimension`,`getSheetViewDimensionWithHeaders`,`getMainViewportRect`,`isVisibleInViewport`,`getEdgeScrollCol`,`getEdgeScrollRow`,`getVisibleFigures`,`getVisibleRect`,`getVisibleRectWithoutHeaders`,`getVisibleCellPositions`,`getColRowOffsetInViewport`,`getMainViewportCoordinates`,`getActiveSheetScrollInfo`,`getActiveSheetDOMScrollInfo`,`getSheetViewVisibleCols`,`getSheetViewVisibleRows`,`getFrozenSheetViewRatio`,`isPositionVisible`,`getAllActiveViewportsZonesAndRect`,`getRect`];viewports={};sheetViewWidth=Ge();sheetViewHeight=Ge();gridOffsetX=0;gridOffsetY=0;sheetsWithDirtyViewports=new Set;shouldAdjustViewports=!1;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`Success`}}handleEvent(e){let t=this.getters.getActiveSheetId();if(e.options.scrollIntoView){let{col:n,row:r}=Ta(e.previousAnchor.zone,e.anchor.zone);if(e.mode===`updateAnchor`){let i=e.previousAnchor.zone,a=e.anchor.zone,{top:o,bottom:s,left:c,right:l}=this.getMainInternalViewport(t);i.left===a.left&&i.right===a.right&&(n=c>n||n>l?c:n),i.top===a.top&&i.bottom===a.bottom&&(r=o>r||r>s?o:r)}n=Math.min(n,this.getters.getNumberCols(t)-1),r=Math.min(r,this.getters.getNumberRows(t)-1),this.sheetsWithDirtyViewports.has(t)||this.refreshViewport(this.getters.getActiveSheetId(),{col:n,row:r})}}handle(e){if(ar.has(e.type))for(let e of this.getters.getSheetIds())this.sheetsWithDirtyViewports.add(e);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.cleanViewports();for(let e of this.getters.getSheetIds())this.sheetsWithDirtyViewports.add(e);this.shouldAdjustViewports=!0;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`:let t=this.getters.getActiveSheetId(),{top:n,viewportHeight:r,offsetCorrectionY:i}=this.getMainInternalViewport(t),a=this.getters.getRowDimensions(t,n);this.shiftVertically(a.start+r-i);break;case`SHIFT_VIEWPORT_UP`:{let e=this.getters.getActiveSheetId(),{top:t,viewportHeight:n,offsetCorrectionY:r}=this.getMainInternalViewport(e),i=this.getters.getRowDimensions(e,t);this.shiftVertically(i.end-r-n);break}case`REMOVE_FILTER_TABLE`:case`UPDATE_FILTER`:case`UNFREEZE_ROWS`:case`UNFREEZE_COLUMNS`:case`FREEZE_COLUMNS`:case`FREEZE_ROWS`:case`UNFREEZE_COLUMNS_ROWS`:case`REMOVE_COLUMNS_ROWS`:case`RESIZE_COLUMNS_ROWS`:case`HIDE_COLUMNS_ROWS`:case`ADD_COLUMNS_ROWS`:case`UNHIDE_COLUMNS_ROWS`:case`UNGROUP_HEADERS`:case`GROUP_HEADERS`:case`FOLD_HEADER_GROUP`:case`UNFOLD_HEADER_GROUP`:case`FOLD_HEADER_GROUPS_IN_ZONE`:case`UNFOLD_HEADER_GROUPS_IN_ZONE`:case`UNFOLD_ALL_HEADER_GROUPS`:case`FOLD_ALL_HEADER_GROUPS`:this.sheetsWithDirtyViewports.add(e.sheetId);break;case`UPDATE_CELL`:for(let e of this.getters.getSheetIds())this.sheetsWithDirtyViewports.add(e);break;case`DELETE_SHEET`:this.cleanViewports(),this.sheetsWithDirtyViewports.delete(e.sheetId);break;case`ACTIVATE_SHEET`:this.sheetsWithDirtyViewports.add(e.sheetIdTo);break;case`DELETE_SHEET`:this.sheetsWithDirtyViewports.delete(e.sheetId);break;case`START_EDITION`:let{col:o,row:s}=this.getters.getActivePosition();this.refreshViewport(this.getters.getActiveSheetId(),{col:o,row:s});break}}finalize(){for(let e of this.sheetsWithDirtyViewports)if(this.resetViewports(e),this.shouldAdjustViewports){let t=this.getters.getSheetPosition(e),n=this.getSubViewports(e);Object.values(n).forEach(e=>{e.adjustPosition(t)})}this.sheetsWithDirtyViewports=new Set,this.shouldAdjustViewports=!1,this.setViewports()}setViewports(){let e=this.getters.getSheetIds();for(let t of e)this.viewports[t]?.bottomRight||this.resetViewports(t)}getColIndex(e){let t=this.getters.getActiveSheetId();return Math.max(...this.getSubViewports(t).map(t=>t.getColIndex(e)))}getRowIndex(e){let 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(){let e=this.getters.getActiveSheetId();return this.getMainViewport(e)}getActiveSheetScrollInfo(){let e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e);return{scrollX:t.offsetX,scrollY:t.offsetY}}getActiveSheetDOMScrollInfo(){let e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e);return{scrollX:t.offsetScrollbarX,scrollY:t.offsetScrollbarY}}getSheetViewVisibleCols(){let e=this.getters.getActiveSheetId(),t=this.getSubViewports(e);return[...new Set(t.map(e=>w(e.left,e.right+1)).flat())].filter(t=>t>=0&&!this.getters.isHeaderHidden(e,`COL`,t))}getSheetViewVisibleRows(){let e=this.getters.getActiveSheetId(),t=this.getSubViewports(e);return[...new Set(t.map(e=>w(e.top,e.bottom+1)).flat())].filter(t=>t>=0&&!this.getters.isHeaderHidden(e,`ROW`,t))}getVisibleCellPositions(){let e=this.getSheetViewVisibleCols(),t=this.getSheetViewVisibleRows(),n=this.getters.getActiveSheetId(),r=[];for(let i of e)for(let e of t){let t={sheetId:n,col:i,row:e},a=this.getters.getMainCellPosition(t);a.row!==e||a.col!==i||r.push(t)}return r}getMainViewportRect(){let e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e),{xSplit:n,ySplit:r}=this.getters.getPaneDivisions(e),{width:i,height:a}=t.getMaxSize();return{x:this.getters.getColDimensions(e,n).start,y:this.getters.getRowDimensions(e,r).start,width:i,height:a}}getMaximumSheetOffset(){let e=this.getters.getActiveSheetId(),{width:t,height:n}=this.getMainViewportRect(),r=this.getMainInternalViewport(e);return{maxOffsetX:Math.max(0,t-r.viewportWidth+1),maxOffsetY:Math.max(0,n-r.viewportHeight+1)}}getColRowOffsetInViewport(e,t,n){if(n<t)return-this.getColRowOffsetInViewport(e,n,t);let r=this.getters.getActiveSheetId(),i=e===`COL`?this.getters.getSheetViewVisibleCols():this.getters.getSheetViewVisibleRows(),a=i.findIndex(e=>t>=e),o=i.findIndex(e=>n<=e);o=o===-1?i.length:o;let s=i.slice(a,o),c=0;for(let t of s)c+=this.getters.getHeaderSize(r,e,t);return c}isVisibleInViewport({sheetId:e,col:t,row:n}){return this.getSubViewports(e).some(e=>e.isVisible(t,n))}getEdgeScrollCol(e,t,n){let r=!1,i=0,a=0,{xSplit:o}=this.getters.getPaneDivisions(this.getters.getActiveSheetId()),{width:s}=this.getSheetViewDimension(),{x:c}=this.getMainViewportCoordinates(),l=this.getActiveSheetScrollInfo().scrollX;return e>s?(r=!0,a=$r(e-s),i=1):e<c&&n>=c&&l>0?(r=!0,a=$r(c-e),i=-1):o&&t<c&&e>c&&(r=!0,a=$r(e),i=`reset`),{canEdgeScroll:r,direction:i,delay:a}}getEdgeScrollRow(e,t,n){let r=!1,i=0,a=0,{ySplit:o}=this.getters.getPaneDivisions(this.getters.getActiveSheetId()),{height:s}=this.getSheetViewDimension(),{y:c}=this.getMainViewportCoordinates(),l=this.getActiveSheetScrollInfo().scrollY;return e>s?(r=!0,a=$r(e-s),i=1):e<c&&n>=c&&l>0?(r=!0,a=$r(c-e),i=-1):o&&t<c&&e>c&&(r=!0,a=$r(e),i=`reset`),{canEdgeScroll:r,direction:i,delay:a}}getVisibleRect(e){let t=this.getVisibleRectWithoutHeaders(e);return{...t,x:t.x+this.gridOffsetX,y:t.y+this.gridOffsetY}}getVisibleRectWithoutHeaders(e){let t=this.getters.getActiveSheetId();return this.mapViewportsToRect(t,t=>t.getVisibleRect(e))}getRect(e){let t=this.getters.getActiveSheetId(),n=this.mapViewportsToRect(t,t=>t.getFullRect(e));return{...n,x:n.x+this.gridOffsetX,y:n.y+this.gridOffsetY}}getMainViewportCoordinates(){let e=this.getters.getActiveSheetId(),{xSplit:t,ySplit:n}=this.getters.getPaneDivisions(e);return{x:this.getters.getColDimensions(e,t).start,y:this.getters.getRowDimensions(e,n).start}}getAllActiveViewportsZonesAndRect(){let e=this.getters.getActiveSheetId();return this.getSubViewports(e).map(e=>({zone:e,rect:{x:e.offsetCorrectionX+this.gridOffsetX,y:e.offsetCorrectionY+this.gridOffsetY,...e.getMaxSize()}}))}ensureMainViewportExist(e){this.viewports[e]||this.resetViewports(e)}getSubViewports(e){return this.ensureMainViewportExist(e),Object.values(this.viewports[e]).filter(T)}checkPositiveDimension(e){return e.width<0||e.height<0?`InvalidViewportSize`:`Success`}checkValuesAreDifferent(e){let{height:t,width:n}=this.getSheetViewDimension();return e.gridOffsetX===this.gridOffsetX&&e.gridOffsetY===this.gridOffsetY&&e.width===n&&e.height===t?`ValuesNotChanged`:`Success`}checkScrollingDirection({offsetX:e,offsetY:t}){let n=this.getMainInternalViewport(this.getters.getActiveSheetId());return!n.canScrollHorizontally&&e>0||!n.canScrollVertically&&t>0?`InvalidScrollingDirection`:`Success`}getMainViewport(e){let 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(){let e={};for(let t of this.getters.getSheetIds())e[t]=this.viewports[t];this.viewports=e}resizeSheetView(e,t,n=0,r=0){this.sheetViewHeight=e,this.sheetViewWidth=t,this.gridOffsetX=n,this.gridOffsetY=r,this.recomputeViewports()}recomputeViewports(){for(let e of this.getters.getSheetIds())this.resetViewports(e)}setSheetViewOffset(e,t){let n=this.getters.getActiveSheetId(),{maxOffsetX:r,maxOffsetY:i}=this.getMaximumSheetOffset();this.getSubViewports(n).forEach(n=>n.setViewportOffset(C(e,0,r),C(t,0,i)))}getViewportOffset(e){return{x:this.viewports[e]?.bottomRight.offsetScrollbarX||0,y:this.viewports[e]?.bottomRight.offsetScrollbarY||0}}resetViewports(e){if(!this.getters.tryGetSheet(e))return;let{xSplit:t,ySplit:n}=this.getters.getPaneDivisions(e),r=this.getters.getNumberCols(e),i=this.getters.getNumberRows(e),a=Math.min(this.getters.getColRowOffset(`COL`,0,t,e),this.sheetViewWidth),o=Math.min(this.getters.getColRowOffset(`ROW`,0,n,e),this.sheetViewHeight),s=Math.max(this.sheetViewWidth-a,0),c=Math.max(this.sheetViewHeight-o,0),{xRatio:l,yRatio:u}=this.getFrozenSheetViewRatio(e),d=l<1,f=u<1,p=this.getViewportOffset(e),m={topLeft:n&&t&&new gj(this.getters,e,{left:0,right:t-1,top:0,bottom:n-1},{width:a,height:o},{canScrollHorizontally:!1,canScrollVertically:!1},{x:0,y:0})||void 0,topRight:n&&new gj(this.getters,e,{left:t,right:r-1,top:0,bottom:n-1},{width:s,height:o},{canScrollHorizontally:d,canScrollVertically:!1},{x:d?p.x:0,y:0})||void 0,bottomLeft:t&&new gj(this.getters,e,{left:0,right:t-1,top:n,bottom:i-1},{width:a,height:c},{canScrollHorizontally:!1,canScrollVertically:f},{x:0,y:f?p.y:0})||void 0,bottomRight:new gj(this.getters,e,{left:t,right:r-1,top:n,bottom:i-1},{width:s,height:c},{canScrollHorizontally:d,canScrollVertically:f},{x:d?p.x:0,y:f?p.y:0})};this.viewports[e]=m}refreshViewport(e,t){this.getSubViewports(e).forEach(e=>{e.adjustViewportZone(),e.adjustPosition(t)})}shiftVertically(e){let t=this.getters.getActiveSheetId(),{top:n}=this.getMainInternalViewport(t),{scrollX:r}=this.getActiveSheetScrollInfo();this.setSheetViewOffset(r,e);let{anchor:i}=this.getters.getSelection();if(i.cell.row>=this.getters.getPaneDivisions(t).ySplit){let e=this.getMainInternalViewport(t).top-n;this.selection.selectCell(i.cell.col,i.cell.row+e)}}getVisibleFigures(){let e=this.getters.getActiveSheetId(),t=[],n=this.getters.getFigures(e),{scrollX:r,scrollY:i}=this.getActiveSheetScrollInfo(),{x:a,y:o}=this.getters.getMainViewportCoordinates(),{width:s,height:c}=this.getters.getSheetViewDimensionWithHeaders();for(let e of n)e.x>=a&&(e.x+e.width<=a+r||e.x>=s+r+a)||e.y>=o&&(e.y+e.height<=o+i||e.y>=c+i+o)||t.push(e);return t}isPositionVisible(e){let{scrollX:t,scrollY:n}=this.getters.getActiveSheetScrollInfo(),{x:r,y:i}=this.getters.getMainViewportCoordinates(),{width:a,height:o}=this.getters.getSheetViewDimension();return!(e.x>=r&&(e.x<r+t||e.x>a+t+r)||e.y>=i&&(e.y<i+n||e.y>o+n+i))}getFrozenSheetViewRatio(e){let{xSplit:t,ySplit:n}=this.getters.getPaneDivisions(e),r=this.getters.getColDimensions(e,t).start,i=this.getters.getRowDimensions(e,n).start,a=this.sheetViewWidth+this.gridOffsetX,o=this.sheetViewHeight+this.gridOffsetY;return{xRatio:r/a,yRatio:i/o}}mapViewportsToRect(e,t){let n=1/0,r=1/0,i=0,a=0,o=!1;for(let s of this.getSubViewports(e)){let e=t(s);e&&(o=!0,n=Math.min(n,e.x),r=Math.min(r,e.y),i=Math.max(i,e.x+e.width),a=Math.max(a,e.y+e.height))}return o?{x:n,y:r,width:i-n,height:a-r}:{x:0,y:0,width:0,height:0}}},vj=class extends Q{static getters=[`getColDimensions`,`getRowDimensions`,`getColRowOffset`];headerPositions={};isDirty=!0;handle(e){switch(ar.has(e.type)&&(this.headerPositions={},this.isDirty=!0),e.type){case`START`:for(let e of this.getters.getSheetIds())this.headerPositions[e]=this.computeHeaderPositionsOfSheet(e);break;case`UPDATE_CELL`:this.headerPositions={},this.isDirty=!0;break;case`UPDATE_FILTER`:case`REMOVE_FILTER_TABLE`:this.headerPositions={},this.isDirty=!0;break;case`REMOVE_COLUMNS_ROWS`:case`RESIZE_COLUMNS_ROWS`:case`HIDE_COLUMNS_ROWS`:case`ADD_COLUMNS_ROWS`:case`UNHIDE_COLUMNS_ROWS`:case`FOLD_HEADER_GROUP`:case`UNFOLD_HEADER_GROUP`:case`FOLD_HEADER_GROUPS_IN_ZONE`:case`UNFOLD_HEADER_GROUPS_IN_ZONE`:case`UNFOLD_ALL_HEADER_GROUPS`:case`FOLD_ALL_HEADER_GROUPS`:case`UNGROUP_HEADERS`:case`GROUP_HEADERS`:case`CREATE_SHEET`:this.getters.tryGetSheet(e.sheetId)&&(this.headerPositions[e.sheetId]=this.computeHeaderPositionsOfSheet(e.sheetId));break;case`DUPLICATE_SHEET`:this.headerPositions[e.sheetIdTo]=S(this.headerPositions[e.sheetId]);break}}finalize(){for(let e of this.getters.getSheetIds())(this.isDirty||!this.headerPositions[e])&&(this.headerPositions[e]=this.computeHeaderPositionsOfSheet(e));this.isDirty=!1}getColDimensions(e,t){let n=this.headerPositions[e].COL[t],r=this.getters.getColSize(e,t);return{start:n,size:r,end:n+(this.getters.isColHidden(e,t)?0:r)}}getRowDimensions(e,t){let n=this.headerPositions[e].ROW[t],r=this.getters.getRowSize(e,t);return{start:n,size:r,end:n+(this.getters.isRowHidden(e,t)?0:r)}}getColRowOffset(e,t,n,r=this.getters.getActiveSheetId()){let i=this.headerPositions[r][e][t];return this.headerPositions[r][e][n]-i}computeHeaderPositionsOfSheet(e){return{COL:this.computePositions(e,`COL`),ROW:this.computePositions(e,`ROW`)}}computePositions(e,t){let n={},r=0;for(let i=0;i<this.getters.getNumberHeaders(e,t)+1;i++)n[i]=r,!this.getters.isHeaderHidden(e,t,i)&&(r+=this.getters.getHeaderSize(e,t,i));return n}};let yj=new H().add(`settings`,pk).add(`sheet`,dk).add(`header grouping`,fk).add(`header visibility`,ak).add(`filters`,rk).add(`cell`,RO).add(`merge`,sk).add(`headerSize`,ik).add(`borders`,LO).add(`conditional formatting`,QO).add(`figures`,ek).add(`chart`,VO).add(`image`,ok).add(`dataValidation`,$O),bj=new H().add(`ui_sheet`,EA).add(`ui_options`,TA).add(`selectionInputManager`,CA).add(`highlight`,bA).add(`grid renderer`,xA).add(`autofill`,Lk).add(`find_and_replace`,_A).add(`sort`,wA).add(`automatic_sum`,Rk).add(`format`,vA).add(`split_to_columns`,QA).add(`cell_popovers`,zk).add(`collaborative`,pA).add(`history`,ZA).add(`data_cleanup`,gA),xj=new H().add(`selection`,hj).add(`evaluation_filter`,pj).add(`header_visibility_ui`,yA).add(`header_positions`,vj).add(`viewport`,_j).add(`clipboard`,rj).add(`edition`,fj),Sj=new H().add(`evaluation`,Ek).add(`evaluation_chart`,jk).add(`evaluation_cf`,Mk).add(`row_size`,Fk).add(`custom_colors`,Ak).add(`data_validation_ui`,Pk),Cj=new H;Cj.add(`link`,{condition:(e,t)=>!!t.model.getters.getEvaluatedCell(e).link,execute:(e,t)=>Qa(t.model.getters.getEvaluatedCell(e).link,t),sequence:5});var wj=class{fileStore;constructor(e){this.fileStore=e}async requestImage(){let e=await this.getImageFromUser(),t=await this.fileStore.upload(e);return{path:t,size:await this.getImageOriginalSize(t),mimetype:e.type}}getImageFromUser(){return new Promise((e,t)=>{let n=document.createElement(`input`);n.setAttribute(`type`,`file`),n.setAttribute(`accept`,`image/*`),n.addEventListener(`change`,async()=>{n.files===null||n.files.length!==1?t():e(n.files[0])}),n.click()})}getImageOriginalSize(e){return new Promise((t,n)=>{let r=new Image;r.src=e,r.addEventListener(`load`,()=>{t({width:r.width,height:r.height})}),r.addEventListener(`error`,n)})}},Tj=class{focusableElement=void 0;setFocusableElement(e){this.focusableElement=e}focus(){this.focusableElement?.focus()}};let Ej=[{transform:`scale(0)`},{transform:`scale(0.8)`,offset:.33},{opacity:`0`,transform:`scale(1)`,offset:1}];U`
@@ -1589,6 +1589,9 @@
1589
1589
  position: absolute;
1590
1590
  cursor: pointer;
1591
1591
  }
1592
+ .o-grid.o-dashboard-grid {
1593
+ background: #ffffff;
1594
+ }
1592
1595
  `;var Nj=class extends t.Component{static template=`o-spreadsheet-SpreadsheetDashboard`;static components={GridOverlay:bw,GridPopover:xw,Popover:lc,VerticalScrollBar:Pw,HorizontalScrollBar:Nw,FilterIconsOverlay:YC};onMouseWheel;canvasPosition;hoveredCell;setup(){let e=(0,t.useRef)(`grid`);this.canvasPosition=rc(e),this.hoveredCell=(0,t.useState)({col:void 0,row:void 0}),(0,t.useChildSubEnv)({getPopoverContainerRect:()=>this.getGridRect()}),Ew(`canvas`,this.env.model,()=>this.env.model.getters.getSheetViewDimension()),this.onMouseWheel=Dw((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(){let e=this.env.model.getters.getActiveSheetId(),{right:t}=this.env.model.getters.getSheetZone(e),{end:n}=this.env.model.getters.getColDimensions(e,t);return W({"max-width":`${n}px`})}get gridOverlayDimensions(){return W({height:`100%`,width:`100%`})}getCellClickableStyle(e){return W({top:`${e.y}px`,left:`${e.x}px`,width:`${e.width}px`,height:`${e.height}px`})}getClickableCells(){let e=[],t=this.env.model.getters.getActiveSheetId();for(let n of this.env.model.getters.getSheetViewVisibleCols())for(let r of this.env.model.getters.getSheetViewVisibleRows()){let i={sheetId:t,col:n,row:r},a=this.getClickableAction(i);if(!a)continue;let o;o=this.env.model.getters.isInMerge(i)?this.env.model.getters.getMerge(i):V({col:n,row:r});let s=this.env.model.getters.getVisibleRect(o);e.push({coordinates:s,position:{col:n,row:r},action:a})}return e}getClickableAction(e){for(let t of Cj.getAll().sort((e,t)=>e.sequence-t.sequence))if(t.condition(e,this.env))return t.execute;return!1}selectClickableCell(e){let{position:t,action:n}=e;n({...t,sheetId:this.env.model.getters.getActiveSheetId()},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){let{scrollX:n,scrollY:r}=this.env.model.getters.getActiveSheetDOMScrollInfo();this.env.model.dispatch(`SET_VIEWPORT_OFFSET`,{offsetX:n+e,offsetY:r+t})}getGridRect(){return{...this.canvasPosition,...this.env.model.getters.getSheetViewDimensionWithHeaders()}}};Nj.props={},U`
1593
1596
  .o-header-group {
1594
1597
  .o-header-group-header {
@@ -2674,4 +2677,4 @@
2674
2677
  <Relationships xmlns="${Hw.Relationships}">
2675
2678
  <Relationship ${Y(e)} />
2676
2679
  </Relationships>
2677
- `),`_rels/.rels`)}var AN=class extends Bk{corePlugins=[];featurePlugins=[];statefulUIPlugins=[];coreViewsPlugins=[];range;session;isReplayingCommand=!1;renderers=[];status=0;config;corePluginConfig;uiPluginConfig;state;selection;getters;coreGetters;uuidGenerator;handlers=[];uiHandlers=[];coreHandlers=[];constructor(e={},n={},r=[],i=new ko,a=!0){super(),v(),r=TO(e,r);let o=yO(e,a);this.state=new fM,this.uuidGenerator=i,this.config=this.setupConfig(n),this.session=this.setupSession(o.revisionId),this.coreGetters={},this.range=new uk(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.getRangeFromZone=this.range.getRangeFromZone.bind(this.range),this.getters={isReadonly:()=>this.config.mode===`readonly`||this.config.mode===`dashboard`,isDashboard:()=>this.config.mode===`dashboard`},this.uuidGenerator.setIsFastStrategy(!0),this.selection=new dM(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range),this.corePluginConfig=this.setupCorePluginConfig(),this.uiPluginConfig=this.setupUiPluginConfig();for(let e of yj.getAll())this.setupCorePlugin(e,o);Object.assign(this.getters,this.coreGetters),this.session.loadInitialMessages(r);for(let e of Sj.getAll()){let t=this.setupUiPlugin(e);this.coreViewsPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t),this.coreHandlers.push(t)}for(let e of xj.getAll()){let t=this.setupUiPlugin(e);this.statefulUIPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}for(let e of bj.getAll()){let t=this.setupUiPlugin(e);this.featurePlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}this.uuidGenerator.setIsFastStrategy(!1),this.dispatch(`START`),this.selection.observe(this,{handleEvent:()=>this.trigger(`update`)}),this.setupSessionEvents(),this.joinSession(),n.snapshotRequested&&(this.session.snapshot(this.exportData()),this.garbageCollectExternalResources()),(0,t.markRaw)(this)}joinSession(){this.session.join(this.config.client)}async leaveSession(){let e=this.getters.isReadonly()?void 0:vt(()=>this.exportData());await this.session.leave(e)}setupUiPlugin(e){let t=new e(this.uiPluginConfig);for(let n of e.getters){if(!(n in t))throw Error(`Invalid getter name: ${n} for plugin ${t.constructor}`);if(n in this.getters)throw Error(`Getter "${n}" is already defined.`);this.getters[n]=t[n].bind(t)}let n=e.layers.map(e=>[t,e]);return this.renderers.push(...n),this.renderers.sort((e,t)=>e[1]-t[1]),t}setupCorePlugin(e,t){let n=new e(this.corePluginConfig);for(let t of e.getters){if(!(t in n))throw Error(`Invalid getter name: ${t} for plugin ${n.constructor}`);if(t in this.coreGetters)throw Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=n[t].bind(n)}n.import(t),this.corePlugins.push(n),this.coreHandlers.push(n),this.handlers.push(n)}onRemoteRevisionReceived({commands:e}){for(let t of e){let e=this.status;this.status=2,this.dispatchToHandlers(this.statefulUIPlugins,t),this.status=e}this.finalize()}setupSession(e){return new uA(sM({initialRevisionId:e,recordChanges:this.state.recordChanges.bind(this.state),dispatch:e=>{if(!this.checkDispatchAllowed(e).isSuccessful){this.dispatchToHandlers(this.coreHandlers,{type:`UNDO`,commands:[e]});return}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-undone`,this,({commands:e})=>{this.dispatchFromCorePlugin(`UNDO`,{commands:e}),this.finalize()}),this.session.on(`revision-redone`,this,({commands:e})=>{this.dispatchFromCorePlugin(`REDO`,{commands:e}),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){let t=e.client||{id:this.uuidGenerator.smallUuid(),name:y(`Anonymous`).toString()},n=e.transportService||new Qj;return{...e,mode:e.mode||`normal`,custom:e.custom||{},external:this.setupExternalConfig(e.external||{}),transportService:n,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger(`notify-ui`,e),raiseBlockingErrorUI:e=>this.trigger(`raise-error-ui`,{text:e})}}setupExternalConfig(e){let t=e.loadLocales||(()=>Promise.resolve(hr));return{...e,loadLocales:t}}setupCorePluginConfig(){return{getters:this.coreGetters,stateObserver:this.state,range:this.range,dispatch:this.dispatchFromCorePlugin,uuidGenerator:this.uuidGenerator,custom:this.config.custom,external:this.config.external}}setupUiPluginConfig(){return{getters:this.getters,stateObserver:this.state,dispatch:this.dispatch,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrencyFormat:this.config.defaultCurrencyFormat}}checkDispatchAllowed(e){let t=ur(e)?this.checkDispatchAllowedCoreCommand(e):this.checkDispatchAllowedLocalCommand(e);return t.some(e=>e!==`Success`)?new fr(t.flat()):fr.Success}checkDispatchAllowedCoreCommand(e){let t=this.corePlugins.map(t=>t.allowDispatch(e));return t.push(this.range.allowDispatch(e)),t}checkDispatchAllowedLocalCommand(e){return this.uiHandlers.map(t=>t.allowDispatch(e))}finalize(){this.status=3;for(let e of this.handlers)e.finalize();this.status=0}canDispatch=(e,t)=>this.checkDispatchAllowed(jN(e,t));dispatch=(e,t)=>{let n=jN(e,t),r=this.status;if(this.getters.isReadonly()&&!dr(n))return new fr(`Readonly`);if(!this.session.canApplyOptimisticUpdate())return new fr(`WaitingSessionConfirmation`);switch(r){case 0:let t=this.checkDispatchAllowed(n);if(!t.isSuccessful)return t;this.status=1;let{changes:r,commands:i}=this.state.recordChanges(()=>{ur(n)&&this.state.addCommand(n),this.dispatchToHandlers(this.handlers,n),this.finalize()});this.session.save(n,i,r),this.status=0,this.trigger(`update`);break;case 1:if(ur(n)){let e=this.checkDispatchAllowed(n);if(!e.isSuccessful)return e;this.state.addCommand(n)}this.dispatchToHandlers(this.handlers,n);break;case 3:throw Error(`Cannot dispatch commands in the finalize state`);case 2:if(ur(n))throw Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,n)}return fr.Success};dispatchFromCorePlugin=(e,t)=>{let n=jN(e,t),r=this.status;this.status=2;let i=this.isReplayingCommand?this.coreHandlers:this.handlers;return this.dispatchToHandlers(i,n),this.status=r,fr.Success};dispatchToHandlers(e,t){let n=ur(t);for(let r of e)!n&&r instanceof IO||r.beforeHandle(t);for(let r of e)!n&&r instanceof IO||r.handle(t)}drawGrid(e){for(let[t,n]of this.renderers)e.ctx.save(),t.drawGrid(e,n),e.ctx.restore()}exportData(){let e=MO();for(let t of this.handlers)t instanceof IO&&t.export(e);return e.revisionId=this.session.getRevisionId()||`START_REVISION`,e=S(e),e}updateMode(e){e!==`normal`&&this.dispatch(`CANCEL_EDITION`),this.config.mode=e,this.trigger(`update`)}exportXLSX(){this.dispatch(`EVALUATE_CELLS`);let e=PO();for(let t of this.handlers)t instanceof FO&&t.exportForExcel(e);return e=S(e),xN(e)}garbageCollectExternalResources(){for(let e of this.corePlugins)e.garbageCollectExternalResources()}};function jN(e,t={}){let n=S(t);return n.type=e,n}let MN={},NN={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:26,HEADER_WIDTH:48,TOPBAR_HEIGHT:63,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:96,DEFAULT_CELL_HEIGHT:23,SCROLLBAR_WIDTH:15},PN={autofillModifiersRegistry:Ss,autofillRulesRegistry:Cs,cellMenuRegistry:db,colMenuRegistry:rS,linkMenuRegistry:sl,functionRegistry:Ny,featurePluginRegistry:bj,statefulUIPluginRegistry:xj,coreViewsPluginRegistry:Sj,corePluginRegistry:yj,rowMenuRegistry:oS,sidePanelRegistry:bC,figureRegistry:wu,chartSidePanelComponentRegistry:kS,chartComponentRegistry:vu,chartRegistry:_u,topbarMenuRegistry:cS,topbarComponentRegistry:xC,clickableCellRegistry:Cj,otRegistry:lS,inverseCommandRegistry:Au,urlRegistry:qa,cellPopoverRegistry:ul,numberFormatMenuRegistry:iS,repeatLocalCommandTransformRegistry:WA,repeatCommandTransformRegistry:$},FN={arg:K,toBoolean:F,toJsDate:I,toNumber:N,toString:P,toXC:O,toZone:ea,toUnboundedZone:Qi,toCartesian:rn,numberToLetters:D,lettersToNumber:en,UuidGenerator:ko,formatValue:z,createCurrencyFormat:Ei,computeTextWidth:_o,createEmptyWorkbookData:MO,createEmptySheet:jO,createEmptyExcelSheet:NO,getDefaultChartJsRuntime:Dl,chartFontColor:Jo,ChartColors:qo,EvaluationError:b,CellErrorLevel:te,getFillingMode:Ml,rgbaToHex:Kt,colorToRGBA:qt,positionToZone:V,isDefined:T,isMatrix:j,lazy:vt,genericRepeat:GA,createAction:Mo,createActions:Ao,transformRangeData:Po,deepEquals:E,isNumber:Yn,isDateTime:_n},IN={isMarkdownLink:at,parseMarkdownLink:ct,markdownLink:st,openLink:Qa,urlRepresentation:Za},LN={ChartPanel:AS,ChartFigure:bu,ChartJsComponent:Fo,Grid:Lw,GridOverlay:bw,ScorecardChart:xs,LineConfigPanel:TS,LineBarPieDesignPanel:xS,BarConfigPanel:gS,LineBarPieConfigPanel:hS,GaugeChartConfigPanel:CS,GaugeChartDesignPanel:wS,ScorecardChartConfigPanel:DS,ScorecardChartDesignPanel:OS,FigureComponent:SC,Menu:pc,SelectionInput:pS},RN={useDragAndDropListItems:FS};function zN(e,t){return Ny.add(e,t),{addFunction:(e,t)=>zN(e,t)}}let BN={DEFAULT_LOCALE:A};e.AbstractChart=Io,e.CommandResult=mr,e.CorePlugin=IO,e.DispatchResult=fr,e.EvaluationError=b,e.Model=AN,e.Registry=H,e.Revision=cA,e.SPREADSHEET_DIMENSIONS=NN,e.Spreadsheet=Zj,e.UIPlugin=Q,e.__info__=MN,e.addFunction=zN,e.astToFormula=ET,e.compile=NT,e.compileTokens=PT,e.components=LN,e.constants=BN,e.convertAstNodes=ST,e.coreTypes=lr,e.findCellInNewZone=Ta,e.functionCache=MT,e.helpers=FN,e.hooks=RN,e.invalidateCFEvaluationCommands=sr,e.invalidateDependenciesCommands=or,e.invalidateEvaluationCommands=ar,e.iterateAstNodes=CT,e.links=IN,e.load=yO,e.parse=bT,e.parseTokens=xT,e.readonlyAllowedCommands=cr,e.registries=PN,e.setDefaultSheetViewSize=Ke,e.setTranslationMethod=_,e.tokenize=vc,MN.version=`17.0.104`,MN.date=`2026-07-23T07:43:17.811Z`,MN.hash=`ff598a7`})(this.o_spreadsheet=this.o_spreadsheet||{},owl);
2680
+ `),`_rels/.rels`)}var AN=class extends Bk{corePlugins=[];featurePlugins=[];statefulUIPlugins=[];coreViewsPlugins=[];range;session;isReplayingCommand=!1;renderers=[];status=0;config;corePluginConfig;uiPluginConfig;state;selection;getters;coreGetters;uuidGenerator;handlers=[];uiHandlers=[];coreHandlers=[];constructor(e={},n={},r=[],i=new ko,a=!0){super(),v(),r=TO(e,r);let o=yO(e,a);this.state=new fM,this.uuidGenerator=i,this.config=this.setupConfig(n),this.session=this.setupSession(o.revisionId),this.coreGetters={},this.range=new uk(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.getRangeFromZone=this.range.getRangeFromZone.bind(this.range),this.getters={isReadonly:()=>this.config.mode===`readonly`||this.config.mode===`dashboard`,isDashboard:()=>this.config.mode===`dashboard`},this.uuidGenerator.setIsFastStrategy(!0),this.selection=new dM(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range),this.corePluginConfig=this.setupCorePluginConfig(),this.uiPluginConfig=this.setupUiPluginConfig();for(let e of yj.getAll())this.setupCorePlugin(e,o);Object.assign(this.getters,this.coreGetters),this.session.loadInitialMessages(r);for(let e of Sj.getAll()){let t=this.setupUiPlugin(e);this.coreViewsPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t),this.coreHandlers.push(t)}for(let e of xj.getAll()){let t=this.setupUiPlugin(e);this.statefulUIPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}for(let e of bj.getAll()){let t=this.setupUiPlugin(e);this.featurePlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}this.uuidGenerator.setIsFastStrategy(!1),this.dispatch(`START`),this.selection.observe(this,{handleEvent:()=>this.trigger(`update`)}),this.setupSessionEvents(),this.joinSession(),n.snapshotRequested&&(this.session.snapshot(this.exportData()),this.garbageCollectExternalResources()),(0,t.markRaw)(this)}joinSession(){this.session.join(this.config.client)}async leaveSession(){let e=this.getters.isReadonly()?void 0:vt(()=>this.exportData());await this.session.leave(e)}setupUiPlugin(e){let t=new e(this.uiPluginConfig);for(let n of e.getters){if(!(n in t))throw Error(`Invalid getter name: ${n} for plugin ${t.constructor}`);if(n in this.getters)throw Error(`Getter "${n}" is already defined.`);this.getters[n]=t[n].bind(t)}let n=e.layers.map(e=>[t,e]);return this.renderers.push(...n),this.renderers.sort((e,t)=>e[1]-t[1]),t}setupCorePlugin(e,t){let n=new e(this.corePluginConfig);for(let t of e.getters){if(!(t in n))throw Error(`Invalid getter name: ${t} for plugin ${n.constructor}`);if(t in this.coreGetters)throw Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=n[t].bind(n)}n.import(t),this.corePlugins.push(n),this.coreHandlers.push(n),this.handlers.push(n)}onRemoteRevisionReceived({commands:e}){for(let t of e){let e=this.status;this.status=2,this.dispatchToHandlers(this.statefulUIPlugins,t),this.status=e}this.finalize()}setupSession(e){return new uA(sM({initialRevisionId:e,recordChanges:this.state.recordChanges.bind(this.state),dispatch:e=>{if(!this.checkDispatchAllowed(e).isSuccessful){this.dispatchToHandlers(this.coreHandlers,{type:`UNDO`,commands:[e]});return}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-undone`,this,({commands:e})=>{this.dispatchFromCorePlugin(`UNDO`,{commands:e}),this.finalize()}),this.session.on(`revision-redone`,this,({commands:e})=>{this.dispatchFromCorePlugin(`REDO`,{commands:e}),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){let t=e.client||{id:this.uuidGenerator.smallUuid(),name:y(`Anonymous`).toString()},n=e.transportService||new Qj;return{...e,mode:e.mode||`normal`,custom:e.custom||{},external:this.setupExternalConfig(e.external||{}),transportService:n,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger(`notify-ui`,e),raiseBlockingErrorUI:e=>this.trigger(`raise-error-ui`,{text:e})}}setupExternalConfig(e){let t=e.loadLocales||(()=>Promise.resolve(hr));return{...e,loadLocales:t}}setupCorePluginConfig(){return{getters:this.coreGetters,stateObserver:this.state,range:this.range,dispatch:this.dispatchFromCorePlugin,uuidGenerator:this.uuidGenerator,custom:this.config.custom,external:this.config.external}}setupUiPluginConfig(){return{getters:this.getters,stateObserver:this.state,dispatch:this.dispatch,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrencyFormat:this.config.defaultCurrencyFormat}}checkDispatchAllowed(e){let t=ur(e)?this.checkDispatchAllowedCoreCommand(e):this.checkDispatchAllowedLocalCommand(e);return t.some(e=>e!==`Success`)?new fr(t.flat()):fr.Success}checkDispatchAllowedCoreCommand(e){let t=this.corePlugins.map(t=>t.allowDispatch(e));return t.push(this.range.allowDispatch(e)),t}checkDispatchAllowedLocalCommand(e){return this.uiHandlers.map(t=>t.allowDispatch(e))}finalize(){this.status=3;for(let e of this.handlers)e.finalize();this.status=0}canDispatch=(e,t)=>this.checkDispatchAllowed(jN(e,t));dispatch=(e,t)=>{let n=jN(e,t),r=this.status;if(this.getters.isReadonly()&&!dr(n))return new fr(`Readonly`);if(!this.session.canApplyOptimisticUpdate())return new fr(`WaitingSessionConfirmation`);switch(r){case 0:let t=this.checkDispatchAllowed(n);if(!t.isSuccessful)return t;this.status=1;let{changes:r,commands:i}=this.state.recordChanges(()=>{ur(n)&&this.state.addCommand(n),this.dispatchToHandlers(this.handlers,n),this.finalize()});this.session.save(n,i,r),this.status=0,this.trigger(`update`);break;case 1:if(ur(n)){let e=this.checkDispatchAllowed(n);if(!e.isSuccessful)return e;this.state.addCommand(n)}this.dispatchToHandlers(this.handlers,n);break;case 3:throw Error(`Cannot dispatch commands in the finalize state`);case 2:if(ur(n))throw Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,n)}return fr.Success};dispatchFromCorePlugin=(e,t)=>{let n=jN(e,t),r=this.status;this.status=2;let i=this.isReplayingCommand?this.coreHandlers:this.handlers;return this.dispatchToHandlers(i,n),this.status=r,fr.Success};dispatchToHandlers(e,t){let n=ur(t);for(let r of e)!n&&r instanceof IO||r.beforeHandle(t);for(let r of e)!n&&r instanceof IO||r.handle(t)}drawGrid(e){for(let[t,n]of this.renderers)e.ctx.save(),t.drawGrid(e,n),e.ctx.restore()}exportData(){let e=MO();for(let t of this.handlers)t instanceof IO&&t.export(e);return e.revisionId=this.session.getRevisionId()||`START_REVISION`,e=S(e),e}updateMode(e){e!==`normal`&&this.dispatch(`CANCEL_EDITION`),this.config.mode=e,this.trigger(`update`)}exportXLSX(){this.dispatch(`EVALUATE_CELLS`);let e=PO();for(let t of this.handlers)t instanceof FO&&t.exportForExcel(e);return e=S(e),xN(e)}garbageCollectExternalResources(){for(let e of this.corePlugins)e.garbageCollectExternalResources()}};function jN(e,t={}){let n=S(t);return n.type=e,n}let MN={},NN={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:26,HEADER_WIDTH:48,TOPBAR_HEIGHT:63,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:96,DEFAULT_CELL_HEIGHT:23,SCROLLBAR_WIDTH:15},PN={autofillModifiersRegistry:Ss,autofillRulesRegistry:Cs,cellMenuRegistry:db,colMenuRegistry:rS,linkMenuRegistry:sl,functionRegistry:Ny,featurePluginRegistry:bj,statefulUIPluginRegistry:xj,coreViewsPluginRegistry:Sj,corePluginRegistry:yj,rowMenuRegistry:oS,sidePanelRegistry:bC,figureRegistry:wu,chartSidePanelComponentRegistry:kS,chartComponentRegistry:vu,chartRegistry:_u,topbarMenuRegistry:cS,topbarComponentRegistry:xC,clickableCellRegistry:Cj,otRegistry:lS,inverseCommandRegistry:Au,urlRegistry:qa,cellPopoverRegistry:ul,numberFormatMenuRegistry:iS,repeatLocalCommandTransformRegistry:WA,repeatCommandTransformRegistry:$},FN={arg:K,toBoolean:F,toJsDate:I,toNumber:N,toString:P,toXC:O,toZone:ea,toUnboundedZone:Qi,toCartesian:rn,numberToLetters:D,lettersToNumber:en,UuidGenerator:ko,formatValue:z,createCurrencyFormat:Ei,computeTextWidth:_o,createEmptyWorkbookData:MO,createEmptySheet:jO,createEmptyExcelSheet:NO,getDefaultChartJsRuntime:Dl,chartFontColor:Jo,ChartColors:qo,EvaluationError:b,CellErrorLevel:te,getFillingMode:Ml,rgbaToHex:Kt,colorToRGBA:qt,positionToZone:V,isDefined:T,isMatrix:j,lazy:vt,genericRepeat:GA,createAction:Mo,createActions:Ao,transformRangeData:Po,deepEquals:E,isNumber:Yn,isDateTime:_n},IN={isMarkdownLink:at,parseMarkdownLink:ct,markdownLink:st,openLink:Qa,urlRepresentation:Za},LN={ChartPanel:AS,ChartFigure:bu,ChartJsComponent:Fo,Grid:Lw,GridOverlay:bw,ScorecardChart:xs,LineConfigPanel:TS,LineBarPieDesignPanel:xS,BarConfigPanel:gS,LineBarPieConfigPanel:hS,GaugeChartConfigPanel:CS,GaugeChartDesignPanel:wS,ScorecardChartConfigPanel:DS,ScorecardChartDesignPanel:OS,FigureComponent:SC,Menu:pc,SelectionInput:pS},RN={useDragAndDropListItems:FS};function zN(e,t){return Ny.add(e,t),{addFunction:(e,t)=>zN(e,t)}}let BN={DEFAULT_LOCALE:A};e.AbstractChart=Io,e.CommandResult=mr,e.CorePlugin=IO,e.DispatchResult=fr,e.EvaluationError=b,e.Model=AN,e.Registry=H,e.Revision=cA,e.SPREADSHEET_DIMENSIONS=NN,e.Spreadsheet=Zj,e.UIPlugin=Q,e.__info__=MN,e.addFunction=zN,e.astToFormula=ET,e.compile=NT,e.compileTokens=PT,e.components=LN,e.constants=BN,e.convertAstNodes=ST,e.coreTypes=lr,e.findCellInNewZone=Ta,e.functionCache=MT,e.helpers=FN,e.hooks=RN,e.invalidateCFEvaluationCommands=sr,e.invalidateDependenciesCommands=or,e.invalidateEvaluationCommands=ar,e.iterateAstNodes=CT,e.links=IN,e.load=yO,e.parse=bT,e.parseTokens=xT,e.readonlyAllowedCommands=cr,e.registries=PN,e.setDefaultSheetViewSize=Ke,e.setTranslationMethod=_,e.tokenize=vc,MN.version=`17.0.106`,MN.date=`2026-08-29T09:12:26.343Z`,MN.hash=`c877406`})(this.o_spreadsheet=this.o_spreadsheet||{},owl);
@@ -1,9 +1,9 @@
1
1
  <!--
2
2
  This file is generated by o-spreadsheet build tools. Do not edit it.
3
3
  @see https://github.com/odoo/o-spreadsheet
4
- @version 17.0.104
5
- @date 2026-07-23T07:43:18.351Z
6
- @hash ff598a7
4
+ @version 17.0.106
5
+ @date 2026-08-29T09:12:26.859Z
6
+ @hash c877406
7
7
  -->
8
8
  <odoo>
9
9
  <t t-name="o-spreadsheet-ActionButton">
@@ -597,7 +597,7 @@
597
597
 
598
598
  <t t-name="o-spreadsheet-SpreadsheetDashboard">
599
599
  <div
600
- class="o-grid o-two-columns"
600
+ class="o-grid o-dashboard-grid o-two-columns"
601
601
  tabindex="-1"
602
602
  t-on-wheel="onMouseWheel"
603
603
  t-on-click="onClosePopover">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odoo/o-spreadsheet",
3
- "version": "17.0.104",
3
+ "version": "17.0.106",
4
4
  "description": "A spreadsheet component",
5
5
  "type": "module",
6
6
  "main": "dist/o-spreadsheet.cjs.js",